@@ -495,6 +495,9 @@ struct mac80211_hwsim_data {
495
495
const struct ieee80211_regdomain * regd ;
496
496
497
497
struct ieee80211_channel * tmp_chan ;
498
+ struct ieee80211_channel * roc_chan ;
499
+ u32 roc_duration ;
500
+ struct delayed_work roc_start ;
498
501
struct delayed_work roc_done ;
499
502
struct delayed_work hw_scan ;
500
503
struct cfg80211_scan_request * hw_scan_request ;
@@ -514,6 +517,7 @@ struct mac80211_hwsim_data {
514
517
bool ps_poll_pending ;
515
518
struct dentry * debugfs ;
516
519
520
+ uintptr_t pending_cookie ;
517
521
struct sk_buff_head pending ; /* packets pending */
518
522
/*
519
523
* Only radios in the same group can communicate together (the
@@ -810,6 +814,9 @@ static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
810
814
struct ieee80211_tx_info * info = IEEE80211_SKB_CB (tx_skb );
811
815
struct ieee80211_rate * txrate = ieee80211_get_tx_rate (hw , info );
812
816
817
+ if (WARN_ON (!txrate ))
818
+ return ;
819
+
813
820
if (!netif_running (hwsim_mon ))
814
821
return ;
815
822
@@ -960,6 +967,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
960
967
unsigned int hwsim_flags = 0 ;
961
968
int i ;
962
969
struct hwsim_tx_rate tx_attempts [IEEE80211_TX_MAX_RATES ];
970
+ uintptr_t cookie ;
963
971
964
972
if (data -> ps != PS_DISABLED )
965
973
hdr -> frame_control |= cpu_to_le16 (IEEE80211_FCTL_PM );
@@ -1018,7 +1026,10 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
1018
1026
goto nla_put_failure ;
1019
1027
1020
1028
/* We create a cookie to identify this skb */
1021
- if (nla_put_u64 (skb , HWSIM_ATTR_COOKIE , (unsigned long ) my_skb ))
1029
+ data -> pending_cookie ++ ;
1030
+ cookie = data -> pending_cookie ;
1031
+ info -> rate_driver_data [0 ] = (void * )cookie ;
1032
+ if (nla_put_u64 (skb , HWSIM_ATTR_COOKIE , cookie ))
1022
1033
goto nla_put_failure ;
1023
1034
1024
1035
genlmsg_end (skb , msg_head );
@@ -1247,6 +1258,7 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
1247
1258
{
1248
1259
struct mac80211_hwsim_data * data = hw -> priv ;
1249
1260
struct ieee80211_tx_info * txi = IEEE80211_SKB_CB (skb );
1261
+ struct ieee80211_hdr * hdr = (void * )skb -> data ;
1250
1262
struct ieee80211_chanctx_conf * chanctx_conf ;
1251
1263
struct ieee80211_channel * channel ;
1252
1264
bool ack ;
@@ -1292,6 +1304,22 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
1292
1304
ARRAY_SIZE (txi -> control .rates ));
1293
1305
1294
1306
txi -> rate_driver_data [0 ] = channel ;
1307
+
1308
+ if (skb -> len >= 24 + 8 &&
1309
+ ieee80211_is_probe_resp (hdr -> frame_control )) {
1310
+ /* fake header transmission time */
1311
+ struct ieee80211_mgmt * mgmt ;
1312
+ struct ieee80211_rate * txrate ;
1313
+ u64 ts ;
1314
+
1315
+ mgmt = (struct ieee80211_mgmt * )skb -> data ;
1316
+ txrate = ieee80211_get_tx_rate (hw , txi );
1317
+ ts = mac80211_hwsim_get_tsf_raw ();
1318
+ mgmt -> u .probe_resp .timestamp =
1319
+ cpu_to_le64 (ts + data -> tsf_offset +
1320
+ 24 * 8 * 10 / txrate -> bitrate );
1321
+ }
1322
+
1295
1323
mac80211_hwsim_monitor_rx (hw , skb , channel );
1296
1324
1297
1325
/* wmediumd mode check */
@@ -1871,7 +1899,8 @@ static void hw_scan_work(struct work_struct *work)
1871
1899
req -> channels [hwsim -> scan_chan_idx ]-> center_freq );
1872
1900
1873
1901
hwsim -> tmp_chan = req -> channels [hwsim -> scan_chan_idx ];
1874
- if (hwsim -> tmp_chan -> flags & IEEE80211_CHAN_NO_IR ||
1902
+ if (hwsim -> tmp_chan -> flags & (IEEE80211_CHAN_NO_IR |
1903
+ IEEE80211_CHAN_RADAR ) ||
1875
1904
!req -> n_ssids ) {
1876
1905
dwell = 120 ;
1877
1906
} else {
@@ -1987,6 +2016,23 @@ static void mac80211_hwsim_sw_scan_complete(struct ieee80211_hw *hw,
1987
2016
mutex_unlock (& hwsim -> mutex );
1988
2017
}
1989
2018
2019
+ static void hw_roc_start (struct work_struct * work )
2020
+ {
2021
+ struct mac80211_hwsim_data * hwsim =
2022
+ container_of (work , struct mac80211_hwsim_data , roc_start .work );
2023
+
2024
+ mutex_lock (& hwsim -> mutex );
2025
+
2026
+ wiphy_debug (hwsim -> hw -> wiphy , "hwsim ROC begins\n" );
2027
+ hwsim -> tmp_chan = hwsim -> roc_chan ;
2028
+ ieee80211_ready_on_channel (hwsim -> hw );
2029
+
2030
+ ieee80211_queue_delayed_work (hwsim -> hw , & hwsim -> roc_done ,
2031
+ msecs_to_jiffies (hwsim -> roc_duration ));
2032
+
2033
+ mutex_unlock (& hwsim -> mutex );
2034
+ }
2035
+
1990
2036
static void hw_roc_done (struct work_struct * work )
1991
2037
{
1992
2038
struct mac80211_hwsim_data * hwsim =
@@ -2014,23 +2060,22 @@ static int mac80211_hwsim_roc(struct ieee80211_hw *hw,
2014
2060
return - EBUSY ;
2015
2061
}
2016
2062
2017
- hwsim -> tmp_chan = chan ;
2063
+ hwsim -> roc_chan = chan ;
2064
+ hwsim -> roc_duration = duration ;
2018
2065
mutex_unlock (& hwsim -> mutex );
2019
2066
2020
2067
wiphy_debug (hw -> wiphy , "hwsim ROC (%d MHz, %d ms)\n" ,
2021
2068
chan -> center_freq , duration );
2069
+ ieee80211_queue_delayed_work (hw , & hwsim -> roc_start , HZ /50 );
2022
2070
2023
- ieee80211_ready_on_channel (hw );
2024
-
2025
- ieee80211_queue_delayed_work (hw , & hwsim -> roc_done ,
2026
- msecs_to_jiffies (duration ));
2027
2071
return 0 ;
2028
2072
}
2029
2073
2030
2074
static int mac80211_hwsim_croc (struct ieee80211_hw * hw )
2031
2075
{
2032
2076
struct mac80211_hwsim_data * hwsim = hw -> priv ;
2033
2077
2078
+ cancel_delayed_work_sync (& hwsim -> roc_start );
2034
2079
cancel_delayed_work_sync (& hwsim -> roc_done );
2035
2080
2036
2081
mutex_lock (& hwsim -> mutex );
@@ -2375,6 +2420,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
2375
2420
hw -> wiphy -> n_iface_combinations = ARRAY_SIZE (hwsim_if_comb );
2376
2421
}
2377
2422
2423
+ INIT_DELAYED_WORK (& data -> roc_start , hw_roc_start );
2378
2424
INIT_DELAYED_WORK (& data -> roc_done , hw_roc_done );
2379
2425
INIT_DELAYED_WORK (& data -> hw_scan , hw_scan_work );
2380
2426
@@ -2411,6 +2457,7 @@ static int mac80211_hwsim_new_radio(struct genl_info *info,
2411
2457
NL80211_FEATURE_STATIC_SMPS |
2412
2458
NL80211_FEATURE_DYNAMIC_SMPS |
2413
2459
NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR ;
2460
+ wiphy_ext_feature_set (hw -> wiphy , NL80211_EXT_FEATURE_VHT_IBSS );
2414
2461
2415
2462
/* ask mac80211 to reserve space for magic */
2416
2463
hw -> vif_data_size = sizeof (struct hwsim_vif_priv );
@@ -2710,7 +2757,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
2710
2757
struct mac80211_hwsim_data * data2 ;
2711
2758
struct ieee80211_tx_info * txi ;
2712
2759
struct hwsim_tx_rate * tx_attempts ;
2713
- unsigned long ret_skb_ptr ;
2760
+ u64 ret_skb_cookie ;
2714
2761
struct sk_buff * skb , * tmp ;
2715
2762
const u8 * src ;
2716
2763
unsigned int hwsim_flags ;
@@ -2728,15 +2775,20 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
2728
2775
2729
2776
src = (void * )nla_data (info -> attrs [HWSIM_ATTR_ADDR_TRANSMITTER ]);
2730
2777
hwsim_flags = nla_get_u32 (info -> attrs [HWSIM_ATTR_FLAGS ]);
2731
- ret_skb_ptr = nla_get_u64 (info -> attrs [HWSIM_ATTR_COOKIE ]);
2778
+ ret_skb_cookie = nla_get_u64 (info -> attrs [HWSIM_ATTR_COOKIE ]);
2732
2779
2733
2780
data2 = get_hwsim_data_ref_from_addr (src );
2734
2781
if (!data2 )
2735
2782
goto out ;
2736
2783
2737
2784
/* look for the skb matching the cookie passed back from user */
2738
2785
skb_queue_walk_safe (& data2 -> pending , skb , tmp ) {
2739
- if ((unsigned long )skb == ret_skb_ptr ) {
2786
+ u64 skb_cookie ;
2787
+
2788
+ txi = IEEE80211_SKB_CB (skb );
2789
+ skb_cookie = (u64 )(uintptr_t )txi -> rate_driver_data [0 ];
2790
+
2791
+ if (skb_cookie == ret_skb_cookie ) {
2740
2792
skb_unlink (skb , & data2 -> pending );
2741
2793
found = true;
2742
2794
break ;
@@ -2827,10 +2879,25 @@ static int hwsim_cloned_frame_received_nl(struct sk_buff *skb_2,
2827
2879
2828
2880
/* A frame is received from user space */
2829
2881
memset (& rx_status , 0 , sizeof (rx_status ));
2830
- /* TODO: Check ATTR_FREQ if it exists, and maybe throw away off-channel
2831
- * packets?
2832
- */
2833
- rx_status .freq = data2 -> channel -> center_freq ;
2882
+ if (info -> attrs [HWSIM_ATTR_FREQ ]) {
2883
+ /* throw away off-channel packets, but allow both the temporary
2884
+ * ("hw" scan/remain-on-channel) and regular channel, since the
2885
+ * internal datapath also allows this
2886
+ */
2887
+ mutex_lock (& data2 -> mutex );
2888
+ rx_status .freq = nla_get_u32 (info -> attrs [HWSIM_ATTR_FREQ ]);
2889
+
2890
+ if (rx_status .freq != data2 -> channel -> center_freq &&
2891
+ (!data2 -> tmp_chan ||
2892
+ rx_status .freq != data2 -> tmp_chan -> center_freq )) {
2893
+ mutex_unlock (& data2 -> mutex );
2894
+ goto out ;
2895
+ }
2896
+ mutex_unlock (& data2 -> mutex );
2897
+ } else {
2898
+ rx_status .freq = data2 -> channel -> center_freq ;
2899
+ }
2900
+
2834
2901
rx_status .band = data2 -> channel -> band ;
2835
2902
rx_status .rate_idx = nla_get_u32 (info -> attrs [HWSIM_ATTR_RX_RATE ]);
2836
2903
rx_status .signal = nla_get_u32 (info -> attrs [HWSIM_ATTR_SIGNAL ]);
0 commit comments