2525#include <linux/if_arp.h>
2626#include <linux/rtnetlink.h>
2727#include <linux/etherdevice.h>
28+ #include <linux/platform_device.h>
2829#include <linux/debugfs.h>
2930#include <linux/module.h>
3031#include <linux/ktime.h>
@@ -52,6 +53,10 @@ static bool paged_rx = false;
5253module_param (paged_rx , bool , 0644 );
5354MODULE_PARM_DESC (paged_rx , "Use paged SKBs for RX instead of linear ones" );
5455
56+ static bool rctbl = false;
57+ module_param (rctbl , bool , 0444 );
58+ MODULE_PARM_DESC (rctbl , "Handle rate control table" );
59+
5560/**
5661 * enum hwsim_regtest - the type of regulatory tests we offer
5762 *
@@ -717,9 +722,17 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
717722 rx_status .flag |= RX_FLAG_MACTIME_START ;
718723 rx_status .freq = chan -> center_freq ;
719724 rx_status .band = chan -> band ;
720- rx_status .rate_idx = info -> control .rates [0 ].idx ;
721- if (info -> control .rates [0 ].flags & IEEE80211_TX_RC_MCS )
722- rx_status .flag |= RX_FLAG_HT ;
725+ if (info -> control .rates [0 ].flags & IEEE80211_TX_RC_VHT_MCS ) {
726+ rx_status .rate_idx =
727+ ieee80211_rate_get_vht_mcs (& info -> control .rates [0 ]);
728+ rx_status .vht_nss =
729+ ieee80211_rate_get_vht_nss (& info -> control .rates [0 ]);
730+ rx_status .flag |= RX_FLAG_VHT ;
731+ } else {
732+ rx_status .rate_idx = info -> control .rates [0 ].idx ;
733+ if (info -> control .rates [0 ].flags & IEEE80211_TX_RC_MCS )
734+ rx_status .flag |= RX_FLAG_HT ;
735+ }
723736 if (info -> control .rates [0 ].flags & IEEE80211_TX_RC_40_MHZ_WIDTH )
724737 rx_status .flag |= RX_FLAG_40MHZ ;
725738 if (info -> control .rates [0 ].flags & IEEE80211_TX_RC_SHORT_GI )
@@ -886,8 +899,12 @@ static void mac80211_hwsim_tx(struct ieee80211_hw *hw,
886899 if (control -> sta )
887900 hwsim_check_sta_magic (control -> sta );
888901
889- txi -> rate_driver_data [0 ] = channel ;
902+ if (rctbl )
903+ ieee80211_get_tx_rates (txi -> control .vif , control -> sta , skb ,
904+ txi -> control .rates ,
905+ ARRAY_SIZE (txi -> control .rates ));
890906
907+ txi -> rate_driver_data [0 ] = channel ;
891908 mac80211_hwsim_monitor_rx (hw , skb , channel );
892909
893910 /* wmediumd mode check */
@@ -989,6 +1006,13 @@ static void mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
9891006{
9901007 u32 _pid = ACCESS_ONCE (wmediumd_portid );
9911008
1009+ if (rctbl ) {
1010+ struct ieee80211_tx_info * txi = IEEE80211_SKB_CB (skb );
1011+ ieee80211_get_tx_rates (txi -> control .vif , NULL , skb ,
1012+ txi -> control .rates ,
1013+ ARRAY_SIZE (txi -> control .rates ));
1014+ }
1015+
9921016 mac80211_hwsim_monitor_rx (hw , skb , chan );
9931017
9941018 if (_pid )
@@ -1019,6 +1043,11 @@ static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
10191043 if (skb == NULL )
10201044 return ;
10211045 info = IEEE80211_SKB_CB (skb );
1046+ if (rctbl )
1047+ ieee80211_get_tx_rates (vif , NULL , skb ,
1048+ info -> control .rates ,
1049+ ARRAY_SIZE (info -> control .rates ));
1050+
10221051 txrate = ieee80211_get_tx_rate (hw , info );
10231052
10241053 mgmt = (struct ieee80211_mgmt * ) skb -> data ;
@@ -1687,6 +1716,7 @@ static void mac80211_hwsim_free(void)
16871716 debugfs_remove (data -> debugfs_ps );
16881717 debugfs_remove (data -> debugfs );
16891718 ieee80211_unregister_hw (data -> hw );
1719+ device_release_driver (data -> dev );
16901720 device_unregister (data -> dev );
16911721 ieee80211_free_hw (data -> hw );
16921722 }
@@ -1695,7 +1725,9 @@ static void mac80211_hwsim_free(void)
16951725
16961726
16971727static struct device_driver mac80211_hwsim_driver = {
1698- .name = "mac80211_hwsim"
1728+ .name = "mac80211_hwsim" ,
1729+ .bus = & platform_bus_type ,
1730+ .owner = THIS_MODULE ,
16991731};
17001732
17011733static const struct net_device_ops hwsim_netdev_ops = {
@@ -2187,9 +2219,15 @@ static int __init init_mac80211_hwsim(void)
21872219 spin_lock_init (& hwsim_radio_lock );
21882220 INIT_LIST_HEAD (& hwsim_radios );
21892221
2222+ err = driver_register (& mac80211_hwsim_driver );
2223+ if (err )
2224+ return err ;
2225+
21902226 hwsim_class = class_create (THIS_MODULE , "mac80211_hwsim" );
2191- if (IS_ERR (hwsim_class ))
2192- return PTR_ERR (hwsim_class );
2227+ if (IS_ERR (hwsim_class )) {
2228+ err = PTR_ERR (hwsim_class );
2229+ goto failed_unregister_driver ;
2230+ }
21932231
21942232 memset (addr , 0 , ETH_ALEN );
21952233 addr [0 ] = 0x02 ;
@@ -2211,12 +2249,20 @@ static int __init init_mac80211_hwsim(void)
22112249 "hwsim%d" , i );
22122250 if (IS_ERR (data -> dev )) {
22132251 printk (KERN_DEBUG
2214- "mac80211_hwsim: device_create "
2215- "failed (%ld)\n" , PTR_ERR (data -> dev ));
2252+ "mac80211_hwsim: device_create failed (%ld)\n" ,
2253+ PTR_ERR (data -> dev ));
22162254 err = - ENOMEM ;
22172255 goto failed_drvdata ;
22182256 }
22192257 data -> dev -> driver = & mac80211_hwsim_driver ;
2258+ err = device_bind_driver (data -> dev );
2259+ if (err != 0 ) {
2260+ printk (KERN_DEBUG
2261+ "mac80211_hwsim: device_bind_driver failed (%d)\n" ,
2262+ err );
2263+ goto failed_hw ;
2264+ }
2265+
22202266 skb_queue_head_init (& data -> pending );
22212267
22222268 SET_IEEE80211_DEV (hw , data -> dev );
@@ -2259,6 +2305,8 @@ static int __init init_mac80211_hwsim(void)
22592305 IEEE80211_HW_AMPDU_AGGREGATION |
22602306 IEEE80211_HW_WANT_MONITOR_VIF |
22612307 IEEE80211_HW_QUEUE_CONTROL ;
2308+ if (rctbl )
2309+ hw -> flags |= IEEE80211_HW_SUPPORTS_RC_TABLE ;
22622310
22632311 hw -> wiphy -> flags |= WIPHY_FLAG_SUPPORTS_TDLS |
22642312 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL ;
@@ -2515,6 +2563,8 @@ static int __init init_mac80211_hwsim(void)
25152563 ieee80211_free_hw (hw );
25162564failed :
25172565 mac80211_hwsim_free ();
2566+ failed_unregister_driver :
2567+ driver_unregister (& mac80211_hwsim_driver );
25182568 return err ;
25192569}
25202570module_init (init_mac80211_hwsim );
@@ -2527,5 +2577,6 @@ static void __exit exit_mac80211_hwsim(void)
25272577
25282578 mac80211_hwsim_free ();
25292579 unregister_netdev (hwsim_mon );
2580+ driver_unregister (& mac80211_hwsim_driver );
25302581}
25312582module_exit (exit_mac80211_hwsim );
0 commit comments