1 /*
2 * mac80211 configuration hooks for cfg80211
3 *
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
5 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
9 #include <linux/ieee80211.h>
10 #include <linux/nl80211.h>
11 #include <linux/rtnetlink.h>
12 #include <linux/slab.h>
13 #include <net/net_namespace.h>
14 #include <linux/rcupdate.h>
15 #include <linux/if_ether.h>
16 #include <net/cfg80211.h>
17 #include "ieee80211_i.h"
18 #include "driver-ops.h"
19 #include "cfg.h"
20 #include "rate.h"
21 #include "mesh.h"
22
ieee80211_add_iface(struct wiphy * wiphy,char * name,enum nl80211_iftype type,u32 * flags,struct vif_params * params)23 static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
27 {
28 struct ieee80211_local *local = wiphy_priv(wiphy);
29 struct net_device *dev;
30 struct ieee80211_sub_if_data *sdata;
31 int err;
32
33 err = ieee80211_if_add(local, name, &dev, type, params);
34 if (err)
35 return ERR_PTR(err);
36
37 if (type == NL80211_IFTYPE_MONITOR && flags) {
38 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
39 sdata->u.mntr_flags = *flags;
40 }
41
42 return dev;
43 }
44
ieee80211_del_iface(struct wiphy * wiphy,struct net_device * dev)45 static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
46 {
47 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
48
49 return 0;
50 }
51
ieee80211_change_iface(struct wiphy * wiphy,struct net_device * dev,enum nl80211_iftype type,u32 * flags,struct vif_params * params)52 static int ieee80211_change_iface(struct wiphy *wiphy,
53 struct net_device *dev,
54 enum nl80211_iftype type, u32 *flags,
55 struct vif_params *params)
56 {
57 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
58 int ret;
59
60 ret = ieee80211_if_change_type(sdata, type);
61 if (ret)
62 return ret;
63
64 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
66 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
67 else if (type == NL80211_IFTYPE_STATION &&
68 params && params->use_4addr >= 0)
69 sdata->u.mgd.use_4addr = params->use_4addr;
70
71 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
73
74 if (ieee80211_sdata_running(sdata)) {
75 /*
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
82 */
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
85 return -EBUSY;
86
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
90
91 ieee80211_configure_filter(local);
92 } else {
93 /*
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
97 */
98 sdata->u.mntr_flags = *flags;
99 }
100 }
101
102 return 0;
103 }
104
ieee80211_set_noack_map(struct wiphy * wiphy,struct net_device * dev,u16 noack_map)105 static int ieee80211_set_noack_map(struct wiphy *wiphy,
106 struct net_device *dev,
107 u16 noack_map)
108 {
109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
110
111 sdata->noack_map = noack_map;
112 return 0;
113 }
114
ieee80211_add_key(struct wiphy * wiphy,struct net_device * dev,u8 key_idx,bool pairwise,const u8 * mac_addr,struct key_params * params)115 static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
116 u8 key_idx, bool pairwise, const u8 *mac_addr,
117 struct key_params *params)
118 {
119 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
120 struct sta_info *sta = NULL;
121 struct ieee80211_key *key;
122 int err;
123
124 if (!ieee80211_sdata_running(sdata))
125 return -ENETDOWN;
126
127 /* reject WEP and TKIP keys if WEP failed to initialize */
128 switch (params->cipher) {
129 case WLAN_CIPHER_SUITE_WEP40:
130 case WLAN_CIPHER_SUITE_TKIP:
131 case WLAN_CIPHER_SUITE_WEP104:
132 if (IS_ERR(sdata->local->wep_tx_tfm))
133 return -EINVAL;
134 break;
135 default:
136 break;
137 }
138
139 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
140 params->key, params->seq_len, params->seq);
141 if (IS_ERR(key))
142 return PTR_ERR(key);
143
144 if (pairwise)
145 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
146
147 mutex_lock(&sdata->local->sta_mtx);
148
149 if (mac_addr) {
150 if (ieee80211_vif_is_mesh(&sdata->vif))
151 sta = sta_info_get(sdata, mac_addr);
152 else
153 sta = sta_info_get_bss(sdata, mac_addr);
154 /*
155 * The ASSOC test makes sure the driver is ready to
156 * receive the key. When wpa_supplicant has roamed
157 * using FT, it attempts to set the key before
158 * association has completed, this rejects that attempt
159 * so it will set the key again after assocation.
160 *
161 * TODO: accept the key if we have a station entry and
162 * add it to the device after the station.
163 */
164 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
165 ieee80211_key_free(sdata->local, key);
166 err = -ENOENT;
167 goto out_unlock;
168 }
169 }
170
171 err = ieee80211_key_link(key, sdata, sta);
172 if (err)
173 ieee80211_key_free(sdata->local, key);
174
175 out_unlock:
176 mutex_unlock(&sdata->local->sta_mtx);
177
178 return err;
179 }
180
ieee80211_del_key(struct wiphy * wiphy,struct net_device * dev,u8 key_idx,bool pairwise,const u8 * mac_addr)181 static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
182 u8 key_idx, bool pairwise, const u8 *mac_addr)
183 {
184 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
185 struct ieee80211_local *local = sdata->local;
186 struct sta_info *sta;
187 struct ieee80211_key *key = NULL;
188 int ret;
189
190 mutex_lock(&local->sta_mtx);
191 mutex_lock(&local->key_mtx);
192
193 if (mac_addr) {
194 ret = -ENOENT;
195
196 sta = sta_info_get_bss(sdata, mac_addr);
197 if (!sta)
198 goto out_unlock;
199
200 if (pairwise)
201 key = key_mtx_dereference(local, sta->ptk);
202 else
203 key = key_mtx_dereference(local, sta->gtk[key_idx]);
204 } else
205 key = key_mtx_dereference(local, sdata->keys[key_idx]);
206
207 if (!key) {
208 ret = -ENOENT;
209 goto out_unlock;
210 }
211
212 __ieee80211_key_free(key);
213
214 ret = 0;
215 out_unlock:
216 mutex_unlock(&local->key_mtx);
217 mutex_unlock(&local->sta_mtx);
218
219 return ret;
220 }
221
ieee80211_get_key(struct wiphy * wiphy,struct net_device * dev,u8 key_idx,bool pairwise,const u8 * mac_addr,void * cookie,void (* callback)(void * cookie,struct key_params * params))222 static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
223 u8 key_idx, bool pairwise, const u8 *mac_addr,
224 void *cookie,
225 void (*callback)(void *cookie,
226 struct key_params *params))
227 {
228 struct ieee80211_sub_if_data *sdata;
229 struct sta_info *sta = NULL;
230 u8 seq[6] = {0};
231 struct key_params params;
232 struct ieee80211_key *key = NULL;
233 u64 pn64;
234 u32 iv32;
235 u16 iv16;
236 int err = -ENOENT;
237
238 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
239
240 rcu_read_lock();
241
242 if (mac_addr) {
243 sta = sta_info_get_bss(sdata, mac_addr);
244 if (!sta)
245 goto out;
246
247 if (pairwise)
248 key = rcu_dereference(sta->ptk);
249 else if (key_idx < NUM_DEFAULT_KEYS)
250 key = rcu_dereference(sta->gtk[key_idx]);
251 } else
252 key = rcu_dereference(sdata->keys[key_idx]);
253
254 if (!key)
255 goto out;
256
257 memset(¶ms, 0, sizeof(params));
258
259 params.cipher = key->conf.cipher;
260
261 switch (key->conf.cipher) {
262 case WLAN_CIPHER_SUITE_TKIP:
263 iv32 = key->u.tkip.tx.iv32;
264 iv16 = key->u.tkip.tx.iv16;
265
266 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
267 drv_get_tkip_seq(sdata->local,
268 key->conf.hw_key_idx,
269 &iv32, &iv16);
270
271 seq[0] = iv16 & 0xff;
272 seq[1] = (iv16 >> 8) & 0xff;
273 seq[2] = iv32 & 0xff;
274 seq[3] = (iv32 >> 8) & 0xff;
275 seq[4] = (iv32 >> 16) & 0xff;
276 seq[5] = (iv32 >> 24) & 0xff;
277 params.seq = seq;
278 params.seq_len = 6;
279 break;
280 case WLAN_CIPHER_SUITE_CCMP:
281 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
282 seq[0] = pn64;
283 seq[1] = pn64 >> 8;
284 seq[2] = pn64 >> 16;
285 seq[3] = pn64 >> 24;
286 seq[4] = pn64 >> 32;
287 seq[5] = pn64 >> 40;
288 params.seq = seq;
289 params.seq_len = 6;
290 break;
291 case WLAN_CIPHER_SUITE_AES_CMAC:
292 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
293 seq[0] = pn64;
294 seq[1] = pn64 >> 8;
295 seq[2] = pn64 >> 16;
296 seq[3] = pn64 >> 24;
297 seq[4] = pn64 >> 32;
298 seq[5] = pn64 >> 40;
299 params.seq = seq;
300 params.seq_len = 6;
301 break;
302 }
303
304 params.key = key->conf.key;
305 params.key_len = key->conf.keylen;
306
307 callback(cookie, ¶ms);
308 err = 0;
309
310 out:
311 rcu_read_unlock();
312 return err;
313 }
314
ieee80211_config_default_key(struct wiphy * wiphy,struct net_device * dev,u8 key_idx,bool uni,bool multi)315 static int ieee80211_config_default_key(struct wiphy *wiphy,
316 struct net_device *dev,
317 u8 key_idx, bool uni,
318 bool multi)
319 {
320 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
321
322 ieee80211_set_default_key(sdata, key_idx, uni, multi);
323
324 return 0;
325 }
326
ieee80211_config_default_mgmt_key(struct wiphy * wiphy,struct net_device * dev,u8 key_idx)327 static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
328 struct net_device *dev,
329 u8 key_idx)
330 {
331 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
332
333 ieee80211_set_default_mgmt_key(sdata, key_idx);
334
335 return 0;
336 }
337
rate_idx_to_bitrate(struct rate_info * rate,struct sta_info * sta,int idx)338 static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
339 {
340 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
341 struct ieee80211_supported_band *sband;
342 sband = sta->local->hw.wiphy->bands[
343 sta->local->hw.conf.channel->band];
344 rate->legacy = sband->bitrates[idx].bitrate;
345 } else
346 rate->mcs = idx;
347 }
348
sta_set_rate_info_tx(struct sta_info * sta,const struct ieee80211_tx_rate * rate,struct rate_info * rinfo)349 void sta_set_rate_info_tx(struct sta_info *sta,
350 const struct ieee80211_tx_rate *rate,
351 struct rate_info *rinfo)
352 {
353 rinfo->flags = 0;
354 if (rate->flags & IEEE80211_TX_RC_MCS)
355 rinfo->flags |= RATE_INFO_FLAGS_MCS;
356 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
357 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
358 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
359 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
360 rate_idx_to_bitrate(rinfo, sta, rate->idx);
361 }
362
sta_set_sinfo(struct sta_info * sta,struct station_info * sinfo)363 static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
364 {
365 struct ieee80211_sub_if_data *sdata = sta->sdata;
366 struct timespec uptime;
367
368 sinfo->generation = sdata->local->sta_generation;
369
370 sinfo->filled = STATION_INFO_INACTIVE_TIME |
371 STATION_INFO_RX_BYTES |
372 STATION_INFO_TX_BYTES |
373 STATION_INFO_RX_PACKETS |
374 STATION_INFO_TX_PACKETS |
375 STATION_INFO_TX_RETRIES |
376 STATION_INFO_TX_FAILED |
377 STATION_INFO_TX_BITRATE |
378 STATION_INFO_RX_BITRATE |
379 STATION_INFO_RX_DROP_MISC |
380 STATION_INFO_BSS_PARAM |
381 STATION_INFO_CONNECTED_TIME |
382 STATION_INFO_STA_FLAGS |
383 STATION_INFO_BEACON_LOSS_COUNT;
384
385 do_posix_clock_monotonic_gettime(&uptime);
386 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
387
388 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
389 sinfo->rx_bytes = sta->rx_bytes;
390 sinfo->tx_bytes = sta->tx_bytes;
391 sinfo->rx_packets = sta->rx_packets;
392 sinfo->tx_packets = sta->tx_packets;
393 sinfo->tx_retries = sta->tx_retry_count;
394 sinfo->tx_failed = sta->tx_retry_failed;
395 sinfo->rx_dropped_misc = sta->rx_dropped;
396 sinfo->beacon_loss_count = sta->beacon_loss_count;
397
398 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
399 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
400 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
401 sinfo->signal = (s8)sta->last_signal;
402 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
403 }
404
405 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
406
407 sinfo->rxrate.flags = 0;
408 if (sta->last_rx_rate_flag & RX_FLAG_HT)
409 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
410 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
411 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
412 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
413 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
414 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
415
416 if (ieee80211_vif_is_mesh(&sdata->vif)) {
417 #ifdef CONFIG_MAC80211_MESH
418 sinfo->filled |= STATION_INFO_LLID |
419 STATION_INFO_PLID |
420 STATION_INFO_PLINK_STATE;
421
422 sinfo->llid = le16_to_cpu(sta->llid);
423 sinfo->plid = le16_to_cpu(sta->plid);
424 sinfo->plink_state = sta->plink_state;
425 #endif
426 }
427
428 sinfo->bss_param.flags = 0;
429 if (sdata->vif.bss_conf.use_cts_prot)
430 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
431 if (sdata->vif.bss_conf.use_short_preamble)
432 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
433 if (sdata->vif.bss_conf.use_short_slot)
434 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
435 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
436 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
437
438 sinfo->sta_flags.set = 0;
439 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
440 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
441 BIT(NL80211_STA_FLAG_WME) |
442 BIT(NL80211_STA_FLAG_MFP) |
443 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
444 BIT(NL80211_STA_FLAG_TDLS_PEER);
445 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
446 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
447 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
448 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
449 if (test_sta_flag(sta, WLAN_STA_WME))
450 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
451 if (test_sta_flag(sta, WLAN_STA_MFP))
452 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
453 if (test_sta_flag(sta, WLAN_STA_AUTH))
454 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
455 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
456 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
457 }
458
459
ieee80211_dump_station(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * mac,struct station_info * sinfo)460 static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
461 int idx, u8 *mac, struct station_info *sinfo)
462 {
463 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
464 struct sta_info *sta;
465 int ret = -ENOENT;
466
467 rcu_read_lock();
468
469 sta = sta_info_get_by_idx(sdata, idx);
470 if (sta) {
471 ret = 0;
472 memcpy(mac, sta->sta.addr, ETH_ALEN);
473 sta_set_sinfo(sta, sinfo);
474 }
475
476 rcu_read_unlock();
477
478 return ret;
479 }
480
ieee80211_dump_survey(struct wiphy * wiphy,struct net_device * dev,int idx,struct survey_info * survey)481 static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
482 int idx, struct survey_info *survey)
483 {
484 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
485
486 return drv_get_survey(local, idx, survey);
487 }
488
ieee80211_get_station(struct wiphy * wiphy,struct net_device * dev,u8 * mac,struct station_info * sinfo)489 static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
490 u8 *mac, struct station_info *sinfo)
491 {
492 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
493 struct sta_info *sta;
494 int ret = -ENOENT;
495
496 rcu_read_lock();
497
498 sta = sta_info_get_bss(sdata, mac);
499 if (sta) {
500 ret = 0;
501 sta_set_sinfo(sta, sinfo);
502 }
503
504 rcu_read_unlock();
505
506 return ret;
507 }
508
ieee80211_set_probe_resp(struct ieee80211_sub_if_data * sdata,const u8 * resp,size_t resp_len)509 static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
510 const u8 *resp, size_t resp_len)
511 {
512 struct sk_buff *new, *old;
513
514 if (!resp || !resp_len)
515 return 1;
516
517 old = rtnl_dereference(sdata->u.ap.probe_resp);
518
519 new = dev_alloc_skb(resp_len);
520 if (!new)
521 return -ENOMEM;
522
523 memcpy(skb_put(new, resp_len), resp, resp_len);
524
525 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
526 if (old) {
527 /* TODO: use call_rcu() */
528 synchronize_rcu();
529 dev_kfree_skb(old);
530 }
531
532 return 0;
533 }
534
ieee80211_assign_beacon(struct ieee80211_sub_if_data * sdata,struct cfg80211_beacon_data * params)535 static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
536 struct cfg80211_beacon_data *params)
537 {
538 struct beacon_data *new, *old;
539 int new_head_len, new_tail_len;
540 int size, err;
541 u32 changed = BSS_CHANGED_BEACON;
542
543 old = rtnl_dereference(sdata->u.ap.beacon);
544
545 /* Need to have a beacon head if we don't have one yet */
546 if (!params->head && !old)
547 return -EINVAL;
548
549 /* new or old head? */
550 if (params->head)
551 new_head_len = params->head_len;
552 else
553 new_head_len = old->head_len;
554
555 /* new or old tail? */
556 if (params->tail || !old)
557 /* params->tail_len will be zero for !params->tail */
558 new_tail_len = params->tail_len;
559 else
560 new_tail_len = old->tail_len;
561
562 size = sizeof(*new) + new_head_len + new_tail_len;
563
564 new = kzalloc(size, GFP_KERNEL);
565 if (!new)
566 return -ENOMEM;
567
568 /* start filling the new info now */
569
570 /*
571 * pointers go into the block we allocated,
572 * memory is | beacon_data | head | tail |
573 */
574 new->head = ((u8 *) new) + sizeof(*new);
575 new->tail = new->head + new_head_len;
576 new->head_len = new_head_len;
577 new->tail_len = new_tail_len;
578
579 /* copy in head */
580 if (params->head)
581 memcpy(new->head, params->head, new_head_len);
582 else
583 memcpy(new->head, old->head, new_head_len);
584
585 /* copy in optional tail */
586 if (params->tail)
587 memcpy(new->tail, params->tail, new_tail_len);
588 else
589 if (old)
590 memcpy(new->tail, old->tail, new_tail_len);
591
592 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
593 params->probe_resp_len);
594 if (err < 0)
595 return err;
596 if (err == 0)
597 changed |= BSS_CHANGED_AP_PROBE_RESP;
598
599 rcu_assign_pointer(sdata->u.ap.beacon, new);
600
601 if (old)
602 kfree_rcu(old, rcu_head);
603
604 return changed;
605 }
606
ieee80211_start_ap(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ap_settings * params)607 static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
608 struct cfg80211_ap_settings *params)
609 {
610 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
611 struct beacon_data *old;
612 struct ieee80211_sub_if_data *vlan;
613 u32 changed = BSS_CHANGED_BEACON_INT |
614 BSS_CHANGED_BEACON_ENABLED |
615 BSS_CHANGED_BEACON |
616 BSS_CHANGED_SSID;
617 int err;
618
619 old = rtnl_dereference(sdata->u.ap.beacon);
620 if (old)
621 return -EALREADY;
622
623 /*
624 * Apply control port protocol, this allows us to
625 * not encrypt dynamic WEP control frames.
626 */
627 sdata->control_port_protocol = params->crypto.control_port_ethertype;
628 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
629 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
630 vlan->control_port_protocol =
631 params->crypto.control_port_ethertype;
632 vlan->control_port_no_encrypt =
633 params->crypto.control_port_no_encrypt;
634 }
635
636 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
637 sdata->vif.bss_conf.dtim_period = params->dtim_period;
638
639 sdata->vif.bss_conf.ssid_len = params->ssid_len;
640 if (params->ssid_len)
641 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
642 params->ssid_len);
643 sdata->vif.bss_conf.hidden_ssid =
644 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
645
646 err = ieee80211_assign_beacon(sdata, ¶ms->beacon);
647 if (err < 0)
648 return err;
649 changed |= err;
650
651 ieee80211_bss_info_change_notify(sdata, changed);
652
653 return 0;
654 }
655
ieee80211_change_beacon(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_beacon_data * params)656 static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
657 struct cfg80211_beacon_data *params)
658 {
659 struct ieee80211_sub_if_data *sdata;
660 struct beacon_data *old;
661 int err;
662
663 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
664
665 old = rtnl_dereference(sdata->u.ap.beacon);
666 if (!old)
667 return -ENOENT;
668
669 err = ieee80211_assign_beacon(sdata, params);
670 if (err < 0)
671 return err;
672 ieee80211_bss_info_change_notify(sdata, err);
673 return 0;
674 }
675
ieee80211_stop_ap(struct wiphy * wiphy,struct net_device * dev)676 static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
677 {
678 struct ieee80211_sub_if_data *sdata;
679 struct beacon_data *old;
680
681 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
682
683 old = rtnl_dereference(sdata->u.ap.beacon);
684 if (!old)
685 return -ENOENT;
686
687 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
688
689 kfree_rcu(old, rcu_head);
690
691 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
692
693 return 0;
694 }
695
696 /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
697 struct iapp_layer2_update {
698 u8 da[ETH_ALEN]; /* broadcast */
699 u8 sa[ETH_ALEN]; /* STA addr */
700 __be16 len; /* 6 */
701 u8 dsap; /* 0 */
702 u8 ssap; /* 0 */
703 u8 control;
704 u8 xid_info[3];
705 } __packed;
706
ieee80211_send_layer2_update(struct sta_info * sta)707 static void ieee80211_send_layer2_update(struct sta_info *sta)
708 {
709 struct iapp_layer2_update *msg;
710 struct sk_buff *skb;
711
712 /* Send Level 2 Update Frame to update forwarding tables in layer 2
713 * bridge devices */
714
715 skb = dev_alloc_skb(sizeof(*msg));
716 if (!skb)
717 return;
718 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
719
720 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
721 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
722
723 memset(msg->da, 0xff, ETH_ALEN);
724 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
725 msg->len = htons(6);
726 msg->dsap = 0;
727 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
728 msg->control = 0xaf; /* XID response lsb.1111F101.
729 * F=0 (no poll command; unsolicited frame) */
730 msg->xid_info[0] = 0x81; /* XID format identifier */
731 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
732 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
733
734 skb->dev = sta->sdata->dev;
735 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
736 memset(skb->cb, 0, sizeof(skb->cb));
737 netif_rx_ni(skb);
738 }
739
sta_apply_parameters(struct ieee80211_local * local,struct sta_info * sta,struct station_parameters * params)740 static int sta_apply_parameters(struct ieee80211_local *local,
741 struct sta_info *sta,
742 struct station_parameters *params)
743 {
744 int ret = 0;
745 u32 rates;
746 int i, j;
747 struct ieee80211_supported_band *sband;
748 struct ieee80211_sub_if_data *sdata = sta->sdata;
749 u32 mask, set;
750
751 sband = local->hw.wiphy->bands[local->oper_channel->band];
752
753 mask = params->sta_flags_mask;
754 set = params->sta_flags_set;
755
756 /*
757 * In mesh mode, we can clear AUTHENTICATED flag but must
758 * also make ASSOCIATED follow appropriately for the driver
759 * API. See also below, after AUTHORIZED changes.
760 */
761 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
762 /* cfg80211 should not allow this in non-mesh modes */
763 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
764 return -EINVAL;
765
766 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
767 !test_sta_flag(sta, WLAN_STA_AUTH)) {
768 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
769 if (ret)
770 return ret;
771 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
772 if (ret)
773 return ret;
774 }
775 }
776
777 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
778 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
779 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
780 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
781 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
782 if (ret)
783 return ret;
784 }
785
786 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
787 /* cfg80211 should not allow this in non-mesh modes */
788 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
789 return -EINVAL;
790
791 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
792 test_sta_flag(sta, WLAN_STA_AUTH)) {
793 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
794 if (ret)
795 return ret;
796 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
797 if (ret)
798 return ret;
799 }
800 }
801
802
803 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
804 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
805 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
806 else
807 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
808 }
809
810 if (mask & BIT(NL80211_STA_FLAG_WME)) {
811 if (set & BIT(NL80211_STA_FLAG_WME)) {
812 set_sta_flag(sta, WLAN_STA_WME);
813 sta->sta.wme = true;
814 } else {
815 clear_sta_flag(sta, WLAN_STA_WME);
816 sta->sta.wme = false;
817 }
818 }
819
820 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
821 if (set & BIT(NL80211_STA_FLAG_MFP))
822 set_sta_flag(sta, WLAN_STA_MFP);
823 else
824 clear_sta_flag(sta, WLAN_STA_MFP);
825 }
826
827 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
828 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
829 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
830 else
831 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
832 }
833
834 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
835 sta->sta.uapsd_queues = params->uapsd_queues;
836 sta->sta.max_sp = params->max_sp;
837 }
838
839 /*
840 * cfg80211 validates this (1-2007) and allows setting the AID
841 * only when creating a new station entry
842 */
843 if (params->aid)
844 sta->sta.aid = params->aid;
845
846 /*
847 * FIXME: updating the following information is racy when this
848 * function is called from ieee80211_change_station().
849 * However, all this information should be static so
850 * maybe we should just reject attemps to change it.
851 */
852
853 if (params->listen_interval >= 0)
854 sta->listen_interval = params->listen_interval;
855
856 if (params->supported_rates) {
857 rates = 0;
858
859 for (i = 0; i < params->supported_rates_len; i++) {
860 int rate = (params->supported_rates[i] & 0x7f) * 5;
861 for (j = 0; j < sband->n_bitrates; j++) {
862 if (sband->bitrates[j].bitrate == rate)
863 rates |= BIT(j);
864 }
865 }
866 sta->sta.supp_rates[local->oper_channel->band] = rates;
867 }
868
869 if (params->ht_capa)
870 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
871 params->ht_capa,
872 &sta->sta.ht_cap);
873
874 if (ieee80211_vif_is_mesh(&sdata->vif)) {
875 #ifdef CONFIG_MAC80211_MESH
876 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
877 switch (params->plink_state) {
878 case NL80211_PLINK_LISTEN:
879 case NL80211_PLINK_ESTAB:
880 case NL80211_PLINK_BLOCKED:
881 sta->plink_state = params->plink_state;
882 break;
883 default:
884 /* nothing */
885 break;
886 }
887 else
888 switch (params->plink_action) {
889 case PLINK_ACTION_OPEN:
890 mesh_plink_open(sta);
891 break;
892 case PLINK_ACTION_BLOCK:
893 mesh_plink_block(sta);
894 break;
895 }
896 #endif
897 }
898
899 return 0;
900 }
901
ieee80211_add_station(struct wiphy * wiphy,struct net_device * dev,u8 * mac,struct station_parameters * params)902 static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
903 u8 *mac, struct station_parameters *params)
904 {
905 struct ieee80211_local *local = wiphy_priv(wiphy);
906 struct sta_info *sta;
907 struct ieee80211_sub_if_data *sdata;
908 int err;
909 int layer2_update;
910
911 if (params->vlan) {
912 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
913
914 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
915 sdata->vif.type != NL80211_IFTYPE_AP)
916 return -EINVAL;
917 } else
918 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
919
920 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
921 return -EINVAL;
922
923 if (is_multicast_ether_addr(mac))
924 return -EINVAL;
925
926 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
927 if (!sta)
928 return -ENOMEM;
929
930 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
931 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
932
933 err = sta_apply_parameters(local, sta, params);
934 if (err) {
935 sta_info_free(local, sta);
936 return err;
937 }
938
939 /*
940 * for TDLS, rate control should be initialized only when supported
941 * rates are known.
942 */
943 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
944 rate_control_rate_init(sta);
945
946 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
947 sdata->vif.type == NL80211_IFTYPE_AP;
948
949 err = sta_info_insert_rcu(sta);
950 if (err) {
951 rcu_read_unlock();
952 return err;
953 }
954
955 if (layer2_update)
956 ieee80211_send_layer2_update(sta);
957
958 rcu_read_unlock();
959
960 return 0;
961 }
962
ieee80211_del_station(struct wiphy * wiphy,struct net_device * dev,u8 * mac)963 static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
964 u8 *mac)
965 {
966 struct ieee80211_local *local = wiphy_priv(wiphy);
967 struct ieee80211_sub_if_data *sdata;
968
969 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
970
971 if (mac)
972 return sta_info_destroy_addr_bss(sdata, mac);
973
974 sta_info_flush(local, sdata);
975 return 0;
976 }
977
ieee80211_change_station(struct wiphy * wiphy,struct net_device * dev,u8 * mac,struct station_parameters * params)978 static int ieee80211_change_station(struct wiphy *wiphy,
979 struct net_device *dev,
980 u8 *mac,
981 struct station_parameters *params)
982 {
983 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
984 struct ieee80211_local *local = wiphy_priv(wiphy);
985 struct sta_info *sta;
986 struct ieee80211_sub_if_data *vlansdata;
987 int err;
988
989 mutex_lock(&local->sta_mtx);
990
991 sta = sta_info_get_bss(sdata, mac);
992 if (!sta) {
993 mutex_unlock(&local->sta_mtx);
994 return -ENOENT;
995 }
996
997 /* in station mode, supported rates are only valid with TDLS */
998 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
999 params->supported_rates &&
1000 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1001 mutex_unlock(&local->sta_mtx);
1002 return -EINVAL;
1003 }
1004
1005 if (params->vlan && params->vlan != sta->sdata->dev) {
1006 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1007
1008 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1009 vlansdata->vif.type != NL80211_IFTYPE_AP) {
1010 mutex_unlock(&local->sta_mtx);
1011 return -EINVAL;
1012 }
1013
1014 if (params->vlan->ieee80211_ptr->use_4addr) {
1015 if (vlansdata->u.vlan.sta) {
1016 mutex_unlock(&local->sta_mtx);
1017 return -EBUSY;
1018 }
1019
1020 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
1021 }
1022
1023 sta->sdata = vlansdata;
1024 ieee80211_send_layer2_update(sta);
1025 }
1026
1027 err = sta_apply_parameters(local, sta, params);
1028 if (err) {
1029 mutex_unlock(&local->sta_mtx);
1030 return err;
1031 }
1032
1033 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1034 rate_control_rate_init(sta);
1035
1036 mutex_unlock(&local->sta_mtx);
1037
1038 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1039 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1040 ieee80211_recalc_ps(local, -1);
1041
1042 return 0;
1043 }
1044
1045 #ifdef CONFIG_MAC80211_MESH
ieee80211_add_mpath(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * next_hop)1046 static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1047 u8 *dst, u8 *next_hop)
1048 {
1049 struct ieee80211_sub_if_data *sdata;
1050 struct mesh_path *mpath;
1051 struct sta_info *sta;
1052 int err;
1053
1054 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1055
1056 rcu_read_lock();
1057 sta = sta_info_get(sdata, next_hop);
1058 if (!sta) {
1059 rcu_read_unlock();
1060 return -ENOENT;
1061 }
1062
1063 err = mesh_path_add(dst, sdata);
1064 if (err) {
1065 rcu_read_unlock();
1066 return err;
1067 }
1068
1069 mpath = mesh_path_lookup(dst, sdata);
1070 if (!mpath) {
1071 rcu_read_unlock();
1072 return -ENXIO;
1073 }
1074 mesh_path_fix_nexthop(mpath, sta);
1075
1076 rcu_read_unlock();
1077 return 0;
1078 }
1079
ieee80211_del_mpath(struct wiphy * wiphy,struct net_device * dev,u8 * dst)1080 static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1081 u8 *dst)
1082 {
1083 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1084
1085 if (dst)
1086 return mesh_path_del(dst, sdata);
1087
1088 mesh_path_flush_by_iface(sdata);
1089 return 0;
1090 }
1091
ieee80211_change_mpath(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * next_hop)1092 static int ieee80211_change_mpath(struct wiphy *wiphy,
1093 struct net_device *dev,
1094 u8 *dst, u8 *next_hop)
1095 {
1096 struct ieee80211_sub_if_data *sdata;
1097 struct mesh_path *mpath;
1098 struct sta_info *sta;
1099
1100 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1101
1102 rcu_read_lock();
1103
1104 sta = sta_info_get(sdata, next_hop);
1105 if (!sta) {
1106 rcu_read_unlock();
1107 return -ENOENT;
1108 }
1109
1110 mpath = mesh_path_lookup(dst, sdata);
1111 if (!mpath) {
1112 rcu_read_unlock();
1113 return -ENOENT;
1114 }
1115
1116 mesh_path_fix_nexthop(mpath, sta);
1117
1118 rcu_read_unlock();
1119 return 0;
1120 }
1121
mpath_set_pinfo(struct mesh_path * mpath,u8 * next_hop,struct mpath_info * pinfo)1122 static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1123 struct mpath_info *pinfo)
1124 {
1125 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1126
1127 if (next_hop_sta)
1128 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
1129 else
1130 memset(next_hop, 0, ETH_ALEN);
1131
1132 pinfo->generation = mesh_paths_generation;
1133
1134 pinfo->filled = MPATH_INFO_FRAME_QLEN |
1135 MPATH_INFO_SN |
1136 MPATH_INFO_METRIC |
1137 MPATH_INFO_EXPTIME |
1138 MPATH_INFO_DISCOVERY_TIMEOUT |
1139 MPATH_INFO_DISCOVERY_RETRIES |
1140 MPATH_INFO_FLAGS;
1141
1142 pinfo->frame_qlen = mpath->frame_queue.qlen;
1143 pinfo->sn = mpath->sn;
1144 pinfo->metric = mpath->metric;
1145 if (time_before(jiffies, mpath->exp_time))
1146 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1147 pinfo->discovery_timeout =
1148 jiffies_to_msecs(mpath->discovery_timeout);
1149 pinfo->discovery_retries = mpath->discovery_retries;
1150 pinfo->flags = 0;
1151 if (mpath->flags & MESH_PATH_ACTIVE)
1152 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1153 if (mpath->flags & MESH_PATH_RESOLVING)
1154 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1155 if (mpath->flags & MESH_PATH_SN_VALID)
1156 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
1157 if (mpath->flags & MESH_PATH_FIXED)
1158 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1159 if (mpath->flags & MESH_PATH_RESOLVING)
1160 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1161
1162 pinfo->flags = mpath->flags;
1163 }
1164
ieee80211_get_mpath(struct wiphy * wiphy,struct net_device * dev,u8 * dst,u8 * next_hop,struct mpath_info * pinfo)1165 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1166 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1167
1168 {
1169 struct ieee80211_sub_if_data *sdata;
1170 struct mesh_path *mpath;
1171
1172 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1173
1174 rcu_read_lock();
1175 mpath = mesh_path_lookup(dst, sdata);
1176 if (!mpath) {
1177 rcu_read_unlock();
1178 return -ENOENT;
1179 }
1180 memcpy(dst, mpath->dst, ETH_ALEN);
1181 mpath_set_pinfo(mpath, next_hop, pinfo);
1182 rcu_read_unlock();
1183 return 0;
1184 }
1185
ieee80211_dump_mpath(struct wiphy * wiphy,struct net_device * dev,int idx,u8 * dst,u8 * next_hop,struct mpath_info * pinfo)1186 static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1187 int idx, u8 *dst, u8 *next_hop,
1188 struct mpath_info *pinfo)
1189 {
1190 struct ieee80211_sub_if_data *sdata;
1191 struct mesh_path *mpath;
1192
1193 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1194
1195 rcu_read_lock();
1196 mpath = mesh_path_lookup_by_idx(idx, sdata);
1197 if (!mpath) {
1198 rcu_read_unlock();
1199 return -ENOENT;
1200 }
1201 memcpy(dst, mpath->dst, ETH_ALEN);
1202 mpath_set_pinfo(mpath, next_hop, pinfo);
1203 rcu_read_unlock();
1204 return 0;
1205 }
1206
ieee80211_get_mesh_config(struct wiphy * wiphy,struct net_device * dev,struct mesh_config * conf)1207 static int ieee80211_get_mesh_config(struct wiphy *wiphy,
1208 struct net_device *dev,
1209 struct mesh_config *conf)
1210 {
1211 struct ieee80211_sub_if_data *sdata;
1212 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1213
1214 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1215 return 0;
1216 }
1217
_chg_mesh_attr(enum nl80211_meshconf_params parm,u32 mask)1218 static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1219 {
1220 return (mask >> (parm-1)) & 0x1;
1221 }
1222
copy_mesh_setup(struct ieee80211_if_mesh * ifmsh,const struct mesh_setup * setup)1223 static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1224 const struct mesh_setup *setup)
1225 {
1226 u8 *new_ie;
1227 const u8 *old_ie;
1228 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1229 struct ieee80211_sub_if_data, u.mesh);
1230
1231 /* allocate information elements */
1232 new_ie = NULL;
1233 old_ie = ifmsh->ie;
1234
1235 if (setup->ie_len) {
1236 new_ie = kmemdup(setup->ie, setup->ie_len,
1237 GFP_KERNEL);
1238 if (!new_ie)
1239 return -ENOMEM;
1240 }
1241 ifmsh->ie_len = setup->ie_len;
1242 ifmsh->ie = new_ie;
1243 kfree(old_ie);
1244
1245 /* now copy the rest of the setup parameters */
1246 ifmsh->mesh_id_len = setup->mesh_id_len;
1247 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1248 ifmsh->mesh_pp_id = setup->path_sel_proto;
1249 ifmsh->mesh_pm_id = setup->path_metric;
1250 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1251 if (setup->is_authenticated)
1252 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1253 if (setup->is_secure)
1254 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
1255
1256 /* mcast rate setting in Mesh Node */
1257 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1258 sizeof(setup->mcast_rate));
1259
1260 return 0;
1261 }
1262
ieee80211_update_mesh_config(struct wiphy * wiphy,struct net_device * dev,u32 mask,const struct mesh_config * nconf)1263 static int ieee80211_update_mesh_config(struct wiphy *wiphy,
1264 struct net_device *dev, u32 mask,
1265 const struct mesh_config *nconf)
1266 {
1267 struct mesh_config *conf;
1268 struct ieee80211_sub_if_data *sdata;
1269 struct ieee80211_if_mesh *ifmsh;
1270
1271 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1272 ifmsh = &sdata->u.mesh;
1273
1274 /* Set the config options which we are interested in setting */
1275 conf = &(sdata->u.mesh.mshcfg);
1276 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1277 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1278 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1279 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1280 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1281 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1282 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1283 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1284 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1285 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1286 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1287 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1288 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1289 conf->dot11MeshTTL = nconf->element_ttl;
1290 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1291 conf->auto_open_plinks = nconf->auto_open_plinks;
1292 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1293 conf->dot11MeshHWMPmaxPREQretries =
1294 nconf->dot11MeshHWMPmaxPREQretries;
1295 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1296 conf->path_refresh_time = nconf->path_refresh_time;
1297 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1298 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1299 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1300 conf->dot11MeshHWMPactivePathTimeout =
1301 nconf->dot11MeshHWMPactivePathTimeout;
1302 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1303 conf->dot11MeshHWMPpreqMinInterval =
1304 nconf->dot11MeshHWMPpreqMinInterval;
1305 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1306 conf->dot11MeshHWMPperrMinInterval =
1307 nconf->dot11MeshHWMPperrMinInterval;
1308 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1309 mask))
1310 conf->dot11MeshHWMPnetDiameterTraversalTime =
1311 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1312 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1313 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1314 ieee80211_mesh_root_setup(ifmsh);
1315 }
1316 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
1317 /* our current gate announcement implementation rides on root
1318 * announcements, so require this ifmsh to also be a root node
1319 * */
1320 if (nconf->dot11MeshGateAnnouncementProtocol &&
1321 !conf->dot11MeshHWMPRootMode) {
1322 conf->dot11MeshHWMPRootMode = 1;
1323 ieee80211_mesh_root_setup(ifmsh);
1324 }
1325 conf->dot11MeshGateAnnouncementProtocol =
1326 nconf->dot11MeshGateAnnouncementProtocol;
1327 }
1328 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1329 conf->dot11MeshHWMPRannInterval =
1330 nconf->dot11MeshHWMPRannInterval;
1331 }
1332 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1333 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
1334 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1335 /* our RSSI threshold implementation is supported only for
1336 * devices that report signal in dBm.
1337 */
1338 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1339 return -ENOTSUPP;
1340 conf->rssi_threshold = nconf->rssi_threshold;
1341 }
1342 return 0;
1343 }
1344
ieee80211_join_mesh(struct wiphy * wiphy,struct net_device * dev,const struct mesh_config * conf,const struct mesh_setup * setup)1345 static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1346 const struct mesh_config *conf,
1347 const struct mesh_setup *setup)
1348 {
1349 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1350 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
1351 int err;
1352
1353 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1354 err = copy_mesh_setup(ifmsh, setup);
1355 if (err)
1356 return err;
1357 ieee80211_start_mesh(sdata);
1358
1359 return 0;
1360 }
1361
ieee80211_leave_mesh(struct wiphy * wiphy,struct net_device * dev)1362 static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1363 {
1364 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1365
1366 ieee80211_stop_mesh(sdata);
1367
1368 return 0;
1369 }
1370 #endif
1371
ieee80211_change_bss(struct wiphy * wiphy,struct net_device * dev,struct bss_parameters * params)1372 static int ieee80211_change_bss(struct wiphy *wiphy,
1373 struct net_device *dev,
1374 struct bss_parameters *params)
1375 {
1376 struct ieee80211_sub_if_data *sdata;
1377 u32 changed = 0;
1378
1379 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1380
1381 if (params->use_cts_prot >= 0) {
1382 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
1383 changed |= BSS_CHANGED_ERP_CTS_PROT;
1384 }
1385 if (params->use_short_preamble >= 0) {
1386 sdata->vif.bss_conf.use_short_preamble =
1387 params->use_short_preamble;
1388 changed |= BSS_CHANGED_ERP_PREAMBLE;
1389 }
1390
1391 if (!sdata->vif.bss_conf.use_short_slot &&
1392 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1393 sdata->vif.bss_conf.use_short_slot = true;
1394 changed |= BSS_CHANGED_ERP_SLOT;
1395 }
1396
1397 if (params->use_short_slot_time >= 0) {
1398 sdata->vif.bss_conf.use_short_slot =
1399 params->use_short_slot_time;
1400 changed |= BSS_CHANGED_ERP_SLOT;
1401 }
1402
1403 if (params->basic_rates) {
1404 int i, j;
1405 u32 rates = 0;
1406 struct ieee80211_local *local = wiphy_priv(wiphy);
1407 struct ieee80211_supported_band *sband =
1408 wiphy->bands[local->oper_channel->band];
1409
1410 for (i = 0; i < params->basic_rates_len; i++) {
1411 int rate = (params->basic_rates[i] & 0x7f) * 5;
1412 for (j = 0; j < sband->n_bitrates; j++) {
1413 if (sband->bitrates[j].bitrate == rate)
1414 rates |= BIT(j);
1415 }
1416 }
1417 sdata->vif.bss_conf.basic_rates = rates;
1418 changed |= BSS_CHANGED_BASIC_RATES;
1419 }
1420
1421 if (params->ap_isolate >= 0) {
1422 if (params->ap_isolate)
1423 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1424 else
1425 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1426 }
1427
1428 if (params->ht_opmode >= 0) {
1429 sdata->vif.bss_conf.ht_operation_mode =
1430 (u16) params->ht_opmode;
1431 changed |= BSS_CHANGED_HT;
1432 }
1433
1434 ieee80211_bss_info_change_notify(sdata, changed);
1435
1436 return 0;
1437 }
1438
ieee80211_set_txq_params(struct wiphy * wiphy,struct net_device * dev,struct ieee80211_txq_params * params)1439 static int ieee80211_set_txq_params(struct wiphy *wiphy,
1440 struct net_device *dev,
1441 struct ieee80211_txq_params *params)
1442 {
1443 struct ieee80211_local *local = wiphy_priv(wiphy);
1444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1445 struct ieee80211_tx_queue_params p;
1446
1447 if (!local->ops->conf_tx)
1448 return -EOPNOTSUPP;
1449
1450 memset(&p, 0, sizeof(p));
1451 p.aifs = params->aifs;
1452 p.cw_max = params->cwmax;
1453 p.cw_min = params->cwmin;
1454 p.txop = params->txop;
1455
1456 /*
1457 * Setting tx queue params disables u-apsd because it's only
1458 * called in master mode.
1459 */
1460 p.uapsd = false;
1461
1462 if (params->queue >= local->hw.queues)
1463 return -EINVAL;
1464
1465 sdata->tx_conf[params->queue] = p;
1466 if (drv_conf_tx(local, sdata, params->queue, &p)) {
1467 wiphy_debug(local->hw.wiphy,
1468 "failed to set TX queue parameters for queue %d\n",
1469 params->queue);
1470 return -EINVAL;
1471 }
1472
1473 return 0;
1474 }
1475
ieee80211_set_channel(struct wiphy * wiphy,struct net_device * netdev,struct ieee80211_channel * chan,enum nl80211_channel_type channel_type)1476 static int ieee80211_set_channel(struct wiphy *wiphy,
1477 struct net_device *netdev,
1478 struct ieee80211_channel *chan,
1479 enum nl80211_channel_type channel_type)
1480 {
1481 struct ieee80211_local *local = wiphy_priv(wiphy);
1482 struct ieee80211_sub_if_data *sdata = NULL;
1483 struct ieee80211_channel *old_oper;
1484 enum nl80211_channel_type old_oper_type;
1485 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
1486
1487 if (netdev)
1488 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1489
1490 switch (ieee80211_get_channel_mode(local, NULL)) {
1491 case CHAN_MODE_HOPPING:
1492 return -EBUSY;
1493 case CHAN_MODE_FIXED:
1494 if (local->oper_channel != chan)
1495 return -EBUSY;
1496 if (!sdata && local->_oper_channel_type == channel_type)
1497 return 0;
1498 break;
1499 case CHAN_MODE_UNDEFINED:
1500 break;
1501 }
1502
1503 if (sdata)
1504 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1505 old_oper_type = local->_oper_channel_type;
1506
1507 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1508 return -EBUSY;
1509
1510 old_oper = local->oper_channel;
1511 local->oper_channel = chan;
1512
1513 /* Update driver if changes were actually made. */
1514 if ((old_oper != local->oper_channel) ||
1515 (old_oper_type != local->_oper_channel_type))
1516 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1517
1518 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1519 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
1520 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1521
1522 return 0;
1523 }
1524
1525 #ifdef CONFIG_PM
ieee80211_suspend(struct wiphy * wiphy,struct cfg80211_wowlan * wowlan)1526 static int ieee80211_suspend(struct wiphy *wiphy,
1527 struct cfg80211_wowlan *wowlan)
1528 {
1529 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
1530 }
1531
ieee80211_resume(struct wiphy * wiphy)1532 static int ieee80211_resume(struct wiphy *wiphy)
1533 {
1534 return __ieee80211_resume(wiphy_priv(wiphy));
1535 }
1536 #else
1537 #define ieee80211_suspend NULL
1538 #define ieee80211_resume NULL
1539 #endif
1540
ieee80211_scan(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_scan_request * req)1541 static int ieee80211_scan(struct wiphy *wiphy,
1542 struct net_device *dev,
1543 struct cfg80211_scan_request *req)
1544 {
1545 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1546
1547 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1548 case NL80211_IFTYPE_STATION:
1549 case NL80211_IFTYPE_ADHOC:
1550 case NL80211_IFTYPE_MESH_POINT:
1551 case NL80211_IFTYPE_P2P_CLIENT:
1552 break;
1553 case NL80211_IFTYPE_P2P_GO:
1554 if (sdata->local->ops->hw_scan)
1555 break;
1556 /*
1557 * FIXME: implement NoA while scanning in software,
1558 * for now fall through to allow scanning only when
1559 * beaconing hasn't been configured yet
1560 */
1561 case NL80211_IFTYPE_AP:
1562 if (sdata->u.ap.beacon)
1563 return -EOPNOTSUPP;
1564 break;
1565 default:
1566 return -EOPNOTSUPP;
1567 }
1568
1569 return ieee80211_request_scan(sdata, req);
1570 }
1571
1572 static int
ieee80211_sched_scan_start(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_sched_scan_request * req)1573 ieee80211_sched_scan_start(struct wiphy *wiphy,
1574 struct net_device *dev,
1575 struct cfg80211_sched_scan_request *req)
1576 {
1577 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1578
1579 if (!sdata->local->ops->sched_scan_start)
1580 return -EOPNOTSUPP;
1581
1582 return ieee80211_request_sched_scan_start(sdata, req);
1583 }
1584
1585 static int
ieee80211_sched_scan_stop(struct wiphy * wiphy,struct net_device * dev)1586 ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
1587 {
1588 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1589
1590 if (!sdata->local->ops->sched_scan_stop)
1591 return -EOPNOTSUPP;
1592
1593 return ieee80211_request_sched_scan_stop(sdata);
1594 }
1595
ieee80211_auth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_auth_request * req)1596 static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1597 struct cfg80211_auth_request *req)
1598 {
1599 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1600 }
1601
ieee80211_assoc(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_assoc_request * req)1602 static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1603 struct cfg80211_assoc_request *req)
1604 {
1605 struct ieee80211_local *local = wiphy_priv(wiphy);
1606 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1607
1608 switch (ieee80211_get_channel_mode(local, sdata)) {
1609 case CHAN_MODE_HOPPING:
1610 return -EBUSY;
1611 case CHAN_MODE_FIXED:
1612 if (local->oper_channel == req->bss->channel)
1613 break;
1614 return -EBUSY;
1615 case CHAN_MODE_UNDEFINED:
1616 break;
1617 }
1618
1619 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1620 }
1621
ieee80211_deauth(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_deauth_request * req)1622 static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1623 struct cfg80211_deauth_request *req)
1624 {
1625 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
1626 }
1627
ieee80211_disassoc(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_disassoc_request * req)1628 static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1629 struct cfg80211_disassoc_request *req)
1630 {
1631 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
1632 }
1633
ieee80211_join_ibss(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_ibss_params * params)1634 static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1635 struct cfg80211_ibss_params *params)
1636 {
1637 struct ieee80211_local *local = wiphy_priv(wiphy);
1638 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1639
1640 switch (ieee80211_get_channel_mode(local, sdata)) {
1641 case CHAN_MODE_HOPPING:
1642 return -EBUSY;
1643 case CHAN_MODE_FIXED:
1644 if (!params->channel_fixed)
1645 return -EBUSY;
1646 if (local->oper_channel == params->channel)
1647 break;
1648 return -EBUSY;
1649 case CHAN_MODE_UNDEFINED:
1650 break;
1651 }
1652
1653 return ieee80211_ibss_join(sdata, params);
1654 }
1655
ieee80211_leave_ibss(struct wiphy * wiphy,struct net_device * dev)1656 static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1657 {
1658 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1659
1660 return ieee80211_ibss_leave(sdata);
1661 }
1662
ieee80211_set_wiphy_params(struct wiphy * wiphy,u32 changed)1663 static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1664 {
1665 struct ieee80211_local *local = wiphy_priv(wiphy);
1666 int err;
1667
1668 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1669 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1670
1671 if (err)
1672 return err;
1673 }
1674
1675 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1676 err = drv_set_coverage_class(local, wiphy->coverage_class);
1677
1678 if (err)
1679 return err;
1680 }
1681
1682 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1683 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
1684
1685 if (err)
1686 return err;
1687 }
1688
1689 if (changed & WIPHY_PARAM_RETRY_SHORT)
1690 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1691 if (changed & WIPHY_PARAM_RETRY_LONG)
1692 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1693 if (changed &
1694 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1695 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1696
1697 return 0;
1698 }
1699
ieee80211_set_tx_power(struct wiphy * wiphy,enum nl80211_tx_power_setting type,int mbm)1700 static int ieee80211_set_tx_power(struct wiphy *wiphy,
1701 enum nl80211_tx_power_setting type, int mbm)
1702 {
1703 struct ieee80211_local *local = wiphy_priv(wiphy);
1704 struct ieee80211_channel *chan = local->hw.conf.channel;
1705 u32 changes = 0;
1706
1707 switch (type) {
1708 case NL80211_TX_POWER_AUTOMATIC:
1709 local->user_power_level = -1;
1710 break;
1711 case NL80211_TX_POWER_LIMITED:
1712 if (mbm < 0 || (mbm % 100))
1713 return -EOPNOTSUPP;
1714 local->user_power_level = MBM_TO_DBM(mbm);
1715 break;
1716 case NL80211_TX_POWER_FIXED:
1717 if (mbm < 0 || (mbm % 100))
1718 return -EOPNOTSUPP;
1719 /* TODO: move to cfg80211 when it knows the channel */
1720 if (MBM_TO_DBM(mbm) > chan->max_power)
1721 return -EINVAL;
1722 local->user_power_level = MBM_TO_DBM(mbm);
1723 break;
1724 }
1725
1726 ieee80211_hw_config(local, changes);
1727
1728 return 0;
1729 }
1730
ieee80211_get_tx_power(struct wiphy * wiphy,int * dbm)1731 static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1732 {
1733 struct ieee80211_local *local = wiphy_priv(wiphy);
1734
1735 *dbm = local->hw.conf.power_level;
1736
1737 return 0;
1738 }
1739
ieee80211_set_wds_peer(struct wiphy * wiphy,struct net_device * dev,const u8 * addr)1740 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1741 const u8 *addr)
1742 {
1743 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1744
1745 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1746
1747 return 0;
1748 }
1749
ieee80211_rfkill_poll(struct wiphy * wiphy)1750 static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1751 {
1752 struct ieee80211_local *local = wiphy_priv(wiphy);
1753
1754 drv_rfkill_poll(local);
1755 }
1756
1757 #ifdef CONFIG_NL80211_TESTMODE
ieee80211_testmode_cmd(struct wiphy * wiphy,void * data,int len)1758 static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
1759 {
1760 struct ieee80211_local *local = wiphy_priv(wiphy);
1761
1762 if (!local->ops->testmode_cmd)
1763 return -EOPNOTSUPP;
1764
1765 return local->ops->testmode_cmd(&local->hw, data, len);
1766 }
1767
ieee80211_testmode_dump(struct wiphy * wiphy,struct sk_buff * skb,struct netlink_callback * cb,void * data,int len)1768 static int ieee80211_testmode_dump(struct wiphy *wiphy,
1769 struct sk_buff *skb,
1770 struct netlink_callback *cb,
1771 void *data, int len)
1772 {
1773 struct ieee80211_local *local = wiphy_priv(wiphy);
1774
1775 if (!local->ops->testmode_dump)
1776 return -EOPNOTSUPP;
1777
1778 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1779 }
1780 #endif
1781
__ieee80211_request_smps(struct ieee80211_sub_if_data * sdata,enum ieee80211_smps_mode smps_mode)1782 int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1783 enum ieee80211_smps_mode smps_mode)
1784 {
1785 const u8 *ap;
1786 enum ieee80211_smps_mode old_req;
1787 int err;
1788
1789 lockdep_assert_held(&sdata->u.mgd.mtx);
1790
1791 old_req = sdata->u.mgd.req_smps;
1792 sdata->u.mgd.req_smps = smps_mode;
1793
1794 if (old_req == smps_mode &&
1795 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1796 return 0;
1797
1798 /*
1799 * If not associated, or current association is not an HT
1800 * association, there's no need to send an action frame.
1801 */
1802 if (!sdata->u.mgd.associated ||
1803 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
1804 mutex_lock(&sdata->local->iflist_mtx);
1805 ieee80211_recalc_smps(sdata->local);
1806 mutex_unlock(&sdata->local->iflist_mtx);
1807 return 0;
1808 }
1809
1810 ap = sdata->u.mgd.associated->bssid;
1811
1812 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1813 if (sdata->u.mgd.powersave)
1814 smps_mode = IEEE80211_SMPS_DYNAMIC;
1815 else
1816 smps_mode = IEEE80211_SMPS_OFF;
1817 }
1818
1819 /* send SM PS frame to AP */
1820 err = ieee80211_send_smps_action(sdata, smps_mode,
1821 ap, ap);
1822 if (err)
1823 sdata->u.mgd.req_smps = old_req;
1824
1825 return err;
1826 }
1827
ieee80211_set_power_mgmt(struct wiphy * wiphy,struct net_device * dev,bool enabled,int timeout)1828 static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1829 bool enabled, int timeout)
1830 {
1831 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1832 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1833
1834 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1835 return -EOPNOTSUPP;
1836
1837 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1838 return -EOPNOTSUPP;
1839
1840 if (enabled == sdata->u.mgd.powersave &&
1841 timeout == local->dynamic_ps_forced_timeout)
1842 return 0;
1843
1844 sdata->u.mgd.powersave = enabled;
1845 local->dynamic_ps_forced_timeout = timeout;
1846
1847 /* no change, but if automatic follow powersave */
1848 mutex_lock(&sdata->u.mgd.mtx);
1849 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1850 mutex_unlock(&sdata->u.mgd.mtx);
1851
1852 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1853 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1854
1855 ieee80211_recalc_ps(local, -1);
1856
1857 return 0;
1858 }
1859
ieee80211_set_cqm_rssi_config(struct wiphy * wiphy,struct net_device * dev,s32 rssi_thold,u32 rssi_hyst)1860 static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1861 struct net_device *dev,
1862 s32 rssi_thold, u32 rssi_hyst)
1863 {
1864 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1865 struct ieee80211_vif *vif = &sdata->vif;
1866 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1867
1868 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1869 rssi_hyst == bss_conf->cqm_rssi_hyst)
1870 return 0;
1871
1872 bss_conf->cqm_rssi_thold = rssi_thold;
1873 bss_conf->cqm_rssi_hyst = rssi_hyst;
1874
1875 /* tell the driver upon association, unless already associated */
1876 if (sdata->u.mgd.associated &&
1877 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
1878 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1879
1880 return 0;
1881 }
1882
ieee80211_set_bitrate_mask(struct wiphy * wiphy,struct net_device * dev,const u8 * addr,const struct cfg80211_bitrate_mask * mask)1883 static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1884 struct net_device *dev,
1885 const u8 *addr,
1886 const struct cfg80211_bitrate_mask *mask)
1887 {
1888 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1889 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1890 int i, ret;
1891
1892 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1893 ret = drv_set_bitrate_mask(local, sdata, mask);
1894 if (ret)
1895 return ret;
1896 }
1897
1898 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
1899 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
1900 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
1901 sizeof(mask->control[i].mcs));
1902 }
1903
1904 return 0;
1905 }
1906
ieee80211_remain_on_channel_hw(struct ieee80211_local * local,struct net_device * dev,struct ieee80211_channel * chan,enum nl80211_channel_type chantype,unsigned int duration,u64 * cookie)1907 static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1908 struct net_device *dev,
1909 struct ieee80211_channel *chan,
1910 enum nl80211_channel_type chantype,
1911 unsigned int duration, u64 *cookie)
1912 {
1913 int ret;
1914 u32 random_cookie;
1915
1916 lockdep_assert_held(&local->mtx);
1917
1918 if (local->hw_roc_cookie)
1919 return -EBUSY;
1920 /* must be nonzero */
1921 random_cookie = random32() | 1;
1922
1923 *cookie = random_cookie;
1924 local->hw_roc_dev = dev;
1925 local->hw_roc_cookie = random_cookie;
1926 local->hw_roc_channel = chan;
1927 local->hw_roc_channel_type = chantype;
1928 local->hw_roc_duration = duration;
1929 ret = drv_remain_on_channel(local, chan, chantype, duration);
1930 if (ret) {
1931 local->hw_roc_channel = NULL;
1932 local->hw_roc_cookie = 0;
1933 }
1934
1935 return ret;
1936 }
1937
ieee80211_remain_on_channel(struct wiphy * wiphy,struct net_device * dev,struct ieee80211_channel * chan,enum nl80211_channel_type channel_type,unsigned int duration,u64 * cookie)1938 static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1939 struct net_device *dev,
1940 struct ieee80211_channel *chan,
1941 enum nl80211_channel_type channel_type,
1942 unsigned int duration,
1943 u64 *cookie)
1944 {
1945 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1946 struct ieee80211_local *local = sdata->local;
1947
1948 if (local->ops->remain_on_channel) {
1949 int ret;
1950
1951 mutex_lock(&local->mtx);
1952 ret = ieee80211_remain_on_channel_hw(local, dev,
1953 chan, channel_type,
1954 duration, cookie);
1955 local->hw_roc_for_tx = false;
1956 mutex_unlock(&local->mtx);
1957
1958 return ret;
1959 }
1960
1961 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1962 duration, cookie);
1963 }
1964
ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local * local,u64 cookie)1965 static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1966 u64 cookie)
1967 {
1968 int ret;
1969
1970 lockdep_assert_held(&local->mtx);
1971
1972 if (local->hw_roc_cookie != cookie)
1973 return -ENOENT;
1974
1975 ret = drv_cancel_remain_on_channel(local);
1976 if (ret)
1977 return ret;
1978
1979 local->hw_roc_cookie = 0;
1980 local->hw_roc_channel = NULL;
1981
1982 ieee80211_recalc_idle(local);
1983
1984 return 0;
1985 }
1986
ieee80211_cancel_remain_on_channel(struct wiphy * wiphy,struct net_device * dev,u64 cookie)1987 static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1988 struct net_device *dev,
1989 u64 cookie)
1990 {
1991 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1992 struct ieee80211_local *local = sdata->local;
1993
1994 if (local->ops->cancel_remain_on_channel) {
1995 int ret;
1996
1997 mutex_lock(&local->mtx);
1998 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1999 mutex_unlock(&local->mtx);
2000
2001 return ret;
2002 }
2003
2004 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
2005 }
2006
2007 static enum work_done_result
ieee80211_offchan_tx_done(struct ieee80211_work * wk,struct sk_buff * skb)2008 ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
2009 {
2010 /*
2011 * Use the data embedded in the work struct for reporting
2012 * here so if the driver mangled the SKB before dropping
2013 * it (which is the only way we really should get here)
2014 * then we don't report mangled data.
2015 *
2016 * If there was no wait time, then by the time we get here
2017 * the driver will likely not have reported the status yet,
2018 * so in that case userspace will have to deal with it.
2019 */
2020
2021 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
2022 cfg80211_mgmt_tx_status(wk->sdata->dev,
2023 (unsigned long) wk->offchan_tx.frame,
2024 wk->data, wk->data_len, false, GFP_KERNEL);
2025
2026 return WORK_DONE_DESTROY;
2027 }
2028
ieee80211_mgmt_tx(struct wiphy * wiphy,struct net_device * dev,struct ieee80211_channel * chan,bool offchan,enum nl80211_channel_type channel_type,bool channel_type_valid,unsigned int wait,const u8 * buf,size_t len,bool no_cck,bool dont_wait_for_ack,u64 * cookie)2029 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2030 struct ieee80211_channel *chan, bool offchan,
2031 enum nl80211_channel_type channel_type,
2032 bool channel_type_valid, unsigned int wait,
2033 const u8 *buf, size_t len, bool no_cck,
2034 bool dont_wait_for_ack, u64 *cookie)
2035 {
2036 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2037 struct ieee80211_local *local = sdata->local;
2038 struct sk_buff *skb;
2039 struct sta_info *sta;
2040 struct ieee80211_work *wk;
2041 const struct ieee80211_mgmt *mgmt = (void *)buf;
2042 u32 flags;
2043 bool is_offchan = false;
2044
2045 if (dont_wait_for_ack)
2046 flags = IEEE80211_TX_CTL_NO_ACK;
2047 else
2048 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2049 IEEE80211_TX_CTL_REQ_TX_STATUS;
2050
2051 /* Check that we are on the requested channel for transmission */
2052 if (chan != local->tmp_channel &&
2053 chan != local->oper_channel)
2054 is_offchan = true;
2055 if (channel_type_valid &&
2056 (channel_type != local->tmp_channel_type &&
2057 channel_type != local->_oper_channel_type))
2058 is_offchan = true;
2059
2060 if (chan == local->hw_roc_channel) {
2061 /* TODO: check channel type? */
2062 is_offchan = false;
2063 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2064 }
2065
2066 if (no_cck)
2067 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2068
2069 if (is_offchan && !offchan)
2070 return -EBUSY;
2071
2072 switch (sdata->vif.type) {
2073 case NL80211_IFTYPE_ADHOC:
2074 case NL80211_IFTYPE_AP:
2075 case NL80211_IFTYPE_AP_VLAN:
2076 case NL80211_IFTYPE_P2P_GO:
2077 case NL80211_IFTYPE_MESH_POINT:
2078 if (!ieee80211_is_action(mgmt->frame_control) ||
2079 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2080 break;
2081 rcu_read_lock();
2082 sta = sta_info_get(sdata, mgmt->da);
2083 rcu_read_unlock();
2084 if (!sta)
2085 return -ENOLINK;
2086 break;
2087 case NL80211_IFTYPE_STATION:
2088 case NL80211_IFTYPE_P2P_CLIENT:
2089 break;
2090 default:
2091 return -EOPNOTSUPP;
2092 }
2093
2094 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2095 if (!skb)
2096 return -ENOMEM;
2097 skb_reserve(skb, local->hw.extra_tx_headroom);
2098
2099 memcpy(skb_put(skb, len), buf, len);
2100
2101 IEEE80211_SKB_CB(skb)->flags = flags;
2102
2103 skb->dev = sdata->dev;
2104
2105 *cookie = (unsigned long) skb;
2106
2107 if (is_offchan && local->ops->remain_on_channel) {
2108 unsigned int duration;
2109 int ret;
2110
2111 mutex_lock(&local->mtx);
2112 /*
2113 * If the duration is zero, then the driver
2114 * wouldn't actually do anything. Set it to
2115 * 100 for now.
2116 *
2117 * TODO: cancel the off-channel operation
2118 * when we get the SKB's TX status and
2119 * the wait time was zero before.
2120 */
2121 duration = 100;
2122 if (wait)
2123 duration = wait;
2124 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2125 channel_type,
2126 duration, cookie);
2127 if (ret) {
2128 kfree_skb(skb);
2129 mutex_unlock(&local->mtx);
2130 return ret;
2131 }
2132
2133 local->hw_roc_for_tx = true;
2134 local->hw_roc_duration = wait;
2135
2136 /*
2137 * queue up frame for transmission after
2138 * ieee80211_ready_on_channel call
2139 */
2140
2141 /* modify cookie to prevent API mismatches */
2142 *cookie ^= 2;
2143 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2144 local->hw_roc_skb = skb;
2145 local->hw_roc_skb_for_status = skb;
2146 mutex_unlock(&local->mtx);
2147
2148 return 0;
2149 }
2150
2151 /*
2152 * Can transmit right away if the channel was the
2153 * right one and there's no wait involved... If a
2154 * wait is involved, we might otherwise not be on
2155 * the right channel for long enough!
2156 */
2157 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2158 ieee80211_tx_skb(sdata, skb);
2159 return 0;
2160 }
2161
2162 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2163 if (!wk) {
2164 kfree_skb(skb);
2165 return -ENOMEM;
2166 }
2167
2168 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2169 wk->chan = chan;
2170 wk->chan_type = channel_type;
2171 wk->sdata = sdata;
2172 wk->done = ieee80211_offchan_tx_done;
2173 wk->offchan_tx.frame = skb;
2174 wk->offchan_tx.wait = wait;
2175 wk->data_len = len;
2176 memcpy(wk->data, buf, len);
2177
2178 ieee80211_add_work(wk);
2179 return 0;
2180 }
2181
ieee80211_mgmt_tx_cancel_wait(struct wiphy * wiphy,struct net_device * dev,u64 cookie)2182 static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2183 struct net_device *dev,
2184 u64 cookie)
2185 {
2186 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2187 struct ieee80211_local *local = sdata->local;
2188 struct ieee80211_work *wk;
2189 int ret = -ENOENT;
2190
2191 mutex_lock(&local->mtx);
2192
2193 if (local->ops->cancel_remain_on_channel) {
2194 cookie ^= 2;
2195 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2196
2197 if (ret == 0) {
2198 kfree_skb(local->hw_roc_skb);
2199 local->hw_roc_skb = NULL;
2200 local->hw_roc_skb_for_status = NULL;
2201 }
2202
2203 mutex_unlock(&local->mtx);
2204
2205 return ret;
2206 }
2207
2208 list_for_each_entry(wk, &local->work_list, list) {
2209 if (wk->sdata != sdata)
2210 continue;
2211
2212 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2213 continue;
2214
2215 if (cookie != (unsigned long) wk->offchan_tx.frame)
2216 continue;
2217
2218 wk->timeout = jiffies;
2219
2220 ieee80211_queue_work(&local->hw, &local->work_work);
2221 ret = 0;
2222 break;
2223 }
2224 mutex_unlock(&local->mtx);
2225
2226 return ret;
2227 }
2228
ieee80211_mgmt_frame_register(struct wiphy * wiphy,struct net_device * dev,u16 frame_type,bool reg)2229 static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2230 struct net_device *dev,
2231 u16 frame_type, bool reg)
2232 {
2233 struct ieee80211_local *local = wiphy_priv(wiphy);
2234
2235 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2236 return;
2237
2238 if (reg)
2239 local->probe_req_reg++;
2240 else
2241 local->probe_req_reg--;
2242
2243 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2244 }
2245
ieee80211_set_antenna(struct wiphy * wiphy,u32 tx_ant,u32 rx_ant)2246 static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2247 {
2248 struct ieee80211_local *local = wiphy_priv(wiphy);
2249
2250 if (local->started)
2251 return -EOPNOTSUPP;
2252
2253 return drv_set_antenna(local, tx_ant, rx_ant);
2254 }
2255
ieee80211_get_antenna(struct wiphy * wiphy,u32 * tx_ant,u32 * rx_ant)2256 static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2257 {
2258 struct ieee80211_local *local = wiphy_priv(wiphy);
2259
2260 return drv_get_antenna(local, tx_ant, rx_ant);
2261 }
2262
ieee80211_set_ringparam(struct wiphy * wiphy,u32 tx,u32 rx)2263 static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2264 {
2265 struct ieee80211_local *local = wiphy_priv(wiphy);
2266
2267 return drv_set_ringparam(local, tx, rx);
2268 }
2269
ieee80211_get_ringparam(struct wiphy * wiphy,u32 * tx,u32 * tx_max,u32 * rx,u32 * rx_max)2270 static void ieee80211_get_ringparam(struct wiphy *wiphy,
2271 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2272 {
2273 struct ieee80211_local *local = wiphy_priv(wiphy);
2274
2275 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2276 }
2277
ieee80211_set_rekey_data(struct wiphy * wiphy,struct net_device * dev,struct cfg80211_gtk_rekey_data * data)2278 static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2279 struct net_device *dev,
2280 struct cfg80211_gtk_rekey_data *data)
2281 {
2282 struct ieee80211_local *local = wiphy_priv(wiphy);
2283 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2284
2285 if (!local->ops->set_rekey_data)
2286 return -EOPNOTSUPP;
2287
2288 drv_set_rekey_data(local, sdata, data);
2289
2290 return 0;
2291 }
2292
ieee80211_tdls_add_ext_capab(struct sk_buff * skb)2293 static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2294 {
2295 u8 *pos = (void *)skb_put(skb, 7);
2296
2297 *pos++ = WLAN_EID_EXT_CAPABILITY;
2298 *pos++ = 5; /* len */
2299 *pos++ = 0x0;
2300 *pos++ = 0x0;
2301 *pos++ = 0x0;
2302 *pos++ = 0x0;
2303 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2304 }
2305
ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data * sdata)2306 static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2307 {
2308 struct ieee80211_local *local = sdata->local;
2309 u16 capab;
2310
2311 capab = 0;
2312 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2313 return capab;
2314
2315 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2316 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2317 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2318 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2319
2320 return capab;
2321 }
2322
ieee80211_tdls_add_link_ie(struct sk_buff * skb,u8 * src_addr,u8 * peer,u8 * bssid)2323 static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2324 u8 *peer, u8 *bssid)
2325 {
2326 struct ieee80211_tdls_lnkie *lnkid;
2327
2328 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2329
2330 lnkid->ie_type = WLAN_EID_LINK_ID;
2331 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2332
2333 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2334 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2335 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2336 }
2337
2338 static int
ieee80211_prep_tdls_encap_data(struct wiphy * wiphy,struct net_device * dev,u8 * peer,u8 action_code,u8 dialog_token,u16 status_code,struct sk_buff * skb)2339 ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2340 u8 *peer, u8 action_code, u8 dialog_token,
2341 u16 status_code, struct sk_buff *skb)
2342 {
2343 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2344 struct ieee80211_tdls_data *tf;
2345
2346 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2347
2348 memcpy(tf->da, peer, ETH_ALEN);
2349 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2350 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2351 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2352
2353 switch (action_code) {
2354 case WLAN_TDLS_SETUP_REQUEST:
2355 tf->category = WLAN_CATEGORY_TDLS;
2356 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2357
2358 skb_put(skb, sizeof(tf->u.setup_req));
2359 tf->u.setup_req.dialog_token = dialog_token;
2360 tf->u.setup_req.capability =
2361 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2362
2363 ieee80211_add_srates_ie(&sdata->vif, skb);
2364 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2365 ieee80211_tdls_add_ext_capab(skb);
2366 break;
2367 case WLAN_TDLS_SETUP_RESPONSE:
2368 tf->category = WLAN_CATEGORY_TDLS;
2369 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2370
2371 skb_put(skb, sizeof(tf->u.setup_resp));
2372 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2373 tf->u.setup_resp.dialog_token = dialog_token;
2374 tf->u.setup_resp.capability =
2375 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2376
2377 ieee80211_add_srates_ie(&sdata->vif, skb);
2378 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2379 ieee80211_tdls_add_ext_capab(skb);
2380 break;
2381 case WLAN_TDLS_SETUP_CONFIRM:
2382 tf->category = WLAN_CATEGORY_TDLS;
2383 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2384
2385 skb_put(skb, sizeof(tf->u.setup_cfm));
2386 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2387 tf->u.setup_cfm.dialog_token = dialog_token;
2388 break;
2389 case WLAN_TDLS_TEARDOWN:
2390 tf->category = WLAN_CATEGORY_TDLS;
2391 tf->action_code = WLAN_TDLS_TEARDOWN;
2392
2393 skb_put(skb, sizeof(tf->u.teardown));
2394 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2395 break;
2396 case WLAN_TDLS_DISCOVERY_REQUEST:
2397 tf->category = WLAN_CATEGORY_TDLS;
2398 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2399
2400 skb_put(skb, sizeof(tf->u.discover_req));
2401 tf->u.discover_req.dialog_token = dialog_token;
2402 break;
2403 default:
2404 return -EINVAL;
2405 }
2406
2407 return 0;
2408 }
2409
2410 static int
ieee80211_prep_tdls_direct(struct wiphy * wiphy,struct net_device * dev,u8 * peer,u8 action_code,u8 dialog_token,u16 status_code,struct sk_buff * skb)2411 ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2412 u8 *peer, u8 action_code, u8 dialog_token,
2413 u16 status_code, struct sk_buff *skb)
2414 {
2415 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2416 struct ieee80211_mgmt *mgmt;
2417
2418 mgmt = (void *)skb_put(skb, 24);
2419 memset(mgmt, 0, 24);
2420 memcpy(mgmt->da, peer, ETH_ALEN);
2421 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2422 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2423
2424 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2425 IEEE80211_STYPE_ACTION);
2426
2427 switch (action_code) {
2428 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2429 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2430 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2431 mgmt->u.action.u.tdls_discover_resp.action_code =
2432 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2433 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2434 dialog_token;
2435 mgmt->u.action.u.tdls_discover_resp.capability =
2436 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2437
2438 ieee80211_add_srates_ie(&sdata->vif, skb);
2439 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2440 ieee80211_tdls_add_ext_capab(skb);
2441 break;
2442 default:
2443 return -EINVAL;
2444 }
2445
2446 return 0;
2447 }
2448
ieee80211_tdls_mgmt(struct wiphy * wiphy,struct net_device * dev,u8 * peer,u8 action_code,u8 dialog_token,u16 status_code,const u8 * extra_ies,size_t extra_ies_len)2449 static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2450 u8 *peer, u8 action_code, u8 dialog_token,
2451 u16 status_code, const u8 *extra_ies,
2452 size_t extra_ies_len)
2453 {
2454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2455 struct ieee80211_local *local = sdata->local;
2456 struct ieee80211_tx_info *info;
2457 struct sk_buff *skb = NULL;
2458 bool send_direct;
2459 int ret;
2460
2461 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2462 return -ENOTSUPP;
2463
2464 /* make sure we are in managed mode, and associated */
2465 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2466 !sdata->u.mgd.associated)
2467 return -EINVAL;
2468
2469 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2470 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2471 #endif
2472
2473 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2474 max(sizeof(struct ieee80211_mgmt),
2475 sizeof(struct ieee80211_tdls_data)) +
2476 50 + /* supported rates */
2477 7 + /* ext capab */
2478 extra_ies_len +
2479 sizeof(struct ieee80211_tdls_lnkie));
2480 if (!skb)
2481 return -ENOMEM;
2482
2483 info = IEEE80211_SKB_CB(skb);
2484 skb_reserve(skb, local->hw.extra_tx_headroom);
2485
2486 switch (action_code) {
2487 case WLAN_TDLS_SETUP_REQUEST:
2488 case WLAN_TDLS_SETUP_RESPONSE:
2489 case WLAN_TDLS_SETUP_CONFIRM:
2490 case WLAN_TDLS_TEARDOWN:
2491 case WLAN_TDLS_DISCOVERY_REQUEST:
2492 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2493 action_code, dialog_token,
2494 status_code, skb);
2495 send_direct = false;
2496 break;
2497 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2498 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2499 dialog_token, status_code,
2500 skb);
2501 send_direct = true;
2502 break;
2503 default:
2504 ret = -ENOTSUPP;
2505 break;
2506 }
2507
2508 if (ret < 0)
2509 goto fail;
2510
2511 if (extra_ies_len)
2512 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2513
2514 /* the TDLS link IE is always added last */
2515 switch (action_code) {
2516 case WLAN_TDLS_SETUP_REQUEST:
2517 case WLAN_TDLS_SETUP_CONFIRM:
2518 case WLAN_TDLS_TEARDOWN:
2519 case WLAN_TDLS_DISCOVERY_REQUEST:
2520 /* we are the initiator */
2521 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2522 sdata->u.mgd.bssid);
2523 break;
2524 case WLAN_TDLS_SETUP_RESPONSE:
2525 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2526 /* we are the responder */
2527 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2528 sdata->u.mgd.bssid);
2529 break;
2530 default:
2531 ret = -ENOTSUPP;
2532 goto fail;
2533 }
2534
2535 if (send_direct) {
2536 ieee80211_tx_skb(sdata, skb);
2537 return 0;
2538 }
2539
2540 /*
2541 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2542 * we should default to AC_VI.
2543 */
2544 switch (action_code) {
2545 case WLAN_TDLS_SETUP_REQUEST:
2546 case WLAN_TDLS_SETUP_RESPONSE:
2547 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2548 skb->priority = 2;
2549 break;
2550 default:
2551 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2552 skb->priority = 5;
2553 break;
2554 }
2555
2556 /* disable bottom halves when entering the Tx path */
2557 local_bh_disable();
2558 ret = ieee80211_subif_start_xmit(skb, dev);
2559 local_bh_enable();
2560
2561 return ret;
2562
2563 fail:
2564 dev_kfree_skb(skb);
2565 return ret;
2566 }
2567
ieee80211_tdls_oper(struct wiphy * wiphy,struct net_device * dev,u8 * peer,enum nl80211_tdls_operation oper)2568 static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2569 u8 *peer, enum nl80211_tdls_operation oper)
2570 {
2571 struct sta_info *sta;
2572 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2573
2574 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2575 return -ENOTSUPP;
2576
2577 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2578 return -EINVAL;
2579
2580 #ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2581 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2582 #endif
2583
2584 switch (oper) {
2585 case NL80211_TDLS_ENABLE_LINK:
2586 rcu_read_lock();
2587 sta = sta_info_get(sdata, peer);
2588 if (!sta) {
2589 rcu_read_unlock();
2590 return -ENOLINK;
2591 }
2592
2593 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
2594 rcu_read_unlock();
2595 break;
2596 case NL80211_TDLS_DISABLE_LINK:
2597 return sta_info_destroy_addr(sdata, peer);
2598 case NL80211_TDLS_TEARDOWN:
2599 case NL80211_TDLS_SETUP:
2600 case NL80211_TDLS_DISCOVERY_REQ:
2601 /* We don't support in-driver setup/teardown/discovery */
2602 return -ENOTSUPP;
2603 default:
2604 return -ENOTSUPP;
2605 }
2606
2607 return 0;
2608 }
2609
ieee80211_probe_client(struct wiphy * wiphy,struct net_device * dev,const u8 * peer,u64 * cookie)2610 static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2611 const u8 *peer, u64 *cookie)
2612 {
2613 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2614 struct ieee80211_local *local = sdata->local;
2615 struct ieee80211_qos_hdr *nullfunc;
2616 struct sk_buff *skb;
2617 int size = sizeof(*nullfunc);
2618 __le16 fc;
2619 bool qos;
2620 struct ieee80211_tx_info *info;
2621 struct sta_info *sta;
2622
2623 rcu_read_lock();
2624 sta = sta_info_get(sdata, peer);
2625 if (sta) {
2626 qos = test_sta_flag(sta, WLAN_STA_WME);
2627 rcu_read_unlock();
2628 } else {
2629 rcu_read_unlock();
2630 return -ENOLINK;
2631 }
2632
2633 if (qos) {
2634 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2635 IEEE80211_STYPE_QOS_NULLFUNC |
2636 IEEE80211_FCTL_FROMDS);
2637 } else {
2638 size -= 2;
2639 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2640 IEEE80211_STYPE_NULLFUNC |
2641 IEEE80211_FCTL_FROMDS);
2642 }
2643
2644 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2645 if (!skb)
2646 return -ENOMEM;
2647
2648 skb->dev = dev;
2649
2650 skb_reserve(skb, local->hw.extra_tx_headroom);
2651
2652 nullfunc = (void *) skb_put(skb, size);
2653 nullfunc->frame_control = fc;
2654 nullfunc->duration_id = 0;
2655 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2656 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2657 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2658 nullfunc->seq_ctrl = 0;
2659
2660 info = IEEE80211_SKB_CB(skb);
2661
2662 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2663 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2664
2665 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2666 skb->priority = 7;
2667 if (qos)
2668 nullfunc->qos_ctrl = cpu_to_le16(7);
2669
2670 local_bh_disable();
2671 ieee80211_xmit(sdata, skb);
2672 local_bh_enable();
2673
2674 *cookie = (unsigned long) skb;
2675 return 0;
2676 }
2677
2678 static struct ieee80211_channel *
ieee80211_wiphy_get_channel(struct wiphy * wiphy)2679 ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2680 {
2681 struct ieee80211_local *local = wiphy_priv(wiphy);
2682
2683 return local->oper_channel;
2684 }
2685
2686 struct cfg80211_ops mac80211_config_ops = {
2687 .add_virtual_intf = ieee80211_add_iface,
2688 .del_virtual_intf = ieee80211_del_iface,
2689 .change_virtual_intf = ieee80211_change_iface,
2690 .add_key = ieee80211_add_key,
2691 .del_key = ieee80211_del_key,
2692 .get_key = ieee80211_get_key,
2693 .set_default_key = ieee80211_config_default_key,
2694 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
2695 .start_ap = ieee80211_start_ap,
2696 .change_beacon = ieee80211_change_beacon,
2697 .stop_ap = ieee80211_stop_ap,
2698 .add_station = ieee80211_add_station,
2699 .del_station = ieee80211_del_station,
2700 .change_station = ieee80211_change_station,
2701 .get_station = ieee80211_get_station,
2702 .dump_station = ieee80211_dump_station,
2703 .dump_survey = ieee80211_dump_survey,
2704 #ifdef CONFIG_MAC80211_MESH
2705 .add_mpath = ieee80211_add_mpath,
2706 .del_mpath = ieee80211_del_mpath,
2707 .change_mpath = ieee80211_change_mpath,
2708 .get_mpath = ieee80211_get_mpath,
2709 .dump_mpath = ieee80211_dump_mpath,
2710 .update_mesh_config = ieee80211_update_mesh_config,
2711 .get_mesh_config = ieee80211_get_mesh_config,
2712 .join_mesh = ieee80211_join_mesh,
2713 .leave_mesh = ieee80211_leave_mesh,
2714 #endif
2715 .change_bss = ieee80211_change_bss,
2716 .set_txq_params = ieee80211_set_txq_params,
2717 .set_channel = ieee80211_set_channel,
2718 .suspend = ieee80211_suspend,
2719 .resume = ieee80211_resume,
2720 .scan = ieee80211_scan,
2721 .sched_scan_start = ieee80211_sched_scan_start,
2722 .sched_scan_stop = ieee80211_sched_scan_stop,
2723 .auth = ieee80211_auth,
2724 .assoc = ieee80211_assoc,
2725 .deauth = ieee80211_deauth,
2726 .disassoc = ieee80211_disassoc,
2727 .join_ibss = ieee80211_join_ibss,
2728 .leave_ibss = ieee80211_leave_ibss,
2729 .set_wiphy_params = ieee80211_set_wiphy_params,
2730 .set_tx_power = ieee80211_set_tx_power,
2731 .get_tx_power = ieee80211_get_tx_power,
2732 .set_wds_peer = ieee80211_set_wds_peer,
2733 .rfkill_poll = ieee80211_rfkill_poll,
2734 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
2735 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
2736 .set_power_mgmt = ieee80211_set_power_mgmt,
2737 .set_bitrate_mask = ieee80211_set_bitrate_mask,
2738 .remain_on_channel = ieee80211_remain_on_channel,
2739 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
2740 .mgmt_tx = ieee80211_mgmt_tx,
2741 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
2742 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
2743 .mgmt_frame_register = ieee80211_mgmt_frame_register,
2744 .set_antenna = ieee80211_set_antenna,
2745 .get_antenna = ieee80211_get_antenna,
2746 .set_ringparam = ieee80211_set_ringparam,
2747 .get_ringparam = ieee80211_get_ringparam,
2748 .set_rekey_data = ieee80211_set_rekey_data,
2749 .tdls_oper = ieee80211_tdls_oper,
2750 .tdls_mgmt = ieee80211_tdls_mgmt,
2751 .probe_client = ieee80211_probe_client,
2752 .get_channel = ieee80211_wiphy_get_channel,
2753 .set_noack_map = ieee80211_set_noack_map,
2754 };
2755