mac80211_hwsim.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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_VIF_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_VIF_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->tx_rate_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. memset(&txi->status, 0, sizeof(txi->status));
  223. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK)) {
  224. if (ack)
  225. txi->flags |= IEEE80211_TX_STAT_ACK;
  226. else
  227. txi->status.excessive_retries = 1;
  228. }
  229. ieee80211_tx_status_irqsafe(hw, skb);
  230. return NETDEV_TX_OK;
  231. }
  232. static int mac80211_hwsim_start(struct ieee80211_hw *hw)
  233. {
  234. struct mac80211_hwsim_data *data = hw->priv;
  235. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  236. data->started = 1;
  237. return 0;
  238. }
  239. static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
  240. {
  241. struct mac80211_hwsim_data *data = hw->priv;
  242. data->started = 0;
  243. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  244. }
  245. static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
  246. struct ieee80211_if_init_conf *conf)
  247. {
  248. DECLARE_MAC_BUF(mac);
  249. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n",
  250. wiphy_name(hw->wiphy), __func__, conf->type,
  251. print_mac(mac, conf->mac_addr));
  252. hwsim_set_magic(conf->vif);
  253. return 0;
  254. }
  255. static void mac80211_hwsim_remove_interface(
  256. struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf)
  257. {
  258. DECLARE_MAC_BUF(mac);
  259. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n",
  260. wiphy_name(hw->wiphy), __func__, conf->type,
  261. print_mac(mac, conf->mac_addr));
  262. hwsim_check_magic(conf->vif);
  263. hwsim_clear_magic(conf->vif);
  264. }
  265. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  266. struct ieee80211_vif *vif)
  267. {
  268. struct ieee80211_hw *hw = arg;
  269. struct sk_buff *skb;
  270. struct ieee80211_tx_info *info;
  271. hwsim_check_magic(vif);
  272. if (vif->type != NL80211_IFTYPE_AP)
  273. return;
  274. skb = ieee80211_beacon_get(hw, vif);
  275. if (skb == NULL)
  276. return;
  277. info = IEEE80211_SKB_CB(skb);
  278. mac80211_hwsim_monitor_rx(hw, skb);
  279. mac80211_hwsim_tx_frame(hw, skb);
  280. dev_kfree_skb(skb);
  281. }
  282. static void mac80211_hwsim_beacon(unsigned long arg)
  283. {
  284. struct ieee80211_hw *hw = (struct ieee80211_hw *) arg;
  285. struct mac80211_hwsim_data *data = hw->priv;
  286. if (!data->started || !data->radio_enabled)
  287. return;
  288. ieee80211_iterate_active_interfaces_atomic(
  289. hw, mac80211_hwsim_beacon_tx, hw);
  290. data->beacon_timer.expires = jiffies + data->beacon_int;
  291. add_timer(&data->beacon_timer);
  292. }
  293. static int mac80211_hwsim_config(struct ieee80211_hw *hw,
  294. struct ieee80211_conf *conf)
  295. {
  296. struct mac80211_hwsim_data *data = hw->priv;
  297. printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d beacon_int=%d)\n",
  298. wiphy_name(hw->wiphy), __func__,
  299. conf->channel->center_freq, conf->radio_enabled,
  300. conf->beacon_int);
  301. data->channel = conf->channel;
  302. data->radio_enabled = conf->radio_enabled;
  303. data->beacon_int = 1024 * conf->beacon_int / 1000 * HZ / 1000;
  304. if (data->beacon_int < 1)
  305. data->beacon_int = 1;
  306. if (!data->started || !data->radio_enabled)
  307. del_timer(&data->beacon_timer);
  308. else
  309. mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
  310. return 0;
  311. }
  312. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  313. unsigned int changed_flags,
  314. unsigned int *total_flags,
  315. int mc_count,
  316. struct dev_addr_list *mc_list)
  317. {
  318. struct mac80211_hwsim_data *data = hw->priv;
  319. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  320. data->rx_filter = 0;
  321. if (*total_flags & FIF_PROMISC_IN_BSS)
  322. data->rx_filter |= FIF_PROMISC_IN_BSS;
  323. if (*total_flags & FIF_ALLMULTI)
  324. data->rx_filter |= FIF_ALLMULTI;
  325. *total_flags = data->rx_filter;
  326. }
  327. static int mac80211_hwsim_config_interface(struct ieee80211_hw *hw,
  328. struct ieee80211_vif *vif,
  329. struct ieee80211_if_conf *conf)
  330. {
  331. hwsim_check_magic(vif);
  332. return 0;
  333. }
  334. static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
  335. struct ieee80211_vif *vif,
  336. struct ieee80211_bss_conf *info,
  337. u32 changed)
  338. {
  339. hwsim_check_magic(vif);
  340. }
  341. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  342. struct ieee80211_vif *vif,
  343. enum sta_notify_cmd cmd,
  344. struct ieee80211_sta *sta)
  345. {
  346. hwsim_check_magic(vif);
  347. switch (cmd) {
  348. case STA_NOTIFY_ADD:
  349. hwsim_set_sta_magic(sta);
  350. break;
  351. case STA_NOTIFY_REMOVE:
  352. hwsim_clear_sta_magic(sta);
  353. break;
  354. }
  355. }
  356. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  357. struct ieee80211_sta *sta,
  358. bool set)
  359. {
  360. hwsim_check_sta_magic(sta);
  361. return 0;
  362. }
  363. static const struct ieee80211_ops mac80211_hwsim_ops =
  364. {
  365. .tx = mac80211_hwsim_tx,
  366. .start = mac80211_hwsim_start,
  367. .stop = mac80211_hwsim_stop,
  368. .add_interface = mac80211_hwsim_add_interface,
  369. .remove_interface = mac80211_hwsim_remove_interface,
  370. .config = mac80211_hwsim_config,
  371. .configure_filter = mac80211_hwsim_configure_filter,
  372. .config_interface = mac80211_hwsim_config_interface,
  373. .bss_info_changed = mac80211_hwsim_bss_info_changed,
  374. .sta_notify = mac80211_hwsim_sta_notify,
  375. .set_tim = mac80211_hwsim_set_tim,
  376. };
  377. static void mac80211_hwsim_free(void)
  378. {
  379. struct list_head tmplist, *i, *tmp;
  380. struct mac80211_hwsim_data *data;
  381. INIT_LIST_HEAD(&tmplist);
  382. spin_lock_bh(&hwsim_radio_lock);
  383. list_for_each_safe(i, tmp, &hwsim_radios)
  384. list_move(i, &tmplist);
  385. spin_unlock_bh(&hwsim_radio_lock);
  386. list_for_each_entry(data, &tmplist, list) {
  387. ieee80211_unregister_hw(data->hw);
  388. device_unregister(data->dev);
  389. ieee80211_free_hw(data->hw);
  390. }
  391. class_destroy(hwsim_class);
  392. }
  393. static struct device_driver mac80211_hwsim_driver = {
  394. .name = "mac80211_hwsim"
  395. };
  396. static void hwsim_mon_setup(struct net_device *dev)
  397. {
  398. dev->hard_start_xmit = hwsim_mon_xmit;
  399. dev->destructor = free_netdev;
  400. ether_setup(dev);
  401. dev->tx_queue_len = 0;
  402. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  403. memset(dev->dev_addr, 0, ETH_ALEN);
  404. dev->dev_addr[0] = 0x12;
  405. }
  406. static int __init init_mac80211_hwsim(void)
  407. {
  408. int i, err = 0;
  409. u8 addr[ETH_ALEN];
  410. struct mac80211_hwsim_data *data;
  411. struct ieee80211_hw *hw;
  412. DECLARE_MAC_BUF(mac);
  413. if (radios < 1 || radios > 100)
  414. return -EINVAL;
  415. spin_lock_init(&hwsim_radio_lock);
  416. INIT_LIST_HEAD(&hwsim_radios);
  417. hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
  418. if (IS_ERR(hwsim_class))
  419. return PTR_ERR(hwsim_class);
  420. memset(addr, 0, ETH_ALEN);
  421. addr[0] = 0x02;
  422. for (i = 0; i < radios; i++) {
  423. printk(KERN_DEBUG "mac80211_hwsim: Initializing radio %d\n",
  424. i);
  425. hw = ieee80211_alloc_hw(sizeof(*data), &mac80211_hwsim_ops);
  426. if (!hw) {
  427. printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw "
  428. "failed\n");
  429. err = -ENOMEM;
  430. goto failed;
  431. }
  432. data = hw->priv;
  433. data->hw = hw;
  434. data->dev = device_create(hwsim_class, NULL, 0, hw,
  435. "hwsim%d", i);
  436. if (IS_ERR(data->dev)) {
  437. printk(KERN_DEBUG
  438. "mac80211_hwsim: device_create "
  439. "failed (%ld)\n", PTR_ERR(data->dev));
  440. err = -ENOMEM;
  441. goto failed_drvdata;
  442. }
  443. data->dev->driver = &mac80211_hwsim_driver;
  444. SET_IEEE80211_DEV(hw, data->dev);
  445. addr[3] = i >> 8;
  446. addr[4] = i;
  447. SET_IEEE80211_PERM_ADDR(hw, addr);
  448. hw->channel_change_time = 1;
  449. hw->queues = 4;
  450. hw->wiphy->interface_modes =
  451. BIT(NL80211_IFTYPE_STATION) |
  452. BIT(NL80211_IFTYPE_AP);
  453. hw->ampdu_queues = 1;
  454. /* ask mac80211 to reserve space for magic */
  455. hw->vif_data_size = sizeof(struct hwsim_vif_priv);
  456. hw->sta_data_size = sizeof(struct hwsim_sta_priv);
  457. memcpy(data->channels, hwsim_channels, sizeof(hwsim_channels));
  458. memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
  459. data->band.channels = data->channels;
  460. data->band.n_channels = ARRAY_SIZE(hwsim_channels);
  461. data->band.bitrates = data->rates;
  462. data->band.n_bitrates = ARRAY_SIZE(hwsim_rates);
  463. data->band.ht_info.ht_supported = 1;
  464. data->band.ht_info.cap = IEEE80211_HT_CAP_SUP_WIDTH |
  465. IEEE80211_HT_CAP_GRN_FLD |
  466. IEEE80211_HT_CAP_SGI_40 |
  467. IEEE80211_HT_CAP_DSSSCCK40;
  468. data->band.ht_info.ampdu_factor = 0x3;
  469. data->band.ht_info.ampdu_density = 0x6;
  470. memset(data->band.ht_info.supp_mcs_set, 0,
  471. sizeof(data->band.ht_info.supp_mcs_set));
  472. data->band.ht_info.supp_mcs_set[0] = 0xff;
  473. data->band.ht_info.supp_mcs_set[1] = 0xff;
  474. data->band.ht_info.supp_mcs_set[12] =
  475. IEEE80211_HT_CAP_MCS_TX_DEFINED;
  476. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &data->band;
  477. err = ieee80211_register_hw(hw);
  478. if (err < 0) {
  479. printk(KERN_DEBUG "mac80211_hwsim: "
  480. "ieee80211_register_hw failed (%d)\n", err);
  481. goto failed_hw;
  482. }
  483. printk(KERN_DEBUG "%s: hwaddr %s registered\n",
  484. wiphy_name(hw->wiphy),
  485. print_mac(mac, hw->wiphy->perm_addr));
  486. setup_timer(&data->beacon_timer, mac80211_hwsim_beacon,
  487. (unsigned long) hw);
  488. list_add_tail(&data->list, &hwsim_radios);
  489. }
  490. hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup);
  491. if (hwsim_mon == NULL)
  492. goto failed;
  493. rtnl_lock();
  494. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  495. if (err < 0)
  496. goto failed_mon;
  497. err = register_netdevice(hwsim_mon);
  498. if (err < 0)
  499. goto failed_mon;
  500. rtnl_unlock();
  501. return 0;
  502. failed_mon:
  503. rtnl_unlock();
  504. free_netdev(hwsim_mon);
  505. mac80211_hwsim_free();
  506. return err;
  507. failed_hw:
  508. device_unregister(data->dev);
  509. failed_drvdata:
  510. ieee80211_free_hw(hw);
  511. failed:
  512. mac80211_hwsim_free();
  513. return err;
  514. }
  515. static void __exit exit_mac80211_hwsim(void)
  516. {
  517. printk(KERN_DEBUG "mac80211_hwsim: unregister radios\n");
  518. unregister_netdev(hwsim_mon);
  519. mac80211_hwsim_free();
  520. }
  521. module_init(init_mac80211_hwsim);
  522. module_exit(exit_mac80211_hwsim);