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