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