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