mac80211_hwsim.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. * mac80211_hwsim - software simulator of 802.11 radio(s) for mac80211
  3. * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. */
  9. /*
  10. * TODO:
  11. * - IBSS mode simulation (Beacon transmission with competition for "air time")
  12. * - IEEE 802.11a and 802.11n modes
  13. * - RX filtering based on filter configuration (data->rx_filter)
  14. */
  15. #include <linux/list.h>
  16. #include <linux/spinlock.h>
  17. #include <net/mac80211.h>
  18. #include <net/ieee80211_radiotap.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/rtnetlink.h>
  21. #include <linux/etherdevice.h>
  22. MODULE_AUTHOR("Jouni Malinen");
  23. MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211");
  24. MODULE_LICENSE("GPL");
  25. static int radios = 2;
  26. module_param(radios, int, 0444);
  27. MODULE_PARM_DESC(radios, "Number of simulated radios");
  28. struct hwsim_vif_priv {
  29. u32 magic;
  30. };
  31. #define HWSIM_VIF_MAGIC 0x69537748
  32. static inline void hwsim_check_magic(struct ieee80211_vif *vif)
  33. {
  34. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  35. WARN_ON(vp->magic != HWSIM_VIF_MAGIC);
  36. }
  37. static inline void hwsim_set_magic(struct ieee80211_vif *vif)
  38. {
  39. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  40. vp->magic = HWSIM_VIF_MAGIC;
  41. }
  42. static inline void hwsim_clear_magic(struct ieee80211_vif *vif)
  43. {
  44. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  45. vp->magic = 0;
  46. }
  47. struct hwsim_sta_priv {
  48. u32 magic;
  49. };
  50. #define HWSIM_STA_MAGIC 0x6d537748
  51. static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta)
  52. {
  53. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  54. WARN_ON(sp->magic != HWSIM_STA_MAGIC);
  55. }
  56. static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta)
  57. {
  58. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  59. sp->magic = HWSIM_STA_MAGIC;
  60. }
  61. static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta)
  62. {
  63. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  64. sp->magic = 0;
  65. }
  66. static struct class *hwsim_class;
  67. static struct net_device *hwsim_mon; /* global monitor netdev */
  68. static const struct ieee80211_channel hwsim_channels[] = {
  69. { .center_freq = 2412 },
  70. { .center_freq = 2417 },
  71. { .center_freq = 2422 },
  72. { .center_freq = 2427 },
  73. { .center_freq = 2432 },
  74. { .center_freq = 2437 },
  75. { .center_freq = 2442 },
  76. { .center_freq = 2447 },
  77. { .center_freq = 2452 },
  78. { .center_freq = 2457 },
  79. { .center_freq = 2462 },
  80. { .center_freq = 2467 },
  81. { .center_freq = 2472 },
  82. { .center_freq = 2484 },
  83. };
  84. static const struct ieee80211_rate hwsim_rates[] = {
  85. { .bitrate = 10 },
  86. { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  87. { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  88. { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  89. { .bitrate = 60 },
  90. { .bitrate = 90 },
  91. { .bitrate = 120 },
  92. { .bitrate = 180 },
  93. { .bitrate = 240 },
  94. { .bitrate = 360 },
  95. { .bitrate = 480 },
  96. { .bitrate = 540 }
  97. };
  98. static spinlock_t hwsim_radio_lock;
  99. static struct list_head hwsim_radios;
  100. struct mac80211_hwsim_data {
  101. struct list_head list;
  102. struct ieee80211_hw *hw;
  103. struct device *dev;
  104. struct ieee80211_supported_band band;
  105. struct ieee80211_channel channels[ARRAY_SIZE(hwsim_channels)];
  106. struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)];
  107. struct ieee80211_channel *channel;
  108. int radio_enabled;
  109. unsigned long beacon_int; /* in jiffies unit */
  110. unsigned int rx_filter;
  111. int started;
  112. struct timer_list beacon_timer;
  113. };
  114. struct hwsim_radiotap_hdr {
  115. struct ieee80211_radiotap_header hdr;
  116. u8 rt_flags;
  117. u8 rt_rate;
  118. __le16 rt_channel;
  119. __le16 rt_chbitmask;
  120. } __attribute__ ((packed));
  121. static int hwsim_mon_xmit(struct sk_buff *skb, struct net_device *dev)
  122. {
  123. /* TODO: allow packet injection */
  124. dev_kfree_skb(skb);
  125. return 0;
  126. }
  127. static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
  128. struct sk_buff *tx_skb)
  129. {
  130. struct mac80211_hwsim_data *data = hw->priv;
  131. struct sk_buff *skb;
  132. struct hwsim_radiotap_hdr *hdr;
  133. u16 flags;
  134. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
  135. struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
  136. if (!netif_running(hwsim_mon))
  137. return;
  138. skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
  139. if (skb == NULL)
  140. return;
  141. hdr = (struct hwsim_radiotap_hdr *) skb_push(skb, sizeof(*hdr));
  142. hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  143. hdr->hdr.it_pad = 0;
  144. hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
  145. hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  146. (1 << IEEE80211_RADIOTAP_RATE) |
  147. (1 << IEEE80211_RADIOTAP_CHANNEL));
  148. hdr->rt_flags = 0;
  149. hdr->rt_rate = txrate->bitrate / 5;
  150. hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
  151. flags = IEEE80211_CHAN_2GHZ;
  152. if (txrate->flags & IEEE80211_RATE_ERP_G)
  153. flags |= IEEE80211_CHAN_OFDM;
  154. else
  155. flags |= IEEE80211_CHAN_CCK;
  156. hdr->rt_chbitmask = cpu_to_le16(flags);
  157. skb->dev = hwsim_mon;
  158. skb_set_mac_header(skb, 0);
  159. skb->ip_summed = CHECKSUM_UNNECESSARY;
  160. skb->pkt_type = PACKET_OTHERHOST;
  161. skb->protocol = htons(ETH_P_802_2);
  162. memset(skb->cb, 0, sizeof(skb->cb));
  163. netif_rx(skb);
  164. }
  165. static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
  166. struct sk_buff *skb)
  167. {
  168. struct mac80211_hwsim_data *data = hw->priv, *data2;
  169. bool ack = false;
  170. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  171. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  172. struct ieee80211_rx_status rx_status;
  173. memset(&rx_status, 0, sizeof(rx_status));
  174. /* TODO: set mactime */
  175. rx_status.freq = data->channel->center_freq;
  176. rx_status.band = data->channel->band;
  177. rx_status.rate_idx = info->control.rates[0].idx;
  178. /* TODO: simulate signal strength (and optional packet drop) */
  179. /* Copy skb to all enabled radios that are on the current frequency */
  180. spin_lock(&hwsim_radio_lock);
  181. list_for_each_entry(data2, &hwsim_radios, list) {
  182. struct sk_buff *nskb;
  183. if (data == data2)
  184. continue;
  185. if (!data2->started || !data2->radio_enabled ||
  186. data->channel->center_freq != data2->channel->center_freq)
  187. continue;
  188. nskb = skb_copy(skb, GFP_ATOMIC);
  189. if (nskb == NULL)
  190. continue;
  191. if (memcmp(hdr->addr1, data2->hw->wiphy->perm_addr,
  192. ETH_ALEN) == 0)
  193. ack = true;
  194. ieee80211_rx_irqsafe(data2->hw, nskb, &rx_status);
  195. }
  196. spin_unlock(&hwsim_radio_lock);
  197. return ack;
  198. }
  199. static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  200. {
  201. struct mac80211_hwsim_data *data = hw->priv;
  202. bool ack;
  203. struct ieee80211_tx_info *txi;
  204. mac80211_hwsim_monitor_rx(hw, skb);
  205. if (skb->len < 10) {
  206. /* Should not happen; just a sanity check for addr1 use */
  207. dev_kfree_skb(skb);
  208. return NETDEV_TX_OK;
  209. }
  210. if (!data->radio_enabled) {
  211. printk(KERN_DEBUG "%s: dropped TX frame since radio "
  212. "disabled\n", wiphy_name(hw->wiphy));
  213. dev_kfree_skb(skb);
  214. return NETDEV_TX_OK;
  215. }
  216. ack = mac80211_hwsim_tx_frame(hw, skb);
  217. txi = IEEE80211_SKB_CB(skb);
  218. if (txi->control.vif)
  219. hwsim_check_magic(txi->control.vif);
  220. if (txi->control.sta)
  221. hwsim_check_sta_magic(txi->control.sta);
  222. ieee80211_tx_info_clear_status(txi);
  223. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack)
  224. txi->flags |= IEEE80211_TX_STAT_ACK;
  225. ieee80211_tx_status_irqsafe(hw, skb);
  226. return NETDEV_TX_OK;
  227. }
  228. static int mac80211_hwsim_start(struct ieee80211_hw *hw)
  229. {
  230. struct mac80211_hwsim_data *data = hw->priv;
  231. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  232. data->started = 1;
  233. return 0;
  234. }
  235. static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
  236. {
  237. struct mac80211_hwsim_data *data = hw->priv;
  238. data->started = 0;
  239. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  240. }
  241. static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
  242. struct ieee80211_if_init_conf *conf)
  243. {
  244. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%pM)\n",
  245. wiphy_name(hw->wiphy), __func__, conf->type,
  246. conf->mac_addr);
  247. hwsim_set_magic(conf->vif);
  248. return 0;
  249. }
  250. static void mac80211_hwsim_remove_interface(
  251. struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf)
  252. {
  253. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%pM)\n",
  254. wiphy_name(hw->wiphy), __func__, conf->type,
  255. conf->mac_addr);
  256. hwsim_check_magic(conf->vif);
  257. hwsim_clear_magic(conf->vif);
  258. }
  259. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  260. struct ieee80211_vif *vif)
  261. {
  262. struct ieee80211_hw *hw = arg;
  263. struct sk_buff *skb;
  264. struct ieee80211_tx_info *info;
  265. hwsim_check_magic(vif);
  266. if (vif->type != NL80211_IFTYPE_AP)
  267. return;
  268. skb = ieee80211_beacon_get(hw, vif);
  269. if (skb == NULL)
  270. return;
  271. info = IEEE80211_SKB_CB(skb);
  272. mac80211_hwsim_monitor_rx(hw, skb);
  273. mac80211_hwsim_tx_frame(hw, skb);
  274. dev_kfree_skb(skb);
  275. }
  276. static void mac80211_hwsim_beacon(unsigned long arg)
  277. {
  278. struct ieee80211_hw *hw = (struct ieee80211_hw *) arg;
  279. struct mac80211_hwsim_data *data = hw->priv;
  280. if (!data->started || !data->radio_enabled)
  281. return;
  282. ieee80211_iterate_active_interfaces_atomic(
  283. hw, mac80211_hwsim_beacon_tx, hw);
  284. data->beacon_timer.expires = jiffies + data->beacon_int;
  285. add_timer(&data->beacon_timer);
  286. }
  287. static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
  288. {
  289. struct mac80211_hwsim_data *data = hw->priv;
  290. struct ieee80211_conf *conf = &hw->conf;
  291. printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d beacon_int=%d)\n",
  292. wiphy_name(hw->wiphy), __func__,
  293. conf->channel->center_freq, conf->radio_enabled,
  294. conf->beacon_int);
  295. data->channel = conf->channel;
  296. data->radio_enabled = conf->radio_enabled;
  297. data->beacon_int = 1024 * conf->beacon_int / 1000 * HZ / 1000;
  298. if (data->beacon_int < 1)
  299. data->beacon_int = 1;
  300. if (!data->started || !data->radio_enabled)
  301. del_timer(&data->beacon_timer);
  302. else
  303. mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
  304. return 0;
  305. }
  306. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  307. unsigned int changed_flags,
  308. unsigned int *total_flags,
  309. int mc_count,
  310. struct dev_addr_list *mc_list)
  311. {
  312. struct mac80211_hwsim_data *data = hw->priv;
  313. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  314. data->rx_filter = 0;
  315. if (*total_flags & FIF_PROMISC_IN_BSS)
  316. data->rx_filter |= FIF_PROMISC_IN_BSS;
  317. if (*total_flags & FIF_ALLMULTI)
  318. data->rx_filter |= FIF_ALLMULTI;
  319. *total_flags = data->rx_filter;
  320. }
  321. static int mac80211_hwsim_config_interface(struct ieee80211_hw *hw,
  322. struct ieee80211_vif *vif,
  323. struct ieee80211_if_conf *conf)
  324. {
  325. hwsim_check_magic(vif);
  326. return 0;
  327. }
  328. static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
  329. struct ieee80211_vif *vif,
  330. struct ieee80211_bss_conf *info,
  331. u32 changed)
  332. {
  333. hwsim_check_magic(vif);
  334. printk(KERN_DEBUG "%s:%s(changed=0x%x)\n",
  335. wiphy_name(hw->wiphy), __func__, changed);
  336. if (changed & BSS_CHANGED_ASSOC) {
  337. printk(KERN_DEBUG " %s: ASSOC: assoc=%d aid=%d\n",
  338. wiphy_name(hw->wiphy), info->assoc, info->aid);
  339. }
  340. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  341. printk(KERN_DEBUG " %s: ERP_CTS_PROT: %d\n",
  342. wiphy_name(hw->wiphy), info->use_cts_prot);
  343. }
  344. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  345. printk(KERN_DEBUG " %s: ERP_PREAMBLE: %d\n",
  346. wiphy_name(hw->wiphy), info->use_short_preamble);
  347. }
  348. if (changed & BSS_CHANGED_ERP_SLOT) {
  349. printk(KERN_DEBUG " %s: ERP_SLOT: %d\n",
  350. wiphy_name(hw->wiphy), info->use_short_slot);
  351. }
  352. if (changed & BSS_CHANGED_HT) {
  353. printk(KERN_DEBUG " %s: HT: sec_ch_offs=%d width_40_ok=%d "
  354. "op_mode=%d\n",
  355. wiphy_name(hw->wiphy),
  356. info->ht.secondary_channel_offset,
  357. info->ht.width_40_ok, info->ht.operation_mode);
  358. }
  359. if (changed & BSS_CHANGED_BASIC_RATES) {
  360. printk(KERN_DEBUG " %s: BASIC_RATES: 0x%llx\n",
  361. wiphy_name(hw->wiphy),
  362. (unsigned long long) info->basic_rates);
  363. }
  364. }
  365. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  366. struct ieee80211_vif *vif,
  367. enum sta_notify_cmd cmd,
  368. struct ieee80211_sta *sta)
  369. {
  370. hwsim_check_magic(vif);
  371. switch (cmd) {
  372. case STA_NOTIFY_ADD:
  373. hwsim_set_sta_magic(sta);
  374. break;
  375. case STA_NOTIFY_REMOVE:
  376. hwsim_clear_sta_magic(sta);
  377. break;
  378. }
  379. }
  380. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  381. struct ieee80211_sta *sta,
  382. bool set)
  383. {
  384. hwsim_check_sta_magic(sta);
  385. return 0;
  386. }
  387. static int mac80211_hwsim_conf_tx(
  388. struct ieee80211_hw *hw, u16 queue,
  389. const struct ieee80211_tx_queue_params *params)
  390. {
  391. printk(KERN_DEBUG "%s:%s (queue=%d txop=%d cw_min=%d cw_max=%d "
  392. "aifs=%d)\n",
  393. wiphy_name(hw->wiphy), __func__, queue,
  394. params->txop, params->cw_min, params->cw_max, params->aifs);
  395. return 0;
  396. }
  397. static const struct ieee80211_ops mac80211_hwsim_ops =
  398. {
  399. .tx = mac80211_hwsim_tx,
  400. .start = mac80211_hwsim_start,
  401. .stop = mac80211_hwsim_stop,
  402. .add_interface = mac80211_hwsim_add_interface,
  403. .remove_interface = mac80211_hwsim_remove_interface,
  404. .config = mac80211_hwsim_config,
  405. .configure_filter = mac80211_hwsim_configure_filter,
  406. .config_interface = mac80211_hwsim_config_interface,
  407. .bss_info_changed = mac80211_hwsim_bss_info_changed,
  408. .sta_notify = mac80211_hwsim_sta_notify,
  409. .set_tim = mac80211_hwsim_set_tim,
  410. .conf_tx = mac80211_hwsim_conf_tx,
  411. };
  412. static void mac80211_hwsim_free(void)
  413. {
  414. struct list_head tmplist, *i, *tmp;
  415. struct mac80211_hwsim_data *data;
  416. INIT_LIST_HEAD(&tmplist);
  417. spin_lock_bh(&hwsim_radio_lock);
  418. list_for_each_safe(i, tmp, &hwsim_radios)
  419. list_move(i, &tmplist);
  420. spin_unlock_bh(&hwsim_radio_lock);
  421. list_for_each_entry(data, &tmplist, list) {
  422. ieee80211_unregister_hw(data->hw);
  423. device_unregister(data->dev);
  424. ieee80211_free_hw(data->hw);
  425. }
  426. class_destroy(hwsim_class);
  427. }
  428. static struct device_driver mac80211_hwsim_driver = {
  429. .name = "mac80211_hwsim"
  430. };
  431. static void hwsim_mon_setup(struct net_device *dev)
  432. {
  433. dev->hard_start_xmit = hwsim_mon_xmit;
  434. dev->destructor = free_netdev;
  435. ether_setup(dev);
  436. dev->tx_queue_len = 0;
  437. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  438. memset(dev->dev_addr, 0, ETH_ALEN);
  439. dev->dev_addr[0] = 0x12;
  440. }
  441. static int __init init_mac80211_hwsim(void)
  442. {
  443. int i, err = 0;
  444. u8 addr[ETH_ALEN];
  445. struct mac80211_hwsim_data *data;
  446. struct ieee80211_hw *hw;
  447. if (radios < 1 || radios > 100)
  448. return -EINVAL;
  449. spin_lock_init(&hwsim_radio_lock);
  450. INIT_LIST_HEAD(&hwsim_radios);
  451. hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
  452. if (IS_ERR(hwsim_class))
  453. return PTR_ERR(hwsim_class);
  454. memset(addr, 0, ETH_ALEN);
  455. addr[0] = 0x02;
  456. for (i = 0; i < radios; i++) {
  457. printk(KERN_DEBUG "mac80211_hwsim: Initializing radio %d\n",
  458. i);
  459. hw = ieee80211_alloc_hw(sizeof(*data), &mac80211_hwsim_ops);
  460. if (!hw) {
  461. printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw "
  462. "failed\n");
  463. err = -ENOMEM;
  464. goto failed;
  465. }
  466. data = hw->priv;
  467. data->hw = hw;
  468. data->dev = device_create(hwsim_class, NULL, 0, hw,
  469. "hwsim%d", i);
  470. if (IS_ERR(data->dev)) {
  471. printk(KERN_DEBUG
  472. "mac80211_hwsim: device_create "
  473. "failed (%ld)\n", PTR_ERR(data->dev));
  474. err = -ENOMEM;
  475. goto failed_drvdata;
  476. }
  477. data->dev->driver = &mac80211_hwsim_driver;
  478. SET_IEEE80211_DEV(hw, data->dev);
  479. addr[3] = i >> 8;
  480. addr[4] = i;
  481. SET_IEEE80211_PERM_ADDR(hw, addr);
  482. hw->channel_change_time = 1;
  483. hw->queues = 4;
  484. hw->wiphy->interface_modes =
  485. BIT(NL80211_IFTYPE_STATION) |
  486. BIT(NL80211_IFTYPE_AP);
  487. hw->ampdu_queues = 1;
  488. /* ask mac80211 to reserve space for magic */
  489. hw->vif_data_size = sizeof(struct hwsim_vif_priv);
  490. hw->sta_data_size = sizeof(struct hwsim_sta_priv);
  491. memcpy(data->channels, hwsim_channels, sizeof(hwsim_channels));
  492. memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
  493. data->band.channels = data->channels;
  494. data->band.n_channels = ARRAY_SIZE(hwsim_channels);
  495. data->band.bitrates = data->rates;
  496. data->band.n_bitrates = ARRAY_SIZE(hwsim_rates);
  497. data->band.ht_cap.ht_supported = true;
  498. data->band.ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  499. IEEE80211_HT_CAP_GRN_FLD |
  500. IEEE80211_HT_CAP_SGI_40 |
  501. IEEE80211_HT_CAP_DSSSCCK40;
  502. data->band.ht_cap.ampdu_factor = 0x3;
  503. data->band.ht_cap.ampdu_density = 0x6;
  504. memset(&data->band.ht_cap.mcs, 0,
  505. sizeof(data->band.ht_cap.mcs));
  506. data->band.ht_cap.mcs.rx_mask[0] = 0xff;
  507. data->band.ht_cap.mcs.rx_mask[1] = 0xff;
  508. data->band.ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  509. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &data->band;
  510. err = ieee80211_register_hw(hw);
  511. if (err < 0) {
  512. printk(KERN_DEBUG "mac80211_hwsim: "
  513. "ieee80211_register_hw failed (%d)\n", err);
  514. goto failed_hw;
  515. }
  516. printk(KERN_DEBUG "%s: hwaddr %pM registered\n",
  517. wiphy_name(hw->wiphy),
  518. hw->wiphy->perm_addr);
  519. setup_timer(&data->beacon_timer, mac80211_hwsim_beacon,
  520. (unsigned long) hw);
  521. list_add_tail(&data->list, &hwsim_radios);
  522. }
  523. hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup);
  524. if (hwsim_mon == NULL)
  525. goto failed;
  526. rtnl_lock();
  527. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  528. if (err < 0)
  529. goto failed_mon;
  530. err = register_netdevice(hwsim_mon);
  531. if (err < 0)
  532. goto failed_mon;
  533. rtnl_unlock();
  534. return 0;
  535. failed_mon:
  536. rtnl_unlock();
  537. free_netdev(hwsim_mon);
  538. mac80211_hwsim_free();
  539. return err;
  540. failed_hw:
  541. device_unregister(data->dev);
  542. failed_drvdata:
  543. ieee80211_free_hw(hw);
  544. failed:
  545. mac80211_hwsim_free();
  546. return err;
  547. }
  548. static void __exit exit_mac80211_hwsim(void)
  549. {
  550. printk(KERN_DEBUG "mac80211_hwsim: unregister radios\n");
  551. unregister_netdev(hwsim_mon);
  552. mac80211_hwsim_free();
  553. }
  554. module_init(init_mac80211_hwsim);
  555. module_exit(exit_mac80211_hwsim);