diff options
author | John W. Linville <linville@tuxdriver.com> | 2014-01-17 14:43:17 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2014-01-17 14:43:17 -0500 |
commit | 7916a075571f0ccd0830cf3da293188a8b6045e3 (patch) | |
tree | 119c5bb9e513c8205efed485c2dc7b8271123326 /drivers/net/wireless/mac80211_hwsim.c | |
parent | cf84eb0b09c0f09b4c70a648b9dfeec78be61f07 (diff) | |
parent | e4e19c031901e95dc7d1cf0a2c9c50525d71651f (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-next into for-davem
Diffstat (limited to 'drivers/net/wireless/mac80211_hwsim.c')
-rw-r--r-- | drivers/net/wireless/mac80211_hwsim.c | 1246 |
1 files changed, 644 insertions, 602 deletions
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c index fa41a773b79b..69d4c3179d04 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c | |||
@@ -163,6 +163,11 @@ static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = { | |||
163 | } | 163 | } |
164 | }; | 164 | }; |
165 | 165 | ||
166 | static const struct ieee80211_regdomain *hwsim_world_regdom_custom[] = { | ||
167 | &hwsim_world_regdom_custom_01, | ||
168 | &hwsim_world_regdom_custom_02, | ||
169 | }; | ||
170 | |||
166 | struct hwsim_vif_priv { | 171 | struct hwsim_vif_priv { |
167 | u32 magic; | 172 | u32 magic; |
168 | u8 bssid[ETH_ALEN]; | 173 | u8 bssid[ETH_ALEN]; |
@@ -321,8 +326,52 @@ static const struct ieee80211_rate hwsim_rates[] = { | |||
321 | { .bitrate = 540 } | 326 | { .bitrate = 540 } |
322 | }; | 327 | }; |
323 | 328 | ||
329 | static const struct ieee80211_iface_limit hwsim_if_limits[] = { | ||
330 | { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) }, | ||
331 | { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) | | ||
332 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | ||
333 | #ifdef CONFIG_MAC80211_MESH | ||
334 | BIT(NL80211_IFTYPE_MESH_POINT) | | ||
335 | #endif | ||
336 | BIT(NL80211_IFTYPE_AP) | | ||
337 | BIT(NL80211_IFTYPE_P2P_GO) }, | ||
338 | { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) }, | ||
339 | }; | ||
340 | |||
341 | static const struct ieee80211_iface_limit hwsim_if_dfs_limits[] = { | ||
342 | { .max = 8, .types = BIT(NL80211_IFTYPE_AP) }, | ||
343 | }; | ||
344 | |||
345 | static const struct ieee80211_iface_combination hwsim_if_comb[] = { | ||
346 | { | ||
347 | .limits = hwsim_if_limits, | ||
348 | .n_limits = ARRAY_SIZE(hwsim_if_limits), | ||
349 | .max_interfaces = 2048, | ||
350 | .num_different_channels = 1, | ||
351 | }, | ||
352 | { | ||
353 | .limits = hwsim_if_dfs_limits, | ||
354 | .n_limits = ARRAY_SIZE(hwsim_if_dfs_limits), | ||
355 | .max_interfaces = 8, | ||
356 | .num_different_channels = 1, | ||
357 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | ||
358 | BIT(NL80211_CHAN_WIDTH_20) | | ||
359 | BIT(NL80211_CHAN_WIDTH_40) | | ||
360 | BIT(NL80211_CHAN_WIDTH_80) | | ||
361 | BIT(NL80211_CHAN_WIDTH_160), | ||
362 | } | ||
363 | }; | ||
364 | |||
324 | static spinlock_t hwsim_radio_lock; | 365 | static spinlock_t hwsim_radio_lock; |
325 | static struct list_head hwsim_radios; | 366 | static struct list_head hwsim_radios; |
367 | static int hwsim_radio_idx; | ||
368 | |||
369 | static struct platform_driver mac80211_hwsim_driver = { | ||
370 | .driver = { | ||
371 | .name = "mac80211_hwsim", | ||
372 | .owner = THIS_MODULE, | ||
373 | }, | ||
374 | }; | ||
326 | 375 | ||
327 | struct mac80211_hwsim_data { | 376 | struct mac80211_hwsim_data { |
328 | struct list_head list; | 377 | struct list_head list; |
@@ -332,8 +381,10 @@ struct mac80211_hwsim_data { | |||
332 | struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)]; | 381 | struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)]; |
333 | struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)]; | 382 | struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)]; |
334 | struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)]; | 383 | struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)]; |
384 | struct ieee80211_iface_combination if_combination; | ||
335 | 385 | ||
336 | struct mac_address addresses[2]; | 386 | struct mac_address addresses[2]; |
387 | int channels, idx; | ||
337 | 388 | ||
338 | struct ieee80211_channel *tmp_chan; | 389 | struct ieee80211_channel *tmp_chan; |
339 | struct delayed_work roc_done; | 390 | struct delayed_work roc_done; |
@@ -401,21 +452,179 @@ static struct genl_family hwsim_genl_family = { | |||
401 | /* MAC80211_HWSIM netlink policy */ | 452 | /* MAC80211_HWSIM netlink policy */ |
402 | 453 | ||
403 | static struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { | 454 | static struct nla_policy hwsim_genl_policy[HWSIM_ATTR_MAX + 1] = { |
404 | [HWSIM_ATTR_ADDR_RECEIVER] = { .type = NLA_UNSPEC, | 455 | [HWSIM_ATTR_ADDR_RECEIVER] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, |
405 | .len = 6*sizeof(u8) }, | 456 | [HWSIM_ATTR_ADDR_TRANSMITTER] = { .type = NLA_UNSPEC, .len = ETH_ALEN }, |
406 | [HWSIM_ATTR_ADDR_TRANSMITTER] = { .type = NLA_UNSPEC, | ||
407 | .len = 6*sizeof(u8) }, | ||
408 | [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY, | 457 | [HWSIM_ATTR_FRAME] = { .type = NLA_BINARY, |
409 | .len = IEEE80211_MAX_DATA_LEN }, | 458 | .len = IEEE80211_MAX_DATA_LEN }, |
410 | [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 }, | 459 | [HWSIM_ATTR_FLAGS] = { .type = NLA_U32 }, |
411 | [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 }, | 460 | [HWSIM_ATTR_RX_RATE] = { .type = NLA_U32 }, |
412 | [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 }, | 461 | [HWSIM_ATTR_SIGNAL] = { .type = NLA_U32 }, |
413 | [HWSIM_ATTR_TX_INFO] = { .type = NLA_UNSPEC, | 462 | [HWSIM_ATTR_TX_INFO] = { .type = NLA_UNSPEC, |
414 | .len = IEEE80211_TX_MAX_RATES*sizeof( | 463 | .len = IEEE80211_TX_MAX_RATES * |
415 | struct hwsim_tx_rate)}, | 464 | sizeof(struct hwsim_tx_rate)}, |
416 | [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 }, | 465 | [HWSIM_ATTR_COOKIE] = { .type = NLA_U64 }, |
466 | [HWSIM_ATTR_CHANNELS] = { .type = NLA_U32 }, | ||
467 | [HWSIM_ATTR_RADIO_ID] = { .type = NLA_U32 }, | ||
468 | [HWSIM_ATTR_REG_HINT_ALPHA2] = { .type = NLA_STRING, .len = 2 }, | ||
469 | [HWSIM_ATTR_REG_CUSTOM_REG] = { .type = NLA_U32 }, | ||
470 | [HWSIM_ATTR_REG_STRICT_REG] = { .type = NLA_FLAG }, | ||
417 | }; | 471 | }; |
418 | 472 | ||
473 | static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, | ||
474 | struct sk_buff *skb, | ||
475 | struct ieee80211_channel *chan); | ||
476 | |||
477 | /* sysfs attributes */ | ||
478 | static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif) | ||
479 | { | ||
480 | struct mac80211_hwsim_data *data = dat; | ||
481 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | ||
482 | struct sk_buff *skb; | ||
483 | struct ieee80211_pspoll *pspoll; | ||
484 | |||
485 | if (!vp->assoc) | ||
486 | return; | ||
487 | |||
488 | wiphy_debug(data->hw->wiphy, | ||
489 | "%s: send PS-Poll to %pM for aid %d\n", | ||
490 | __func__, vp->bssid, vp->aid); | ||
491 | |||
492 | skb = dev_alloc_skb(sizeof(*pspoll)); | ||
493 | if (!skb) | ||
494 | return; | ||
495 | pspoll = (void *) skb_put(skb, sizeof(*pspoll)); | ||
496 | pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | ||
497 | IEEE80211_STYPE_PSPOLL | | ||
498 | IEEE80211_FCTL_PM); | ||
499 | pspoll->aid = cpu_to_le16(0xc000 | vp->aid); | ||
500 | memcpy(pspoll->bssid, vp->bssid, ETH_ALEN); | ||
501 | memcpy(pspoll->ta, mac, ETH_ALEN); | ||
502 | |||
503 | rcu_read_lock(); | ||
504 | mac80211_hwsim_tx_frame(data->hw, skb, | ||
505 | rcu_dereference(vif->chanctx_conf)->def.chan); | ||
506 | rcu_read_unlock(); | ||
507 | } | ||
508 | |||
509 | static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac, | ||
510 | struct ieee80211_vif *vif, int ps) | ||
511 | { | ||
512 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | ||
513 | struct sk_buff *skb; | ||
514 | struct ieee80211_hdr *hdr; | ||
515 | |||
516 | if (!vp->assoc) | ||
517 | return; | ||
518 | |||
519 | wiphy_debug(data->hw->wiphy, | ||
520 | "%s: send data::nullfunc to %pM ps=%d\n", | ||
521 | __func__, vp->bssid, ps); | ||
522 | |||
523 | skb = dev_alloc_skb(sizeof(*hdr)); | ||
524 | if (!skb) | ||
525 | return; | ||
526 | hdr = (void *) skb_put(skb, sizeof(*hdr) - ETH_ALEN); | ||
527 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
528 | IEEE80211_STYPE_NULLFUNC | | ||
529 | (ps ? IEEE80211_FCTL_PM : 0)); | ||
530 | hdr->duration_id = cpu_to_le16(0); | ||
531 | memcpy(hdr->addr1, vp->bssid, ETH_ALEN); | ||
532 | memcpy(hdr->addr2, mac, ETH_ALEN); | ||
533 | memcpy(hdr->addr3, vp->bssid, ETH_ALEN); | ||
534 | |||
535 | rcu_read_lock(); | ||
536 | mac80211_hwsim_tx_frame(data->hw, skb, | ||
537 | rcu_dereference(vif->chanctx_conf)->def.chan); | ||
538 | rcu_read_unlock(); | ||
539 | } | ||
540 | |||
541 | |||
542 | static void hwsim_send_nullfunc_ps(void *dat, u8 *mac, | ||
543 | struct ieee80211_vif *vif) | ||
544 | { | ||
545 | struct mac80211_hwsim_data *data = dat; | ||
546 | hwsim_send_nullfunc(data, mac, vif, 1); | ||
547 | } | ||
548 | |||
549 | static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac, | ||
550 | struct ieee80211_vif *vif) | ||
551 | { | ||
552 | struct mac80211_hwsim_data *data = dat; | ||
553 | hwsim_send_nullfunc(data, mac, vif, 0); | ||
554 | } | ||
555 | |||
556 | static int hwsim_fops_ps_read(void *dat, u64 *val) | ||
557 | { | ||
558 | struct mac80211_hwsim_data *data = dat; | ||
559 | *val = data->ps; | ||
560 | return 0; | ||
561 | } | ||
562 | |||
563 | static int hwsim_fops_ps_write(void *dat, u64 val) | ||
564 | { | ||
565 | struct mac80211_hwsim_data *data = dat; | ||
566 | enum ps_mode old_ps; | ||
567 | |||
568 | if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL && | ||
569 | val != PS_MANUAL_POLL) | ||
570 | return -EINVAL; | ||
571 | |||
572 | old_ps = data->ps; | ||
573 | data->ps = val; | ||
574 | |||
575 | if (val == PS_MANUAL_POLL) { | ||
576 | ieee80211_iterate_active_interfaces(data->hw, | ||
577 | IEEE80211_IFACE_ITER_NORMAL, | ||
578 | hwsim_send_ps_poll, data); | ||
579 | data->ps_poll_pending = true; | ||
580 | } else if (old_ps == PS_DISABLED && val != PS_DISABLED) { | ||
581 | ieee80211_iterate_active_interfaces(data->hw, | ||
582 | IEEE80211_IFACE_ITER_NORMAL, | ||
583 | hwsim_send_nullfunc_ps, | ||
584 | data); | ||
585 | } else if (old_ps != PS_DISABLED && val == PS_DISABLED) { | ||
586 | ieee80211_iterate_active_interfaces(data->hw, | ||
587 | IEEE80211_IFACE_ITER_NORMAL, | ||
588 | hwsim_send_nullfunc_no_ps, | ||
589 | data); | ||
590 | } | ||
591 | |||
592 | return 0; | ||
593 | } | ||
594 | |||
595 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, | ||
596 | "%llu\n"); | ||
597 | |||
598 | static int hwsim_write_simulate_radar(void *dat, u64 val) | ||
599 | { | ||
600 | struct mac80211_hwsim_data *data = dat; | ||
601 | |||
602 | ieee80211_radar_detected(data->hw); | ||
603 | |||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_simulate_radar, NULL, | ||
608 | hwsim_write_simulate_radar, "%llu\n"); | ||
609 | |||
610 | static int hwsim_fops_group_read(void *dat, u64 *val) | ||
611 | { | ||
612 | struct mac80211_hwsim_data *data = dat; | ||
613 | *val = data->group; | ||
614 | return 0; | ||
615 | } | ||
616 | |||
617 | static int hwsim_fops_group_write(void *dat, u64 val) | ||
618 | { | ||
619 | struct mac80211_hwsim_data *data = dat; | ||
620 | data->group = val; | ||
621 | return 0; | ||
622 | } | ||
623 | |||
624 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group, | ||
625 | hwsim_fops_group_read, hwsim_fops_group_write, | ||
626 | "%llx\n"); | ||
627 | |||
419 | static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb, | 628 | static netdev_tx_t hwsim_mon_xmit(struct sk_buff *skb, |
420 | struct net_device *dev) | 629 | struct net_device *dev) |
421 | { | 630 | { |
@@ -639,7 +848,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw, | |||
639 | } | 848 | } |
640 | 849 | ||
641 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, | 850 | if (nla_put(skb, HWSIM_ATTR_ADDR_TRANSMITTER, |
642 | sizeof(struct mac_address), data->addresses[1].addr)) | 851 | ETH_ALEN, data->addresses[1].addr)) |
643 | goto nla_put_failure; | 852 | goto nla_put_failure; |
644 | 853 | ||
645 | /* We get the skb->data */ | 854 | /* We get the skb->data */ |
@@ -878,7 +1087,7 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw, | |||
878 | return; | 1087 | return; |
879 | } | 1088 | } |
880 | 1089 | ||
881 | if (channels == 1) { | 1090 | if (data->channels == 1) { |
882 | channel = data->channel; | 1091 | channel = data->channel; |
883 | } else if (txi->hw_queue == 4) { | 1092 | } else if (txi->hw_queue == 4) { |
884 | channel = data->tmp_chan; | 1093 | channel = data->tmp_chan; |
@@ -906,7 +1115,7 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw, | |||
906 | if (control->sta) | 1115 | if (control->sta) |
907 | hwsim_check_sta_magic(control->sta); | 1116 | hwsim_check_sta_magic(control->sta); |
908 | 1117 | ||
909 | if (rctbl) | 1118 | if (hw->flags & IEEE80211_HW_SUPPORTS_RC_TABLE) |
910 | ieee80211_get_tx_rates(txi->control.vif, control->sta, skb, | 1119 | ieee80211_get_tx_rates(txi->control.vif, control->sta, skb, |
911 | txi->control.rates, | 1120 | txi->control.rates, |
912 | ARRAY_SIZE(txi->control.rates)); | 1121 | ARRAY_SIZE(txi->control.rates)); |
@@ -1013,7 +1222,7 @@ static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw, | |||
1013 | { | 1222 | { |
1014 | u32 _pid = ACCESS_ONCE(wmediumd_portid); | 1223 | u32 _pid = ACCESS_ONCE(wmediumd_portid); |
1015 | 1224 | ||
1016 | if (rctbl) { | 1225 | if (hw->flags & IEEE80211_HW_SUPPORTS_RC_TABLE) { |
1017 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); | 1226 | struct ieee80211_tx_info *txi = IEEE80211_SKB_CB(skb); |
1018 | ieee80211_get_tx_rates(txi->control.vif, NULL, skb, | 1227 | ieee80211_get_tx_rates(txi->control.vif, NULL, skb, |
1019 | txi->control.rates, | 1228 | txi->control.rates, |
@@ -1050,7 +1259,7 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac, | |||
1050 | if (skb == NULL) | 1259 | if (skb == NULL) |
1051 | return; | 1260 | return; |
1052 | info = IEEE80211_SKB_CB(skb); | 1261 | info = IEEE80211_SKB_CB(skb); |
1053 | if (rctbl) | 1262 | if (hw->flags & IEEE80211_HW_SUPPORTS_RC_TABLE) |
1054 | ieee80211_get_tx_rates(vif, NULL, skb, | 1263 | ieee80211_get_tx_rates(vif, NULL, skb, |
1055 | info->control.rates, | 1264 | info->control.rates, |
1056 | ARRAY_SIZE(info->control.rates)); | 1265 | ARRAY_SIZE(info->control.rates)); |
@@ -1141,7 +1350,7 @@ static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed) | |||
1141 | 1350 | ||
1142 | data->channel = conf->chandef.chan; | 1351 | data->channel = conf->chandef.chan; |
1143 | 1352 | ||
1144 | WARN_ON(data->channel && channels > 1); | 1353 | WARN_ON(data->channel && data->channels > 1); |
1145 | 1354 | ||
1146 | data->power_level = conf->power_level; | 1355 | data->power_level = conf->power_level; |
1147 | if (!data->started || !data->beacon_int) | 1356 | if (!data->started || !data->beacon_int) |
@@ -1388,8 +1597,6 @@ static const struct nla_policy hwsim_testmode_policy[HWSIM_TM_ATTR_MAX + 1] = { | |||
1388 | [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 }, | 1597 | [HWSIM_TM_ATTR_PS] = { .type = NLA_U32 }, |
1389 | }; | 1598 | }; |
1390 | 1599 | ||
1391 | static int hwsim_fops_ps_write(void *dat, u64 val); | ||
1392 | |||
1393 | static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw, | 1600 | static int mac80211_hwsim_testmode_cmd(struct ieee80211_hw *hw, |
1394 | struct ieee80211_vif *vif, | 1601 | struct ieee80211_vif *vif, |
1395 | void *data, int len) | 1602 | void *data, int len) |
@@ -1700,8 +1907,7 @@ static void mac80211_hwsim_unassign_vif_chanctx(struct ieee80211_hw *hw, | |||
1700 | hwsim_check_chanctx_magic(ctx); | 1907 | hwsim_check_chanctx_magic(ctx); |
1701 | } | 1908 | } |
1702 | 1909 | ||
1703 | static struct ieee80211_ops mac80211_hwsim_ops = | 1910 | static const struct ieee80211_ops mac80211_hwsim_ops = { |
1704 | { | ||
1705 | .tx = mac80211_hwsim_tx, | 1911 | .tx = mac80211_hwsim_tx, |
1706 | .start = mac80211_hwsim_start, | 1912 | .start = mac80211_hwsim_start, |
1707 | .stop = mac80211_hwsim_stop, | 1913 | .stop = mac80211_hwsim_stop, |
@@ -1726,217 +1932,290 @@ static struct ieee80211_ops mac80211_hwsim_ops = | |||
1726 | .set_tsf = mac80211_hwsim_set_tsf, | 1932 | .set_tsf = mac80211_hwsim_set_tsf, |
1727 | }; | 1933 | }; |
1728 | 1934 | ||
1935 | static struct ieee80211_ops mac80211_hwsim_mchan_ops; | ||
1729 | 1936 | ||
1730 | static void mac80211_hwsim_free(void) | 1937 | static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2, |
1938 | const struct ieee80211_regdomain *regd, | ||
1939 | bool reg_strict) | ||
1731 | { | 1940 | { |
1732 | struct list_head tmplist, *i, *tmp; | 1941 | int err; |
1733 | struct mac80211_hwsim_data *data, *tmpdata; | 1942 | u8 addr[ETH_ALEN]; |
1734 | 1943 | struct mac80211_hwsim_data *data; | |
1735 | INIT_LIST_HEAD(&tmplist); | 1944 | struct ieee80211_hw *hw; |
1945 | enum ieee80211_band band; | ||
1946 | const struct ieee80211_ops *ops = &mac80211_hwsim_ops; | ||
1947 | int idx; | ||
1736 | 1948 | ||
1737 | spin_lock_bh(&hwsim_radio_lock); | 1949 | spin_lock_bh(&hwsim_radio_lock); |
1738 | list_for_each_safe(i, tmp, &hwsim_radios) | 1950 | idx = hwsim_radio_idx++; |
1739 | list_move(i, &tmplist); | ||
1740 | spin_unlock_bh(&hwsim_radio_lock); | 1951 | spin_unlock_bh(&hwsim_radio_lock); |
1741 | 1952 | ||
1742 | list_for_each_entry_safe(data, tmpdata, &tmplist, list) { | 1953 | if (channels > 1) |
1743 | debugfs_remove_recursive(data->debugfs); | 1954 | ops = &mac80211_hwsim_mchan_ops; |
1744 | ieee80211_unregister_hw(data->hw); | 1955 | hw = ieee80211_alloc_hw(sizeof(*data), ops); |
1745 | device_release_driver(data->dev); | 1956 | if (!hw) { |
1746 | device_unregister(data->dev); | 1957 | printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw failed\n"); |
1747 | ieee80211_free_hw(data->hw); | 1958 | err = -ENOMEM; |
1959 | goto failed; | ||
1960 | } | ||
1961 | data = hw->priv; | ||
1962 | data->hw = hw; | ||
1963 | |||
1964 | data->dev = device_create(hwsim_class, NULL, 0, hw, "hwsim%d", idx); | ||
1965 | if (IS_ERR(data->dev)) { | ||
1966 | printk(KERN_DEBUG | ||
1967 | "mac80211_hwsim: device_create failed (%ld)\n", | ||
1968 | PTR_ERR(data->dev)); | ||
1969 | err = -ENOMEM; | ||
1970 | goto failed_drvdata; | ||
1971 | } | ||
1972 | data->dev->driver = &mac80211_hwsim_driver.driver; | ||
1973 | err = device_bind_driver(data->dev); | ||
1974 | if (err != 0) { | ||
1975 | printk(KERN_DEBUG "mac80211_hwsim: device_bind_driver failed (%d)\n", | ||
1976 | err); | ||
1977 | goto failed_hw; | ||
1748 | } | 1978 | } |
1749 | class_destroy(hwsim_class); | ||
1750 | } | ||
1751 | |||
1752 | static struct platform_driver mac80211_hwsim_driver = { | ||
1753 | .driver = { | ||
1754 | .name = "mac80211_hwsim", | ||
1755 | .owner = THIS_MODULE, | ||
1756 | }, | ||
1757 | }; | ||
1758 | |||
1759 | static const struct net_device_ops hwsim_netdev_ops = { | ||
1760 | .ndo_start_xmit = hwsim_mon_xmit, | ||
1761 | .ndo_change_mtu = eth_change_mtu, | ||
1762 | .ndo_set_mac_address = eth_mac_addr, | ||
1763 | .ndo_validate_addr = eth_validate_addr, | ||
1764 | }; | ||
1765 | |||
1766 | static void hwsim_mon_setup(struct net_device *dev) | ||
1767 | { | ||
1768 | dev->netdev_ops = &hwsim_netdev_ops; | ||
1769 | dev->destructor = free_netdev; | ||
1770 | ether_setup(dev); | ||
1771 | dev->tx_queue_len = 0; | ||
1772 | dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
1773 | memset(dev->dev_addr, 0, ETH_ALEN); | ||
1774 | dev->dev_addr[0] = 0x12; | ||
1775 | } | ||
1776 | 1979 | ||
1980 | skb_queue_head_init(&data->pending); | ||
1777 | 1981 | ||
1778 | static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif) | 1982 | SET_IEEE80211_DEV(hw, data->dev); |
1779 | { | 1983 | memset(addr, 0, ETH_ALEN); |
1780 | struct mac80211_hwsim_data *data = dat; | 1984 | addr[0] = 0x02; |
1781 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | 1985 | addr[3] = idx >> 8; |
1782 | struct sk_buff *skb; | 1986 | addr[4] = idx; |
1783 | struct ieee80211_pspoll *pspoll; | 1987 | memcpy(data->addresses[0].addr, addr, ETH_ALEN); |
1988 | memcpy(data->addresses[1].addr, addr, ETH_ALEN); | ||
1989 | data->addresses[1].addr[0] |= 0x40; | ||
1990 | hw->wiphy->n_addresses = 2; | ||
1991 | hw->wiphy->addresses = data->addresses; | ||
1992 | |||
1993 | data->channels = channels; | ||
1994 | data->idx = idx; | ||
1995 | |||
1996 | if (data->channels > 1) { | ||
1997 | hw->wiphy->max_scan_ssids = 255; | ||
1998 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; | ||
1999 | hw->wiphy->max_remain_on_channel_duration = 1000; | ||
2000 | /* For channels > 1 DFS is not allowed */ | ||
2001 | hw->wiphy->n_iface_combinations = 1; | ||
2002 | hw->wiphy->iface_combinations = &data->if_combination; | ||
2003 | data->if_combination = hwsim_if_comb[0]; | ||
2004 | data->if_combination.num_different_channels = data->channels; | ||
2005 | } else { | ||
2006 | hw->wiphy->iface_combinations = hwsim_if_comb; | ||
2007 | hw->wiphy->n_iface_combinations = ARRAY_SIZE(hwsim_if_comb); | ||
2008 | } | ||
1784 | 2009 | ||
1785 | if (!vp->assoc) | 2010 | INIT_DELAYED_WORK(&data->roc_done, hw_roc_done); |
1786 | return; | 2011 | INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work); |
2012 | |||
2013 | hw->queues = 5; | ||
2014 | hw->offchannel_tx_hw_queue = 4; | ||
2015 | hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | | ||
2016 | BIT(NL80211_IFTYPE_AP) | | ||
2017 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | ||
2018 | BIT(NL80211_IFTYPE_P2P_GO) | | ||
2019 | BIT(NL80211_IFTYPE_ADHOC) | | ||
2020 | BIT(NL80211_IFTYPE_MESH_POINT) | | ||
2021 | BIT(NL80211_IFTYPE_P2P_DEVICE); | ||
2022 | |||
2023 | hw->flags = IEEE80211_HW_MFP_CAPABLE | | ||
2024 | IEEE80211_HW_SIGNAL_DBM | | ||
2025 | IEEE80211_HW_SUPPORTS_STATIC_SMPS | | ||
2026 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | | ||
2027 | IEEE80211_HW_AMPDU_AGGREGATION | | ||
2028 | IEEE80211_HW_WANT_MONITOR_VIF | | ||
2029 | IEEE80211_HW_QUEUE_CONTROL | | ||
2030 | IEEE80211_HW_SUPPORTS_HT_CCK_RATES; | ||
2031 | if (rctbl) | ||
2032 | hw->flags |= IEEE80211_HW_SUPPORTS_RC_TABLE; | ||
2033 | |||
2034 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | | ||
2035 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | | ||
2036 | WIPHY_FLAG_AP_UAPSD; | ||
2037 | hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR; | ||
2038 | |||
2039 | /* ask mac80211 to reserve space for magic */ | ||
2040 | hw->vif_data_size = sizeof(struct hwsim_vif_priv); | ||
2041 | hw->sta_data_size = sizeof(struct hwsim_sta_priv); | ||
2042 | hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv); | ||
2043 | |||
2044 | memcpy(data->channels_2ghz, hwsim_channels_2ghz, | ||
2045 | sizeof(hwsim_channels_2ghz)); | ||
2046 | memcpy(data->channels_5ghz, hwsim_channels_5ghz, | ||
2047 | sizeof(hwsim_channels_5ghz)); | ||
2048 | memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates)); | ||
2049 | |||
2050 | for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) { | ||
2051 | struct ieee80211_supported_band *sband = &data->bands[band]; | ||
2052 | switch (band) { | ||
2053 | case IEEE80211_BAND_2GHZ: | ||
2054 | sband->channels = data->channels_2ghz; | ||
2055 | sband->n_channels = ARRAY_SIZE(hwsim_channels_2ghz); | ||
2056 | sband->bitrates = data->rates; | ||
2057 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates); | ||
2058 | break; | ||
2059 | case IEEE80211_BAND_5GHZ: | ||
2060 | sband->channels = data->channels_5ghz; | ||
2061 | sband->n_channels = ARRAY_SIZE(hwsim_channels_5ghz); | ||
2062 | sband->bitrates = data->rates + 4; | ||
2063 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4; | ||
2064 | break; | ||
2065 | default: | ||
2066 | continue; | ||
2067 | } | ||
1787 | 2068 | ||
1788 | wiphy_debug(data->hw->wiphy, | 2069 | sband->ht_cap.ht_supported = true; |
1789 | "%s: send PS-Poll to %pM for aid %d\n", | 2070 | sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | |
1790 | __func__, vp->bssid, vp->aid); | 2071 | IEEE80211_HT_CAP_GRN_FLD | |
2072 | IEEE80211_HT_CAP_SGI_40 | | ||
2073 | IEEE80211_HT_CAP_DSSSCCK40; | ||
2074 | sband->ht_cap.ampdu_factor = 0x3; | ||
2075 | sband->ht_cap.ampdu_density = 0x6; | ||
2076 | memset(&sband->ht_cap.mcs, 0, | ||
2077 | sizeof(sband->ht_cap.mcs)); | ||
2078 | sband->ht_cap.mcs.rx_mask[0] = 0xff; | ||
2079 | sband->ht_cap.mcs.rx_mask[1] = 0xff; | ||
2080 | sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | ||
2081 | |||
2082 | hw->wiphy->bands[band] = sband; | ||
2083 | |||
2084 | sband->vht_cap.vht_supported = true; | ||
2085 | sband->vht_cap.cap = | ||
2086 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | | ||
2087 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ | | ||
2088 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | | ||
2089 | IEEE80211_VHT_CAP_RXLDPC | | ||
2090 | IEEE80211_VHT_CAP_SHORT_GI_80 | | ||
2091 | IEEE80211_VHT_CAP_SHORT_GI_160 | | ||
2092 | IEEE80211_VHT_CAP_TXSTBC | | ||
2093 | IEEE80211_VHT_CAP_RXSTBC_1 | | ||
2094 | IEEE80211_VHT_CAP_RXSTBC_2 | | ||
2095 | IEEE80211_VHT_CAP_RXSTBC_3 | | ||
2096 | IEEE80211_VHT_CAP_RXSTBC_4 | | ||
2097 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | ||
2098 | sband->vht_cap.vht_mcs.rx_mcs_map = | ||
2099 | cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_8 << 0 | | ||
2100 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 2 | | ||
2101 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 | | ||
2102 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 6 | | ||
2103 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 8 | | ||
2104 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 | | ||
2105 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 | | ||
2106 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 14); | ||
2107 | sband->vht_cap.vht_mcs.tx_mcs_map = | ||
2108 | sband->vht_cap.vht_mcs.rx_mcs_map; | ||
2109 | } | ||
1791 | 2110 | ||
1792 | skb = dev_alloc_skb(sizeof(*pspoll)); | 2111 | /* By default all radios belong to the first group */ |
1793 | if (!skb) | 2112 | data->group = 1; |
1794 | return; | 2113 | mutex_init(&data->mutex); |
1795 | pspoll = (void *) skb_put(skb, sizeof(*pspoll)); | ||
1796 | pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | ||
1797 | IEEE80211_STYPE_PSPOLL | | ||
1798 | IEEE80211_FCTL_PM); | ||
1799 | pspoll->aid = cpu_to_le16(0xc000 | vp->aid); | ||
1800 | memcpy(pspoll->bssid, vp->bssid, ETH_ALEN); | ||
1801 | memcpy(pspoll->ta, mac, ETH_ALEN); | ||
1802 | 2114 | ||
1803 | rcu_read_lock(); | 2115 | /* Enable frame retransmissions for lossy channels */ |
1804 | mac80211_hwsim_tx_frame(data->hw, skb, | 2116 | hw->max_rates = 4; |
1805 | rcu_dereference(vif->chanctx_conf)->def.chan); | 2117 | hw->max_rate_tries = 11; |
1806 | rcu_read_unlock(); | ||
1807 | } | ||
1808 | 2118 | ||
1809 | static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac, | 2119 | if (reg_strict) |
1810 | struct ieee80211_vif *vif, int ps) | 2120 | hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG; |
1811 | { | 2121 | if (regd) { |
1812 | struct hwsim_vif_priv *vp = (void *)vif->drv_priv; | 2122 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; |
1813 | struct sk_buff *skb; | 2123 | wiphy_apply_custom_regulatory(hw->wiphy, regd); |
1814 | struct ieee80211_hdr *hdr; | 2124 | /* give the regulatory workqueue a chance to run */ |
2125 | schedule_timeout_interruptible(1); | ||
2126 | } | ||
1815 | 2127 | ||
1816 | if (!vp->assoc) | 2128 | err = ieee80211_register_hw(hw); |
1817 | return; | 2129 | if (err < 0) { |
2130 | printk(KERN_DEBUG "mac80211_hwsim: ieee80211_register_hw failed (%d)\n", | ||
2131 | err); | ||
2132 | goto failed_hw; | ||
2133 | } | ||
1818 | 2134 | ||
1819 | wiphy_debug(data->hw->wiphy, | 2135 | wiphy_debug(hw->wiphy, "hwaddr %pM registered\n", hw->wiphy->perm_addr); |
1820 | "%s: send data::nullfunc to %pM ps=%d\n", | ||
1821 | __func__, vp->bssid, ps); | ||
1822 | 2136 | ||
1823 | skb = dev_alloc_skb(sizeof(*hdr)); | 2137 | if (reg_alpha2) |
1824 | if (!skb) | 2138 | regulatory_hint(hw->wiphy, reg_alpha2); |
1825 | return; | ||
1826 | hdr = (void *) skb_put(skb, sizeof(*hdr) - ETH_ALEN); | ||
1827 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
1828 | IEEE80211_STYPE_NULLFUNC | | ||
1829 | (ps ? IEEE80211_FCTL_PM : 0)); | ||
1830 | hdr->duration_id = cpu_to_le16(0); | ||
1831 | memcpy(hdr->addr1, vp->bssid, ETH_ALEN); | ||
1832 | memcpy(hdr->addr2, mac, ETH_ALEN); | ||
1833 | memcpy(hdr->addr3, vp->bssid, ETH_ALEN); | ||
1834 | 2139 | ||
1835 | rcu_read_lock(); | 2140 | data->debugfs = debugfs_create_dir("hwsim", hw->wiphy->debugfsdir); |
1836 | mac80211_hwsim_tx_frame(data->hw, skb, | 2141 | debugfs_create_file("ps", 0666, data->debugfs, data, &hwsim_fops_ps); |
1837 | rcu_dereference(vif->chanctx_conf)->def.chan); | 2142 | debugfs_create_file("group", 0666, data->debugfs, data, |
1838 | rcu_read_unlock(); | 2143 | &hwsim_fops_group); |
1839 | } | 2144 | if (data->channels == 1) |
2145 | debugfs_create_file("dfs_simulate_radar", 0222, | ||
2146 | data->debugfs, | ||
2147 | data, &hwsim_simulate_radar); | ||
1840 | 2148 | ||
2149 | tasklet_hrtimer_init(&data->beacon_timer, | ||
2150 | mac80211_hwsim_beacon, | ||
2151 | CLOCK_MONOTONIC_RAW, HRTIMER_MODE_ABS); | ||
1841 | 2152 | ||
1842 | static void hwsim_send_nullfunc_ps(void *dat, u8 *mac, | 2153 | spin_lock_bh(&hwsim_radio_lock); |
1843 | struct ieee80211_vif *vif) | 2154 | list_add_tail(&data->list, &hwsim_radios); |
1844 | { | 2155 | spin_unlock_bh(&hwsim_radio_lock); |
1845 | struct mac80211_hwsim_data *data = dat; | ||
1846 | hwsim_send_nullfunc(data, mac, vif, 1); | ||
1847 | } | ||
1848 | 2156 | ||
2157 | return idx; | ||
1849 | 2158 | ||
1850 | static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac, | 2159 | failed_hw: |
1851 | struct ieee80211_vif *vif) | 2160 | device_unregister(data->dev); |
1852 | { | 2161 | failed_drvdata: |
1853 | struct mac80211_hwsim_data *data = dat; | 2162 | ieee80211_free_hw(hw); |
1854 | hwsim_send_nullfunc(data, mac, vif, 0); | 2163 | failed: |
2164 | return err; | ||
1855 | } | 2165 | } |
1856 | 2166 | ||
1857 | 2167 | static void mac80211_hwsim_destroy_radio(struct mac80211_hwsim_data *data) | |
1858 | static int hwsim_fops_ps_read(void *dat, u64 *val) | ||
1859 | { | 2168 | { |
1860 | struct mac80211_hwsim_data *data = dat; | 2169 | debugfs_remove_recursive(data->debugfs); |
1861 | *val = data->ps; | 2170 | ieee80211_unregister_hw(data->hw); |
1862 | return 0; | 2171 | device_release_driver(data->dev); |
2172 | device_unregister(data->dev); | ||
2173 | ieee80211_free_hw(data->hw); | ||
1863 | } | 2174 | } |
1864 | 2175 | ||
1865 | static int hwsim_fops_ps_write(void *dat, u64 val) | 2176 | static void mac80211_hwsim_free(void) |
1866 | { | 2177 | { |
1867 | struct mac80211_hwsim_data *data = dat; | 2178 | struct mac80211_hwsim_data *data; |
1868 | enum ps_mode old_ps; | ||
1869 | |||
1870 | if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL && | ||
1871 | val != PS_MANUAL_POLL) | ||
1872 | return -EINVAL; | ||
1873 | |||
1874 | old_ps = data->ps; | ||
1875 | data->ps = val; | ||
1876 | 2179 | ||
1877 | if (val == PS_MANUAL_POLL) { | 2180 | spin_lock_bh(&hwsim_radio_lock); |
1878 | ieee80211_iterate_active_interfaces(data->hw, | 2181 | while ((data = list_first_entry_or_null(&hwsim_radios, |
1879 | IEEE80211_IFACE_ITER_NORMAL, | 2182 | struct mac80211_hwsim_data, |
1880 | hwsim_send_ps_poll, data); | 2183 | list))) { |
1881 | data->ps_poll_pending = true; | 2184 | list_del(&data->list); |
1882 | } else if (old_ps == PS_DISABLED && val != PS_DISABLED) { | 2185 | spin_unlock_bh(&hwsim_radio_lock); |
1883 | ieee80211_iterate_active_interfaces(data->hw, | 2186 | mac80211_hwsim_destroy_radio(data); |
1884 | IEEE80211_IFACE_ITER_NORMAL, | 2187 | spin_lock_bh(&hwsim_radio_lock); |
1885 | hwsim_send_nullfunc_ps, | ||
1886 | data); | ||
1887 | } else if (old_ps != PS_DISABLED && val == PS_DISABLED) { | ||
1888 | ieee80211_iterate_active_interfaces(data->hw, | ||
1889 | IEEE80211_IFACE_ITER_NORMAL, | ||
1890 | hwsim_send_nullfunc_no_ps, | ||
1891 | data); | ||
1892 | } | 2188 | } |
1893 | 2189 | spin_unlock_bh(&hwsim_radio_lock); | |
1894 | return 0; | 2190 | class_destroy(hwsim_class); |
1895 | } | ||
1896 | |||
1897 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write, | ||
1898 | "%llu\n"); | ||
1899 | |||
1900 | static int hwsim_write_simulate_radar(void *dat, u64 val) | ||
1901 | { | ||
1902 | struct mac80211_hwsim_data *data = dat; | ||
1903 | |||
1904 | ieee80211_radar_detected(data->hw); | ||
1905 | |||
1906 | return 0; | ||
1907 | } | 2191 | } |
1908 | 2192 | ||
1909 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_simulate_radar, NULL, | 2193 | static const struct net_device_ops hwsim_netdev_ops = { |
1910 | hwsim_write_simulate_radar, "%llu\n"); | 2194 | .ndo_start_xmit = hwsim_mon_xmit, |
1911 | 2195 | .ndo_change_mtu = eth_change_mtu, | |
1912 | static int hwsim_fops_group_read(void *dat, u64 *val) | 2196 | .ndo_set_mac_address = eth_mac_addr, |
1913 | { | 2197 | .ndo_validate_addr = eth_validate_addr, |
1914 | struct mac80211_hwsim_data *data = dat; | 2198 | }; |
1915 | *val = data->group; | ||
1916 | return 0; | ||
1917 | } | ||
1918 | 2199 | ||
1919 | static int hwsim_fops_group_write(void *dat, u64 val) | 2200 | static void hwsim_mon_setup(struct net_device *dev) |
1920 | { | 2201 | { |
1921 | struct mac80211_hwsim_data *data = dat; | 2202 | dev->netdev_ops = &hwsim_netdev_ops; |
1922 | data->group = val; | 2203 | dev->destructor = free_netdev; |
1923 | return 0; | 2204 | ether_setup(dev); |
2205 | dev->tx_queue_len = 0; | ||
2206 | dev->type = ARPHRD_IEEE80211_RADIOTAP; | ||
2207 | memset(dev->dev_addr, 0, ETH_ALEN); | ||
2208 | dev->dev_addr[0] = 0x12; | ||
1924 | } | 2209 | } |
1925 | 2210 | ||
1926 | DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group, | 2211 | static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr(const u8 *addr) |
1927 | hwsim_fops_group_read, hwsim_fops_group_write, | ||
1928 | "%llx\n"); | ||
1929 | |||
1930 | static struct mac80211_hwsim_data *get_hwsim_data_ref_from_addr( | ||
1931 | struct mac_address *addr) | ||
1932 | { | 2212 | { |
1933 | struct mac80211_hwsim_data *data; | 2213 | struct mac80211_hwsim_data *data; |
1934 | bool _found = false; | 2214 | bool _found = false; |
1935 | 2215 | ||
1936 | spin_lock_bh(&hwsim_radio_lock); | 2216 | spin_lock_bh(&hwsim_radio_lock); |
1937 | list_for_each_entry(data, &hwsim_radios, list) { | 2217 | list_for_each_entry(data, &hwsim_radios, list) { |
1938 | if (memcmp(data->addresses[1].addr, addr, | 2218 | if (memcmp(data->addresses[1].addr, addr, ETH_ALEN) == 0) { |
1939 | sizeof(struct mac_address)) == 0) { | ||
1940 | _found = true; | 2219 | _found = true; |
1941 | break; | 2220 | break; |
1942 | } | 2221 | } |
@@ -1959,27 +2238,26 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2, | |||
1959 | struct hwsim_tx_rate *tx_attempts; | 2238 | struct hwsim_tx_rate *tx_attempts; |
1960 | unsigned long ret_skb_ptr; | 2239 | unsigned long ret_skb_ptr; |
1961 | struct sk_buff *skb, *tmp; | 2240 | struct sk_buff *skb, *tmp; |
1962 | struct mac_address *src; | 2241 | const u8 *src; |
1963 | unsigned int hwsim_flags; | 2242 | unsigned int hwsim_flags; |
1964 | |||
1965 | int i; | 2243 | int i; |
1966 | bool found = false; | 2244 | bool found = false; |
1967 | 2245 | ||
2246 | if (info->snd_portid != wmediumd_portid) | ||
2247 | return -EINVAL; | ||
2248 | |||
1968 | if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || | 2249 | if (!info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER] || |
1969 | !info->attrs[HWSIM_ATTR_FLAGS] || | 2250 | !info->attrs[HWSIM_ATTR_FLAGS] || |
1970 | !info->attrs[HWSIM_ATTR_COOKIE] || | 2251 | !info->attrs[HWSIM_ATTR_COOKIE] || |
1971 | !info->attrs[HWSIM_ATTR_TX_INFO]) | 2252 | !info->attrs[HWSIM_ATTR_TX_INFO]) |
1972 | goto out; | 2253 | goto out; |
1973 | 2254 | ||
1974 | src = (struct mac_address *)nla_data( | 2255 | src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); |
1975 | info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]); | ||
1976 | hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); | 2256 | hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]); |
1977 | |||
1978 | ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); | 2257 | ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]); |
1979 | 2258 | ||
1980 | data2 = get_hwsim_data_ref_from_addr(src); | 2259 | data2 = get_hwsim_data_ref_from_addr(src); |
1981 | 2260 | if (!data2) | |
1982 | if (data2 == NULL) | ||
1983 | goto out; | 2261 | goto out; |
1984 | 2262 | ||
1985 | /* look for the skb matching the cookie passed back from user */ | 2263 | /* look for the skb matching the cookie passed back from user */ |
@@ -2036,38 +2314,37 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, | |||
2036 | 2314 | ||
2037 | struct mac80211_hwsim_data *data2; | 2315 | struct mac80211_hwsim_data *data2; |
2038 | struct ieee80211_rx_status rx_status; | 2316 | struct ieee80211_rx_status rx_status; |
2039 | struct mac_address *dst; | 2317 | const u8 *dst; |
2040 | int frame_data_len; | 2318 | int frame_data_len; |
2041 | char *frame_data; | 2319 | void *frame_data; |
2042 | struct sk_buff *skb = NULL; | 2320 | struct sk_buff *skb = NULL; |
2043 | 2321 | ||
2322 | if (info->snd_portid != wmediumd_portid) | ||
2323 | return -EINVAL; | ||
2324 | |||
2044 | if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] || | 2325 | if (!info->attrs[HWSIM_ATTR_ADDR_RECEIVER] || |
2045 | !info->attrs[HWSIM_ATTR_FRAME] || | 2326 | !info->attrs[HWSIM_ATTR_FRAME] || |
2046 | !info->attrs[HWSIM_ATTR_RX_RATE] || | 2327 | !info->attrs[HWSIM_ATTR_RX_RATE] || |
2047 | !info->attrs[HWSIM_ATTR_SIGNAL]) | 2328 | !info->attrs[HWSIM_ATTR_SIGNAL]) |
2048 | goto out; | 2329 | goto out; |
2049 | 2330 | ||
2050 | dst = (struct mac_address *)nla_data( | 2331 | dst = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_RECEIVER]); |
2051 | info->attrs[HWSIM_ATTR_ADDR_RECEIVER]); | ||
2052 | |||
2053 | frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]); | 2332 | frame_data_len = nla_len(info->attrs[HWSIM_ATTR_FRAME]); |
2054 | frame_data = (char *)nla_data(info->attrs[HWSIM_ATTR_FRAME]); | 2333 | frame_data = (void *)nla_data(info->attrs[HWSIM_ATTR_FRAME]); |
2055 | 2334 | ||
2056 | /* Allocate new skb here */ | 2335 | /* Allocate new skb here */ |
2057 | skb = alloc_skb(frame_data_len, GFP_KERNEL); | 2336 | skb = alloc_skb(frame_data_len, GFP_KERNEL); |
2058 | if (skb == NULL) | 2337 | if (skb == NULL) |
2059 | goto err; | 2338 | goto err; |
2060 | 2339 | ||
2061 | if (frame_data_len <= IEEE80211_MAX_DATA_LEN) { | 2340 | if (frame_data_len > IEEE80211_MAX_DATA_LEN) |
2062 | /* Copy the data */ | ||
2063 | memcpy(skb_put(skb, frame_data_len), frame_data, | ||
2064 | frame_data_len); | ||
2065 | } else | ||
2066 | goto err; | 2341 | goto err; |
2067 | 2342 | ||
2068 | data2 = get_hwsim_data_ref_from_addr(dst); | 2343 | /* Copy the data */ |
2344 | memcpy(skb_put(skb, frame_data_len), frame_data, frame_data_len); | ||
2069 | 2345 | ||
2070 | if (data2 == NULL) | 2346 | data2 = get_hwsim_data_ref_from_addr(dst); |
2347 | if (!data2) | ||
2071 | goto out; | 2348 | goto out; |
2072 | 2349 | ||
2073 | /* check if radio is configured properly */ | 2350 | /* check if radio is configured properly */ |
@@ -2075,7 +2352,7 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2, | |||
2075 | if (data2->idle || !data2->started) | 2352 | if (data2->idle || !data2->started) |
2076 | goto out; | 2353 | goto out; |
2077 | 2354 | ||
2078 | /*A frame is received from user space*/ | 2355 | /* A frame is received from user space */ |
2079 | memset(&rx_status, 0, sizeof(rx_status)); | 2356 | memset(&rx_status, 0, sizeof(rx_status)); |
2080 | rx_status.freq = data2->channel->center_freq; | 2357 | rx_status.freq = data2->channel->center_freq; |
2081 | rx_status.band = data2->channel->band; | 2358 | rx_status.band = data2->channel->band; |
@@ -2097,8 +2374,24 @@ out: | |||
2097 | static int hwsim_register_received_nl(struct sk_buff *skb_2, | 2374 | static int hwsim_register_received_nl(struct sk_buff *skb_2, |
2098 | struct genl_info *info) | 2375 | struct genl_info *info) |
2099 | { | 2376 | { |
2100 | if (info == NULL) | 2377 | struct mac80211_hwsim_data *data; |
2101 | goto out; | 2378 | int chans = 1; |
2379 | |||
2380 | spin_lock_bh(&hwsim_radio_lock); | ||
2381 | list_for_each_entry(data, &hwsim_radios, list) | ||
2382 | chans = max(chans, data->channels); | ||
2383 | spin_unlock_bh(&hwsim_radio_lock); | ||
2384 | |||
2385 | /* In the future we should revise the userspace API and allow it | ||
2386 | * to set a flag that it does support multi-channel, then we can | ||
2387 | * let this pass conditionally on the flag. | ||
2388 | * For current userspace, prohibit it since it won't work right. | ||
2389 | */ | ||
2390 | if (chans > 1) | ||
2391 | return -EOPNOTSUPP; | ||
2392 | |||
2393 | if (wmediumd_portid) | ||
2394 | return -EBUSY; | ||
2102 | 2395 | ||
2103 | wmediumd_portid = info->snd_portid; | 2396 | wmediumd_portid = info->snd_portid; |
2104 | 2397 | ||
@@ -2106,9 +2399,53 @@ static int hwsim_register_received_nl(struct sk_buff *skb_2, | |||
2106 | "switching to wmediumd mode with pid %d\n", info->snd_portid); | 2399 | "switching to wmediumd mode with pid %d\n", info->snd_portid); |
2107 | 2400 | ||
2108 | return 0; | 2401 | return 0; |
2109 | out: | 2402 | } |
2110 | printk(KERN_DEBUG "mac80211_hwsim: error occurred in %s\n", __func__); | 2403 | |
2111 | return -EINVAL; | 2404 | static int hwsim_create_radio_nl(struct sk_buff *msg, struct genl_info *info) |
2405 | { | ||
2406 | unsigned int chans = channels; | ||
2407 | const char *alpha2 = NULL; | ||
2408 | const struct ieee80211_regdomain *regd = NULL; | ||
2409 | bool reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG]; | ||
2410 | |||
2411 | if (info->attrs[HWSIM_ATTR_CHANNELS]) | ||
2412 | chans = nla_get_u32(info->attrs[HWSIM_ATTR_CHANNELS]); | ||
2413 | |||
2414 | if (info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]) | ||
2415 | alpha2 = nla_data(info->attrs[HWSIM_ATTR_REG_HINT_ALPHA2]); | ||
2416 | |||
2417 | if (info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]) { | ||
2418 | u32 idx = nla_get_u32(info->attrs[HWSIM_ATTR_REG_CUSTOM_REG]); | ||
2419 | |||
2420 | if (idx >= ARRAY_SIZE(hwsim_world_regdom_custom)) | ||
2421 | return -EINVAL; | ||
2422 | regd = hwsim_world_regdom_custom[idx]; | ||
2423 | } | ||
2424 | |||
2425 | return mac80211_hwsim_create_radio(chans, alpha2, regd, reg_strict); | ||
2426 | } | ||
2427 | |||
2428 | static int hwsim_destroy_radio_nl(struct sk_buff *msg, struct genl_info *info) | ||
2429 | { | ||
2430 | struct mac80211_hwsim_data *data; | ||
2431 | int idx; | ||
2432 | |||
2433 | if (!info->attrs[HWSIM_ATTR_RADIO_ID]) | ||
2434 | return -EINVAL; | ||
2435 | idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); | ||
2436 | |||
2437 | spin_lock_bh(&hwsim_radio_lock); | ||
2438 | list_for_each_entry(data, &hwsim_radios, list) { | ||
2439 | if (data->idx != idx) | ||
2440 | continue; | ||
2441 | list_del(&data->list); | ||
2442 | spin_unlock_bh(&hwsim_radio_lock); | ||
2443 | mac80211_hwsim_destroy_radio(data); | ||
2444 | return 0; | ||
2445 | } | ||
2446 | spin_unlock_bh(&hwsim_radio_lock); | ||
2447 | |||
2448 | return -ENODEV; | ||
2112 | } | 2449 | } |
2113 | 2450 | ||
2114 | /* Generic Netlink operations array */ | 2451 | /* Generic Netlink operations array */ |
@@ -2129,6 +2466,18 @@ static const struct genl_ops hwsim_ops[] = { | |||
2129 | .policy = hwsim_genl_policy, | 2466 | .policy = hwsim_genl_policy, |
2130 | .doit = hwsim_tx_info_frame_received_nl, | 2467 | .doit = hwsim_tx_info_frame_received_nl, |
2131 | }, | 2468 | }, |
2469 | { | ||
2470 | .cmd = HWSIM_CMD_CREATE_RADIO, | ||
2471 | .policy = hwsim_genl_policy, | ||
2472 | .doit = hwsim_create_radio_nl, | ||
2473 | .flags = GENL_ADMIN_PERM, | ||
2474 | }, | ||
2475 | { | ||
2476 | .cmd = HWSIM_CMD_DESTROY_RADIO, | ||
2477 | .policy = hwsim_genl_policy, | ||
2478 | .doit = hwsim_destroy_radio_nl, | ||
2479 | .flags = GENL_ADMIN_PERM, | ||
2480 | }, | ||
2132 | }; | 2481 | }; |
2133 | 2482 | ||
2134 | static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, | 2483 | static int mac80211_hwsim_netlink_notify(struct notifier_block *nb, |
@@ -2157,10 +2506,6 @@ static int hwsim_init_netlink(void) | |||
2157 | { | 2506 | { |
2158 | int rc; | 2507 | int rc; |
2159 | 2508 | ||
2160 | /* userspace test API hasn't been adjusted for multi-channel */ | ||
2161 | if (channels > 1) | ||
2162 | return 0; | ||
2163 | |||
2164 | printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); | 2509 | printk(KERN_INFO "mac80211_hwsim: initializing netlink\n"); |
2165 | 2510 | ||
2166 | rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops); | 2511 | rc = genl_register_family_with_ops(&hwsim_genl_family, hwsim_ops); |
@@ -2180,94 +2525,36 @@ failure: | |||
2180 | 2525 | ||
2181 | static void hwsim_exit_netlink(void) | 2526 | static void hwsim_exit_netlink(void) |
2182 | { | 2527 | { |
2183 | int ret; | ||
2184 | |||
2185 | /* userspace test API hasn't been adjusted for multi-channel */ | ||
2186 | if (channels > 1) | ||
2187 | return; | ||
2188 | |||
2189 | printk(KERN_INFO "mac80211_hwsim: closing netlink\n"); | ||
2190 | /* unregister the notifier */ | 2528 | /* unregister the notifier */ |
2191 | netlink_unregister_notifier(&hwsim_netlink_notifier); | 2529 | netlink_unregister_notifier(&hwsim_netlink_notifier); |
2192 | /* unregister the family */ | 2530 | /* unregister the family */ |
2193 | ret = genl_unregister_family(&hwsim_genl_family); | 2531 | genl_unregister_family(&hwsim_genl_family); |
2194 | if (ret) | ||
2195 | printk(KERN_DEBUG "mac80211_hwsim: " | ||
2196 | "unregister family %i\n", ret); | ||
2197 | } | 2532 | } |
2198 | 2533 | ||
2199 | static const struct ieee80211_iface_limit hwsim_if_limits[] = { | ||
2200 | { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) }, | ||
2201 | { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) | | ||
2202 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | ||
2203 | #ifdef CONFIG_MAC80211_MESH | ||
2204 | BIT(NL80211_IFTYPE_MESH_POINT) | | ||
2205 | #endif | ||
2206 | BIT(NL80211_IFTYPE_AP) | | ||
2207 | BIT(NL80211_IFTYPE_P2P_GO) }, | ||
2208 | { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) }, | ||
2209 | }; | ||
2210 | |||
2211 | static const struct ieee80211_iface_limit hwsim_if_dfs_limits[] = { | ||
2212 | { .max = 8, .types = BIT(NL80211_IFTYPE_AP) }, | ||
2213 | }; | ||
2214 | |||
2215 | static struct ieee80211_iface_combination hwsim_if_comb[] = { | ||
2216 | { | ||
2217 | .limits = hwsim_if_limits, | ||
2218 | .n_limits = ARRAY_SIZE(hwsim_if_limits), | ||
2219 | .max_interfaces = 2048, | ||
2220 | .num_different_channels = 1, | ||
2221 | }, | ||
2222 | { | ||
2223 | .limits = hwsim_if_dfs_limits, | ||
2224 | .n_limits = ARRAY_SIZE(hwsim_if_dfs_limits), | ||
2225 | .max_interfaces = 8, | ||
2226 | .num_different_channels = 1, | ||
2227 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | | ||
2228 | BIT(NL80211_CHAN_WIDTH_20) | | ||
2229 | BIT(NL80211_CHAN_WIDTH_40) | | ||
2230 | BIT(NL80211_CHAN_WIDTH_80) | | ||
2231 | BIT(NL80211_CHAN_WIDTH_160), | ||
2232 | } | ||
2233 | }; | ||
2234 | |||
2235 | static int __init init_mac80211_hwsim(void) | 2534 | static int __init init_mac80211_hwsim(void) |
2236 | { | 2535 | { |
2237 | int i, err = 0; | 2536 | int i, err; |
2238 | u8 addr[ETH_ALEN]; | ||
2239 | struct mac80211_hwsim_data *data; | ||
2240 | struct ieee80211_hw *hw; | ||
2241 | enum ieee80211_band band; | ||
2242 | 2537 | ||
2243 | if (radios < 1 || radios > 100) | 2538 | if (radios < 0 || radios > 100) |
2244 | return -EINVAL; | 2539 | return -EINVAL; |
2245 | 2540 | ||
2246 | if (channels < 1) | 2541 | if (channels < 1) |
2247 | return -EINVAL; | 2542 | return -EINVAL; |
2248 | 2543 | ||
2249 | if (channels > 1) { | 2544 | mac80211_hwsim_mchan_ops = mac80211_hwsim_ops; |
2250 | hwsim_if_comb[0].num_different_channels = channels; | 2545 | mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan; |
2251 | mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan; | 2546 | mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan; |
2252 | mac80211_hwsim_ops.cancel_hw_scan = | 2547 | mac80211_hwsim_mchan_ops.sw_scan_start = NULL; |
2253 | mac80211_hwsim_cancel_hw_scan; | 2548 | mac80211_hwsim_mchan_ops.sw_scan_complete = NULL; |
2254 | mac80211_hwsim_ops.sw_scan_start = NULL; | 2549 | mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc; |
2255 | mac80211_hwsim_ops.sw_scan_complete = NULL; | 2550 | mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc; |
2256 | mac80211_hwsim_ops.remain_on_channel = | 2551 | mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx; |
2257 | mac80211_hwsim_roc; | 2552 | mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx; |
2258 | mac80211_hwsim_ops.cancel_remain_on_channel = | 2553 | mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx; |
2259 | mac80211_hwsim_croc; | 2554 | mac80211_hwsim_mchan_ops.assign_vif_chanctx = |
2260 | mac80211_hwsim_ops.add_chanctx = | 2555 | mac80211_hwsim_assign_vif_chanctx; |
2261 | mac80211_hwsim_add_chanctx; | 2556 | mac80211_hwsim_mchan_ops.unassign_vif_chanctx = |
2262 | mac80211_hwsim_ops.remove_chanctx = | 2557 | mac80211_hwsim_unassign_vif_chanctx; |
2263 | mac80211_hwsim_remove_chanctx; | ||
2264 | mac80211_hwsim_ops.change_chanctx = | ||
2265 | mac80211_hwsim_change_chanctx; | ||
2266 | mac80211_hwsim_ops.assign_vif_chanctx = | ||
2267 | mac80211_hwsim_assign_vif_chanctx; | ||
2268 | mac80211_hwsim_ops.unassign_vif_chanctx = | ||
2269 | mac80211_hwsim_unassign_vif_chanctx; | ||
2270 | } | ||
2271 | 2558 | ||
2272 | spin_lock_init(&hwsim_radio_lock); | 2559 | spin_lock_init(&hwsim_radio_lock); |
2273 | INIT_LIST_HEAD(&hwsim_radios); | 2560 | INIT_LIST_HEAD(&hwsim_radios); |
@@ -2279,361 +2566,116 @@ static int __init init_mac80211_hwsim(void) | |||
2279 | hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim"); | 2566 | hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim"); |
2280 | if (IS_ERR(hwsim_class)) { | 2567 | if (IS_ERR(hwsim_class)) { |
2281 | err = PTR_ERR(hwsim_class); | 2568 | err = PTR_ERR(hwsim_class); |
2282 | goto failed_unregister_driver; | 2569 | goto out_unregister_driver; |
2283 | } | 2570 | } |
2284 | 2571 | ||
2285 | memset(addr, 0, ETH_ALEN); | ||
2286 | addr[0] = 0x02; | ||
2287 | |||
2288 | for (i = 0; i < radios; i++) { | 2572 | for (i = 0; i < radios; i++) { |
2289 | printk(KERN_DEBUG "mac80211_hwsim: Initializing radio %d\n", | 2573 | const char *reg_alpha2 = NULL; |
2290 | i); | 2574 | const struct ieee80211_regdomain *regd = NULL; |
2291 | hw = ieee80211_alloc_hw(sizeof(*data), &mac80211_hwsim_ops); | 2575 | bool reg_strict = false; |
2292 | if (!hw) { | ||
2293 | printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw " | ||
2294 | "failed\n"); | ||
2295 | err = -ENOMEM; | ||
2296 | goto failed; | ||
2297 | } | ||
2298 | data = hw->priv; | ||
2299 | data->hw = hw; | ||
2300 | |||
2301 | data->dev = device_create(hwsim_class, NULL, 0, hw, | ||
2302 | "hwsim%d", i); | ||
2303 | if (IS_ERR(data->dev)) { | ||
2304 | printk(KERN_DEBUG | ||
2305 | "mac80211_hwsim: device_create failed (%ld)\n", | ||
2306 | PTR_ERR(data->dev)); | ||
2307 | err = -ENOMEM; | ||
2308 | goto failed_drvdata; | ||
2309 | } | ||
2310 | data->dev->driver = &mac80211_hwsim_driver.driver; | ||
2311 | err = device_bind_driver(data->dev); | ||
2312 | if (err != 0) { | ||
2313 | printk(KERN_DEBUG | ||
2314 | "mac80211_hwsim: device_bind_driver failed (%d)\n", | ||
2315 | err); | ||
2316 | goto failed_hw; | ||
2317 | } | ||
2318 | |||
2319 | skb_queue_head_init(&data->pending); | ||
2320 | |||
2321 | SET_IEEE80211_DEV(hw, data->dev); | ||
2322 | addr[3] = i >> 8; | ||
2323 | addr[4] = i; | ||
2324 | memcpy(data->addresses[0].addr, addr, ETH_ALEN); | ||
2325 | memcpy(data->addresses[1].addr, addr, ETH_ALEN); | ||
2326 | data->addresses[1].addr[0] |= 0x40; | ||
2327 | hw->wiphy->n_addresses = 2; | ||
2328 | hw->wiphy->addresses = data->addresses; | ||
2329 | |||
2330 | hw->wiphy->iface_combinations = hwsim_if_comb; | ||
2331 | hw->wiphy->n_iface_combinations = ARRAY_SIZE(hwsim_if_comb); | ||
2332 | |||
2333 | if (channels > 1) { | ||
2334 | hw->wiphy->max_scan_ssids = 255; | ||
2335 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; | ||
2336 | hw->wiphy->max_remain_on_channel_duration = 1000; | ||
2337 | /* For channels > 1 DFS is not allowed */ | ||
2338 | hw->wiphy->n_iface_combinations = 1; | ||
2339 | } | ||
2340 | |||
2341 | INIT_DELAYED_WORK(&data->roc_done, hw_roc_done); | ||
2342 | INIT_DELAYED_WORK(&data->hw_scan, hw_scan_work); | ||
2343 | |||
2344 | hw->channel_change_time = 1; | ||
2345 | hw->queues = 5; | ||
2346 | hw->offchannel_tx_hw_queue = 4; | ||
2347 | hw->wiphy->interface_modes = | ||
2348 | BIT(NL80211_IFTYPE_STATION) | | ||
2349 | BIT(NL80211_IFTYPE_AP) | | ||
2350 | BIT(NL80211_IFTYPE_P2P_CLIENT) | | ||
2351 | BIT(NL80211_IFTYPE_P2P_GO) | | ||
2352 | BIT(NL80211_IFTYPE_ADHOC) | | ||
2353 | BIT(NL80211_IFTYPE_MESH_POINT) | | ||
2354 | BIT(NL80211_IFTYPE_P2P_DEVICE); | ||
2355 | |||
2356 | hw->flags = IEEE80211_HW_MFP_CAPABLE | | ||
2357 | IEEE80211_HW_SIGNAL_DBM | | ||
2358 | IEEE80211_HW_SUPPORTS_STATIC_SMPS | | ||
2359 | IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | | ||
2360 | IEEE80211_HW_AMPDU_AGGREGATION | | ||
2361 | IEEE80211_HW_WANT_MONITOR_VIF | | ||
2362 | IEEE80211_HW_QUEUE_CONTROL | | ||
2363 | IEEE80211_HW_SUPPORTS_HT_CCK_RATES; | ||
2364 | if (rctbl) | ||
2365 | hw->flags |= IEEE80211_HW_SUPPORTS_RC_TABLE; | ||
2366 | |||
2367 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS | | ||
2368 | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | | ||
2369 | WIPHY_FLAG_AP_UAPSD; | ||
2370 | hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR; | ||
2371 | |||
2372 | /* ask mac80211 to reserve space for magic */ | ||
2373 | hw->vif_data_size = sizeof(struct hwsim_vif_priv); | ||
2374 | hw->sta_data_size = sizeof(struct hwsim_sta_priv); | ||
2375 | hw->chanctx_data_size = sizeof(struct hwsim_chanctx_priv); | ||
2376 | |||
2377 | memcpy(data->channels_2ghz, hwsim_channels_2ghz, | ||
2378 | sizeof(hwsim_channels_2ghz)); | ||
2379 | memcpy(data->channels_5ghz, hwsim_channels_5ghz, | ||
2380 | sizeof(hwsim_channels_5ghz)); | ||
2381 | memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates)); | ||
2382 | |||
2383 | for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) { | ||
2384 | struct ieee80211_supported_band *sband = &data->bands[band]; | ||
2385 | switch (band) { | ||
2386 | case IEEE80211_BAND_2GHZ: | ||
2387 | sband->channels = data->channels_2ghz; | ||
2388 | sband->n_channels = | ||
2389 | ARRAY_SIZE(hwsim_channels_2ghz); | ||
2390 | sband->bitrates = data->rates; | ||
2391 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates); | ||
2392 | break; | ||
2393 | case IEEE80211_BAND_5GHZ: | ||
2394 | sband->channels = data->channels_5ghz; | ||
2395 | sband->n_channels = | ||
2396 | ARRAY_SIZE(hwsim_channels_5ghz); | ||
2397 | sband->bitrates = data->rates + 4; | ||
2398 | sband->n_bitrates = ARRAY_SIZE(hwsim_rates) - 4; | ||
2399 | break; | ||
2400 | default: | ||
2401 | continue; | ||
2402 | } | ||
2403 | |||
2404 | sband->ht_cap.ht_supported = true; | ||
2405 | sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 | | ||
2406 | IEEE80211_HT_CAP_GRN_FLD | | ||
2407 | IEEE80211_HT_CAP_SGI_40 | | ||
2408 | IEEE80211_HT_CAP_DSSSCCK40; | ||
2409 | sband->ht_cap.ampdu_factor = 0x3; | ||
2410 | sband->ht_cap.ampdu_density = 0x6; | ||
2411 | memset(&sband->ht_cap.mcs, 0, | ||
2412 | sizeof(sband->ht_cap.mcs)); | ||
2413 | sband->ht_cap.mcs.rx_mask[0] = 0xff; | ||
2414 | sband->ht_cap.mcs.rx_mask[1] = 0xff; | ||
2415 | sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED; | ||
2416 | |||
2417 | hw->wiphy->bands[band] = sband; | ||
2418 | |||
2419 | sband->vht_cap.vht_supported = true; | ||
2420 | sband->vht_cap.cap = | ||
2421 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 | | ||
2422 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ | | ||
2423 | IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | | ||
2424 | IEEE80211_VHT_CAP_RXLDPC | | ||
2425 | IEEE80211_VHT_CAP_SHORT_GI_80 | | ||
2426 | IEEE80211_VHT_CAP_SHORT_GI_160 | | ||
2427 | IEEE80211_VHT_CAP_TXSTBC | | ||
2428 | IEEE80211_VHT_CAP_RXSTBC_1 | | ||
2429 | IEEE80211_VHT_CAP_RXSTBC_2 | | ||
2430 | IEEE80211_VHT_CAP_RXSTBC_3 | | ||
2431 | IEEE80211_VHT_CAP_RXSTBC_4 | | ||
2432 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | ||
2433 | sband->vht_cap.vht_mcs.rx_mcs_map = | ||
2434 | cpu_to_le16(IEEE80211_VHT_MCS_SUPPORT_0_8 << 0 | | ||
2435 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 2 | | ||
2436 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 4 | | ||
2437 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 6 | | ||
2438 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 8 | | ||
2439 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 10 | | ||
2440 | IEEE80211_VHT_MCS_SUPPORT_0_9 << 12 | | ||
2441 | IEEE80211_VHT_MCS_SUPPORT_0_8 << 14); | ||
2442 | sband->vht_cap.vht_mcs.tx_mcs_map = | ||
2443 | sband->vht_cap.vht_mcs.rx_mcs_map; | ||
2444 | } | ||
2445 | /* By default all radios are belonging to the first group */ | ||
2446 | data->group = 1; | ||
2447 | mutex_init(&data->mutex); | ||
2448 | |||
2449 | /* Enable frame retransmissions for lossy channels */ | ||
2450 | hw->max_rates = 4; | ||
2451 | hw->max_rate_tries = 11; | ||
2452 | 2576 | ||
2453 | /* Work to be done prior to ieee80211_register_hw() */ | ||
2454 | switch (regtest) { | 2577 | switch (regtest) { |
2455 | case HWSIM_REGTEST_DISABLED: | ||
2456 | case HWSIM_REGTEST_DRIVER_REG_FOLLOW: | ||
2457 | case HWSIM_REGTEST_DRIVER_REG_ALL: | ||
2458 | case HWSIM_REGTEST_DIFF_COUNTRY: | 2578 | case HWSIM_REGTEST_DIFF_COUNTRY: |
2459 | /* | 2579 | if (i < ARRAY_SIZE(hwsim_alpha2s)) |
2460 | * Nothing to be done for driver regulatory domain | 2580 | reg_alpha2 = hwsim_alpha2s[i]; |
2461 | * hints prior to ieee80211_register_hw() | ||
2462 | */ | ||
2463 | break; | ||
2464 | case HWSIM_REGTEST_WORLD_ROAM: | ||
2465 | if (i == 0) { | ||
2466 | hw->wiphy->regulatory_flags |= | ||
2467 | REGULATORY_CUSTOM_REG; | ||
2468 | wiphy_apply_custom_regulatory(hw->wiphy, | ||
2469 | &hwsim_world_regdom_custom_01); | ||
2470 | } | ||
2471 | break; | ||
2472 | case HWSIM_REGTEST_CUSTOM_WORLD: | ||
2473 | hw->wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG; | ||
2474 | wiphy_apply_custom_regulatory(hw->wiphy, | ||
2475 | &hwsim_world_regdom_custom_01); | ||
2476 | break; | ||
2477 | case HWSIM_REGTEST_CUSTOM_WORLD_2: | ||
2478 | if (i == 0) { | ||
2479 | hw->wiphy->regulatory_flags |= | ||
2480 | REGULATORY_CUSTOM_REG; | ||
2481 | wiphy_apply_custom_regulatory(hw->wiphy, | ||
2482 | &hwsim_world_regdom_custom_01); | ||
2483 | } else if (i == 1) { | ||
2484 | hw->wiphy->regulatory_flags |= | ||
2485 | REGULATORY_CUSTOM_REG; | ||
2486 | wiphy_apply_custom_regulatory(hw->wiphy, | ||
2487 | &hwsim_world_regdom_custom_02); | ||
2488 | } | ||
2489 | break; | ||
2490 | case HWSIM_REGTEST_STRICT_ALL: | ||
2491 | hw->wiphy->regulatory_flags |= REGULATORY_STRICT_REG; | ||
2492 | break; | ||
2493 | case HWSIM_REGTEST_STRICT_FOLLOW: | ||
2494 | case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: | ||
2495 | if (i == 0) | ||
2496 | hw->wiphy->regulatory_flags |= | ||
2497 | REGULATORY_STRICT_REG; | ||
2498 | break; | ||
2499 | case HWSIM_REGTEST_ALL: | ||
2500 | if (i == 0) { | ||
2501 | hw->wiphy->regulatory_flags |= | ||
2502 | REGULATORY_CUSTOM_REG; | ||
2503 | wiphy_apply_custom_regulatory(hw->wiphy, | ||
2504 | &hwsim_world_regdom_custom_01); | ||
2505 | } else if (i == 1) { | ||
2506 | hw->wiphy->regulatory_flags |= | ||
2507 | REGULATORY_CUSTOM_REG; | ||
2508 | wiphy_apply_custom_regulatory(hw->wiphy, | ||
2509 | &hwsim_world_regdom_custom_02); | ||
2510 | } else if (i == 4) | ||
2511 | hw->wiphy->regulatory_flags |= | ||
2512 | REGULATORY_STRICT_REG; | ||
2513 | break; | ||
2514 | default: | ||
2515 | break; | ||
2516 | } | ||
2517 | |||
2518 | /* give the regulatory workqueue a chance to run */ | ||
2519 | if (regtest) | ||
2520 | schedule_timeout_interruptible(1); | ||
2521 | err = ieee80211_register_hw(hw); | ||
2522 | if (err < 0) { | ||
2523 | printk(KERN_DEBUG "mac80211_hwsim: " | ||
2524 | "ieee80211_register_hw failed (%d)\n", err); | ||
2525 | goto failed_hw; | ||
2526 | } | ||
2527 | |||
2528 | /* Work to be done after to ieee80211_register_hw() */ | ||
2529 | switch (regtest) { | ||
2530 | case HWSIM_REGTEST_WORLD_ROAM: | ||
2531 | case HWSIM_REGTEST_DISABLED: | ||
2532 | break; | 2581 | break; |
2533 | case HWSIM_REGTEST_DRIVER_REG_FOLLOW: | 2582 | case HWSIM_REGTEST_DRIVER_REG_FOLLOW: |
2534 | if (!i) | 2583 | if (!i) |
2535 | regulatory_hint(hw->wiphy, hwsim_alpha2s[0]); | 2584 | reg_alpha2 = hwsim_alpha2s[0]; |
2536 | break; | 2585 | break; |
2537 | case HWSIM_REGTEST_DRIVER_REG_ALL: | ||
2538 | case HWSIM_REGTEST_STRICT_ALL: | 2586 | case HWSIM_REGTEST_STRICT_ALL: |
2539 | regulatory_hint(hw->wiphy, hwsim_alpha2s[0]); | 2587 | reg_strict = true; |
2588 | case HWSIM_REGTEST_DRIVER_REG_ALL: | ||
2589 | reg_alpha2 = hwsim_alpha2s[0]; | ||
2540 | break; | 2590 | break; |
2541 | case HWSIM_REGTEST_DIFF_COUNTRY: | 2591 | case HWSIM_REGTEST_WORLD_ROAM: |
2542 | if (i < ARRAY_SIZE(hwsim_alpha2s)) | 2592 | if (i == 0) |
2543 | regulatory_hint(hw->wiphy, hwsim_alpha2s[i]); | 2593 | regd = &hwsim_world_regdom_custom_01; |
2544 | break; | 2594 | break; |
2545 | case HWSIM_REGTEST_CUSTOM_WORLD: | 2595 | case HWSIM_REGTEST_CUSTOM_WORLD: |
2596 | regd = &hwsim_world_regdom_custom_01; | ||
2597 | break; | ||
2546 | case HWSIM_REGTEST_CUSTOM_WORLD_2: | 2598 | case HWSIM_REGTEST_CUSTOM_WORLD_2: |
2547 | /* | 2599 | if (i == 0) |
2548 | * Nothing to be done for custom world regulatory | 2600 | regd = &hwsim_world_regdom_custom_01; |
2549 | * domains after to ieee80211_register_hw | 2601 | else if (i == 1) |
2550 | */ | 2602 | regd = &hwsim_world_regdom_custom_02; |
2551 | break; | 2603 | break; |
2552 | case HWSIM_REGTEST_STRICT_FOLLOW: | 2604 | case HWSIM_REGTEST_STRICT_FOLLOW: |
2553 | if (i == 0) | 2605 | if (i == 0) { |
2554 | regulatory_hint(hw->wiphy, hwsim_alpha2s[0]); | 2606 | reg_strict = true; |
2607 | reg_alpha2 = hwsim_alpha2s[0]; | ||
2608 | } | ||
2555 | break; | 2609 | break; |
2556 | case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: | 2610 | case HWSIM_REGTEST_STRICT_AND_DRIVER_REG: |
2557 | if (i == 0) | 2611 | if (i == 0) { |
2558 | regulatory_hint(hw->wiphy, hwsim_alpha2s[0]); | 2612 | reg_strict = true; |
2559 | else if (i == 1) | 2613 | reg_alpha2 = hwsim_alpha2s[0]; |
2560 | regulatory_hint(hw->wiphy, hwsim_alpha2s[1]); | 2614 | } else if (i == 1) { |
2615 | reg_alpha2 = hwsim_alpha2s[1]; | ||
2616 | } | ||
2561 | break; | 2617 | break; |
2562 | case HWSIM_REGTEST_ALL: | 2618 | case HWSIM_REGTEST_ALL: |
2563 | if (i == 2) | 2619 | switch (i) { |
2564 | regulatory_hint(hw->wiphy, hwsim_alpha2s[0]); | 2620 | case 0: |
2565 | else if (i == 3) | 2621 | regd = &hwsim_world_regdom_custom_01; |
2566 | regulatory_hint(hw->wiphy, hwsim_alpha2s[1]); | 2622 | break; |
2567 | else if (i == 4) | 2623 | case 1: |
2568 | regulatory_hint(hw->wiphy, hwsim_alpha2s[2]); | 2624 | regd = &hwsim_world_regdom_custom_02; |
2625 | break; | ||
2626 | case 2: | ||
2627 | reg_alpha2 = hwsim_alpha2s[0]; | ||
2628 | break; | ||
2629 | case 3: | ||
2630 | reg_alpha2 = hwsim_alpha2s[1]; | ||
2631 | break; | ||
2632 | case 4: | ||
2633 | reg_strict = true; | ||
2634 | reg_alpha2 = hwsim_alpha2s[2]; | ||
2635 | break; | ||
2636 | } | ||
2569 | break; | 2637 | break; |
2570 | default: | 2638 | default: |
2571 | break; | 2639 | break; |
2572 | } | 2640 | } |
2573 | 2641 | ||
2574 | wiphy_debug(hw->wiphy, "hwaddr %pm registered\n", | 2642 | err = mac80211_hwsim_create_radio(channels, reg_alpha2, |
2575 | hw->wiphy->perm_addr); | 2643 | regd, reg_strict); |
2576 | 2644 | if (err < 0) | |
2577 | data->debugfs = debugfs_create_dir("hwsim", | 2645 | goto out_free_radios; |
2578 | hw->wiphy->debugfsdir); | ||
2579 | debugfs_create_file("ps", 0666, data->debugfs, data, | ||
2580 | &hwsim_fops_ps); | ||
2581 | debugfs_create_file("group", 0666, data->debugfs, data, | ||
2582 | &hwsim_fops_group); | ||
2583 | if (channels == 1) | ||
2584 | debugfs_create_file("dfs_simulate_radar", 0222, | ||
2585 | data->debugfs, | ||
2586 | data, &hwsim_simulate_radar); | ||
2587 | |||
2588 | tasklet_hrtimer_init(&data->beacon_timer, | ||
2589 | mac80211_hwsim_beacon, | ||
2590 | CLOCK_MONOTONIC_RAW, HRTIMER_MODE_ABS); | ||
2591 | |||
2592 | list_add_tail(&data->list, &hwsim_radios); | ||
2593 | } | 2646 | } |
2594 | 2647 | ||
2595 | hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup); | 2648 | hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup); |
2596 | if (hwsim_mon == NULL) { | 2649 | if (hwsim_mon == NULL) { |
2597 | err = -ENOMEM; | 2650 | err = -ENOMEM; |
2598 | goto failed; | 2651 | goto out_free_radios; |
2599 | } | 2652 | } |
2600 | 2653 | ||
2601 | rtnl_lock(); | 2654 | rtnl_lock(); |
2602 | |||
2603 | err = dev_alloc_name(hwsim_mon, hwsim_mon->name); | 2655 | err = dev_alloc_name(hwsim_mon, hwsim_mon->name); |
2604 | if (err < 0) | 2656 | if (err < 0) { |
2605 | goto failed_mon; | 2657 | rtnl_unlock(); |
2606 | 2658 | goto out_free_radios; | |
2659 | } | ||
2607 | 2660 | ||
2608 | err = register_netdevice(hwsim_mon); | 2661 | err = register_netdevice(hwsim_mon); |
2609 | if (err < 0) | 2662 | if (err < 0) { |
2610 | goto failed_mon; | 2663 | rtnl_unlock(); |
2611 | 2664 | goto out_free_mon; | |
2665 | } | ||
2612 | rtnl_unlock(); | 2666 | rtnl_unlock(); |
2613 | 2667 | ||
2614 | err = hwsim_init_netlink(); | 2668 | err = hwsim_init_netlink(); |
2615 | if (err < 0) | 2669 | if (err < 0) |
2616 | goto failed_nl; | 2670 | goto out_free_mon; |
2617 | 2671 | ||
2618 | return 0; | 2672 | return 0; |
2619 | 2673 | ||
2620 | failed_nl: | 2674 | out_free_mon: |
2621 | printk(KERN_DEBUG "mac_80211_hwsim: failed initializing netlink\n"); | ||
2622 | return err; | ||
2623 | |||
2624 | failed_mon: | ||
2625 | rtnl_unlock(); | ||
2626 | free_netdev(hwsim_mon); | 2675 | free_netdev(hwsim_mon); |
2676 | out_free_radios: | ||
2627 | mac80211_hwsim_free(); | 2677 | mac80211_hwsim_free(); |
2628 | return err; | 2678 | out_unregister_driver: |
2629 | |||
2630 | failed_hw: | ||
2631 | device_unregister(data->dev); | ||
2632 | failed_drvdata: | ||
2633 | ieee80211_free_hw(hw); | ||
2634 | failed: | ||
2635 | mac80211_hwsim_free(); | ||
2636 | failed_unregister_driver: | ||
2637 | platform_driver_unregister(&mac80211_hwsim_driver); | 2679 | platform_driver_unregister(&mac80211_hwsim_driver); |
2638 | return err; | 2680 | return err; |
2639 | } | 2681 | } |