Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4 | * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10 | #include <linux/list.h> |
| 11 | #include <linux/if_ether.h> |
| 12 | #include <linux/ieee80211.h> |
| 13 | #include <linux/nl80211.h> |
| 14 | #include <linux/rtnetlink.h> |
| 15 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16 | #include <linux/etherdevice.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17 | #include <net/genetlink.h> |
| 18 | #include <net/cfg80211.h> |
| 19 | #include "core.h" |
| 20 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 21 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | |
| 23 | /* the netlink family */ |
| 24 | static struct genl_family nl80211_fam = { |
| 25 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 26 | .name = "nl80211", /* have users key off the name instead */ |
| 27 | .hdrsize = 0, /* no private header */ |
| 28 | .version = 1, /* no particular meaning now */ |
| 29 | .maxattr = NL80211_ATTR_MAX, |
| 30 | }; |
| 31 | |
| 32 | /* internal helper: get drv and dev */ |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 33 | static int get_drv_dev_by_info_ifindex(struct nlattr **attrs, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 34 | struct cfg80211_registered_device **drv, |
| 35 | struct net_device **dev) |
| 36 | { |
| 37 | int ifindex; |
| 38 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 39 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 40 | return -EINVAL; |
| 41 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 42 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 43 | *dev = dev_get_by_index(&init_net, ifindex); |
| 44 | if (!*dev) |
| 45 | return -ENODEV; |
| 46 | |
| 47 | *drv = cfg80211_get_dev_from_ifindex(ifindex); |
| 48 | if (IS_ERR(*drv)) { |
| 49 | dev_put(*dev); |
| 50 | return PTR_ERR(*drv); |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | /* policy for the attributes */ |
| 57 | static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { |
| 58 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 59 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 60 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 61 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 62 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 63 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 64 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 65 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 66 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 67 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 68 | |
| 69 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 70 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 71 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 72 | |
| 73 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
| 74 | |
| 75 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 76 | .len = WLAN_MAX_KEY_LEN }, |
| 77 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 78 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 79 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 80 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 81 | |
| 82 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 83 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 84 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 85 | .len = IEEE80211_MAX_DATA_LEN }, |
| 86 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 87 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 88 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 89 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 90 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 91 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 92 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 93 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 94 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 95 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 96 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 97 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 98 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 99 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 100 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 101 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 102 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 103 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 104 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 105 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 106 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 107 | .len = NL80211_MAX_SUPP_RATES }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 108 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 109 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 110 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 111 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 112 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 113 | |
| 114 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 115 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 116 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 117 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 118 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 119 | |
| 120 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 121 | .len = IEEE80211_MAX_SSID_LEN }, |
| 122 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 123 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 124 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 125 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 126 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 127 | [NL80211_ATTR_STA_FLAGS2] = { |
| 128 | .len = sizeof(struct nl80211_sta_flag_update), |
| 129 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 130 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 131 | }; |
| 132 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 133 | /* IE validation */ |
| 134 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 135 | { |
| 136 | const u8 *pos; |
| 137 | int len; |
| 138 | |
| 139 | if (!attr) |
| 140 | return true; |
| 141 | |
| 142 | pos = nla_data(attr); |
| 143 | len = nla_len(attr); |
| 144 | |
| 145 | while (len) { |
| 146 | u8 elemlen; |
| 147 | |
| 148 | if (len < 2) |
| 149 | return false; |
| 150 | len -= 2; |
| 151 | |
| 152 | elemlen = pos[1]; |
| 153 | if (elemlen > len) |
| 154 | return false; |
| 155 | |
| 156 | len -= elemlen; |
| 157 | pos += 2 + elemlen; |
| 158 | } |
| 159 | |
| 160 | return true; |
| 161 | } |
| 162 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 163 | /* message building helper */ |
| 164 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 165 | int flags, u8 cmd) |
| 166 | { |
| 167 | /* since there is no private header just add the generic one */ |
| 168 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 169 | } |
| 170 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 171 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 172 | struct ieee80211_channel *chan) |
| 173 | { |
| 174 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 175 | chan->center_freq); |
| 176 | |
| 177 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 178 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 179 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 180 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 181 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 182 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 183 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 184 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 185 | |
| 186 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 187 | DBM_TO_MBM(chan->max_power)); |
| 188 | |
| 189 | return 0; |
| 190 | |
| 191 | nla_put_failure: |
| 192 | return -ENOBUFS; |
| 193 | } |
| 194 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 195 | /* netlink command implementations */ |
| 196 | |
| 197 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 198 | struct cfg80211_registered_device *dev) |
| 199 | { |
| 200 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 201 | struct nlattr *nl_bands, *nl_band; |
| 202 | struct nlattr *nl_freqs, *nl_freq; |
| 203 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 204 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 205 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 206 | enum ieee80211_band band; |
| 207 | struct ieee80211_channel *chan; |
| 208 | struct ieee80211_rate *rate; |
| 209 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 210 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 211 | |
| 212 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 213 | if (!hdr) |
| 214 | return -1; |
| 215 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 216 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 217 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 218 | |
| 219 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 220 | dev->wiphy.retry_short); |
| 221 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 222 | dev->wiphy.retry_long); |
| 223 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 224 | dev->wiphy.frag_threshold); |
| 225 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 226 | dev->wiphy.rts_threshold); |
| 227 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 228 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 229 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 230 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 231 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 232 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 233 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 234 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 235 | dev->wiphy.cipher_suites); |
| 236 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 237 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 238 | if (!nl_modes) |
| 239 | goto nla_put_failure; |
| 240 | |
| 241 | i = 0; |
| 242 | while (ifmodes) { |
| 243 | if (ifmodes & 1) |
| 244 | NLA_PUT_FLAG(msg, i); |
| 245 | ifmodes >>= 1; |
| 246 | i++; |
| 247 | } |
| 248 | |
| 249 | nla_nest_end(msg, nl_modes); |
| 250 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 251 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 252 | if (!nl_bands) |
| 253 | goto nla_put_failure; |
| 254 | |
| 255 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 256 | if (!dev->wiphy.bands[band]) |
| 257 | continue; |
| 258 | |
| 259 | nl_band = nla_nest_start(msg, band); |
| 260 | if (!nl_band) |
| 261 | goto nla_put_failure; |
| 262 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 263 | /* add HT info */ |
| 264 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 265 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 266 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 267 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 268 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 269 | dev->wiphy.bands[band]->ht_cap.cap); |
| 270 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 271 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 272 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 273 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 274 | } |
| 275 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 276 | /* add frequencies */ |
| 277 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 278 | if (!nl_freqs) |
| 279 | goto nla_put_failure; |
| 280 | |
| 281 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 282 | nl_freq = nla_nest_start(msg, i); |
| 283 | if (!nl_freq) |
| 284 | goto nla_put_failure; |
| 285 | |
| 286 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 287 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 288 | if (nl80211_msg_put_channel(msg, chan)) |
| 289 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 290 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 291 | nla_nest_end(msg, nl_freq); |
| 292 | } |
| 293 | |
| 294 | nla_nest_end(msg, nl_freqs); |
| 295 | |
| 296 | /* add bitrates */ |
| 297 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 298 | if (!nl_rates) |
| 299 | goto nla_put_failure; |
| 300 | |
| 301 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 302 | nl_rate = nla_nest_start(msg, i); |
| 303 | if (!nl_rate) |
| 304 | goto nla_put_failure; |
| 305 | |
| 306 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 307 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 308 | rate->bitrate); |
| 309 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 310 | NLA_PUT_FLAG(msg, |
| 311 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 312 | |
| 313 | nla_nest_end(msg, nl_rate); |
| 314 | } |
| 315 | |
| 316 | nla_nest_end(msg, nl_rates); |
| 317 | |
| 318 | nla_nest_end(msg, nl_band); |
| 319 | } |
| 320 | nla_nest_end(msg, nl_bands); |
| 321 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 322 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 323 | if (!nl_cmds) |
| 324 | goto nla_put_failure; |
| 325 | |
| 326 | i = 0; |
| 327 | #define CMD(op, n) \ |
| 328 | do { \ |
| 329 | if (dev->ops->op) { \ |
| 330 | i++; \ |
| 331 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 332 | } \ |
| 333 | } while (0) |
| 334 | |
| 335 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 336 | CMD(change_virtual_intf, SET_INTERFACE); |
| 337 | CMD(add_key, NEW_KEY); |
| 338 | CMD(add_beacon, NEW_BEACON); |
| 339 | CMD(add_station, NEW_STATION); |
| 340 | CMD(add_mpath, NEW_MPATH); |
| 341 | CMD(set_mesh_params, SET_MESH_PARAMS); |
| 342 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 343 | CMD(auth, AUTHENTICATE); |
| 344 | CMD(assoc, ASSOCIATE); |
| 345 | CMD(deauth, DEAUTHENTICATE); |
| 346 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 347 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 348 | |
| 349 | #undef CMD |
| 350 | nla_nest_end(msg, nl_cmds); |
| 351 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 352 | return genlmsg_end(msg, hdr); |
| 353 | |
| 354 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 355 | genlmsg_cancel(msg, hdr); |
| 356 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 360 | { |
| 361 | int idx = 0; |
| 362 | int start = cb->args[0]; |
| 363 | struct cfg80211_registered_device *dev; |
| 364 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 365 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 366 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 367 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 368 | continue; |
| 369 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 370 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 371 | dev) < 0) { |
| 372 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 373 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 374 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 375 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 376 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 377 | |
| 378 | cb->args[0] = idx; |
| 379 | |
| 380 | return skb->len; |
| 381 | } |
| 382 | |
| 383 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 384 | { |
| 385 | struct sk_buff *msg; |
| 386 | struct cfg80211_registered_device *dev; |
| 387 | |
| 388 | dev = cfg80211_get_dev_from_info(info); |
| 389 | if (IS_ERR(dev)) |
| 390 | return PTR_ERR(dev); |
| 391 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 392 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 393 | if (!msg) |
| 394 | goto out_err; |
| 395 | |
| 396 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) |
| 397 | goto out_free; |
| 398 | |
| 399 | cfg80211_put_dev(dev); |
| 400 | |
| 401 | return genlmsg_unicast(msg, info->snd_pid); |
| 402 | |
| 403 | out_free: |
| 404 | nlmsg_free(msg); |
| 405 | out_err: |
| 406 | cfg80211_put_dev(dev); |
| 407 | return -ENOBUFS; |
| 408 | } |
| 409 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 410 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 411 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 412 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 413 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 414 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 415 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 416 | }; |
| 417 | |
| 418 | static int parse_txq_params(struct nlattr *tb[], |
| 419 | struct ieee80211_txq_params *txq_params) |
| 420 | { |
| 421 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 422 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 423 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 424 | return -EINVAL; |
| 425 | |
| 426 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 427 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 428 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 429 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 430 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 431 | |
| 432 | return 0; |
| 433 | } |
| 434 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 435 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 436 | { |
| 437 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 438 | int result = 0, rem_txq_params = 0; |
| 439 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 440 | u32 changed; |
| 441 | u8 retry_short = 0, retry_long = 0; |
| 442 | u32 frag_threshold = 0, rts_threshold = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 443 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 444 | rtnl_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 445 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 446 | mutex_lock(&cfg80211_mutex); |
| 447 | |
| 448 | rdev = __cfg80211_drv_from_info(info); |
| 449 | if (IS_ERR(rdev)) { |
| 450 | result = PTR_ERR(rdev); |
| 451 | goto unlock; |
| 452 | } |
| 453 | |
| 454 | mutex_lock(&rdev->mtx); |
| 455 | |
| 456 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 457 | result = cfg80211_dev_rename( |
| 458 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 459 | |
| 460 | mutex_unlock(&cfg80211_mutex); |
| 461 | |
| 462 | if (result) |
| 463 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 464 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 465 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 466 | struct ieee80211_txq_params txq_params; |
| 467 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 468 | |
| 469 | if (!rdev->ops->set_txq_params) { |
| 470 | result = -EOPNOTSUPP; |
| 471 | goto bad_res; |
| 472 | } |
| 473 | |
| 474 | nla_for_each_nested(nl_txq_params, |
| 475 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 476 | rem_txq_params) { |
| 477 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 478 | nla_data(nl_txq_params), |
| 479 | nla_len(nl_txq_params), |
| 480 | txq_params_policy); |
| 481 | result = parse_txq_params(tb, &txq_params); |
| 482 | if (result) |
| 483 | goto bad_res; |
| 484 | |
| 485 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 486 | &txq_params); |
| 487 | if (result) |
| 488 | goto bad_res; |
| 489 | } |
| 490 | } |
| 491 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 492 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 493 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 494 | struct ieee80211_channel *chan; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 495 | struct ieee80211_sta_ht_cap *ht_cap; |
Luis R. Rodriguez | 294196a | 2009-05-02 00:37:20 -0400 | [diff] [blame] | 496 | u32 freq; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 497 | |
| 498 | if (!rdev->ops->set_channel) { |
| 499 | result = -EOPNOTSUPP; |
| 500 | goto bad_res; |
| 501 | } |
| 502 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 503 | result = -EINVAL; |
| 504 | |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 505 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 506 | channel_type = nla_get_u32(info->attrs[ |
| 507 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 508 | if (channel_type != NL80211_CHAN_NO_HT && |
| 509 | channel_type != NL80211_CHAN_HT20 && |
| 510 | channel_type != NL80211_CHAN_HT40PLUS && |
| 511 | channel_type != NL80211_CHAN_HT40MINUS) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 512 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 516 | chan = ieee80211_get_channel(&rdev->wiphy, freq); |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 517 | |
| 518 | /* Primary channel not allowed */ |
| 519 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 520 | goto bad_res; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 521 | |
Luis R. Rodriguez | 294196a | 2009-05-02 00:37:20 -0400 | [diff] [blame] | 522 | if (channel_type == NL80211_CHAN_HT40MINUS && |
| 523 | (chan->flags & IEEE80211_CHAN_NO_HT40MINUS)) |
| 524 | goto bad_res; |
| 525 | else if (channel_type == NL80211_CHAN_HT40PLUS && |
| 526 | (chan->flags & IEEE80211_CHAN_NO_HT40PLUS)) |
| 527 | goto bad_res; |
| 528 | |
| 529 | /* |
| 530 | * At this point we know if that if HT40 was requested |
| 531 | * we are allowed to use it and the extension channel |
| 532 | * exists. |
| 533 | */ |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 534 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 535 | ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; |
| 536 | |
Luis R. Rodriguez | 294196a | 2009-05-02 00:37:20 -0400 | [diff] [blame] | 537 | /* no HT capabilities or intolerant */ |
| 538 | if (channel_type != NL80211_CHAN_NO_HT) { |
| 539 | if (!ht_cap->ht_supported) |
| 540 | goto bad_res; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 541 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 542 | (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 543 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | result = rdev->ops->set_channel(&rdev->wiphy, chan, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 547 | channel_type); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 548 | if (result) |
| 549 | goto bad_res; |
| 550 | } |
| 551 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 552 | changed = 0; |
| 553 | |
| 554 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 555 | retry_short = nla_get_u8( |
| 556 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 557 | if (retry_short == 0) { |
| 558 | result = -EINVAL; |
| 559 | goto bad_res; |
| 560 | } |
| 561 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 562 | } |
| 563 | |
| 564 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 565 | retry_long = nla_get_u8( |
| 566 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 567 | if (retry_long == 0) { |
| 568 | result = -EINVAL; |
| 569 | goto bad_res; |
| 570 | } |
| 571 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 572 | } |
| 573 | |
| 574 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 575 | frag_threshold = nla_get_u32( |
| 576 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 577 | if (frag_threshold < 256) { |
| 578 | result = -EINVAL; |
| 579 | goto bad_res; |
| 580 | } |
| 581 | if (frag_threshold != (u32) -1) { |
| 582 | /* |
| 583 | * Fragments (apart from the last one) are required to |
| 584 | * have even length. Make the fragmentation code |
| 585 | * simpler by stripping LSB should someone try to use |
| 586 | * odd threshold value. |
| 587 | */ |
| 588 | frag_threshold &= ~0x1; |
| 589 | } |
| 590 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 591 | } |
| 592 | |
| 593 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 594 | rts_threshold = nla_get_u32( |
| 595 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 596 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 597 | } |
| 598 | |
| 599 | if (changed) { |
| 600 | u8 old_retry_short, old_retry_long; |
| 601 | u32 old_frag_threshold, old_rts_threshold; |
| 602 | |
| 603 | if (!rdev->ops->set_wiphy_params) { |
| 604 | result = -EOPNOTSUPP; |
| 605 | goto bad_res; |
| 606 | } |
| 607 | |
| 608 | old_retry_short = rdev->wiphy.retry_short; |
| 609 | old_retry_long = rdev->wiphy.retry_long; |
| 610 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 611 | old_rts_threshold = rdev->wiphy.rts_threshold; |
| 612 | |
| 613 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 614 | rdev->wiphy.retry_short = retry_short; |
| 615 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 616 | rdev->wiphy.retry_long = retry_long; |
| 617 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 618 | rdev->wiphy.frag_threshold = frag_threshold; |
| 619 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 620 | rdev->wiphy.rts_threshold = rts_threshold; |
| 621 | |
| 622 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 623 | if (result) { |
| 624 | rdev->wiphy.retry_short = old_retry_short; |
| 625 | rdev->wiphy.retry_long = old_retry_long; |
| 626 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 627 | rdev->wiphy.rts_threshold = old_rts_threshold; |
| 628 | } |
| 629 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 630 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 631 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 632 | mutex_unlock(&rdev->mtx); |
| 633 | unlock: |
| 634 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 635 | return result; |
| 636 | } |
| 637 | |
| 638 | |
| 639 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 640 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 641 | struct net_device *dev) |
| 642 | { |
| 643 | void *hdr; |
| 644 | |
| 645 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 646 | if (!hdr) |
| 647 | return -1; |
| 648 | |
| 649 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 650 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 651 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 652 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 653 | return genlmsg_end(msg, hdr); |
| 654 | |
| 655 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 656 | genlmsg_cancel(msg, hdr); |
| 657 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 661 | { |
| 662 | int wp_idx = 0; |
| 663 | int if_idx = 0; |
| 664 | int wp_start = cb->args[0]; |
| 665 | int if_start = cb->args[1]; |
| 666 | struct cfg80211_registered_device *dev; |
| 667 | struct wireless_dev *wdev; |
| 668 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 669 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 670 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 671 | if (wp_idx < wp_start) { |
| 672 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 673 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 674 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 675 | if_idx = 0; |
| 676 | |
| 677 | mutex_lock(&dev->devlist_mtx); |
| 678 | list_for_each_entry(wdev, &dev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 679 | if (if_idx < if_start) { |
| 680 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 681 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 682 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 683 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 684 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 685 | dev, wdev->netdev) < 0) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 686 | mutex_unlock(&dev->devlist_mtx); |
| 687 | goto out; |
| 688 | } |
| 689 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 690 | } |
| 691 | mutex_unlock(&dev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 692 | |
| 693 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 694 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 695 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 696 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 697 | |
| 698 | cb->args[0] = wp_idx; |
| 699 | cb->args[1] = if_idx; |
| 700 | |
| 701 | return skb->len; |
| 702 | } |
| 703 | |
| 704 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 705 | { |
| 706 | struct sk_buff *msg; |
| 707 | struct cfg80211_registered_device *dev; |
| 708 | struct net_device *netdev; |
| 709 | int err; |
| 710 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 711 | err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 712 | if (err) |
| 713 | return err; |
| 714 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 715 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 716 | if (!msg) |
| 717 | goto out_err; |
| 718 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 719 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
| 720 | dev, netdev) < 0) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 721 | goto out_free; |
| 722 | |
| 723 | dev_put(netdev); |
| 724 | cfg80211_put_dev(dev); |
| 725 | |
| 726 | return genlmsg_unicast(msg, info->snd_pid); |
| 727 | |
| 728 | out_free: |
| 729 | nlmsg_free(msg); |
| 730 | out_err: |
| 731 | dev_put(netdev); |
| 732 | cfg80211_put_dev(dev); |
| 733 | return -ENOBUFS; |
| 734 | } |
| 735 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 736 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 737 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 738 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 739 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 740 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 741 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 742 | }; |
| 743 | |
| 744 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 745 | { |
| 746 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 747 | int flag; |
| 748 | |
| 749 | *mntrflags = 0; |
| 750 | |
| 751 | if (!nla) |
| 752 | return -EINVAL; |
| 753 | |
| 754 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 755 | nla, mntr_flags_policy)) |
| 756 | return -EINVAL; |
| 757 | |
| 758 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 759 | if (flags[flag]) |
| 760 | *mntrflags |= (1<<flag); |
| 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 765 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 766 | { |
| 767 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 768 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 769 | int err, ifindex; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 770 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 771 | struct net_device *dev; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 772 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 773 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 774 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 775 | memset(¶ms, 0, sizeof(params)); |
| 776 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 777 | rtnl_lock(); |
| 778 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 779 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 780 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 781 | goto unlock_rtnl; |
| 782 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 783 | ifindex = dev->ifindex; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 784 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 785 | dev_put(dev); |
| 786 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 787 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 788 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 789 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 790 | change = true; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 791 | if (ntype > NL80211_IFTYPE_MAX) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 792 | err = -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 793 | goto unlock; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 794 | } |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 795 | } |
| 796 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 797 | if (!drv->ops->change_virtual_intf || |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 798 | !(drv->wiphy.interface_modes & (1 << ntype))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 799 | err = -EOPNOTSUPP; |
| 800 | goto unlock; |
| 801 | } |
| 802 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 803 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 804 | if (ntype != NL80211_IFTYPE_MESH_POINT) { |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 805 | err = -EINVAL; |
| 806 | goto unlock; |
| 807 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 808 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 809 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 810 | change = true; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 811 | } |
| 812 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 813 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 814 | if (ntype != NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 815 | err = -EINVAL; |
| 816 | goto unlock; |
| 817 | } |
| 818 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 819 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 820 | if (err) |
| 821 | goto unlock; |
| 822 | |
| 823 | flags = &_flags; |
| 824 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 825 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 826 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 827 | if (change) |
| 828 | err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 829 | ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 830 | else |
| 831 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 832 | |
| 833 | dev = __dev_get_by_index(&init_net, ifindex); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 834 | WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != ntype)); |
| 835 | |
| 836 | if (dev && !err && (ntype != otype)) { |
| 837 | if (otype == NL80211_IFTYPE_ADHOC) |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 838 | cfg80211_clear_ibss(dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 839 | } |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 840 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 841 | unlock: |
| 842 | cfg80211_put_dev(drv); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 843 | unlock_rtnl: |
| 844 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 845 | return err; |
| 846 | } |
| 847 | |
| 848 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 849 | { |
| 850 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 851 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 852 | int err; |
| 853 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 854 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 855 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 856 | memset(¶ms, 0, sizeof(params)); |
| 857 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 858 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 859 | return -EINVAL; |
| 860 | |
| 861 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 862 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 863 | if (type > NL80211_IFTYPE_MAX) |
| 864 | return -EINVAL; |
| 865 | } |
| 866 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 867 | rtnl_lock(); |
| 868 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 869 | drv = cfg80211_get_dev_from_info(info); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 870 | if (IS_ERR(drv)) { |
| 871 | err = PTR_ERR(drv); |
| 872 | goto unlock_rtnl; |
| 873 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 874 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 875 | if (!drv->ops->add_virtual_intf || |
| 876 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 877 | err = -EOPNOTSUPP; |
| 878 | goto unlock; |
| 879 | } |
| 880 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 881 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 882 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 883 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 884 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 885 | } |
| 886 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 887 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 888 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 889 | &flags); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 890 | err = drv->ops->add_virtual_intf(&drv->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 891 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 892 | type, err ? NULL : &flags, ¶ms); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 893 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 894 | unlock: |
| 895 | cfg80211_put_dev(drv); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 896 | unlock_rtnl: |
| 897 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 898 | return err; |
| 899 | } |
| 900 | |
| 901 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 902 | { |
| 903 | struct cfg80211_registered_device *drv; |
| 904 | int ifindex, err; |
| 905 | struct net_device *dev; |
| 906 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 907 | rtnl_lock(); |
| 908 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 909 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 910 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 911 | goto unlock_rtnl; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 912 | ifindex = dev->ifindex; |
| 913 | dev_put(dev); |
| 914 | |
| 915 | if (!drv->ops->del_virtual_intf) { |
| 916 | err = -EOPNOTSUPP; |
| 917 | goto out; |
| 918 | } |
| 919 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 920 | err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 921 | |
| 922 | out: |
| 923 | cfg80211_put_dev(drv); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 924 | unlock_rtnl: |
| 925 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 926 | return err; |
| 927 | } |
| 928 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 929 | struct get_key_cookie { |
| 930 | struct sk_buff *msg; |
| 931 | int error; |
| 932 | }; |
| 933 | |
| 934 | static void get_key_callback(void *c, struct key_params *params) |
| 935 | { |
| 936 | struct get_key_cookie *cookie = c; |
| 937 | |
| 938 | if (params->key) |
| 939 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 940 | params->key_len, params->key); |
| 941 | |
| 942 | if (params->seq) |
| 943 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 944 | params->seq_len, params->seq); |
| 945 | |
| 946 | if (params->cipher) |
| 947 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 948 | params->cipher); |
| 949 | |
| 950 | return; |
| 951 | nla_put_failure: |
| 952 | cookie->error = 1; |
| 953 | } |
| 954 | |
| 955 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 956 | { |
| 957 | struct cfg80211_registered_device *drv; |
| 958 | int err; |
| 959 | struct net_device *dev; |
| 960 | u8 key_idx = 0; |
| 961 | u8 *mac_addr = NULL; |
| 962 | struct get_key_cookie cookie = { |
| 963 | .error = 0, |
| 964 | }; |
| 965 | void *hdr; |
| 966 | struct sk_buff *msg; |
| 967 | |
| 968 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 969 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 970 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 971 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 972 | return -EINVAL; |
| 973 | |
| 974 | if (info->attrs[NL80211_ATTR_MAC]) |
| 975 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 976 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 977 | rtnl_lock(); |
| 978 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 979 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 980 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 981 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 982 | |
| 983 | if (!drv->ops->get_key) { |
| 984 | err = -EOPNOTSUPP; |
| 985 | goto out; |
| 986 | } |
| 987 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 988 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 989 | if (!msg) { |
| 990 | err = -ENOMEM; |
| 991 | goto out; |
| 992 | } |
| 993 | |
| 994 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 995 | NL80211_CMD_NEW_KEY); |
| 996 | |
| 997 | if (IS_ERR(hdr)) { |
| 998 | err = PTR_ERR(hdr); |
| 999 | goto out; |
| 1000 | } |
| 1001 | |
| 1002 | cookie.msg = msg; |
| 1003 | |
| 1004 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1005 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1006 | if (mac_addr) |
| 1007 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1008 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1009 | err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, |
| 1010 | &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1011 | |
| 1012 | if (err) |
| 1013 | goto out; |
| 1014 | |
| 1015 | if (cookie.error) |
| 1016 | goto nla_put_failure; |
| 1017 | |
| 1018 | genlmsg_end(msg, hdr); |
| 1019 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1020 | goto out; |
| 1021 | |
| 1022 | nla_put_failure: |
| 1023 | err = -ENOBUFS; |
| 1024 | nlmsg_free(msg); |
| 1025 | out: |
| 1026 | cfg80211_put_dev(drv); |
| 1027 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1028 | unlock_rtnl: |
| 1029 | rtnl_unlock(); |
| 1030 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1031 | return err; |
| 1032 | } |
| 1033 | |
| 1034 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1035 | { |
| 1036 | struct cfg80211_registered_device *drv; |
| 1037 | int err; |
| 1038 | struct net_device *dev; |
| 1039 | u8 key_idx; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1040 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
| 1041 | u8 key_index); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1042 | |
| 1043 | if (!info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1044 | return -EINVAL; |
| 1045 | |
| 1046 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1047 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1048 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) { |
| 1049 | if (key_idx < 4 || key_idx > 5) |
| 1050 | return -EINVAL; |
| 1051 | } else if (key_idx > 3) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1052 | return -EINVAL; |
| 1053 | |
| 1054 | /* currently only support setting default key */ |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1055 | if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] && |
| 1056 | !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1057 | return -EINVAL; |
| 1058 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1059 | rtnl_lock(); |
| 1060 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1061 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1062 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1063 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1064 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1065 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT]) |
| 1066 | func = drv->ops->set_default_key; |
| 1067 | else |
| 1068 | func = drv->ops->set_default_mgmt_key; |
| 1069 | |
| 1070 | if (!func) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1071 | err = -EOPNOTSUPP; |
| 1072 | goto out; |
| 1073 | } |
| 1074 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1075 | err = func(&drv->wiphy, dev, key_idx); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1076 | #ifdef CONFIG_WIRELESS_EXT |
| 1077 | if (!err) { |
| 1078 | if (func == drv->ops->set_default_key) |
| 1079 | dev->ieee80211_ptr->wext.default_key = key_idx; |
| 1080 | else |
| 1081 | dev->ieee80211_ptr->wext.default_mgmt_key = key_idx; |
| 1082 | } |
| 1083 | #endif |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1084 | |
| 1085 | out: |
| 1086 | cfg80211_put_dev(drv); |
| 1087 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1088 | |
| 1089 | unlock_rtnl: |
| 1090 | rtnl_unlock(); |
| 1091 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1092 | return err; |
| 1093 | } |
| 1094 | |
| 1095 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1096 | { |
| 1097 | struct cfg80211_registered_device *drv; |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 1098 | int err, i; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1099 | struct net_device *dev; |
| 1100 | struct key_params params; |
| 1101 | u8 key_idx = 0; |
| 1102 | u8 *mac_addr = NULL; |
| 1103 | |
| 1104 | memset(¶ms, 0, sizeof(params)); |
| 1105 | |
| 1106 | if (!info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 1107 | return -EINVAL; |
| 1108 | |
| 1109 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 1110 | params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1111 | params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1112 | } |
| 1113 | |
Jouni Malinen | faa8fdc | 2009-05-11 21:57:58 +0300 | [diff] [blame] | 1114 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 1115 | params.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1116 | params.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 1117 | } |
| 1118 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1119 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1120 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1121 | |
| 1122 | params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1123 | |
| 1124 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1125 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1126 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1127 | if (cfg80211_validate_key_settings(¶ms, key_idx, mac_addr)) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1128 | return -EINVAL; |
| 1129 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1130 | rtnl_lock(); |
| 1131 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1132 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1133 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1134 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1135 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 1136 | for (i = 0; i < drv->wiphy.n_cipher_suites; i++) |
| 1137 | if (params.cipher == drv->wiphy.cipher_suites[i]) |
| 1138 | break; |
| 1139 | if (i == drv->wiphy.n_cipher_suites) { |
| 1140 | err = -EINVAL; |
| 1141 | goto out; |
| 1142 | } |
| 1143 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1144 | if (!drv->ops->add_key) { |
| 1145 | err = -EOPNOTSUPP; |
| 1146 | goto out; |
| 1147 | } |
| 1148 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1149 | err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1150 | |
| 1151 | out: |
| 1152 | cfg80211_put_dev(drv); |
| 1153 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1154 | unlock_rtnl: |
| 1155 | rtnl_unlock(); |
| 1156 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1157 | return err; |
| 1158 | } |
| 1159 | |
| 1160 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1161 | { |
| 1162 | struct cfg80211_registered_device *drv; |
| 1163 | int err; |
| 1164 | struct net_device *dev; |
| 1165 | u8 key_idx = 0; |
| 1166 | u8 *mac_addr = NULL; |
| 1167 | |
| 1168 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1169 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1170 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1171 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1172 | return -EINVAL; |
| 1173 | |
| 1174 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1175 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1176 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1177 | rtnl_lock(); |
| 1178 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1179 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1180 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1181 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1182 | |
| 1183 | if (!drv->ops->del_key) { |
| 1184 | err = -EOPNOTSUPP; |
| 1185 | goto out; |
| 1186 | } |
| 1187 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1188 | err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1189 | |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1190 | #ifdef CONFIG_WIRELESS_EXT |
| 1191 | if (!err) { |
| 1192 | if (key_idx == dev->ieee80211_ptr->wext.default_key) |
| 1193 | dev->ieee80211_ptr->wext.default_key = -1; |
| 1194 | else if (key_idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
| 1195 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1196 | } |
| 1197 | #endif |
| 1198 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1199 | out: |
| 1200 | cfg80211_put_dev(drv); |
| 1201 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1202 | |
| 1203 | unlock_rtnl: |
| 1204 | rtnl_unlock(); |
| 1205 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1206 | return err; |
| 1207 | } |
| 1208 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1209 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1210 | { |
| 1211 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1212 | struct beacon_parameters *info); |
| 1213 | struct cfg80211_registered_device *drv; |
| 1214 | int err; |
| 1215 | struct net_device *dev; |
| 1216 | struct beacon_parameters params; |
| 1217 | int haveinfo = 0; |
| 1218 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1219 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1220 | return -EINVAL; |
| 1221 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1222 | rtnl_lock(); |
| 1223 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1224 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1225 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1226 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1227 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1228 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 1229 | err = -EOPNOTSUPP; |
| 1230 | goto out; |
| 1231 | } |
| 1232 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1233 | switch (info->genlhdr->cmd) { |
| 1234 | case NL80211_CMD_NEW_BEACON: |
| 1235 | /* these are required for NEW_BEACON */ |
| 1236 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1237 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 1238 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1239 | err = -EINVAL; |
| 1240 | goto out; |
| 1241 | } |
| 1242 | |
| 1243 | call = drv->ops->add_beacon; |
| 1244 | break; |
| 1245 | case NL80211_CMD_SET_BEACON: |
| 1246 | call = drv->ops->set_beacon; |
| 1247 | break; |
| 1248 | default: |
| 1249 | WARN_ON(1); |
| 1250 | err = -EOPNOTSUPP; |
| 1251 | goto out; |
| 1252 | } |
| 1253 | |
| 1254 | if (!call) { |
| 1255 | err = -EOPNOTSUPP; |
| 1256 | goto out; |
| 1257 | } |
| 1258 | |
| 1259 | memset(¶ms, 0, sizeof(params)); |
| 1260 | |
| 1261 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1262 | params.interval = |
| 1263 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1264 | haveinfo = 1; |
| 1265 | } |
| 1266 | |
| 1267 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1268 | params.dtim_period = |
| 1269 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1270 | haveinfo = 1; |
| 1271 | } |
| 1272 | |
| 1273 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1274 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1275 | params.head_len = |
| 1276 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1277 | haveinfo = 1; |
| 1278 | } |
| 1279 | |
| 1280 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1281 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1282 | params.tail_len = |
| 1283 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1284 | haveinfo = 1; |
| 1285 | } |
| 1286 | |
| 1287 | if (!haveinfo) { |
| 1288 | err = -EINVAL; |
| 1289 | goto out; |
| 1290 | } |
| 1291 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1292 | err = call(&drv->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1293 | |
| 1294 | out: |
| 1295 | cfg80211_put_dev(drv); |
| 1296 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1297 | unlock_rtnl: |
| 1298 | rtnl_unlock(); |
| 1299 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1300 | return err; |
| 1301 | } |
| 1302 | |
| 1303 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1304 | { |
| 1305 | struct cfg80211_registered_device *drv; |
| 1306 | int err; |
| 1307 | struct net_device *dev; |
| 1308 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1309 | rtnl_lock(); |
| 1310 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1311 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1312 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1313 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1314 | |
| 1315 | if (!drv->ops->del_beacon) { |
| 1316 | err = -EOPNOTSUPP; |
| 1317 | goto out; |
| 1318 | } |
| 1319 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1320 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 1321 | err = -EOPNOTSUPP; |
| 1322 | goto out; |
| 1323 | } |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1324 | err = drv->ops->del_beacon(&drv->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1325 | |
| 1326 | out: |
| 1327 | cfg80211_put_dev(drv); |
| 1328 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1329 | unlock_rtnl: |
| 1330 | rtnl_unlock(); |
| 1331 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1332 | return err; |
| 1333 | } |
| 1334 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1335 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1336 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1337 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1338 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 1339 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1340 | }; |
| 1341 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1342 | static int parse_station_flags(struct genl_info *info, |
| 1343 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1344 | { |
| 1345 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1346 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1347 | int flag; |
| 1348 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1349 | /* |
| 1350 | * Try parsing the new attribute first so userspace |
| 1351 | * can specify both for older kernels. |
| 1352 | */ |
| 1353 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 1354 | if (nla) { |
| 1355 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1356 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1357 | sta_flags = nla_data(nla); |
| 1358 | params->sta_flags_mask = sta_flags->mask; |
| 1359 | params->sta_flags_set = sta_flags->set; |
| 1360 | if ((params->sta_flags_mask | |
| 1361 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 1362 | return -EINVAL; |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | /* if present, parse the old attribute */ |
| 1367 | |
| 1368 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1369 | if (!nla) |
| 1370 | return 0; |
| 1371 | |
| 1372 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1373 | nla, sta_flags_policy)) |
| 1374 | return -EINVAL; |
| 1375 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1376 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 1377 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1378 | |
| 1379 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1380 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1381 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1382 | |
| 1383 | return 0; |
| 1384 | } |
| 1385 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1386 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) |
| 1387 | { |
| 1388 | int modulation, streams, bitrate; |
| 1389 | |
| 1390 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) |
| 1391 | return rate->legacy; |
| 1392 | |
| 1393 | /* the formula below does only work for MCS values smaller than 32 */ |
| 1394 | if (rate->mcs >= 32) |
| 1395 | return 0; |
| 1396 | |
| 1397 | modulation = rate->mcs & 7; |
| 1398 | streams = (rate->mcs >> 3) + 1; |
| 1399 | |
| 1400 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? |
| 1401 | 13500000 : 6500000; |
| 1402 | |
| 1403 | if (modulation < 4) |
| 1404 | bitrate *= (modulation + 1); |
| 1405 | else if (modulation == 4) |
| 1406 | bitrate *= (modulation + 2); |
| 1407 | else |
| 1408 | bitrate *= (modulation + 3); |
| 1409 | |
| 1410 | bitrate *= streams; |
| 1411 | |
| 1412 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1413 | bitrate = (bitrate / 9) * 10; |
| 1414 | |
| 1415 | /* do NOT round down here */ |
| 1416 | return (bitrate + 50000) / 100000; |
| 1417 | } |
| 1418 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1419 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 1420 | int flags, struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1421 | u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1422 | { |
| 1423 | void *hdr; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1424 | struct nlattr *sinfoattr, *txrate; |
| 1425 | u16 bitrate; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1426 | |
| 1427 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1428 | if (!hdr) |
| 1429 | return -1; |
| 1430 | |
| 1431 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1432 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1433 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1434 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 1435 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1436 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1437 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 1438 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 1439 | sinfo->inactive_time); |
| 1440 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 1441 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 1442 | sinfo->rx_bytes); |
| 1443 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 1444 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 1445 | sinfo->tx_bytes); |
| 1446 | if (sinfo->filled & STATION_INFO_LLID) |
| 1447 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 1448 | sinfo->llid); |
| 1449 | if (sinfo->filled & STATION_INFO_PLID) |
| 1450 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 1451 | sinfo->plid); |
| 1452 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 1453 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 1454 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1455 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 1456 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 1457 | sinfo->signal); |
| 1458 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
| 1459 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); |
| 1460 | if (!txrate) |
| 1461 | goto nla_put_failure; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1462 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1463 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1464 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); |
| 1465 | if (bitrate > 0) |
| 1466 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1467 | |
| 1468 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
| 1469 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, |
| 1470 | sinfo->txrate.mcs); |
| 1471 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1472 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1473 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1474 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1475 | |
| 1476 | nla_nest_end(msg, txrate); |
| 1477 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 1478 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 1479 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 1480 | sinfo->rx_packets); |
| 1481 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 1482 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 1483 | sinfo->tx_packets); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1484 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1485 | |
| 1486 | return genlmsg_end(msg, hdr); |
| 1487 | |
| 1488 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1489 | genlmsg_cancel(msg, hdr); |
| 1490 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1491 | } |
| 1492 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1493 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1494 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1495 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1496 | struct station_info sinfo; |
| 1497 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1498 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1499 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1500 | int ifidx = cb->args[0]; |
| 1501 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1502 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1503 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1504 | if (!ifidx) { |
| 1505 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1506 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1507 | nl80211_policy); |
| 1508 | if (err) |
| 1509 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1510 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1511 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1512 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1513 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1514 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1515 | if (!ifidx) |
| 1516 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1517 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1518 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1519 | rtnl_lock(); |
| 1520 | |
| 1521 | netdev = __dev_get_by_index(&init_net, ifidx); |
| 1522 | if (!netdev) { |
| 1523 | err = -ENODEV; |
| 1524 | goto out_rtnl; |
| 1525 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1526 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1527 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1528 | if (IS_ERR(dev)) { |
| 1529 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1530 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1534 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1535 | goto out_err; |
| 1536 | } |
| 1537 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1538 | while (1) { |
| 1539 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1540 | mac_addr, &sinfo); |
| 1541 | if (err == -ENOENT) |
| 1542 | break; |
| 1543 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1544 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1545 | |
| 1546 | if (nl80211_send_station(skb, |
| 1547 | NETLINK_CB(cb->skb).pid, |
| 1548 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1549 | netdev, mac_addr, |
| 1550 | &sinfo) < 0) |
| 1551 | goto out; |
| 1552 | |
| 1553 | sta_idx++; |
| 1554 | } |
| 1555 | |
| 1556 | |
| 1557 | out: |
| 1558 | cb->args[1] = sta_idx; |
| 1559 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1560 | out_err: |
| 1561 | cfg80211_put_dev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1562 | out_rtnl: |
| 1563 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1564 | |
| 1565 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1566 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1567 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1568 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 1569 | { |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1570 | struct cfg80211_registered_device *drv; |
| 1571 | int err; |
| 1572 | struct net_device *dev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1573 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1574 | struct sk_buff *msg; |
| 1575 | u8 *mac_addr = NULL; |
| 1576 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1577 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1578 | |
| 1579 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1580 | return -EINVAL; |
| 1581 | |
| 1582 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1583 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1584 | rtnl_lock(); |
| 1585 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1586 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1587 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1588 | goto out_rtnl; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1589 | |
| 1590 | if (!drv->ops->get_station) { |
| 1591 | err = -EOPNOTSUPP; |
| 1592 | goto out; |
| 1593 | } |
| 1594 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1595 | err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1596 | if (err) |
| 1597 | goto out; |
| 1598 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1599 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1600 | if (!msg) |
| 1601 | goto out; |
| 1602 | |
| 1603 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1604 | dev, mac_addr, &sinfo) < 0) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1605 | goto out_free; |
| 1606 | |
| 1607 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1608 | goto out; |
| 1609 | |
| 1610 | out_free: |
| 1611 | nlmsg_free(msg); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1612 | out: |
| 1613 | cfg80211_put_dev(drv); |
| 1614 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1615 | out_rtnl: |
| 1616 | rtnl_unlock(); |
| 1617 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1618 | return err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * Get vlan interface making sure it is on the right wiphy. |
| 1623 | */ |
| 1624 | static int get_vlan(struct nlattr *vlanattr, |
| 1625 | struct cfg80211_registered_device *rdev, |
| 1626 | struct net_device **vlan) |
| 1627 | { |
| 1628 | *vlan = NULL; |
| 1629 | |
| 1630 | if (vlanattr) { |
| 1631 | *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr)); |
| 1632 | if (!*vlan) |
| 1633 | return -ENODEV; |
| 1634 | if (!(*vlan)->ieee80211_ptr) |
| 1635 | return -EINVAL; |
| 1636 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 1637 | return -EINVAL; |
| 1638 | } |
| 1639 | return 0; |
| 1640 | } |
| 1641 | |
| 1642 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 1643 | { |
| 1644 | struct cfg80211_registered_device *drv; |
| 1645 | int err; |
| 1646 | struct net_device *dev; |
| 1647 | struct station_parameters params; |
| 1648 | u8 *mac_addr = NULL; |
| 1649 | |
| 1650 | memset(¶ms, 0, sizeof(params)); |
| 1651 | |
| 1652 | params.listen_interval = -1; |
| 1653 | |
| 1654 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 1655 | return -EINVAL; |
| 1656 | |
| 1657 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1658 | return -EINVAL; |
| 1659 | |
| 1660 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1661 | |
| 1662 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 1663 | params.supported_rates = |
| 1664 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1665 | params.supported_rates_len = |
| 1666 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1667 | } |
| 1668 | |
| 1669 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1670 | params.listen_interval = |
| 1671 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 1672 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1673 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1674 | params.ht_capa = |
| 1675 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 1676 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1677 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1678 | return -EINVAL; |
| 1679 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1680 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 1681 | params.plink_action = |
| 1682 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 1683 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1684 | rtnl_lock(); |
| 1685 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1686 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1687 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1688 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1689 | |
| 1690 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1691 | if (err) |
| 1692 | goto out; |
| 1693 | |
| 1694 | if (!drv->ops->change_station) { |
| 1695 | err = -EOPNOTSUPP; |
| 1696 | goto out; |
| 1697 | } |
| 1698 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1699 | err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1700 | |
| 1701 | out: |
| 1702 | if (params.vlan) |
| 1703 | dev_put(params.vlan); |
| 1704 | cfg80211_put_dev(drv); |
| 1705 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1706 | out_rtnl: |
| 1707 | rtnl_unlock(); |
| 1708 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1709 | return err; |
| 1710 | } |
| 1711 | |
| 1712 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 1713 | { |
| 1714 | struct cfg80211_registered_device *drv; |
| 1715 | int err; |
| 1716 | struct net_device *dev; |
| 1717 | struct station_parameters params; |
| 1718 | u8 *mac_addr = NULL; |
| 1719 | |
| 1720 | memset(¶ms, 0, sizeof(params)); |
| 1721 | |
| 1722 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1723 | return -EINVAL; |
| 1724 | |
| 1725 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 1726 | return -EINVAL; |
| 1727 | |
| 1728 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1729 | return -EINVAL; |
| 1730 | |
| 1731 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 1732 | return -EINVAL; |
| 1733 | |
| 1734 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1735 | params.supported_rates = |
| 1736 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1737 | params.supported_rates_len = |
| 1738 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1739 | params.listen_interval = |
| 1740 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame^] | 1741 | |
Johannes Berg | 16f2e85 | 2008-04-07 14:35:46 +0200 | [diff] [blame] | 1742 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame^] | 1743 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 1744 | return -EINVAL; |
| 1745 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1746 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1747 | params.ht_capa = |
| 1748 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1749 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1750 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1751 | return -EINVAL; |
| 1752 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1753 | rtnl_lock(); |
| 1754 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1755 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1756 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1757 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1758 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 1759 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1760 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { |
| 1761 | err = -EINVAL; |
| 1762 | goto out; |
| 1763 | } |
| 1764 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1765 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1766 | if (err) |
| 1767 | goto out; |
| 1768 | |
| 1769 | if (!drv->ops->add_station) { |
| 1770 | err = -EOPNOTSUPP; |
| 1771 | goto out; |
| 1772 | } |
| 1773 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 1774 | if (!netif_running(dev)) { |
| 1775 | err = -ENETDOWN; |
| 1776 | goto out; |
| 1777 | } |
| 1778 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1779 | err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1780 | |
| 1781 | out: |
| 1782 | if (params.vlan) |
| 1783 | dev_put(params.vlan); |
| 1784 | cfg80211_put_dev(drv); |
| 1785 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1786 | out_rtnl: |
| 1787 | rtnl_unlock(); |
| 1788 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1789 | return err; |
| 1790 | } |
| 1791 | |
| 1792 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 1793 | { |
| 1794 | struct cfg80211_registered_device *drv; |
| 1795 | int err; |
| 1796 | struct net_device *dev; |
| 1797 | u8 *mac_addr = NULL; |
| 1798 | |
| 1799 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1800 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1801 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1802 | rtnl_lock(); |
| 1803 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1804 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1805 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1806 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1807 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 1808 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
| 1809 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { |
| 1810 | err = -EINVAL; |
| 1811 | goto out; |
| 1812 | } |
| 1813 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1814 | if (!drv->ops->del_station) { |
| 1815 | err = -EOPNOTSUPP; |
| 1816 | goto out; |
| 1817 | } |
| 1818 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1819 | err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1820 | |
| 1821 | out: |
| 1822 | cfg80211_put_dev(drv); |
| 1823 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1824 | out_rtnl: |
| 1825 | rtnl_unlock(); |
| 1826 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1827 | return err; |
| 1828 | } |
| 1829 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1830 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 1831 | int flags, struct net_device *dev, |
| 1832 | u8 *dst, u8 *next_hop, |
| 1833 | struct mpath_info *pinfo) |
| 1834 | { |
| 1835 | void *hdr; |
| 1836 | struct nlattr *pinfoattr; |
| 1837 | |
| 1838 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1839 | if (!hdr) |
| 1840 | return -1; |
| 1841 | |
| 1842 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1843 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 1844 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 1845 | |
| 1846 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 1847 | if (!pinfoattr) |
| 1848 | goto nla_put_failure; |
| 1849 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 1850 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 1851 | pinfo->frame_qlen); |
| 1852 | if (pinfo->filled & MPATH_INFO_DSN) |
| 1853 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, |
| 1854 | pinfo->dsn); |
| 1855 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 1856 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 1857 | pinfo->metric); |
| 1858 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 1859 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 1860 | pinfo->exptime); |
| 1861 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 1862 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 1863 | pinfo->flags); |
| 1864 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 1865 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 1866 | pinfo->discovery_timeout); |
| 1867 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 1868 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 1869 | pinfo->discovery_retries); |
| 1870 | |
| 1871 | nla_nest_end(msg, pinfoattr); |
| 1872 | |
| 1873 | return genlmsg_end(msg, hdr); |
| 1874 | |
| 1875 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1876 | genlmsg_cancel(msg, hdr); |
| 1877 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1881 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1882 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1883 | struct mpath_info pinfo; |
| 1884 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1885 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1886 | u8 dst[ETH_ALEN]; |
| 1887 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1888 | int ifidx = cb->args[0]; |
| 1889 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1890 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1891 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1892 | if (!ifidx) { |
| 1893 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1894 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1895 | nl80211_policy); |
| 1896 | if (err) |
| 1897 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1898 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1899 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1900 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1901 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1902 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1903 | if (!ifidx) |
| 1904 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1905 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1906 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1907 | rtnl_lock(); |
| 1908 | |
| 1909 | netdev = __dev_get_by_index(&init_net, ifidx); |
| 1910 | if (!netdev) { |
| 1911 | err = -ENODEV; |
| 1912 | goto out_rtnl; |
| 1913 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1914 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1915 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1916 | if (IS_ERR(dev)) { |
| 1917 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1918 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1922 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1923 | goto out_err; |
| 1924 | } |
| 1925 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1926 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1927 | err = -EOPNOTSUPP; |
| 1928 | goto out; |
| 1929 | } |
| 1930 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1931 | while (1) { |
| 1932 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 1933 | dst, next_hop, &pinfo); |
| 1934 | if (err == -ENOENT) |
| 1935 | break; |
| 1936 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1937 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1938 | |
| 1939 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 1940 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1941 | netdev, dst, next_hop, |
| 1942 | &pinfo) < 0) |
| 1943 | goto out; |
| 1944 | |
| 1945 | path_idx++; |
| 1946 | } |
| 1947 | |
| 1948 | |
| 1949 | out: |
| 1950 | cb->args[1] = path_idx; |
| 1951 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1952 | out_err: |
| 1953 | cfg80211_put_dev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1954 | out_rtnl: |
| 1955 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1956 | |
| 1957 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1961 | { |
| 1962 | struct cfg80211_registered_device *drv; |
| 1963 | int err; |
| 1964 | struct net_device *dev; |
| 1965 | struct mpath_info pinfo; |
| 1966 | struct sk_buff *msg; |
| 1967 | u8 *dst = NULL; |
| 1968 | u8 next_hop[ETH_ALEN]; |
| 1969 | |
| 1970 | memset(&pinfo, 0, sizeof(pinfo)); |
| 1971 | |
| 1972 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1973 | return -EINVAL; |
| 1974 | |
| 1975 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1976 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1977 | rtnl_lock(); |
| 1978 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1979 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1980 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1981 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1982 | |
| 1983 | if (!drv->ops->get_mpath) { |
| 1984 | err = -EOPNOTSUPP; |
| 1985 | goto out; |
| 1986 | } |
| 1987 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1988 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1989 | err = -EOPNOTSUPP; |
| 1990 | goto out; |
| 1991 | } |
| 1992 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1993 | err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1994 | if (err) |
| 1995 | goto out; |
| 1996 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1997 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1998 | if (!msg) |
| 1999 | goto out; |
| 2000 | |
| 2001 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 2002 | dev, dst, next_hop, &pinfo) < 0) |
| 2003 | goto out_free; |
| 2004 | |
| 2005 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2006 | goto out; |
| 2007 | |
| 2008 | out_free: |
| 2009 | nlmsg_free(msg); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2010 | out: |
| 2011 | cfg80211_put_dev(drv); |
| 2012 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2013 | out_rtnl: |
| 2014 | rtnl_unlock(); |
| 2015 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2016 | return err; |
| 2017 | } |
| 2018 | |
| 2019 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2020 | { |
| 2021 | struct cfg80211_registered_device *drv; |
| 2022 | int err; |
| 2023 | struct net_device *dev; |
| 2024 | u8 *dst = NULL; |
| 2025 | u8 *next_hop = NULL; |
| 2026 | |
| 2027 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2028 | return -EINVAL; |
| 2029 | |
| 2030 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2031 | return -EINVAL; |
| 2032 | |
| 2033 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2034 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2035 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2036 | rtnl_lock(); |
| 2037 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2038 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2039 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2040 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2041 | |
| 2042 | if (!drv->ops->change_mpath) { |
| 2043 | err = -EOPNOTSUPP; |
| 2044 | goto out; |
| 2045 | } |
| 2046 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2047 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2048 | err = -EOPNOTSUPP; |
| 2049 | goto out; |
| 2050 | } |
| 2051 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2052 | if (!netif_running(dev)) { |
| 2053 | err = -ENETDOWN; |
| 2054 | goto out; |
| 2055 | } |
| 2056 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2057 | err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2058 | |
| 2059 | out: |
| 2060 | cfg80211_put_dev(drv); |
| 2061 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2062 | out_rtnl: |
| 2063 | rtnl_unlock(); |
| 2064 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2065 | return err; |
| 2066 | } |
| 2067 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2068 | { |
| 2069 | struct cfg80211_registered_device *drv; |
| 2070 | int err; |
| 2071 | struct net_device *dev; |
| 2072 | u8 *dst = NULL; |
| 2073 | u8 *next_hop = NULL; |
| 2074 | |
| 2075 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2076 | return -EINVAL; |
| 2077 | |
| 2078 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2079 | return -EINVAL; |
| 2080 | |
| 2081 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2082 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2083 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2084 | rtnl_lock(); |
| 2085 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2086 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2087 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2088 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2089 | |
| 2090 | if (!drv->ops->add_mpath) { |
| 2091 | err = -EOPNOTSUPP; |
| 2092 | goto out; |
| 2093 | } |
| 2094 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2095 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2096 | err = -EOPNOTSUPP; |
| 2097 | goto out; |
| 2098 | } |
| 2099 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2100 | if (!netif_running(dev)) { |
| 2101 | err = -ENETDOWN; |
| 2102 | goto out; |
| 2103 | } |
| 2104 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2105 | err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2106 | |
| 2107 | out: |
| 2108 | cfg80211_put_dev(drv); |
| 2109 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2110 | out_rtnl: |
| 2111 | rtnl_unlock(); |
| 2112 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2113 | return err; |
| 2114 | } |
| 2115 | |
| 2116 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2117 | { |
| 2118 | struct cfg80211_registered_device *drv; |
| 2119 | int err; |
| 2120 | struct net_device *dev; |
| 2121 | u8 *dst = NULL; |
| 2122 | |
| 2123 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2124 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2125 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2126 | rtnl_lock(); |
| 2127 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2128 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2129 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2130 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2131 | |
| 2132 | if (!drv->ops->del_mpath) { |
| 2133 | err = -EOPNOTSUPP; |
| 2134 | goto out; |
| 2135 | } |
| 2136 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2137 | err = drv->ops->del_mpath(&drv->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2138 | |
| 2139 | out: |
| 2140 | cfg80211_put_dev(drv); |
| 2141 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2142 | out_rtnl: |
| 2143 | rtnl_unlock(); |
| 2144 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2145 | return err; |
| 2146 | } |
| 2147 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2148 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2149 | { |
| 2150 | struct cfg80211_registered_device *drv; |
| 2151 | int err; |
| 2152 | struct net_device *dev; |
| 2153 | struct bss_parameters params; |
| 2154 | |
| 2155 | memset(¶ms, 0, sizeof(params)); |
| 2156 | /* default to not changing parameters */ |
| 2157 | params.use_cts_prot = -1; |
| 2158 | params.use_short_preamble = -1; |
| 2159 | params.use_short_slot_time = -1; |
| 2160 | |
| 2161 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2162 | params.use_cts_prot = |
| 2163 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2164 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2165 | params.use_short_preamble = |
| 2166 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2167 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2168 | params.use_short_slot_time = |
| 2169 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2170 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2171 | params.basic_rates = |
| 2172 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2173 | params.basic_rates_len = |
| 2174 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2175 | } |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2176 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2177 | rtnl_lock(); |
| 2178 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2179 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2180 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2181 | goto out_rtnl; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2182 | |
| 2183 | if (!drv->ops->change_bss) { |
| 2184 | err = -EOPNOTSUPP; |
| 2185 | goto out; |
| 2186 | } |
| 2187 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2188 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 2189 | err = -EOPNOTSUPP; |
| 2190 | goto out; |
| 2191 | } |
| 2192 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2193 | err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2194 | |
| 2195 | out: |
| 2196 | cfg80211_put_dev(drv); |
| 2197 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2198 | out_rtnl: |
| 2199 | rtnl_unlock(); |
| 2200 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2201 | return err; |
| 2202 | } |
| 2203 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2204 | static const struct nla_policy |
| 2205 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 2206 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2207 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2208 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2209 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2210 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2211 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2212 | }; |
| 2213 | |
| 2214 | static int parse_reg_rule(struct nlattr *tb[], |
| 2215 | struct ieee80211_reg_rule *reg_rule) |
| 2216 | { |
| 2217 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2218 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2219 | |
| 2220 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2221 | return -EINVAL; |
| 2222 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2223 | return -EINVAL; |
| 2224 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2225 | return -EINVAL; |
| 2226 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2227 | return -EINVAL; |
| 2228 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2229 | return -EINVAL; |
| 2230 | |
| 2231 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2232 | |
| 2233 | freq_range->start_freq_khz = |
| 2234 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2235 | freq_range->end_freq_khz = |
| 2236 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2237 | freq_range->max_bandwidth_khz = |
| 2238 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2239 | |
| 2240 | power_rule->max_eirp = |
| 2241 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2242 | |
| 2243 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2244 | power_rule->max_antenna_gain = |
| 2245 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2246 | |
| 2247 | return 0; |
| 2248 | } |
| 2249 | |
| 2250 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2251 | { |
| 2252 | int r; |
| 2253 | char *data = NULL; |
| 2254 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2255 | /* |
| 2256 | * You should only get this when cfg80211 hasn't yet initialized |
| 2257 | * completely when built-in to the kernel right between the time |
| 2258 | * window between nl80211_init() and regulatory_init(), if that is |
| 2259 | * even possible. |
| 2260 | */ |
| 2261 | mutex_lock(&cfg80211_mutex); |
| 2262 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2263 | mutex_unlock(&cfg80211_mutex); |
| 2264 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2265 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2266 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2267 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2268 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2269 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2270 | |
| 2271 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2272 | |
| 2273 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 2274 | /* We ignore world regdom requests with the old regdom setup */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2275 | if (is_world_regdom(data)) |
| 2276 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2277 | #endif |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2278 | |
| 2279 | r = regulatory_hint_user(data); |
| 2280 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2281 | return r; |
| 2282 | } |
| 2283 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2284 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 2285 | struct genl_info *info) |
| 2286 | { |
| 2287 | struct cfg80211_registered_device *drv; |
| 2288 | struct mesh_config cur_params; |
| 2289 | int err; |
| 2290 | struct net_device *dev; |
| 2291 | void *hdr; |
| 2292 | struct nlattr *pinfoattr; |
| 2293 | struct sk_buff *msg; |
| 2294 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2295 | rtnl_lock(); |
| 2296 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2297 | /* Look up our device */ |
| 2298 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2299 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2300 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2301 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2302 | if (!drv->ops->get_mesh_params) { |
| 2303 | err = -EOPNOTSUPP; |
| 2304 | goto out; |
| 2305 | } |
| 2306 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2307 | /* Get the mesh params */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2308 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2309 | if (err) |
| 2310 | goto out; |
| 2311 | |
| 2312 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2313 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2314 | if (!msg) { |
| 2315 | err = -ENOBUFS; |
| 2316 | goto out; |
| 2317 | } |
| 2318 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2319 | NL80211_CMD_GET_MESH_PARAMS); |
| 2320 | if (!hdr) |
| 2321 | goto nla_put_failure; |
| 2322 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 2323 | if (!pinfoattr) |
| 2324 | goto nla_put_failure; |
| 2325 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2326 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2327 | cur_params.dot11MeshRetryTimeout); |
| 2328 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2329 | cur_params.dot11MeshConfirmTimeout); |
| 2330 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2331 | cur_params.dot11MeshHoldingTimeout); |
| 2332 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2333 | cur_params.dot11MeshMaxPeerLinks); |
| 2334 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2335 | cur_params.dot11MeshMaxRetries); |
| 2336 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2337 | cur_params.dot11MeshTTL); |
| 2338 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2339 | cur_params.auto_open_plinks); |
| 2340 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2341 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2342 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2343 | cur_params.path_refresh_time); |
| 2344 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2345 | cur_params.min_discovery_timeout); |
| 2346 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2347 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2348 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2349 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2350 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2351 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
| 2352 | nla_nest_end(msg, pinfoattr); |
| 2353 | genlmsg_end(msg, hdr); |
| 2354 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2355 | goto out; |
| 2356 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2357 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2358 | genlmsg_cancel(msg, hdr); |
| 2359 | err = -EMSGSIZE; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2360 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2361 | /* Cleanup */ |
| 2362 | cfg80211_put_dev(drv); |
| 2363 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2364 | out_rtnl: |
| 2365 | rtnl_unlock(); |
| 2366 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2367 | return err; |
| 2368 | } |
| 2369 | |
| 2370 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2371 | do {\ |
| 2372 | if (table[attr_num]) {\ |
| 2373 | cfg.param = nla_fn(table[attr_num]); \ |
| 2374 | mask |= (1 << (attr_num - 1)); \ |
| 2375 | } \ |
| 2376 | } while (0);\ |
| 2377 | |
| 2378 | static struct nla_policy |
| 2379 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { |
| 2380 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2381 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2382 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2383 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2384 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2385 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 2386 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2387 | |
| 2388 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2389 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2390 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2391 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2392 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2393 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2394 | }; |
| 2395 | |
| 2396 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 2397 | { |
| 2398 | int err; |
| 2399 | u32 mask; |
| 2400 | struct cfg80211_registered_device *drv; |
| 2401 | struct net_device *dev; |
| 2402 | struct mesh_config cfg; |
| 2403 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 2404 | struct nlattr *parent_attr; |
| 2405 | |
| 2406 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 2407 | if (!parent_attr) |
| 2408 | return -EINVAL; |
| 2409 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 2410 | parent_attr, nl80211_meshconf_params_policy)) |
| 2411 | return -EINVAL; |
| 2412 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2413 | rtnl_lock(); |
| 2414 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2415 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2416 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2417 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2418 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2419 | if (!drv->ops->set_mesh_params) { |
| 2420 | err = -EOPNOTSUPP; |
| 2421 | goto out; |
| 2422 | } |
| 2423 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2424 | /* This makes sure that there aren't more than 32 mesh config |
| 2425 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2426 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2427 | |
| 2428 | /* Fill in the params struct */ |
| 2429 | mask = 0; |
| 2430 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2431 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2432 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2433 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2434 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2435 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2436 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2437 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2438 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2439 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2440 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2441 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 2442 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2443 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2444 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2445 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2446 | nla_get_u8); |
| 2447 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2448 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2449 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2450 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2451 | nla_get_u16); |
| 2452 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2453 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2454 | nla_get_u32); |
| 2455 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2456 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2457 | nla_get_u16); |
| 2458 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2459 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2460 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2461 | nla_get_u16); |
| 2462 | |
| 2463 | /* Apply changes */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2464 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2465 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2466 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2467 | /* cleanup */ |
| 2468 | cfg80211_put_dev(drv); |
| 2469 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2470 | out_rtnl: |
| 2471 | rtnl_unlock(); |
| 2472 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2473 | return err; |
| 2474 | } |
| 2475 | |
| 2476 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2477 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2478 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2479 | { |
| 2480 | struct sk_buff *msg; |
| 2481 | void *hdr = NULL; |
| 2482 | struct nlattr *nl_reg_rules; |
| 2483 | unsigned int i; |
| 2484 | int err = -EINVAL; |
| 2485 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2486 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2487 | |
| 2488 | if (!cfg80211_regdomain) |
| 2489 | goto out; |
| 2490 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2491 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2492 | if (!msg) { |
| 2493 | err = -ENOBUFS; |
| 2494 | goto out; |
| 2495 | } |
| 2496 | |
| 2497 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2498 | NL80211_CMD_GET_REG); |
| 2499 | if (!hdr) |
| 2500 | goto nla_put_failure; |
| 2501 | |
| 2502 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 2503 | cfg80211_regdomain->alpha2); |
| 2504 | |
| 2505 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 2506 | if (!nl_reg_rules) |
| 2507 | goto nla_put_failure; |
| 2508 | |
| 2509 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 2510 | struct nlattr *nl_reg_rule; |
| 2511 | const struct ieee80211_reg_rule *reg_rule; |
| 2512 | const struct ieee80211_freq_range *freq_range; |
| 2513 | const struct ieee80211_power_rule *power_rule; |
| 2514 | |
| 2515 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 2516 | freq_range = ®_rule->freq_range; |
| 2517 | power_rule = ®_rule->power_rule; |
| 2518 | |
| 2519 | nl_reg_rule = nla_nest_start(msg, i); |
| 2520 | if (!nl_reg_rule) |
| 2521 | goto nla_put_failure; |
| 2522 | |
| 2523 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 2524 | reg_rule->flags); |
| 2525 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 2526 | freq_range->start_freq_khz); |
| 2527 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 2528 | freq_range->end_freq_khz); |
| 2529 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 2530 | freq_range->max_bandwidth_khz); |
| 2531 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 2532 | power_rule->max_antenna_gain); |
| 2533 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 2534 | power_rule->max_eirp); |
| 2535 | |
| 2536 | nla_nest_end(msg, nl_reg_rule); |
| 2537 | } |
| 2538 | |
| 2539 | nla_nest_end(msg, nl_reg_rules); |
| 2540 | |
| 2541 | genlmsg_end(msg, hdr); |
| 2542 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2543 | goto out; |
| 2544 | |
| 2545 | nla_put_failure: |
| 2546 | genlmsg_cancel(msg, hdr); |
| 2547 | err = -EMSGSIZE; |
| 2548 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2549 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2550 | return err; |
| 2551 | } |
| 2552 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2553 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2554 | { |
| 2555 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 2556 | struct nlattr *nl_reg_rule; |
| 2557 | char *alpha2 = NULL; |
| 2558 | int rem_reg_rules = 0, r = 0; |
| 2559 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 2560 | struct ieee80211_regdomain *rd = NULL; |
| 2561 | |
| 2562 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2563 | return -EINVAL; |
| 2564 | |
| 2565 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 2566 | return -EINVAL; |
| 2567 | |
| 2568 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2569 | |
| 2570 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2571 | rem_reg_rules) { |
| 2572 | num_rules++; |
| 2573 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 2574 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2575 | } |
| 2576 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2577 | mutex_lock(&cfg80211_mutex); |
| 2578 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2579 | if (!reg_is_valid_request(alpha2)) { |
| 2580 | r = -EINVAL; |
| 2581 | goto bad_reg; |
| 2582 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2583 | |
| 2584 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 2585 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 2586 | |
| 2587 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2588 | if (!rd) { |
| 2589 | r = -ENOMEM; |
| 2590 | goto bad_reg; |
| 2591 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2592 | |
| 2593 | rd->n_reg_rules = num_rules; |
| 2594 | rd->alpha2[0] = alpha2[0]; |
| 2595 | rd->alpha2[1] = alpha2[1]; |
| 2596 | |
| 2597 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2598 | rem_reg_rules) { |
| 2599 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 2600 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 2601 | reg_rule_policy); |
| 2602 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 2603 | if (r) |
| 2604 | goto bad_reg; |
| 2605 | |
| 2606 | rule_idx++; |
| 2607 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2608 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 2609 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2610 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2611 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | BUG_ON(rule_idx != num_rules); |
| 2615 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2616 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2617 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2618 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2619 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2620 | return r; |
| 2621 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2622 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2623 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2624 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2625 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2628 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 2629 | { |
| 2630 | struct cfg80211_registered_device *drv; |
| 2631 | struct net_device *dev; |
| 2632 | struct cfg80211_scan_request *request; |
| 2633 | struct cfg80211_ssid *ssid; |
| 2634 | struct ieee80211_channel *channel; |
| 2635 | struct nlattr *attr; |
| 2636 | struct wiphy *wiphy; |
| 2637 | int err, tmp, n_ssids = 0, n_channels = 0, i; |
| 2638 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2639 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2640 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2641 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2642 | return -EINVAL; |
| 2643 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2644 | rtnl_lock(); |
| 2645 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2646 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2647 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2648 | goto out_rtnl; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2649 | |
| 2650 | wiphy = &drv->wiphy; |
| 2651 | |
| 2652 | if (!drv->ops->scan) { |
| 2653 | err = -EOPNOTSUPP; |
| 2654 | goto out; |
| 2655 | } |
| 2656 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2657 | if (!netif_running(dev)) { |
| 2658 | err = -ENETDOWN; |
| 2659 | goto out; |
| 2660 | } |
| 2661 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2662 | if (drv->scan_req) { |
| 2663 | err = -EBUSY; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2664 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 2668 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) |
| 2669 | n_channels++; |
| 2670 | if (!n_channels) { |
| 2671 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2672 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2673 | } |
| 2674 | } else { |
| 2675 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 2676 | if (wiphy->bands[band]) |
| 2677 | n_channels += wiphy->bands[band]->n_channels; |
| 2678 | } |
| 2679 | |
| 2680 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 2681 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 2682 | n_ssids++; |
| 2683 | |
| 2684 | if (n_ssids > wiphy->max_scan_ssids) { |
| 2685 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2686 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2687 | } |
| 2688 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2689 | if (info->attrs[NL80211_ATTR_IE]) |
| 2690 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2691 | else |
| 2692 | ie_len = 0; |
| 2693 | |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 2694 | if (ie_len > wiphy->max_scan_ie_len) { |
| 2695 | err = -EINVAL; |
| 2696 | goto out; |
| 2697 | } |
| 2698 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2699 | request = kzalloc(sizeof(*request) |
| 2700 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2701 | + sizeof(channel) * n_channels |
| 2702 | + ie_len, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2703 | if (!request) { |
| 2704 | err = -ENOMEM; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2705 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | request->channels = (void *)((char *)request + sizeof(*request)); |
| 2709 | request->n_channels = n_channels; |
| 2710 | if (n_ssids) |
| 2711 | request->ssids = (void *)(request->channels + n_channels); |
| 2712 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2713 | if (ie_len) { |
| 2714 | if (request->ssids) |
| 2715 | request->ie = (void *)(request->ssids + n_ssids); |
| 2716 | else |
| 2717 | request->ie = (void *)(request->channels + n_channels); |
| 2718 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2719 | |
| 2720 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 2721 | /* user specified, bail out if channel not found */ |
| 2722 | request->n_channels = n_channels; |
| 2723 | i = 0; |
| 2724 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
| 2725 | request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 2726 | if (!request->channels[i]) { |
| 2727 | err = -EINVAL; |
| 2728 | goto out_free; |
| 2729 | } |
| 2730 | i++; |
| 2731 | } |
| 2732 | } else { |
| 2733 | /* all channels */ |
| 2734 | i = 0; |
| 2735 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2736 | int j; |
| 2737 | if (!wiphy->bands[band]) |
| 2738 | continue; |
| 2739 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 2740 | request->channels[i] = &wiphy->bands[band]->channels[j]; |
| 2741 | i++; |
| 2742 | } |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | i = 0; |
| 2747 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 2748 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 2749 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 2750 | err = -EINVAL; |
| 2751 | goto out_free; |
| 2752 | } |
| 2753 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 2754 | request->ssids[i].ssid_len = nla_len(attr); |
| 2755 | i++; |
| 2756 | } |
| 2757 | } |
| 2758 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2759 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2760 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 2761 | memcpy((void *)request->ie, |
| 2762 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2763 | request->ie_len); |
| 2764 | } |
| 2765 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2766 | request->ifidx = dev->ifindex; |
| 2767 | request->wiphy = &drv->wiphy; |
| 2768 | |
| 2769 | drv->scan_req = request; |
| 2770 | err = drv->ops->scan(&drv->wiphy, dev, request); |
| 2771 | |
| 2772 | out_free: |
| 2773 | if (err) { |
| 2774 | drv->scan_req = NULL; |
| 2775 | kfree(request); |
| 2776 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2777 | out: |
| 2778 | cfg80211_put_dev(drv); |
| 2779 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2780 | out_rtnl: |
| 2781 | rtnl_unlock(); |
| 2782 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2783 | return err; |
| 2784 | } |
| 2785 | |
| 2786 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 2787 | struct cfg80211_registered_device *rdev, |
| 2788 | struct net_device *dev, |
| 2789 | struct cfg80211_bss *res) |
| 2790 | { |
| 2791 | void *hdr; |
| 2792 | struct nlattr *bss; |
| 2793 | |
| 2794 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 2795 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 2796 | if (!hdr) |
| 2797 | return -1; |
| 2798 | |
| 2799 | NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION, |
| 2800 | rdev->bss_generation); |
| 2801 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2802 | |
| 2803 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 2804 | if (!bss) |
| 2805 | goto nla_put_failure; |
| 2806 | if (!is_zero_ether_addr(res->bssid)) |
| 2807 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 2808 | if (res->information_elements && res->len_information_elements) |
| 2809 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 2810 | res->len_information_elements, |
| 2811 | res->information_elements); |
| 2812 | if (res->tsf) |
| 2813 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 2814 | if (res->beacon_interval) |
| 2815 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 2816 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 2817 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
| 2818 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2819 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2820 | case CFG80211_SIGNAL_TYPE_MBM: |
| 2821 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 2822 | break; |
| 2823 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 2824 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 2825 | break; |
| 2826 | default: |
| 2827 | break; |
| 2828 | } |
| 2829 | |
| 2830 | nla_nest_end(msg, bss); |
| 2831 | |
| 2832 | return genlmsg_end(msg, hdr); |
| 2833 | |
| 2834 | nla_put_failure: |
| 2835 | genlmsg_cancel(msg, hdr); |
| 2836 | return -EMSGSIZE; |
| 2837 | } |
| 2838 | |
| 2839 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 2840 | struct netlink_callback *cb) |
| 2841 | { |
| 2842 | struct cfg80211_registered_device *dev; |
| 2843 | struct net_device *netdev; |
| 2844 | struct cfg80211_internal_bss *scan; |
| 2845 | int ifidx = cb->args[0]; |
| 2846 | int start = cb->args[1], idx = 0; |
| 2847 | int err; |
| 2848 | |
| 2849 | if (!ifidx) { |
| 2850 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2851 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 2852 | nl80211_policy); |
| 2853 | if (err) |
| 2854 | return err; |
| 2855 | |
| 2856 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 2857 | return -EINVAL; |
| 2858 | |
| 2859 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 2860 | if (!ifidx) |
| 2861 | return -EINVAL; |
| 2862 | cb->args[0] = ifidx; |
| 2863 | } |
| 2864 | |
| 2865 | netdev = dev_get_by_index(&init_net, ifidx); |
| 2866 | if (!netdev) |
| 2867 | return -ENODEV; |
| 2868 | |
| 2869 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 2870 | if (IS_ERR(dev)) { |
| 2871 | err = PTR_ERR(dev); |
| 2872 | goto out_put_netdev; |
| 2873 | } |
| 2874 | |
| 2875 | spin_lock_bh(&dev->bss_lock); |
| 2876 | cfg80211_bss_expire(dev); |
| 2877 | |
| 2878 | list_for_each_entry(scan, &dev->bss_list, list) { |
| 2879 | if (++idx <= start) |
| 2880 | continue; |
| 2881 | if (nl80211_send_bss(skb, |
| 2882 | NETLINK_CB(cb->skb).pid, |
| 2883 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2884 | dev, netdev, &scan->pub) < 0) { |
| 2885 | idx--; |
| 2886 | goto out; |
| 2887 | } |
| 2888 | } |
| 2889 | |
| 2890 | out: |
| 2891 | spin_unlock_bh(&dev->bss_lock); |
| 2892 | |
| 2893 | cb->args[1] = idx; |
| 2894 | err = skb->len; |
| 2895 | cfg80211_put_dev(dev); |
| 2896 | out_put_netdev: |
| 2897 | dev_put(netdev); |
| 2898 | |
| 2899 | return err; |
| 2900 | } |
| 2901 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 2902 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 2903 | { |
| 2904 | return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM || |
| 2905 | auth_type == NL80211_AUTHTYPE_SHARED_KEY || |
| 2906 | auth_type == NL80211_AUTHTYPE_FT || |
| 2907 | auth_type == NL80211_AUTHTYPE_NETWORK_EAP; |
| 2908 | } |
| 2909 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2910 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 2911 | { |
| 2912 | struct cfg80211_registered_device *drv; |
| 2913 | struct net_device *dev; |
| 2914 | struct cfg80211_auth_request req; |
| 2915 | struct wiphy *wiphy; |
| 2916 | int err; |
| 2917 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2918 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2919 | return -EINVAL; |
| 2920 | |
| 2921 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2922 | return -EINVAL; |
| 2923 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 2924 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 2925 | return -EINVAL; |
| 2926 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2927 | rtnl_lock(); |
| 2928 | |
| 2929 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2930 | if (err) |
| 2931 | goto unlock_rtnl; |
| 2932 | |
| 2933 | if (!drv->ops->auth) { |
| 2934 | err = -EOPNOTSUPP; |
| 2935 | goto out; |
| 2936 | } |
| 2937 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2938 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 2939 | err = -EOPNOTSUPP; |
| 2940 | goto out; |
| 2941 | } |
| 2942 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2943 | if (!netif_running(dev)) { |
| 2944 | err = -ENETDOWN; |
| 2945 | goto out; |
| 2946 | } |
| 2947 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2948 | wiphy = &drv->wiphy; |
| 2949 | memset(&req, 0, sizeof(req)); |
| 2950 | |
| 2951 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2952 | |
| 2953 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2954 | req.chan = ieee80211_get_channel( |
| 2955 | wiphy, |
| 2956 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2957 | if (!req.chan) { |
| 2958 | err = -EINVAL; |
| 2959 | goto out; |
| 2960 | } |
| 2961 | } |
| 2962 | |
| 2963 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2964 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2965 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2966 | } |
| 2967 | |
| 2968 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2969 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2970 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2971 | } |
| 2972 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 2973 | req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2974 | if (!nl80211_valid_auth_type(req.auth_type)) { |
| 2975 | err = -EINVAL; |
| 2976 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | err = drv->ops->auth(&drv->wiphy, dev, &req); |
| 2980 | |
| 2981 | out: |
| 2982 | cfg80211_put_dev(drv); |
| 2983 | dev_put(dev); |
| 2984 | unlock_rtnl: |
| 2985 | rtnl_unlock(); |
| 2986 | return err; |
| 2987 | } |
| 2988 | |
| 2989 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 2990 | { |
| 2991 | struct cfg80211_registered_device *drv; |
| 2992 | struct net_device *dev; |
| 2993 | struct cfg80211_assoc_request req; |
| 2994 | struct wiphy *wiphy; |
| 2995 | int err; |
| 2996 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2997 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2998 | return -EINVAL; |
| 2999 | |
| 3000 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 3001 | !info->attrs[NL80211_ATTR_SSID]) |
| 3002 | return -EINVAL; |
| 3003 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3004 | rtnl_lock(); |
| 3005 | |
| 3006 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3007 | if (err) |
| 3008 | goto unlock_rtnl; |
| 3009 | |
| 3010 | if (!drv->ops->assoc) { |
| 3011 | err = -EOPNOTSUPP; |
| 3012 | goto out; |
| 3013 | } |
| 3014 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3016 | err = -EOPNOTSUPP; |
| 3017 | goto out; |
| 3018 | } |
| 3019 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3020 | if (!netif_running(dev)) { |
| 3021 | err = -ENETDOWN; |
| 3022 | goto out; |
| 3023 | } |
| 3024 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3025 | wiphy = &drv->wiphy; |
| 3026 | memset(&req, 0, sizeof(req)); |
| 3027 | |
| 3028 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3029 | |
| 3030 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 3031 | req.chan = ieee80211_get_channel( |
| 3032 | wiphy, |
| 3033 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3034 | if (!req.chan) { |
| 3035 | err = -EINVAL; |
| 3036 | goto out; |
| 3037 | } |
| 3038 | } |
| 3039 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3040 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3041 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3042 | |
| 3043 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3044 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3045 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3046 | } |
| 3047 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3048 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 3049 | enum nl80211_mfp use_mfp = |
| 3050 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 3051 | if (use_mfp == NL80211_MFP_REQUIRED) |
| 3052 | req.use_mfp = true; |
| 3053 | else if (use_mfp != NL80211_MFP_NO) { |
| 3054 | err = -EINVAL; |
| 3055 | goto out; |
| 3056 | } |
| 3057 | } |
| 3058 | |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 3059 | req.control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3060 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3061 | err = drv->ops->assoc(&drv->wiphy, dev, &req); |
| 3062 | |
| 3063 | out: |
| 3064 | cfg80211_put_dev(drv); |
| 3065 | dev_put(dev); |
| 3066 | unlock_rtnl: |
| 3067 | rtnl_unlock(); |
| 3068 | return err; |
| 3069 | } |
| 3070 | |
| 3071 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3072 | { |
| 3073 | struct cfg80211_registered_device *drv; |
| 3074 | struct net_device *dev; |
| 3075 | struct cfg80211_deauth_request req; |
| 3076 | struct wiphy *wiphy; |
| 3077 | int err; |
| 3078 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3079 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3080 | return -EINVAL; |
| 3081 | |
| 3082 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3083 | return -EINVAL; |
| 3084 | |
| 3085 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3086 | return -EINVAL; |
| 3087 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3088 | rtnl_lock(); |
| 3089 | |
| 3090 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3091 | if (err) |
| 3092 | goto unlock_rtnl; |
| 3093 | |
| 3094 | if (!drv->ops->deauth) { |
| 3095 | err = -EOPNOTSUPP; |
| 3096 | goto out; |
| 3097 | } |
| 3098 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3099 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3100 | err = -EOPNOTSUPP; |
| 3101 | goto out; |
| 3102 | } |
| 3103 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3104 | if (!netif_running(dev)) { |
| 3105 | err = -ENETDOWN; |
| 3106 | goto out; |
| 3107 | } |
| 3108 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3109 | wiphy = &drv->wiphy; |
| 3110 | memset(&req, 0, sizeof(req)); |
| 3111 | |
| 3112 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3113 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3114 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3115 | if (req.reason_code == 0) { |
| 3116 | /* Reason Code 0 is reserved */ |
| 3117 | err = -EINVAL; |
| 3118 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3119 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3120 | |
| 3121 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3122 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3123 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3124 | } |
| 3125 | |
| 3126 | err = drv->ops->deauth(&drv->wiphy, dev, &req); |
| 3127 | |
| 3128 | out: |
| 3129 | cfg80211_put_dev(drv); |
| 3130 | dev_put(dev); |
| 3131 | unlock_rtnl: |
| 3132 | rtnl_unlock(); |
| 3133 | return err; |
| 3134 | } |
| 3135 | |
| 3136 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3137 | { |
| 3138 | struct cfg80211_registered_device *drv; |
| 3139 | struct net_device *dev; |
| 3140 | struct cfg80211_disassoc_request req; |
| 3141 | struct wiphy *wiphy; |
| 3142 | int err; |
| 3143 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3144 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3145 | return -EINVAL; |
| 3146 | |
| 3147 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3148 | return -EINVAL; |
| 3149 | |
| 3150 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3151 | return -EINVAL; |
| 3152 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3153 | rtnl_lock(); |
| 3154 | |
| 3155 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3156 | if (err) |
| 3157 | goto unlock_rtnl; |
| 3158 | |
| 3159 | if (!drv->ops->disassoc) { |
| 3160 | err = -EOPNOTSUPP; |
| 3161 | goto out; |
| 3162 | } |
| 3163 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3164 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3165 | err = -EOPNOTSUPP; |
| 3166 | goto out; |
| 3167 | } |
| 3168 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3169 | if (!netif_running(dev)) { |
| 3170 | err = -ENETDOWN; |
| 3171 | goto out; |
| 3172 | } |
| 3173 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3174 | wiphy = &drv->wiphy; |
| 3175 | memset(&req, 0, sizeof(req)); |
| 3176 | |
| 3177 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3178 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3179 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3180 | if (req.reason_code == 0) { |
| 3181 | /* Reason Code 0 is reserved */ |
| 3182 | err = -EINVAL; |
| 3183 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3184 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3185 | |
| 3186 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3187 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3188 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3189 | } |
| 3190 | |
| 3191 | err = drv->ops->disassoc(&drv->wiphy, dev, &req); |
| 3192 | |
| 3193 | out: |
| 3194 | cfg80211_put_dev(drv); |
| 3195 | dev_put(dev); |
| 3196 | unlock_rtnl: |
| 3197 | rtnl_unlock(); |
| 3198 | return err; |
| 3199 | } |
| 3200 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3201 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3202 | { |
| 3203 | struct cfg80211_registered_device *drv; |
| 3204 | struct net_device *dev; |
| 3205 | struct cfg80211_ibss_params ibss; |
| 3206 | struct wiphy *wiphy; |
| 3207 | int err; |
| 3208 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3209 | memset(&ibss, 0, sizeof(ibss)); |
| 3210 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3211 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3212 | return -EINVAL; |
| 3213 | |
| 3214 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 3215 | !info->attrs[NL80211_ATTR_SSID] || |
| 3216 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3217 | return -EINVAL; |
| 3218 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3219 | ibss.beacon_interval = 100; |
| 3220 | |
| 3221 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 3222 | ibss.beacon_interval = |
| 3223 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3224 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 3225 | return -EINVAL; |
| 3226 | } |
| 3227 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3228 | rtnl_lock(); |
| 3229 | |
| 3230 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3231 | if (err) |
| 3232 | goto unlock_rtnl; |
| 3233 | |
| 3234 | if (!drv->ops->join_ibss) { |
| 3235 | err = -EOPNOTSUPP; |
| 3236 | goto out; |
| 3237 | } |
| 3238 | |
| 3239 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 3240 | err = -EOPNOTSUPP; |
| 3241 | goto out; |
| 3242 | } |
| 3243 | |
| 3244 | if (!netif_running(dev)) { |
| 3245 | err = -ENETDOWN; |
| 3246 | goto out; |
| 3247 | } |
| 3248 | |
| 3249 | wiphy = &drv->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3250 | |
| 3251 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3252 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3253 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3254 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3255 | |
| 3256 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3257 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3258 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3259 | } |
| 3260 | |
| 3261 | ibss.channel = ieee80211_get_channel(wiphy, |
| 3262 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3263 | if (!ibss.channel || |
| 3264 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
| 3265 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 3266 | err = -EINVAL; |
| 3267 | goto out; |
| 3268 | } |
| 3269 | |
| 3270 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
| 3271 | |
| 3272 | err = cfg80211_join_ibss(drv, dev, &ibss); |
| 3273 | |
| 3274 | out: |
| 3275 | cfg80211_put_dev(drv); |
| 3276 | dev_put(dev); |
| 3277 | unlock_rtnl: |
| 3278 | rtnl_unlock(); |
| 3279 | return err; |
| 3280 | } |
| 3281 | |
| 3282 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3283 | { |
| 3284 | struct cfg80211_registered_device *drv; |
| 3285 | struct net_device *dev; |
| 3286 | int err; |
| 3287 | |
| 3288 | rtnl_lock(); |
| 3289 | |
| 3290 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3291 | if (err) |
| 3292 | goto unlock_rtnl; |
| 3293 | |
| 3294 | if (!drv->ops->leave_ibss) { |
| 3295 | err = -EOPNOTSUPP; |
| 3296 | goto out; |
| 3297 | } |
| 3298 | |
| 3299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 3300 | err = -EOPNOTSUPP; |
| 3301 | goto out; |
| 3302 | } |
| 3303 | |
| 3304 | if (!netif_running(dev)) { |
| 3305 | err = -ENETDOWN; |
| 3306 | goto out; |
| 3307 | } |
| 3308 | |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 3309 | err = cfg80211_leave_ibss(drv, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3310 | |
| 3311 | out: |
| 3312 | cfg80211_put_dev(drv); |
| 3313 | dev_put(dev); |
| 3314 | unlock_rtnl: |
| 3315 | rtnl_unlock(); |
| 3316 | return err; |
| 3317 | } |
| 3318 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3319 | static struct genl_ops nl80211_ops[] = { |
| 3320 | { |
| 3321 | .cmd = NL80211_CMD_GET_WIPHY, |
| 3322 | .doit = nl80211_get_wiphy, |
| 3323 | .dumpit = nl80211_dump_wiphy, |
| 3324 | .policy = nl80211_policy, |
| 3325 | /* can be retrieved by unprivileged users */ |
| 3326 | }, |
| 3327 | { |
| 3328 | .cmd = NL80211_CMD_SET_WIPHY, |
| 3329 | .doit = nl80211_set_wiphy, |
| 3330 | .policy = nl80211_policy, |
| 3331 | .flags = GENL_ADMIN_PERM, |
| 3332 | }, |
| 3333 | { |
| 3334 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 3335 | .doit = nl80211_get_interface, |
| 3336 | .dumpit = nl80211_dump_interface, |
| 3337 | .policy = nl80211_policy, |
| 3338 | /* can be retrieved by unprivileged users */ |
| 3339 | }, |
| 3340 | { |
| 3341 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 3342 | .doit = nl80211_set_interface, |
| 3343 | .policy = nl80211_policy, |
| 3344 | .flags = GENL_ADMIN_PERM, |
| 3345 | }, |
| 3346 | { |
| 3347 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 3348 | .doit = nl80211_new_interface, |
| 3349 | .policy = nl80211_policy, |
| 3350 | .flags = GENL_ADMIN_PERM, |
| 3351 | }, |
| 3352 | { |
| 3353 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 3354 | .doit = nl80211_del_interface, |
| 3355 | .policy = nl80211_policy, |
| 3356 | .flags = GENL_ADMIN_PERM, |
| 3357 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3358 | { |
| 3359 | .cmd = NL80211_CMD_GET_KEY, |
| 3360 | .doit = nl80211_get_key, |
| 3361 | .policy = nl80211_policy, |
| 3362 | .flags = GENL_ADMIN_PERM, |
| 3363 | }, |
| 3364 | { |
| 3365 | .cmd = NL80211_CMD_SET_KEY, |
| 3366 | .doit = nl80211_set_key, |
| 3367 | .policy = nl80211_policy, |
| 3368 | .flags = GENL_ADMIN_PERM, |
| 3369 | }, |
| 3370 | { |
| 3371 | .cmd = NL80211_CMD_NEW_KEY, |
| 3372 | .doit = nl80211_new_key, |
| 3373 | .policy = nl80211_policy, |
| 3374 | .flags = GENL_ADMIN_PERM, |
| 3375 | }, |
| 3376 | { |
| 3377 | .cmd = NL80211_CMD_DEL_KEY, |
| 3378 | .doit = nl80211_del_key, |
| 3379 | .policy = nl80211_policy, |
| 3380 | .flags = GENL_ADMIN_PERM, |
| 3381 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3382 | { |
| 3383 | .cmd = NL80211_CMD_SET_BEACON, |
| 3384 | .policy = nl80211_policy, |
| 3385 | .flags = GENL_ADMIN_PERM, |
| 3386 | .doit = nl80211_addset_beacon, |
| 3387 | }, |
| 3388 | { |
| 3389 | .cmd = NL80211_CMD_NEW_BEACON, |
| 3390 | .policy = nl80211_policy, |
| 3391 | .flags = GENL_ADMIN_PERM, |
| 3392 | .doit = nl80211_addset_beacon, |
| 3393 | }, |
| 3394 | { |
| 3395 | .cmd = NL80211_CMD_DEL_BEACON, |
| 3396 | .policy = nl80211_policy, |
| 3397 | .flags = GENL_ADMIN_PERM, |
| 3398 | .doit = nl80211_del_beacon, |
| 3399 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3400 | { |
| 3401 | .cmd = NL80211_CMD_GET_STATION, |
| 3402 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3403 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3404 | .policy = nl80211_policy, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3405 | }, |
| 3406 | { |
| 3407 | .cmd = NL80211_CMD_SET_STATION, |
| 3408 | .doit = nl80211_set_station, |
| 3409 | .policy = nl80211_policy, |
| 3410 | .flags = GENL_ADMIN_PERM, |
| 3411 | }, |
| 3412 | { |
| 3413 | .cmd = NL80211_CMD_NEW_STATION, |
| 3414 | .doit = nl80211_new_station, |
| 3415 | .policy = nl80211_policy, |
| 3416 | .flags = GENL_ADMIN_PERM, |
| 3417 | }, |
| 3418 | { |
| 3419 | .cmd = NL80211_CMD_DEL_STATION, |
| 3420 | .doit = nl80211_del_station, |
| 3421 | .policy = nl80211_policy, |
| 3422 | .flags = GENL_ADMIN_PERM, |
| 3423 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3424 | { |
| 3425 | .cmd = NL80211_CMD_GET_MPATH, |
| 3426 | .doit = nl80211_get_mpath, |
| 3427 | .dumpit = nl80211_dump_mpath, |
| 3428 | .policy = nl80211_policy, |
| 3429 | .flags = GENL_ADMIN_PERM, |
| 3430 | }, |
| 3431 | { |
| 3432 | .cmd = NL80211_CMD_SET_MPATH, |
| 3433 | .doit = nl80211_set_mpath, |
| 3434 | .policy = nl80211_policy, |
| 3435 | .flags = GENL_ADMIN_PERM, |
| 3436 | }, |
| 3437 | { |
| 3438 | .cmd = NL80211_CMD_NEW_MPATH, |
| 3439 | .doit = nl80211_new_mpath, |
| 3440 | .policy = nl80211_policy, |
| 3441 | .flags = GENL_ADMIN_PERM, |
| 3442 | }, |
| 3443 | { |
| 3444 | .cmd = NL80211_CMD_DEL_MPATH, |
| 3445 | .doit = nl80211_del_mpath, |
| 3446 | .policy = nl80211_policy, |
| 3447 | .flags = GENL_ADMIN_PERM, |
| 3448 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3449 | { |
| 3450 | .cmd = NL80211_CMD_SET_BSS, |
| 3451 | .doit = nl80211_set_bss, |
| 3452 | .policy = nl80211_policy, |
| 3453 | .flags = GENL_ADMIN_PERM, |
| 3454 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3455 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3456 | .cmd = NL80211_CMD_GET_REG, |
| 3457 | .doit = nl80211_get_reg, |
| 3458 | .policy = nl80211_policy, |
| 3459 | /* can be retrieved by unprivileged users */ |
| 3460 | }, |
| 3461 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3462 | .cmd = NL80211_CMD_SET_REG, |
| 3463 | .doit = nl80211_set_reg, |
| 3464 | .policy = nl80211_policy, |
| 3465 | .flags = GENL_ADMIN_PERM, |
| 3466 | }, |
| 3467 | { |
| 3468 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 3469 | .doit = nl80211_req_set_reg, |
| 3470 | .policy = nl80211_policy, |
| 3471 | .flags = GENL_ADMIN_PERM, |
| 3472 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3473 | { |
| 3474 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 3475 | .doit = nl80211_get_mesh_params, |
| 3476 | .policy = nl80211_policy, |
| 3477 | /* can be retrieved by unprivileged users */ |
| 3478 | }, |
| 3479 | { |
| 3480 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 3481 | .doit = nl80211_set_mesh_params, |
| 3482 | .policy = nl80211_policy, |
| 3483 | .flags = GENL_ADMIN_PERM, |
| 3484 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 3485 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3486 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 3487 | .doit = nl80211_trigger_scan, |
| 3488 | .policy = nl80211_policy, |
| 3489 | .flags = GENL_ADMIN_PERM, |
| 3490 | }, |
| 3491 | { |
| 3492 | .cmd = NL80211_CMD_GET_SCAN, |
| 3493 | .policy = nl80211_policy, |
| 3494 | .dumpit = nl80211_dump_scan, |
| 3495 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3496 | { |
| 3497 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 3498 | .doit = nl80211_authenticate, |
| 3499 | .policy = nl80211_policy, |
| 3500 | .flags = GENL_ADMIN_PERM, |
| 3501 | }, |
| 3502 | { |
| 3503 | .cmd = NL80211_CMD_ASSOCIATE, |
| 3504 | .doit = nl80211_associate, |
| 3505 | .policy = nl80211_policy, |
| 3506 | .flags = GENL_ADMIN_PERM, |
| 3507 | }, |
| 3508 | { |
| 3509 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 3510 | .doit = nl80211_deauthenticate, |
| 3511 | .policy = nl80211_policy, |
| 3512 | .flags = GENL_ADMIN_PERM, |
| 3513 | }, |
| 3514 | { |
| 3515 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 3516 | .doit = nl80211_disassociate, |
| 3517 | .policy = nl80211_policy, |
| 3518 | .flags = GENL_ADMIN_PERM, |
| 3519 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3520 | { |
| 3521 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 3522 | .doit = nl80211_join_ibss, |
| 3523 | .policy = nl80211_policy, |
| 3524 | .flags = GENL_ADMIN_PERM, |
| 3525 | }, |
| 3526 | { |
| 3527 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 3528 | .doit = nl80211_leave_ibss, |
| 3529 | .policy = nl80211_policy, |
| 3530 | .flags = GENL_ADMIN_PERM, |
| 3531 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3532 | }; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3533 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 3534 | .name = "mlme", |
| 3535 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3536 | |
| 3537 | /* multicast groups */ |
| 3538 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 3539 | .name = "config", |
| 3540 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3541 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 3542 | .name = "scan", |
| 3543 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3544 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 3545 | .name = "regulatory", |
| 3546 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3547 | |
| 3548 | /* notification functions */ |
| 3549 | |
| 3550 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 3551 | { |
| 3552 | struct sk_buff *msg; |
| 3553 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3554 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3555 | if (!msg) |
| 3556 | return; |
| 3557 | |
| 3558 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 3559 | nlmsg_free(msg); |
| 3560 | return; |
| 3561 | } |
| 3562 | |
| 3563 | genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); |
| 3564 | } |
| 3565 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3566 | static int nl80211_send_scan_donemsg(struct sk_buff *msg, |
| 3567 | struct cfg80211_registered_device *rdev, |
| 3568 | struct net_device *netdev, |
| 3569 | u32 pid, u32 seq, int flags, |
| 3570 | u32 cmd) |
| 3571 | { |
| 3572 | void *hdr; |
| 3573 | |
| 3574 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 3575 | if (!hdr) |
| 3576 | return -1; |
| 3577 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 3578 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3579 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3580 | |
| 3581 | /* XXX: we should probably bounce back the request? */ |
| 3582 | |
| 3583 | return genlmsg_end(msg, hdr); |
| 3584 | |
| 3585 | nla_put_failure: |
| 3586 | genlmsg_cancel(msg, hdr); |
| 3587 | return -EMSGSIZE; |
| 3588 | } |
| 3589 | |
| 3590 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 3591 | struct net_device *netdev) |
| 3592 | { |
| 3593 | struct sk_buff *msg; |
| 3594 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3595 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3596 | if (!msg) |
| 3597 | return; |
| 3598 | |
| 3599 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, |
| 3600 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
| 3601 | nlmsg_free(msg); |
| 3602 | return; |
| 3603 | } |
| 3604 | |
| 3605 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 3606 | } |
| 3607 | |
| 3608 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 3609 | struct net_device *netdev) |
| 3610 | { |
| 3611 | struct sk_buff *msg; |
| 3612 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3613 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3614 | if (!msg) |
| 3615 | return; |
| 3616 | |
| 3617 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, |
| 3618 | NL80211_CMD_SCAN_ABORTED) < 0) { |
| 3619 | nlmsg_free(msg); |
| 3620 | return; |
| 3621 | } |
| 3622 | |
| 3623 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 3624 | } |
| 3625 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3626 | /* |
| 3627 | * This can happen on global regulatory changes or device specific settings |
| 3628 | * based on custom world regulatory domains. |
| 3629 | */ |
| 3630 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 3631 | { |
| 3632 | struct sk_buff *msg; |
| 3633 | void *hdr; |
| 3634 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3635 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3636 | if (!msg) |
| 3637 | return; |
| 3638 | |
| 3639 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 3640 | if (!hdr) { |
| 3641 | nlmsg_free(msg); |
| 3642 | return; |
| 3643 | } |
| 3644 | |
| 3645 | /* Userspace can always count this one always being set */ |
| 3646 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 3647 | |
| 3648 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 3649 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3650 | NL80211_REGDOM_TYPE_WORLD); |
| 3651 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 3652 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3653 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 3654 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 3655 | request->intersect) |
| 3656 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3657 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 3658 | else { |
| 3659 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3660 | NL80211_REGDOM_TYPE_COUNTRY); |
| 3661 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 3662 | } |
| 3663 | |
| 3664 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 3665 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 3666 | |
| 3667 | if (genlmsg_end(msg, hdr) < 0) { |
| 3668 | nlmsg_free(msg); |
| 3669 | return; |
| 3670 | } |
| 3671 | |
| 3672 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL); |
| 3673 | |
| 3674 | return; |
| 3675 | |
| 3676 | nla_put_failure: |
| 3677 | genlmsg_cancel(msg, hdr); |
| 3678 | nlmsg_free(msg); |
| 3679 | } |
| 3680 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3681 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 3682 | struct net_device *netdev, |
| 3683 | const u8 *buf, size_t len, |
| 3684 | enum nl80211_commands cmd) |
| 3685 | { |
| 3686 | struct sk_buff *msg; |
| 3687 | void *hdr; |
| 3688 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3689 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3690 | if (!msg) |
| 3691 | return; |
| 3692 | |
| 3693 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 3694 | if (!hdr) { |
| 3695 | nlmsg_free(msg); |
| 3696 | return; |
| 3697 | } |
| 3698 | |
| 3699 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3700 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3701 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 3702 | |
| 3703 | if (genlmsg_end(msg, hdr) < 0) { |
| 3704 | nlmsg_free(msg); |
| 3705 | return; |
| 3706 | } |
| 3707 | |
Jouni Malinen | d91c01c | 2009-04-18 21:53:15 +0300 | [diff] [blame] | 3708 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3709 | return; |
| 3710 | |
| 3711 | nla_put_failure: |
| 3712 | genlmsg_cancel(msg, hdr); |
| 3713 | nlmsg_free(msg); |
| 3714 | } |
| 3715 | |
| 3716 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
| 3717 | struct net_device *netdev, const u8 *buf, size_t len) |
| 3718 | { |
| 3719 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3720 | NL80211_CMD_AUTHENTICATE); |
| 3721 | } |
| 3722 | |
| 3723 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 3724 | struct net_device *netdev, const u8 *buf, |
| 3725 | size_t len) |
| 3726 | { |
| 3727 | nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE); |
| 3728 | } |
| 3729 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 3730 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
| 3731 | struct net_device *netdev, const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3732 | { |
| 3733 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3734 | NL80211_CMD_DEAUTHENTICATE); |
| 3735 | } |
| 3736 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 3737 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 3738 | struct net_device *netdev, const u8 *buf, |
| 3739 | size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3740 | { |
| 3741 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3742 | NL80211_CMD_DISASSOCIATE); |
| 3743 | } |
| 3744 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 3745 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 3746 | struct net_device *netdev, int cmd, |
| 3747 | const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 3748 | { |
| 3749 | struct sk_buff *msg; |
| 3750 | void *hdr; |
| 3751 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3752 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 3753 | if (!msg) |
| 3754 | return; |
| 3755 | |
| 3756 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 3757 | if (!hdr) { |
| 3758 | nlmsg_free(msg); |
| 3759 | return; |
| 3760 | } |
| 3761 | |
| 3762 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3763 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3764 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 3765 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 3766 | |
| 3767 | if (genlmsg_end(msg, hdr) < 0) { |
| 3768 | nlmsg_free(msg); |
| 3769 | return; |
| 3770 | } |
| 3771 | |
| 3772 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); |
| 3773 | return; |
| 3774 | |
| 3775 | nla_put_failure: |
| 3776 | genlmsg_cancel(msg, hdr); |
| 3777 | nlmsg_free(msg); |
| 3778 | } |
| 3779 | |
| 3780 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
| 3781 | struct net_device *netdev, const u8 *addr) |
| 3782 | { |
| 3783 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
| 3784 | addr); |
| 3785 | } |
| 3786 | |
| 3787 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
| 3788 | struct net_device *netdev, const u8 *addr) |
| 3789 | { |
| 3790 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, addr); |
| 3791 | } |
| 3792 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3793 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 3794 | struct net_device *netdev, const u8 *bssid, |
| 3795 | gfp_t gfp) |
| 3796 | { |
| 3797 | struct sk_buff *msg; |
| 3798 | void *hdr; |
| 3799 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3800 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3801 | if (!msg) |
| 3802 | return; |
| 3803 | |
| 3804 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 3805 | if (!hdr) { |
| 3806 | nlmsg_free(msg); |
| 3807 | return; |
| 3808 | } |
| 3809 | |
| 3810 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3811 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3812 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 3813 | |
| 3814 | if (genlmsg_end(msg, hdr) < 0) { |
| 3815 | nlmsg_free(msg); |
| 3816 | return; |
| 3817 | } |
| 3818 | |
| 3819 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 3820 | return; |
| 3821 | |
| 3822 | nla_put_failure: |
| 3823 | genlmsg_cancel(msg, hdr); |
| 3824 | nlmsg_free(msg); |
| 3825 | } |
| 3826 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 3827 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 3828 | struct net_device *netdev, const u8 *addr, |
| 3829 | enum nl80211_key_type key_type, int key_id, |
| 3830 | const u8 *tsc) |
| 3831 | { |
| 3832 | struct sk_buff *msg; |
| 3833 | void *hdr; |
| 3834 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3835 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 3836 | if (!msg) |
| 3837 | return; |
| 3838 | |
| 3839 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 3840 | if (!hdr) { |
| 3841 | nlmsg_free(msg); |
| 3842 | return; |
| 3843 | } |
| 3844 | |
| 3845 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3846 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3847 | if (addr) |
| 3848 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 3849 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 3850 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 3851 | if (tsc) |
| 3852 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 3853 | |
| 3854 | if (genlmsg_end(msg, hdr) < 0) { |
| 3855 | nlmsg_free(msg); |
| 3856 | return; |
| 3857 | } |
| 3858 | |
| 3859 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 3860 | return; |
| 3861 | |
| 3862 | nla_put_failure: |
| 3863 | genlmsg_cancel(msg, hdr); |
| 3864 | nlmsg_free(msg); |
| 3865 | } |
| 3866 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 3867 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 3868 | struct ieee80211_channel *channel_before, |
| 3869 | struct ieee80211_channel *channel_after) |
| 3870 | { |
| 3871 | struct sk_buff *msg; |
| 3872 | void *hdr; |
| 3873 | struct nlattr *nl_freq; |
| 3874 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 3875 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 3876 | if (!msg) |
| 3877 | return; |
| 3878 | |
| 3879 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 3880 | if (!hdr) { |
| 3881 | nlmsg_free(msg); |
| 3882 | return; |
| 3883 | } |
| 3884 | |
| 3885 | /* |
| 3886 | * Since we are applying the beacon hint to a wiphy we know its |
| 3887 | * wiphy_idx is valid |
| 3888 | */ |
| 3889 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 3890 | |
| 3891 | /* Before */ |
| 3892 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 3893 | if (!nl_freq) |
| 3894 | goto nla_put_failure; |
| 3895 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 3896 | goto nla_put_failure; |
| 3897 | nla_nest_end(msg, nl_freq); |
| 3898 | |
| 3899 | /* After */ |
| 3900 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 3901 | if (!nl_freq) |
| 3902 | goto nla_put_failure; |
| 3903 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 3904 | goto nla_put_failure; |
| 3905 | nla_nest_end(msg, nl_freq); |
| 3906 | |
| 3907 | if (genlmsg_end(msg, hdr) < 0) { |
| 3908 | nlmsg_free(msg); |
| 3909 | return; |
| 3910 | } |
| 3911 | |
| 3912 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC); |
| 3913 | |
| 3914 | return; |
| 3915 | |
| 3916 | nla_put_failure: |
| 3917 | genlmsg_cancel(msg, hdr); |
| 3918 | nlmsg_free(msg); |
| 3919 | } |
| 3920 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3921 | /* initialisation/exit functions */ |
| 3922 | |
| 3923 | int nl80211_init(void) |
| 3924 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 3925 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3926 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 3927 | err = genl_register_family_with_ops(&nl80211_fam, |
| 3928 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3929 | if (err) |
| 3930 | return err; |
| 3931 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3932 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 3933 | if (err) |
| 3934 | goto err_out; |
| 3935 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3936 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 3937 | if (err) |
| 3938 | goto err_out; |
| 3939 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3940 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 3941 | if (err) |
| 3942 | goto err_out; |
| 3943 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3944 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 3945 | if (err) |
| 3946 | goto err_out; |
| 3947 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3948 | return 0; |
| 3949 | err_out: |
| 3950 | genl_unregister_family(&nl80211_fam); |
| 3951 | return err; |
| 3952 | } |
| 3953 | |
| 3954 | void nl80211_exit(void) |
| 3955 | { |
| 3956 | genl_unregister_family(&nl80211_fam); |
| 3957 | } |