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 | |
| 1749 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1750 | if (err) |
| 1751 | goto out; |
| 1752 | |
| 1753 | if (!drv->ops->add_station) { |
| 1754 | err = -EOPNOTSUPP; |
| 1755 | goto out; |
| 1756 | } |
| 1757 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 1758 | if (!netif_running(dev)) { |
| 1759 | err = -ENETDOWN; |
| 1760 | goto out; |
| 1761 | } |
| 1762 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1763 | err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1764 | |
| 1765 | out: |
| 1766 | if (params.vlan) |
| 1767 | dev_put(params.vlan); |
| 1768 | cfg80211_put_dev(drv); |
| 1769 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1770 | out_rtnl: |
| 1771 | rtnl_unlock(); |
| 1772 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1773 | return err; |
| 1774 | } |
| 1775 | |
| 1776 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 1777 | { |
| 1778 | struct cfg80211_registered_device *drv; |
| 1779 | int err; |
| 1780 | struct net_device *dev; |
| 1781 | u8 *mac_addr = NULL; |
| 1782 | |
| 1783 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1784 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1785 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1786 | rtnl_lock(); |
| 1787 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1788 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1789 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1790 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1791 | |
| 1792 | if (!drv->ops->del_station) { |
| 1793 | err = -EOPNOTSUPP; |
| 1794 | goto out; |
| 1795 | } |
| 1796 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1797 | err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1798 | |
| 1799 | out: |
| 1800 | cfg80211_put_dev(drv); |
| 1801 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1802 | out_rtnl: |
| 1803 | rtnl_unlock(); |
| 1804 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1805 | return err; |
| 1806 | } |
| 1807 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1808 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 1809 | int flags, struct net_device *dev, |
| 1810 | u8 *dst, u8 *next_hop, |
| 1811 | struct mpath_info *pinfo) |
| 1812 | { |
| 1813 | void *hdr; |
| 1814 | struct nlattr *pinfoattr; |
| 1815 | |
| 1816 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1817 | if (!hdr) |
| 1818 | return -1; |
| 1819 | |
| 1820 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1821 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 1822 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 1823 | |
| 1824 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 1825 | if (!pinfoattr) |
| 1826 | goto nla_put_failure; |
| 1827 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 1828 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 1829 | pinfo->frame_qlen); |
| 1830 | if (pinfo->filled & MPATH_INFO_DSN) |
| 1831 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, |
| 1832 | pinfo->dsn); |
| 1833 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 1834 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 1835 | pinfo->metric); |
| 1836 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 1837 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 1838 | pinfo->exptime); |
| 1839 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 1840 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 1841 | pinfo->flags); |
| 1842 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 1843 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 1844 | pinfo->discovery_timeout); |
| 1845 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 1846 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 1847 | pinfo->discovery_retries); |
| 1848 | |
| 1849 | nla_nest_end(msg, pinfoattr); |
| 1850 | |
| 1851 | return genlmsg_end(msg, hdr); |
| 1852 | |
| 1853 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1854 | genlmsg_cancel(msg, hdr); |
| 1855 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1856 | } |
| 1857 | |
| 1858 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1859 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1860 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1861 | struct mpath_info pinfo; |
| 1862 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1863 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1864 | u8 dst[ETH_ALEN]; |
| 1865 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1866 | int ifidx = cb->args[0]; |
| 1867 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1868 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1869 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1870 | if (!ifidx) { |
| 1871 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1872 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1873 | nl80211_policy); |
| 1874 | if (err) |
| 1875 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1876 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1877 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1878 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1879 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1880 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1881 | if (!ifidx) |
| 1882 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1883 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1884 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1885 | rtnl_lock(); |
| 1886 | |
| 1887 | netdev = __dev_get_by_index(&init_net, ifidx); |
| 1888 | if (!netdev) { |
| 1889 | err = -ENODEV; |
| 1890 | goto out_rtnl; |
| 1891 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1892 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1893 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1894 | if (IS_ERR(dev)) { |
| 1895 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1896 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1900 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1901 | goto out_err; |
| 1902 | } |
| 1903 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1904 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1905 | err = -EOPNOTSUPP; |
| 1906 | goto out; |
| 1907 | } |
| 1908 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1909 | while (1) { |
| 1910 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 1911 | dst, next_hop, &pinfo); |
| 1912 | if (err == -ENOENT) |
| 1913 | break; |
| 1914 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1915 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1916 | |
| 1917 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 1918 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1919 | netdev, dst, next_hop, |
| 1920 | &pinfo) < 0) |
| 1921 | goto out; |
| 1922 | |
| 1923 | path_idx++; |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | out: |
| 1928 | cb->args[1] = path_idx; |
| 1929 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1930 | out_err: |
| 1931 | cfg80211_put_dev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1932 | out_rtnl: |
| 1933 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1934 | |
| 1935 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1939 | { |
| 1940 | struct cfg80211_registered_device *drv; |
| 1941 | int err; |
| 1942 | struct net_device *dev; |
| 1943 | struct mpath_info pinfo; |
| 1944 | struct sk_buff *msg; |
| 1945 | u8 *dst = NULL; |
| 1946 | u8 next_hop[ETH_ALEN]; |
| 1947 | |
| 1948 | memset(&pinfo, 0, sizeof(pinfo)); |
| 1949 | |
| 1950 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1951 | return -EINVAL; |
| 1952 | |
| 1953 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1954 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1955 | rtnl_lock(); |
| 1956 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1957 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1958 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1959 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1960 | |
| 1961 | if (!drv->ops->get_mpath) { |
| 1962 | err = -EOPNOTSUPP; |
| 1963 | goto out; |
| 1964 | } |
| 1965 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1966 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1967 | err = -EOPNOTSUPP; |
| 1968 | goto out; |
| 1969 | } |
| 1970 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1971 | 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] | 1972 | if (err) |
| 1973 | goto out; |
| 1974 | |
| 1975 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1976 | if (!msg) |
| 1977 | goto out; |
| 1978 | |
| 1979 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 1980 | dev, dst, next_hop, &pinfo) < 0) |
| 1981 | goto out_free; |
| 1982 | |
| 1983 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1984 | goto out; |
| 1985 | |
| 1986 | out_free: |
| 1987 | nlmsg_free(msg); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1988 | out: |
| 1989 | cfg80211_put_dev(drv); |
| 1990 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1991 | out_rtnl: |
| 1992 | rtnl_unlock(); |
| 1993 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1994 | return err; |
| 1995 | } |
| 1996 | |
| 1997 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1998 | { |
| 1999 | struct cfg80211_registered_device *drv; |
| 2000 | int err; |
| 2001 | struct net_device *dev; |
| 2002 | u8 *dst = NULL; |
| 2003 | u8 *next_hop = NULL; |
| 2004 | |
| 2005 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2006 | return -EINVAL; |
| 2007 | |
| 2008 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2009 | return -EINVAL; |
| 2010 | |
| 2011 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2012 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2013 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2014 | rtnl_lock(); |
| 2015 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2016 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2017 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2018 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2019 | |
| 2020 | if (!drv->ops->change_mpath) { |
| 2021 | err = -EOPNOTSUPP; |
| 2022 | goto out; |
| 2023 | } |
| 2024 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2025 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2026 | err = -EOPNOTSUPP; |
| 2027 | goto out; |
| 2028 | } |
| 2029 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2030 | if (!netif_running(dev)) { |
| 2031 | err = -ENETDOWN; |
| 2032 | goto out; |
| 2033 | } |
| 2034 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2035 | err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2036 | |
| 2037 | out: |
| 2038 | cfg80211_put_dev(drv); |
| 2039 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2040 | out_rtnl: |
| 2041 | rtnl_unlock(); |
| 2042 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2043 | return err; |
| 2044 | } |
| 2045 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2046 | { |
| 2047 | struct cfg80211_registered_device *drv; |
| 2048 | int err; |
| 2049 | struct net_device *dev; |
| 2050 | u8 *dst = NULL; |
| 2051 | u8 *next_hop = NULL; |
| 2052 | |
| 2053 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2054 | return -EINVAL; |
| 2055 | |
| 2056 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2057 | return -EINVAL; |
| 2058 | |
| 2059 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2060 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2061 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2062 | rtnl_lock(); |
| 2063 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2064 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2065 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2066 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2067 | |
| 2068 | if (!drv->ops->add_mpath) { |
| 2069 | err = -EOPNOTSUPP; |
| 2070 | goto out; |
| 2071 | } |
| 2072 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2073 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2074 | err = -EOPNOTSUPP; |
| 2075 | goto out; |
| 2076 | } |
| 2077 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2078 | if (!netif_running(dev)) { |
| 2079 | err = -ENETDOWN; |
| 2080 | goto out; |
| 2081 | } |
| 2082 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2083 | err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2084 | |
| 2085 | out: |
| 2086 | cfg80211_put_dev(drv); |
| 2087 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2088 | out_rtnl: |
| 2089 | rtnl_unlock(); |
| 2090 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2091 | return err; |
| 2092 | } |
| 2093 | |
| 2094 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2095 | { |
| 2096 | struct cfg80211_registered_device *drv; |
| 2097 | int err; |
| 2098 | struct net_device *dev; |
| 2099 | u8 *dst = NULL; |
| 2100 | |
| 2101 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2102 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2103 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2104 | rtnl_lock(); |
| 2105 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2106 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2107 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2108 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2109 | |
| 2110 | if (!drv->ops->del_mpath) { |
| 2111 | err = -EOPNOTSUPP; |
| 2112 | goto out; |
| 2113 | } |
| 2114 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2115 | err = drv->ops->del_mpath(&drv->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2116 | |
| 2117 | out: |
| 2118 | cfg80211_put_dev(drv); |
| 2119 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2120 | out_rtnl: |
| 2121 | rtnl_unlock(); |
| 2122 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2123 | return err; |
| 2124 | } |
| 2125 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2126 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2127 | { |
| 2128 | struct cfg80211_registered_device *drv; |
| 2129 | int err; |
| 2130 | struct net_device *dev; |
| 2131 | struct bss_parameters params; |
| 2132 | |
| 2133 | memset(¶ms, 0, sizeof(params)); |
| 2134 | /* default to not changing parameters */ |
| 2135 | params.use_cts_prot = -1; |
| 2136 | params.use_short_preamble = -1; |
| 2137 | params.use_short_slot_time = -1; |
| 2138 | |
| 2139 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2140 | params.use_cts_prot = |
| 2141 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2142 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2143 | params.use_short_preamble = |
| 2144 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2145 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2146 | params.use_short_slot_time = |
| 2147 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2148 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2149 | params.basic_rates = |
| 2150 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2151 | params.basic_rates_len = |
| 2152 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2153 | } |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2154 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2155 | rtnl_lock(); |
| 2156 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2157 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2158 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2159 | goto out_rtnl; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2160 | |
| 2161 | if (!drv->ops->change_bss) { |
| 2162 | err = -EOPNOTSUPP; |
| 2163 | goto out; |
| 2164 | } |
| 2165 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2166 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 2167 | err = -EOPNOTSUPP; |
| 2168 | goto out; |
| 2169 | } |
| 2170 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2171 | err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2172 | |
| 2173 | out: |
| 2174 | cfg80211_put_dev(drv); |
| 2175 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2176 | out_rtnl: |
| 2177 | rtnl_unlock(); |
| 2178 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2179 | return err; |
| 2180 | } |
| 2181 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2182 | static const struct nla_policy |
| 2183 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 2184 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2185 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2186 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2187 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2188 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2189 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2190 | }; |
| 2191 | |
| 2192 | static int parse_reg_rule(struct nlattr *tb[], |
| 2193 | struct ieee80211_reg_rule *reg_rule) |
| 2194 | { |
| 2195 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2196 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2197 | |
| 2198 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2199 | return -EINVAL; |
| 2200 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2201 | return -EINVAL; |
| 2202 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2203 | return -EINVAL; |
| 2204 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2205 | return -EINVAL; |
| 2206 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2207 | return -EINVAL; |
| 2208 | |
| 2209 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2210 | |
| 2211 | freq_range->start_freq_khz = |
| 2212 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2213 | freq_range->end_freq_khz = |
| 2214 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2215 | freq_range->max_bandwidth_khz = |
| 2216 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2217 | |
| 2218 | power_rule->max_eirp = |
| 2219 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2220 | |
| 2221 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2222 | power_rule->max_antenna_gain = |
| 2223 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2224 | |
| 2225 | return 0; |
| 2226 | } |
| 2227 | |
| 2228 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2229 | { |
| 2230 | int r; |
| 2231 | char *data = NULL; |
| 2232 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2233 | /* |
| 2234 | * You should only get this when cfg80211 hasn't yet initialized |
| 2235 | * completely when built-in to the kernel right between the time |
| 2236 | * window between nl80211_init() and regulatory_init(), if that is |
| 2237 | * even possible. |
| 2238 | */ |
| 2239 | mutex_lock(&cfg80211_mutex); |
| 2240 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2241 | mutex_unlock(&cfg80211_mutex); |
| 2242 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2243 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2244 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2245 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2246 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2247 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2248 | |
| 2249 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2250 | |
| 2251 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 2252 | /* We ignore world regdom requests with the old regdom setup */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2253 | if (is_world_regdom(data)) |
| 2254 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2255 | #endif |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2256 | |
| 2257 | r = regulatory_hint_user(data); |
| 2258 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2259 | return r; |
| 2260 | } |
| 2261 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2262 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 2263 | struct genl_info *info) |
| 2264 | { |
| 2265 | struct cfg80211_registered_device *drv; |
| 2266 | struct mesh_config cur_params; |
| 2267 | int err; |
| 2268 | struct net_device *dev; |
| 2269 | void *hdr; |
| 2270 | struct nlattr *pinfoattr; |
| 2271 | struct sk_buff *msg; |
| 2272 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2273 | rtnl_lock(); |
| 2274 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2275 | /* Look up our device */ |
| 2276 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2277 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2278 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2279 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2280 | if (!drv->ops->get_mesh_params) { |
| 2281 | err = -EOPNOTSUPP; |
| 2282 | goto out; |
| 2283 | } |
| 2284 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2285 | /* Get the mesh params */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2286 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2287 | if (err) |
| 2288 | goto out; |
| 2289 | |
| 2290 | /* Draw up a netlink message to send back */ |
| 2291 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 2292 | if (!msg) { |
| 2293 | err = -ENOBUFS; |
| 2294 | goto out; |
| 2295 | } |
| 2296 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2297 | NL80211_CMD_GET_MESH_PARAMS); |
| 2298 | if (!hdr) |
| 2299 | goto nla_put_failure; |
| 2300 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 2301 | if (!pinfoattr) |
| 2302 | goto nla_put_failure; |
| 2303 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2304 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2305 | cur_params.dot11MeshRetryTimeout); |
| 2306 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2307 | cur_params.dot11MeshConfirmTimeout); |
| 2308 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2309 | cur_params.dot11MeshHoldingTimeout); |
| 2310 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2311 | cur_params.dot11MeshMaxPeerLinks); |
| 2312 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2313 | cur_params.dot11MeshMaxRetries); |
| 2314 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2315 | cur_params.dot11MeshTTL); |
| 2316 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2317 | cur_params.auto_open_plinks); |
| 2318 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2319 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2320 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2321 | cur_params.path_refresh_time); |
| 2322 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2323 | cur_params.min_discovery_timeout); |
| 2324 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2325 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2326 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2327 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2328 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2329 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
| 2330 | nla_nest_end(msg, pinfoattr); |
| 2331 | genlmsg_end(msg, hdr); |
| 2332 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2333 | goto out; |
| 2334 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2335 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2336 | genlmsg_cancel(msg, hdr); |
| 2337 | err = -EMSGSIZE; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2338 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2339 | /* Cleanup */ |
| 2340 | cfg80211_put_dev(drv); |
| 2341 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2342 | out_rtnl: |
| 2343 | rtnl_unlock(); |
| 2344 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2345 | return err; |
| 2346 | } |
| 2347 | |
| 2348 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2349 | do {\ |
| 2350 | if (table[attr_num]) {\ |
| 2351 | cfg.param = nla_fn(table[attr_num]); \ |
| 2352 | mask |= (1 << (attr_num - 1)); \ |
| 2353 | } \ |
| 2354 | } while (0);\ |
| 2355 | |
| 2356 | static struct nla_policy |
| 2357 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { |
| 2358 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2359 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2360 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2361 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2362 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2363 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 2364 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2365 | |
| 2366 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2367 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2368 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2369 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2370 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2371 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2372 | }; |
| 2373 | |
| 2374 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 2375 | { |
| 2376 | int err; |
| 2377 | u32 mask; |
| 2378 | struct cfg80211_registered_device *drv; |
| 2379 | struct net_device *dev; |
| 2380 | struct mesh_config cfg; |
| 2381 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 2382 | struct nlattr *parent_attr; |
| 2383 | |
| 2384 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 2385 | if (!parent_attr) |
| 2386 | return -EINVAL; |
| 2387 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 2388 | parent_attr, nl80211_meshconf_params_policy)) |
| 2389 | return -EINVAL; |
| 2390 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2391 | rtnl_lock(); |
| 2392 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2393 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2394 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2395 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2396 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2397 | if (!drv->ops->set_mesh_params) { |
| 2398 | err = -EOPNOTSUPP; |
| 2399 | goto out; |
| 2400 | } |
| 2401 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2402 | /* This makes sure that there aren't more than 32 mesh config |
| 2403 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2404 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2405 | |
| 2406 | /* Fill in the params struct */ |
| 2407 | mask = 0; |
| 2408 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2409 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2410 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2411 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2412 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2413 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2414 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2415 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2416 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2417 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2418 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2419 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 2420 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2421 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2422 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2423 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2424 | nla_get_u8); |
| 2425 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2426 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2427 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2428 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2429 | nla_get_u16); |
| 2430 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2431 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2432 | nla_get_u32); |
| 2433 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2434 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2435 | nla_get_u16); |
| 2436 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2437 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2438 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2439 | nla_get_u16); |
| 2440 | |
| 2441 | /* Apply changes */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2442 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2443 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2444 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2445 | /* cleanup */ |
| 2446 | cfg80211_put_dev(drv); |
| 2447 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2448 | out_rtnl: |
| 2449 | rtnl_unlock(); |
| 2450 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2451 | return err; |
| 2452 | } |
| 2453 | |
| 2454 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2455 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2456 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2457 | { |
| 2458 | struct sk_buff *msg; |
| 2459 | void *hdr = NULL; |
| 2460 | struct nlattr *nl_reg_rules; |
| 2461 | unsigned int i; |
| 2462 | int err = -EINVAL; |
| 2463 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2464 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2465 | |
| 2466 | if (!cfg80211_regdomain) |
| 2467 | goto out; |
| 2468 | |
| 2469 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 2470 | if (!msg) { |
| 2471 | err = -ENOBUFS; |
| 2472 | goto out; |
| 2473 | } |
| 2474 | |
| 2475 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2476 | NL80211_CMD_GET_REG); |
| 2477 | if (!hdr) |
| 2478 | goto nla_put_failure; |
| 2479 | |
| 2480 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 2481 | cfg80211_regdomain->alpha2); |
| 2482 | |
| 2483 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 2484 | if (!nl_reg_rules) |
| 2485 | goto nla_put_failure; |
| 2486 | |
| 2487 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 2488 | struct nlattr *nl_reg_rule; |
| 2489 | const struct ieee80211_reg_rule *reg_rule; |
| 2490 | const struct ieee80211_freq_range *freq_range; |
| 2491 | const struct ieee80211_power_rule *power_rule; |
| 2492 | |
| 2493 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 2494 | freq_range = ®_rule->freq_range; |
| 2495 | power_rule = ®_rule->power_rule; |
| 2496 | |
| 2497 | nl_reg_rule = nla_nest_start(msg, i); |
| 2498 | if (!nl_reg_rule) |
| 2499 | goto nla_put_failure; |
| 2500 | |
| 2501 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 2502 | reg_rule->flags); |
| 2503 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 2504 | freq_range->start_freq_khz); |
| 2505 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 2506 | freq_range->end_freq_khz); |
| 2507 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 2508 | freq_range->max_bandwidth_khz); |
| 2509 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 2510 | power_rule->max_antenna_gain); |
| 2511 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 2512 | power_rule->max_eirp); |
| 2513 | |
| 2514 | nla_nest_end(msg, nl_reg_rule); |
| 2515 | } |
| 2516 | |
| 2517 | nla_nest_end(msg, nl_reg_rules); |
| 2518 | |
| 2519 | genlmsg_end(msg, hdr); |
| 2520 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2521 | goto out; |
| 2522 | |
| 2523 | nla_put_failure: |
| 2524 | genlmsg_cancel(msg, hdr); |
| 2525 | err = -EMSGSIZE; |
| 2526 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2527 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2528 | return err; |
| 2529 | } |
| 2530 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2531 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2532 | { |
| 2533 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 2534 | struct nlattr *nl_reg_rule; |
| 2535 | char *alpha2 = NULL; |
| 2536 | int rem_reg_rules = 0, r = 0; |
| 2537 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 2538 | struct ieee80211_regdomain *rd = NULL; |
| 2539 | |
| 2540 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2541 | return -EINVAL; |
| 2542 | |
| 2543 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 2544 | return -EINVAL; |
| 2545 | |
| 2546 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2547 | |
| 2548 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2549 | rem_reg_rules) { |
| 2550 | num_rules++; |
| 2551 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 2552 | goto bad_reg; |
| 2553 | } |
| 2554 | |
| 2555 | if (!reg_is_valid_request(alpha2)) |
| 2556 | return -EINVAL; |
| 2557 | |
| 2558 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 2559 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 2560 | |
| 2561 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 2562 | if (!rd) |
| 2563 | return -ENOMEM; |
| 2564 | |
| 2565 | rd->n_reg_rules = num_rules; |
| 2566 | rd->alpha2[0] = alpha2[0]; |
| 2567 | rd->alpha2[1] = alpha2[1]; |
| 2568 | |
| 2569 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2570 | rem_reg_rules) { |
| 2571 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 2572 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 2573 | reg_rule_policy); |
| 2574 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 2575 | if (r) |
| 2576 | goto bad_reg; |
| 2577 | |
| 2578 | rule_idx++; |
| 2579 | |
| 2580 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) |
| 2581 | goto bad_reg; |
| 2582 | } |
| 2583 | |
| 2584 | BUG_ON(rule_idx != num_rules); |
| 2585 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2586 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2587 | r = set_regdom(rd); |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2588 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2589 | return r; |
| 2590 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2591 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2592 | kfree(rd); |
| 2593 | return -EINVAL; |
| 2594 | } |
| 2595 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2596 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 2597 | { |
| 2598 | struct cfg80211_registered_device *drv; |
| 2599 | struct net_device *dev; |
| 2600 | struct cfg80211_scan_request *request; |
| 2601 | struct cfg80211_ssid *ssid; |
| 2602 | struct ieee80211_channel *channel; |
| 2603 | struct nlattr *attr; |
| 2604 | struct wiphy *wiphy; |
| 2605 | int err, tmp, n_ssids = 0, n_channels = 0, i; |
| 2606 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2607 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2608 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2609 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2610 | return -EINVAL; |
| 2611 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2612 | rtnl_lock(); |
| 2613 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2614 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2615 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2616 | goto out_rtnl; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2617 | |
| 2618 | wiphy = &drv->wiphy; |
| 2619 | |
| 2620 | if (!drv->ops->scan) { |
| 2621 | err = -EOPNOTSUPP; |
| 2622 | goto out; |
| 2623 | } |
| 2624 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2625 | if (!netif_running(dev)) { |
| 2626 | err = -ENETDOWN; |
| 2627 | goto out; |
| 2628 | } |
| 2629 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2630 | if (drv->scan_req) { |
| 2631 | err = -EBUSY; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2632 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 2636 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) |
| 2637 | n_channels++; |
| 2638 | if (!n_channels) { |
| 2639 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2640 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2641 | } |
| 2642 | } else { |
| 2643 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 2644 | if (wiphy->bands[band]) |
| 2645 | n_channels += wiphy->bands[band]->n_channels; |
| 2646 | } |
| 2647 | |
| 2648 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 2649 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 2650 | n_ssids++; |
| 2651 | |
| 2652 | if (n_ssids > wiphy->max_scan_ssids) { |
| 2653 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2654 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2655 | } |
| 2656 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2657 | if (info->attrs[NL80211_ATTR_IE]) |
| 2658 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2659 | else |
| 2660 | ie_len = 0; |
| 2661 | |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 2662 | if (ie_len > wiphy->max_scan_ie_len) { |
| 2663 | err = -EINVAL; |
| 2664 | goto out; |
| 2665 | } |
| 2666 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2667 | request = kzalloc(sizeof(*request) |
| 2668 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2669 | + sizeof(channel) * n_channels |
| 2670 | + ie_len, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2671 | if (!request) { |
| 2672 | err = -ENOMEM; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2673 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2674 | } |
| 2675 | |
| 2676 | request->channels = (void *)((char *)request + sizeof(*request)); |
| 2677 | request->n_channels = n_channels; |
| 2678 | if (n_ssids) |
| 2679 | request->ssids = (void *)(request->channels + n_channels); |
| 2680 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2681 | if (ie_len) { |
| 2682 | if (request->ssids) |
| 2683 | request->ie = (void *)(request->ssids + n_ssids); |
| 2684 | else |
| 2685 | request->ie = (void *)(request->channels + n_channels); |
| 2686 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2687 | |
| 2688 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 2689 | /* user specified, bail out if channel not found */ |
| 2690 | request->n_channels = n_channels; |
| 2691 | i = 0; |
| 2692 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
| 2693 | request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 2694 | if (!request->channels[i]) { |
| 2695 | err = -EINVAL; |
| 2696 | goto out_free; |
| 2697 | } |
| 2698 | i++; |
| 2699 | } |
| 2700 | } else { |
| 2701 | /* all channels */ |
| 2702 | i = 0; |
| 2703 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2704 | int j; |
| 2705 | if (!wiphy->bands[band]) |
| 2706 | continue; |
| 2707 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 2708 | request->channels[i] = &wiphy->bands[band]->channels[j]; |
| 2709 | i++; |
| 2710 | } |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | i = 0; |
| 2715 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 2716 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 2717 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 2718 | err = -EINVAL; |
| 2719 | goto out_free; |
| 2720 | } |
| 2721 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 2722 | request->ssids[i].ssid_len = nla_len(attr); |
| 2723 | i++; |
| 2724 | } |
| 2725 | } |
| 2726 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2727 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2728 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 2729 | memcpy((void *)request->ie, |
| 2730 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2731 | request->ie_len); |
| 2732 | } |
| 2733 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2734 | request->ifidx = dev->ifindex; |
| 2735 | request->wiphy = &drv->wiphy; |
| 2736 | |
| 2737 | drv->scan_req = request; |
| 2738 | err = drv->ops->scan(&drv->wiphy, dev, request); |
| 2739 | |
| 2740 | out_free: |
| 2741 | if (err) { |
| 2742 | drv->scan_req = NULL; |
| 2743 | kfree(request); |
| 2744 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2745 | out: |
| 2746 | cfg80211_put_dev(drv); |
| 2747 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2748 | out_rtnl: |
| 2749 | rtnl_unlock(); |
| 2750 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2751 | return err; |
| 2752 | } |
| 2753 | |
| 2754 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 2755 | struct cfg80211_registered_device *rdev, |
| 2756 | struct net_device *dev, |
| 2757 | struct cfg80211_bss *res) |
| 2758 | { |
| 2759 | void *hdr; |
| 2760 | struct nlattr *bss; |
| 2761 | |
| 2762 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 2763 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 2764 | if (!hdr) |
| 2765 | return -1; |
| 2766 | |
| 2767 | NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION, |
| 2768 | rdev->bss_generation); |
| 2769 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2770 | |
| 2771 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 2772 | if (!bss) |
| 2773 | goto nla_put_failure; |
| 2774 | if (!is_zero_ether_addr(res->bssid)) |
| 2775 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 2776 | if (res->information_elements && res->len_information_elements) |
| 2777 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 2778 | res->len_information_elements, |
| 2779 | res->information_elements); |
| 2780 | if (res->tsf) |
| 2781 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 2782 | if (res->beacon_interval) |
| 2783 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 2784 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 2785 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
| 2786 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2787 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2788 | case CFG80211_SIGNAL_TYPE_MBM: |
| 2789 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 2790 | break; |
| 2791 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 2792 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 2793 | break; |
| 2794 | default: |
| 2795 | break; |
| 2796 | } |
| 2797 | |
| 2798 | nla_nest_end(msg, bss); |
| 2799 | |
| 2800 | return genlmsg_end(msg, hdr); |
| 2801 | |
| 2802 | nla_put_failure: |
| 2803 | genlmsg_cancel(msg, hdr); |
| 2804 | return -EMSGSIZE; |
| 2805 | } |
| 2806 | |
| 2807 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 2808 | struct netlink_callback *cb) |
| 2809 | { |
| 2810 | struct cfg80211_registered_device *dev; |
| 2811 | struct net_device *netdev; |
| 2812 | struct cfg80211_internal_bss *scan; |
| 2813 | int ifidx = cb->args[0]; |
| 2814 | int start = cb->args[1], idx = 0; |
| 2815 | int err; |
| 2816 | |
| 2817 | if (!ifidx) { |
| 2818 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2819 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 2820 | nl80211_policy); |
| 2821 | if (err) |
| 2822 | return err; |
| 2823 | |
| 2824 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 2825 | return -EINVAL; |
| 2826 | |
| 2827 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 2828 | if (!ifidx) |
| 2829 | return -EINVAL; |
| 2830 | cb->args[0] = ifidx; |
| 2831 | } |
| 2832 | |
| 2833 | netdev = dev_get_by_index(&init_net, ifidx); |
| 2834 | if (!netdev) |
| 2835 | return -ENODEV; |
| 2836 | |
| 2837 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 2838 | if (IS_ERR(dev)) { |
| 2839 | err = PTR_ERR(dev); |
| 2840 | goto out_put_netdev; |
| 2841 | } |
| 2842 | |
| 2843 | spin_lock_bh(&dev->bss_lock); |
| 2844 | cfg80211_bss_expire(dev); |
| 2845 | |
| 2846 | list_for_each_entry(scan, &dev->bss_list, list) { |
| 2847 | if (++idx <= start) |
| 2848 | continue; |
| 2849 | if (nl80211_send_bss(skb, |
| 2850 | NETLINK_CB(cb->skb).pid, |
| 2851 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2852 | dev, netdev, &scan->pub) < 0) { |
| 2853 | idx--; |
| 2854 | goto out; |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | out: |
| 2859 | spin_unlock_bh(&dev->bss_lock); |
| 2860 | |
| 2861 | cb->args[1] = idx; |
| 2862 | err = skb->len; |
| 2863 | cfg80211_put_dev(dev); |
| 2864 | out_put_netdev: |
| 2865 | dev_put(netdev); |
| 2866 | |
| 2867 | return err; |
| 2868 | } |
| 2869 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 2870 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 2871 | { |
| 2872 | return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM || |
| 2873 | auth_type == NL80211_AUTHTYPE_SHARED_KEY || |
| 2874 | auth_type == NL80211_AUTHTYPE_FT || |
| 2875 | auth_type == NL80211_AUTHTYPE_NETWORK_EAP; |
| 2876 | } |
| 2877 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2878 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 2879 | { |
| 2880 | struct cfg80211_registered_device *drv; |
| 2881 | struct net_device *dev; |
| 2882 | struct cfg80211_auth_request req; |
| 2883 | struct wiphy *wiphy; |
| 2884 | int err; |
| 2885 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2886 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2887 | return -EINVAL; |
| 2888 | |
| 2889 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2890 | return -EINVAL; |
| 2891 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 2892 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 2893 | return -EINVAL; |
| 2894 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2895 | rtnl_lock(); |
| 2896 | |
| 2897 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2898 | if (err) |
| 2899 | goto unlock_rtnl; |
| 2900 | |
| 2901 | if (!drv->ops->auth) { |
| 2902 | err = -EOPNOTSUPP; |
| 2903 | goto out; |
| 2904 | } |
| 2905 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2906 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 2907 | err = -EOPNOTSUPP; |
| 2908 | goto out; |
| 2909 | } |
| 2910 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2911 | if (!netif_running(dev)) { |
| 2912 | err = -ENETDOWN; |
| 2913 | goto out; |
| 2914 | } |
| 2915 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2916 | wiphy = &drv->wiphy; |
| 2917 | memset(&req, 0, sizeof(req)); |
| 2918 | |
| 2919 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2920 | |
| 2921 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2922 | req.chan = ieee80211_get_channel( |
| 2923 | wiphy, |
| 2924 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2925 | if (!req.chan) { |
| 2926 | err = -EINVAL; |
| 2927 | goto out; |
| 2928 | } |
| 2929 | } |
| 2930 | |
| 2931 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2932 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2933 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2934 | } |
| 2935 | |
| 2936 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2937 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2938 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2939 | } |
| 2940 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 2941 | req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2942 | if (!nl80211_valid_auth_type(req.auth_type)) { |
| 2943 | err = -EINVAL; |
| 2944 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | err = drv->ops->auth(&drv->wiphy, dev, &req); |
| 2948 | |
| 2949 | out: |
| 2950 | cfg80211_put_dev(drv); |
| 2951 | dev_put(dev); |
| 2952 | unlock_rtnl: |
| 2953 | rtnl_unlock(); |
| 2954 | return err; |
| 2955 | } |
| 2956 | |
| 2957 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 2958 | { |
| 2959 | struct cfg80211_registered_device *drv; |
| 2960 | struct net_device *dev; |
| 2961 | struct cfg80211_assoc_request req; |
| 2962 | struct wiphy *wiphy; |
| 2963 | int err; |
| 2964 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2965 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2966 | return -EINVAL; |
| 2967 | |
| 2968 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 2969 | !info->attrs[NL80211_ATTR_SSID]) |
| 2970 | return -EINVAL; |
| 2971 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2972 | rtnl_lock(); |
| 2973 | |
| 2974 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2975 | if (err) |
| 2976 | goto unlock_rtnl; |
| 2977 | |
| 2978 | if (!drv->ops->assoc) { |
| 2979 | err = -EOPNOTSUPP; |
| 2980 | goto out; |
| 2981 | } |
| 2982 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2983 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 2984 | err = -EOPNOTSUPP; |
| 2985 | goto out; |
| 2986 | } |
| 2987 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2988 | if (!netif_running(dev)) { |
| 2989 | err = -ENETDOWN; |
| 2990 | goto out; |
| 2991 | } |
| 2992 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2993 | wiphy = &drv->wiphy; |
| 2994 | memset(&req, 0, sizeof(req)); |
| 2995 | |
| 2996 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2997 | |
| 2998 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2999 | req.chan = ieee80211_get_channel( |
| 3000 | wiphy, |
| 3001 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3002 | if (!req.chan) { |
| 3003 | err = -EINVAL; |
| 3004 | goto out; |
| 3005 | } |
| 3006 | } |
| 3007 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3008 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3009 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3010 | |
| 3011 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3012 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3013 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3014 | } |
| 3015 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame^] | 3016 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
| 3017 | enum nl80211_mfp use_mfp = |
| 3018 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
| 3019 | if (use_mfp == NL80211_MFP_REQUIRED) |
| 3020 | req.use_mfp = true; |
| 3021 | else if (use_mfp != NL80211_MFP_NO) { |
| 3022 | err = -EINVAL; |
| 3023 | goto out; |
| 3024 | } |
| 3025 | } |
| 3026 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3027 | err = drv->ops->assoc(&drv->wiphy, dev, &req); |
| 3028 | |
| 3029 | out: |
| 3030 | cfg80211_put_dev(drv); |
| 3031 | dev_put(dev); |
| 3032 | unlock_rtnl: |
| 3033 | rtnl_unlock(); |
| 3034 | return err; |
| 3035 | } |
| 3036 | |
| 3037 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3038 | { |
| 3039 | struct cfg80211_registered_device *drv; |
| 3040 | struct net_device *dev; |
| 3041 | struct cfg80211_deauth_request req; |
| 3042 | struct wiphy *wiphy; |
| 3043 | int err; |
| 3044 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3045 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3046 | return -EINVAL; |
| 3047 | |
| 3048 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3049 | return -EINVAL; |
| 3050 | |
| 3051 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3052 | return -EINVAL; |
| 3053 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3054 | rtnl_lock(); |
| 3055 | |
| 3056 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3057 | if (err) |
| 3058 | goto unlock_rtnl; |
| 3059 | |
| 3060 | if (!drv->ops->deauth) { |
| 3061 | err = -EOPNOTSUPP; |
| 3062 | goto out; |
| 3063 | } |
| 3064 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3065 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3066 | err = -EOPNOTSUPP; |
| 3067 | goto out; |
| 3068 | } |
| 3069 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3070 | if (!netif_running(dev)) { |
| 3071 | err = -ENETDOWN; |
| 3072 | goto out; |
| 3073 | } |
| 3074 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3075 | wiphy = &drv->wiphy; |
| 3076 | memset(&req, 0, sizeof(req)); |
| 3077 | |
| 3078 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3079 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3080 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3081 | if (req.reason_code == 0) { |
| 3082 | /* Reason Code 0 is reserved */ |
| 3083 | err = -EINVAL; |
| 3084 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3085 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3086 | |
| 3087 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3088 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3089 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3090 | } |
| 3091 | |
| 3092 | err = drv->ops->deauth(&drv->wiphy, dev, &req); |
| 3093 | |
| 3094 | out: |
| 3095 | cfg80211_put_dev(drv); |
| 3096 | dev_put(dev); |
| 3097 | unlock_rtnl: |
| 3098 | rtnl_unlock(); |
| 3099 | return err; |
| 3100 | } |
| 3101 | |
| 3102 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3103 | { |
| 3104 | struct cfg80211_registered_device *drv; |
| 3105 | struct net_device *dev; |
| 3106 | struct cfg80211_disassoc_request req; |
| 3107 | struct wiphy *wiphy; |
| 3108 | int err; |
| 3109 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3110 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3111 | return -EINVAL; |
| 3112 | |
| 3113 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3114 | return -EINVAL; |
| 3115 | |
| 3116 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3117 | return -EINVAL; |
| 3118 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3119 | rtnl_lock(); |
| 3120 | |
| 3121 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3122 | if (err) |
| 3123 | goto unlock_rtnl; |
| 3124 | |
| 3125 | if (!drv->ops->disassoc) { |
| 3126 | err = -EOPNOTSUPP; |
| 3127 | goto out; |
| 3128 | } |
| 3129 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3130 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3131 | err = -EOPNOTSUPP; |
| 3132 | goto out; |
| 3133 | } |
| 3134 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3135 | if (!netif_running(dev)) { |
| 3136 | err = -ENETDOWN; |
| 3137 | goto out; |
| 3138 | } |
| 3139 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3140 | wiphy = &drv->wiphy; |
| 3141 | memset(&req, 0, sizeof(req)); |
| 3142 | |
| 3143 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3144 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3145 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3146 | if (req.reason_code == 0) { |
| 3147 | /* Reason Code 0 is reserved */ |
| 3148 | err = -EINVAL; |
| 3149 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3150 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3151 | |
| 3152 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3153 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3154 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3155 | } |
| 3156 | |
| 3157 | err = drv->ops->disassoc(&drv->wiphy, dev, &req); |
| 3158 | |
| 3159 | out: |
| 3160 | cfg80211_put_dev(drv); |
| 3161 | dev_put(dev); |
| 3162 | unlock_rtnl: |
| 3163 | rtnl_unlock(); |
| 3164 | return err; |
| 3165 | } |
| 3166 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3167 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3168 | { |
| 3169 | struct cfg80211_registered_device *drv; |
| 3170 | struct net_device *dev; |
| 3171 | struct cfg80211_ibss_params ibss; |
| 3172 | struct wiphy *wiphy; |
| 3173 | int err; |
| 3174 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3175 | memset(&ibss, 0, sizeof(ibss)); |
| 3176 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3177 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3178 | return -EINVAL; |
| 3179 | |
| 3180 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 3181 | !info->attrs[NL80211_ATTR_SSID] || |
| 3182 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3183 | return -EINVAL; |
| 3184 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3185 | ibss.beacon_interval = 100; |
| 3186 | |
| 3187 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 3188 | ibss.beacon_interval = |
| 3189 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3190 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 3191 | return -EINVAL; |
| 3192 | } |
| 3193 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3194 | rtnl_lock(); |
| 3195 | |
| 3196 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3197 | if (err) |
| 3198 | goto unlock_rtnl; |
| 3199 | |
| 3200 | if (!drv->ops->join_ibss) { |
| 3201 | err = -EOPNOTSUPP; |
| 3202 | goto out; |
| 3203 | } |
| 3204 | |
| 3205 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 3206 | err = -EOPNOTSUPP; |
| 3207 | goto out; |
| 3208 | } |
| 3209 | |
| 3210 | if (!netif_running(dev)) { |
| 3211 | err = -ENETDOWN; |
| 3212 | goto out; |
| 3213 | } |
| 3214 | |
| 3215 | wiphy = &drv->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3216 | |
| 3217 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3218 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3219 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3220 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3221 | |
| 3222 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3223 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3224 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3225 | } |
| 3226 | |
| 3227 | ibss.channel = ieee80211_get_channel(wiphy, |
| 3228 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3229 | if (!ibss.channel || |
| 3230 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
| 3231 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 3232 | err = -EINVAL; |
| 3233 | goto out; |
| 3234 | } |
| 3235 | |
| 3236 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
| 3237 | |
| 3238 | err = cfg80211_join_ibss(drv, dev, &ibss); |
| 3239 | |
| 3240 | out: |
| 3241 | cfg80211_put_dev(drv); |
| 3242 | dev_put(dev); |
| 3243 | unlock_rtnl: |
| 3244 | rtnl_unlock(); |
| 3245 | return err; |
| 3246 | } |
| 3247 | |
| 3248 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3249 | { |
| 3250 | struct cfg80211_registered_device *drv; |
| 3251 | struct net_device *dev; |
| 3252 | int err; |
| 3253 | |
| 3254 | rtnl_lock(); |
| 3255 | |
| 3256 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3257 | if (err) |
| 3258 | goto unlock_rtnl; |
| 3259 | |
| 3260 | if (!drv->ops->leave_ibss) { |
| 3261 | err = -EOPNOTSUPP; |
| 3262 | goto out; |
| 3263 | } |
| 3264 | |
| 3265 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 3266 | err = -EOPNOTSUPP; |
| 3267 | goto out; |
| 3268 | } |
| 3269 | |
| 3270 | if (!netif_running(dev)) { |
| 3271 | err = -ENETDOWN; |
| 3272 | goto out; |
| 3273 | } |
| 3274 | |
Johannes Berg | 9d30842 | 2009-04-20 18:43:46 +0200 | [diff] [blame] | 3275 | err = cfg80211_leave_ibss(drv, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3276 | |
| 3277 | out: |
| 3278 | cfg80211_put_dev(drv); |
| 3279 | dev_put(dev); |
| 3280 | unlock_rtnl: |
| 3281 | rtnl_unlock(); |
| 3282 | return err; |
| 3283 | } |
| 3284 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3285 | static struct genl_ops nl80211_ops[] = { |
| 3286 | { |
| 3287 | .cmd = NL80211_CMD_GET_WIPHY, |
| 3288 | .doit = nl80211_get_wiphy, |
| 3289 | .dumpit = nl80211_dump_wiphy, |
| 3290 | .policy = nl80211_policy, |
| 3291 | /* can be retrieved by unprivileged users */ |
| 3292 | }, |
| 3293 | { |
| 3294 | .cmd = NL80211_CMD_SET_WIPHY, |
| 3295 | .doit = nl80211_set_wiphy, |
| 3296 | .policy = nl80211_policy, |
| 3297 | .flags = GENL_ADMIN_PERM, |
| 3298 | }, |
| 3299 | { |
| 3300 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 3301 | .doit = nl80211_get_interface, |
| 3302 | .dumpit = nl80211_dump_interface, |
| 3303 | .policy = nl80211_policy, |
| 3304 | /* can be retrieved by unprivileged users */ |
| 3305 | }, |
| 3306 | { |
| 3307 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 3308 | .doit = nl80211_set_interface, |
| 3309 | .policy = nl80211_policy, |
| 3310 | .flags = GENL_ADMIN_PERM, |
| 3311 | }, |
| 3312 | { |
| 3313 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 3314 | .doit = nl80211_new_interface, |
| 3315 | .policy = nl80211_policy, |
| 3316 | .flags = GENL_ADMIN_PERM, |
| 3317 | }, |
| 3318 | { |
| 3319 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 3320 | .doit = nl80211_del_interface, |
| 3321 | .policy = nl80211_policy, |
| 3322 | .flags = GENL_ADMIN_PERM, |
| 3323 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3324 | { |
| 3325 | .cmd = NL80211_CMD_GET_KEY, |
| 3326 | .doit = nl80211_get_key, |
| 3327 | .policy = nl80211_policy, |
| 3328 | .flags = GENL_ADMIN_PERM, |
| 3329 | }, |
| 3330 | { |
| 3331 | .cmd = NL80211_CMD_SET_KEY, |
| 3332 | .doit = nl80211_set_key, |
| 3333 | .policy = nl80211_policy, |
| 3334 | .flags = GENL_ADMIN_PERM, |
| 3335 | }, |
| 3336 | { |
| 3337 | .cmd = NL80211_CMD_NEW_KEY, |
| 3338 | .doit = nl80211_new_key, |
| 3339 | .policy = nl80211_policy, |
| 3340 | .flags = GENL_ADMIN_PERM, |
| 3341 | }, |
| 3342 | { |
| 3343 | .cmd = NL80211_CMD_DEL_KEY, |
| 3344 | .doit = nl80211_del_key, |
| 3345 | .policy = nl80211_policy, |
| 3346 | .flags = GENL_ADMIN_PERM, |
| 3347 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3348 | { |
| 3349 | .cmd = NL80211_CMD_SET_BEACON, |
| 3350 | .policy = nl80211_policy, |
| 3351 | .flags = GENL_ADMIN_PERM, |
| 3352 | .doit = nl80211_addset_beacon, |
| 3353 | }, |
| 3354 | { |
| 3355 | .cmd = NL80211_CMD_NEW_BEACON, |
| 3356 | .policy = nl80211_policy, |
| 3357 | .flags = GENL_ADMIN_PERM, |
| 3358 | .doit = nl80211_addset_beacon, |
| 3359 | }, |
| 3360 | { |
| 3361 | .cmd = NL80211_CMD_DEL_BEACON, |
| 3362 | .policy = nl80211_policy, |
| 3363 | .flags = GENL_ADMIN_PERM, |
| 3364 | .doit = nl80211_del_beacon, |
| 3365 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3366 | { |
| 3367 | .cmd = NL80211_CMD_GET_STATION, |
| 3368 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3369 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3370 | .policy = nl80211_policy, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3371 | }, |
| 3372 | { |
| 3373 | .cmd = NL80211_CMD_SET_STATION, |
| 3374 | .doit = nl80211_set_station, |
| 3375 | .policy = nl80211_policy, |
| 3376 | .flags = GENL_ADMIN_PERM, |
| 3377 | }, |
| 3378 | { |
| 3379 | .cmd = NL80211_CMD_NEW_STATION, |
| 3380 | .doit = nl80211_new_station, |
| 3381 | .policy = nl80211_policy, |
| 3382 | .flags = GENL_ADMIN_PERM, |
| 3383 | }, |
| 3384 | { |
| 3385 | .cmd = NL80211_CMD_DEL_STATION, |
| 3386 | .doit = nl80211_del_station, |
| 3387 | .policy = nl80211_policy, |
| 3388 | .flags = GENL_ADMIN_PERM, |
| 3389 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3390 | { |
| 3391 | .cmd = NL80211_CMD_GET_MPATH, |
| 3392 | .doit = nl80211_get_mpath, |
| 3393 | .dumpit = nl80211_dump_mpath, |
| 3394 | .policy = nl80211_policy, |
| 3395 | .flags = GENL_ADMIN_PERM, |
| 3396 | }, |
| 3397 | { |
| 3398 | .cmd = NL80211_CMD_SET_MPATH, |
| 3399 | .doit = nl80211_set_mpath, |
| 3400 | .policy = nl80211_policy, |
| 3401 | .flags = GENL_ADMIN_PERM, |
| 3402 | }, |
| 3403 | { |
| 3404 | .cmd = NL80211_CMD_NEW_MPATH, |
| 3405 | .doit = nl80211_new_mpath, |
| 3406 | .policy = nl80211_policy, |
| 3407 | .flags = GENL_ADMIN_PERM, |
| 3408 | }, |
| 3409 | { |
| 3410 | .cmd = NL80211_CMD_DEL_MPATH, |
| 3411 | .doit = nl80211_del_mpath, |
| 3412 | .policy = nl80211_policy, |
| 3413 | .flags = GENL_ADMIN_PERM, |
| 3414 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3415 | { |
| 3416 | .cmd = NL80211_CMD_SET_BSS, |
| 3417 | .doit = nl80211_set_bss, |
| 3418 | .policy = nl80211_policy, |
| 3419 | .flags = GENL_ADMIN_PERM, |
| 3420 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3421 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3422 | .cmd = NL80211_CMD_GET_REG, |
| 3423 | .doit = nl80211_get_reg, |
| 3424 | .policy = nl80211_policy, |
| 3425 | /* can be retrieved by unprivileged users */ |
| 3426 | }, |
| 3427 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3428 | .cmd = NL80211_CMD_SET_REG, |
| 3429 | .doit = nl80211_set_reg, |
| 3430 | .policy = nl80211_policy, |
| 3431 | .flags = GENL_ADMIN_PERM, |
| 3432 | }, |
| 3433 | { |
| 3434 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 3435 | .doit = nl80211_req_set_reg, |
| 3436 | .policy = nl80211_policy, |
| 3437 | .flags = GENL_ADMIN_PERM, |
| 3438 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3439 | { |
| 3440 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 3441 | .doit = nl80211_get_mesh_params, |
| 3442 | .policy = nl80211_policy, |
| 3443 | /* can be retrieved by unprivileged users */ |
| 3444 | }, |
| 3445 | { |
| 3446 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 3447 | .doit = nl80211_set_mesh_params, |
| 3448 | .policy = nl80211_policy, |
| 3449 | .flags = GENL_ADMIN_PERM, |
| 3450 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 3451 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3452 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 3453 | .doit = nl80211_trigger_scan, |
| 3454 | .policy = nl80211_policy, |
| 3455 | .flags = GENL_ADMIN_PERM, |
| 3456 | }, |
| 3457 | { |
| 3458 | .cmd = NL80211_CMD_GET_SCAN, |
| 3459 | .policy = nl80211_policy, |
| 3460 | .dumpit = nl80211_dump_scan, |
| 3461 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3462 | { |
| 3463 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 3464 | .doit = nl80211_authenticate, |
| 3465 | .policy = nl80211_policy, |
| 3466 | .flags = GENL_ADMIN_PERM, |
| 3467 | }, |
| 3468 | { |
| 3469 | .cmd = NL80211_CMD_ASSOCIATE, |
| 3470 | .doit = nl80211_associate, |
| 3471 | .policy = nl80211_policy, |
| 3472 | .flags = GENL_ADMIN_PERM, |
| 3473 | }, |
| 3474 | { |
| 3475 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 3476 | .doit = nl80211_deauthenticate, |
| 3477 | .policy = nl80211_policy, |
| 3478 | .flags = GENL_ADMIN_PERM, |
| 3479 | }, |
| 3480 | { |
| 3481 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 3482 | .doit = nl80211_disassociate, |
| 3483 | .policy = nl80211_policy, |
| 3484 | .flags = GENL_ADMIN_PERM, |
| 3485 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3486 | { |
| 3487 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 3488 | .doit = nl80211_join_ibss, |
| 3489 | .policy = nl80211_policy, |
| 3490 | .flags = GENL_ADMIN_PERM, |
| 3491 | }, |
| 3492 | { |
| 3493 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 3494 | .doit = nl80211_leave_ibss, |
| 3495 | .policy = nl80211_policy, |
| 3496 | .flags = GENL_ADMIN_PERM, |
| 3497 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3498 | }; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3499 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 3500 | .name = "mlme", |
| 3501 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3502 | |
| 3503 | /* multicast groups */ |
| 3504 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 3505 | .name = "config", |
| 3506 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3507 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 3508 | .name = "scan", |
| 3509 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3510 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 3511 | .name = "regulatory", |
| 3512 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3513 | |
| 3514 | /* notification functions */ |
| 3515 | |
| 3516 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 3517 | { |
| 3518 | struct sk_buff *msg; |
| 3519 | |
| 3520 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3521 | if (!msg) |
| 3522 | return; |
| 3523 | |
| 3524 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 3525 | nlmsg_free(msg); |
| 3526 | return; |
| 3527 | } |
| 3528 | |
| 3529 | genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); |
| 3530 | } |
| 3531 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3532 | static int nl80211_send_scan_donemsg(struct sk_buff *msg, |
| 3533 | struct cfg80211_registered_device *rdev, |
| 3534 | struct net_device *netdev, |
| 3535 | u32 pid, u32 seq, int flags, |
| 3536 | u32 cmd) |
| 3537 | { |
| 3538 | void *hdr; |
| 3539 | |
| 3540 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 3541 | if (!hdr) |
| 3542 | return -1; |
| 3543 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 3544 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3545 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3546 | |
| 3547 | /* XXX: we should probably bounce back the request? */ |
| 3548 | |
| 3549 | return genlmsg_end(msg, hdr); |
| 3550 | |
| 3551 | nla_put_failure: |
| 3552 | genlmsg_cancel(msg, hdr); |
| 3553 | return -EMSGSIZE; |
| 3554 | } |
| 3555 | |
| 3556 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 3557 | struct net_device *netdev) |
| 3558 | { |
| 3559 | struct sk_buff *msg; |
| 3560 | |
| 3561 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3562 | if (!msg) |
| 3563 | return; |
| 3564 | |
| 3565 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, |
| 3566 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
| 3567 | nlmsg_free(msg); |
| 3568 | return; |
| 3569 | } |
| 3570 | |
| 3571 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 3572 | } |
| 3573 | |
| 3574 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 3575 | struct net_device *netdev) |
| 3576 | { |
| 3577 | struct sk_buff *msg; |
| 3578 | |
| 3579 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3580 | if (!msg) |
| 3581 | return; |
| 3582 | |
| 3583 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, |
| 3584 | NL80211_CMD_SCAN_ABORTED) < 0) { |
| 3585 | nlmsg_free(msg); |
| 3586 | return; |
| 3587 | } |
| 3588 | |
| 3589 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 3590 | } |
| 3591 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3592 | /* |
| 3593 | * This can happen on global regulatory changes or device specific settings |
| 3594 | * based on custom world regulatory domains. |
| 3595 | */ |
| 3596 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 3597 | { |
| 3598 | struct sk_buff *msg; |
| 3599 | void *hdr; |
| 3600 | |
| 3601 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3602 | if (!msg) |
| 3603 | return; |
| 3604 | |
| 3605 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 3606 | if (!hdr) { |
| 3607 | nlmsg_free(msg); |
| 3608 | return; |
| 3609 | } |
| 3610 | |
| 3611 | /* Userspace can always count this one always being set */ |
| 3612 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 3613 | |
| 3614 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 3615 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3616 | NL80211_REGDOM_TYPE_WORLD); |
| 3617 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 3618 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3619 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 3620 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 3621 | request->intersect) |
| 3622 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3623 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 3624 | else { |
| 3625 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3626 | NL80211_REGDOM_TYPE_COUNTRY); |
| 3627 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 3628 | } |
| 3629 | |
| 3630 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 3631 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 3632 | |
| 3633 | if (genlmsg_end(msg, hdr) < 0) { |
| 3634 | nlmsg_free(msg); |
| 3635 | return; |
| 3636 | } |
| 3637 | |
| 3638 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL); |
| 3639 | |
| 3640 | return; |
| 3641 | |
| 3642 | nla_put_failure: |
| 3643 | genlmsg_cancel(msg, hdr); |
| 3644 | nlmsg_free(msg); |
| 3645 | } |
| 3646 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3647 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 3648 | struct net_device *netdev, |
| 3649 | const u8 *buf, size_t len, |
| 3650 | enum nl80211_commands cmd) |
| 3651 | { |
| 3652 | struct sk_buff *msg; |
| 3653 | void *hdr; |
| 3654 | |
Jouni Malinen | d91c01c | 2009-04-18 21:53:15 +0300 | [diff] [blame] | 3655 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3656 | if (!msg) |
| 3657 | return; |
| 3658 | |
| 3659 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 3660 | if (!hdr) { |
| 3661 | nlmsg_free(msg); |
| 3662 | return; |
| 3663 | } |
| 3664 | |
| 3665 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3666 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3667 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 3668 | |
| 3669 | if (genlmsg_end(msg, hdr) < 0) { |
| 3670 | nlmsg_free(msg); |
| 3671 | return; |
| 3672 | } |
| 3673 | |
Jouni Malinen | d91c01c | 2009-04-18 21:53:15 +0300 | [diff] [blame] | 3674 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3675 | return; |
| 3676 | |
| 3677 | nla_put_failure: |
| 3678 | genlmsg_cancel(msg, hdr); |
| 3679 | nlmsg_free(msg); |
| 3680 | } |
| 3681 | |
| 3682 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
| 3683 | struct net_device *netdev, const u8 *buf, size_t len) |
| 3684 | { |
| 3685 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3686 | NL80211_CMD_AUTHENTICATE); |
| 3687 | } |
| 3688 | |
| 3689 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 3690 | struct net_device *netdev, const u8 *buf, |
| 3691 | size_t len) |
| 3692 | { |
| 3693 | nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE); |
| 3694 | } |
| 3695 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 3696 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
| 3697 | struct net_device *netdev, const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3698 | { |
| 3699 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3700 | NL80211_CMD_DEAUTHENTICATE); |
| 3701 | } |
| 3702 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 3703 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 3704 | struct net_device *netdev, const u8 *buf, |
| 3705 | size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3706 | { |
| 3707 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3708 | NL80211_CMD_DISASSOCIATE); |
| 3709 | } |
| 3710 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 3711 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 3712 | struct net_device *netdev, int cmd, |
| 3713 | const u8 *addr) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 3714 | { |
| 3715 | struct sk_buff *msg; |
| 3716 | void *hdr; |
| 3717 | |
| 3718 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
| 3719 | if (!msg) |
| 3720 | return; |
| 3721 | |
| 3722 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 3723 | if (!hdr) { |
| 3724 | nlmsg_free(msg); |
| 3725 | return; |
| 3726 | } |
| 3727 | |
| 3728 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3729 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3730 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 3731 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 3732 | |
| 3733 | if (genlmsg_end(msg, hdr) < 0) { |
| 3734 | nlmsg_free(msg); |
| 3735 | return; |
| 3736 | } |
| 3737 | |
| 3738 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); |
| 3739 | return; |
| 3740 | |
| 3741 | nla_put_failure: |
| 3742 | genlmsg_cancel(msg, hdr); |
| 3743 | nlmsg_free(msg); |
| 3744 | } |
| 3745 | |
| 3746 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
| 3747 | struct net_device *netdev, const u8 *addr) |
| 3748 | { |
| 3749 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
| 3750 | addr); |
| 3751 | } |
| 3752 | |
| 3753 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
| 3754 | struct net_device *netdev, const u8 *addr) |
| 3755 | { |
| 3756 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, addr); |
| 3757 | } |
| 3758 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3759 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 3760 | struct net_device *netdev, const u8 *bssid, |
| 3761 | gfp_t gfp) |
| 3762 | { |
| 3763 | struct sk_buff *msg; |
| 3764 | void *hdr; |
| 3765 | |
| 3766 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 3767 | if (!msg) |
| 3768 | return; |
| 3769 | |
| 3770 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 3771 | if (!hdr) { |
| 3772 | nlmsg_free(msg); |
| 3773 | return; |
| 3774 | } |
| 3775 | |
| 3776 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3777 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3778 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 3779 | |
| 3780 | if (genlmsg_end(msg, hdr) < 0) { |
| 3781 | nlmsg_free(msg); |
| 3782 | return; |
| 3783 | } |
| 3784 | |
| 3785 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); |
| 3786 | return; |
| 3787 | |
| 3788 | nla_put_failure: |
| 3789 | genlmsg_cancel(msg, hdr); |
| 3790 | nlmsg_free(msg); |
| 3791 | } |
| 3792 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 3793 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 3794 | struct net_device *netdev, const u8 *addr, |
| 3795 | enum nl80211_key_type key_type, int key_id, |
| 3796 | const u8 *tsc) |
| 3797 | { |
| 3798 | struct sk_buff *msg; |
| 3799 | void *hdr; |
| 3800 | |
| 3801 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3802 | if (!msg) |
| 3803 | return; |
| 3804 | |
| 3805 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 3806 | if (!hdr) { |
| 3807 | nlmsg_free(msg); |
| 3808 | return; |
| 3809 | } |
| 3810 | |
| 3811 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3812 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3813 | if (addr) |
| 3814 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 3815 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 3816 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 3817 | if (tsc) |
| 3818 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 3819 | |
| 3820 | if (genlmsg_end(msg, hdr) < 0) { |
| 3821 | nlmsg_free(msg); |
| 3822 | return; |
| 3823 | } |
| 3824 | |
| 3825 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 3826 | return; |
| 3827 | |
| 3828 | nla_put_failure: |
| 3829 | genlmsg_cancel(msg, hdr); |
| 3830 | nlmsg_free(msg); |
| 3831 | } |
| 3832 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 3833 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 3834 | struct ieee80211_channel *channel_before, |
| 3835 | struct ieee80211_channel *channel_after) |
| 3836 | { |
| 3837 | struct sk_buff *msg; |
| 3838 | void *hdr; |
| 3839 | struct nlattr *nl_freq; |
| 3840 | |
| 3841 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
| 3842 | if (!msg) |
| 3843 | return; |
| 3844 | |
| 3845 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 3846 | if (!hdr) { |
| 3847 | nlmsg_free(msg); |
| 3848 | return; |
| 3849 | } |
| 3850 | |
| 3851 | /* |
| 3852 | * Since we are applying the beacon hint to a wiphy we know its |
| 3853 | * wiphy_idx is valid |
| 3854 | */ |
| 3855 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 3856 | |
| 3857 | /* Before */ |
| 3858 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 3859 | if (!nl_freq) |
| 3860 | goto nla_put_failure; |
| 3861 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 3862 | goto nla_put_failure; |
| 3863 | nla_nest_end(msg, nl_freq); |
| 3864 | |
| 3865 | /* After */ |
| 3866 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 3867 | if (!nl_freq) |
| 3868 | goto nla_put_failure; |
| 3869 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 3870 | goto nla_put_failure; |
| 3871 | nla_nest_end(msg, nl_freq); |
| 3872 | |
| 3873 | if (genlmsg_end(msg, hdr) < 0) { |
| 3874 | nlmsg_free(msg); |
| 3875 | return; |
| 3876 | } |
| 3877 | |
| 3878 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC); |
| 3879 | |
| 3880 | return; |
| 3881 | |
| 3882 | nla_put_failure: |
| 3883 | genlmsg_cancel(msg, hdr); |
| 3884 | nlmsg_free(msg); |
| 3885 | } |
| 3886 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3887 | /* initialisation/exit functions */ |
| 3888 | |
| 3889 | int nl80211_init(void) |
| 3890 | { |
| 3891 | int err, i; |
| 3892 | |
| 3893 | err = genl_register_family(&nl80211_fam); |
| 3894 | if (err) |
| 3895 | return err; |
| 3896 | |
| 3897 | for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) { |
| 3898 | err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]); |
| 3899 | if (err) |
| 3900 | goto err_out; |
| 3901 | } |
| 3902 | |
| 3903 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 3904 | if (err) |
| 3905 | goto err_out; |
| 3906 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3907 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 3908 | if (err) |
| 3909 | goto err_out; |
| 3910 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3911 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 3912 | if (err) |
| 3913 | goto err_out; |
| 3914 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3915 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 3916 | if (err) |
| 3917 | goto err_out; |
| 3918 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3919 | return 0; |
| 3920 | err_out: |
| 3921 | genl_unregister_family(&nl80211_fam); |
| 3922 | return err; |
| 3923 | } |
| 3924 | |
| 3925 | void nl80211_exit(void) |
| 3926 | { |
| 3927 | genl_unregister_family(&nl80211_fam); |
| 3928 | } |