mac80211_hwsim.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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 <net/mac80211.h>
  16. #include <net/ieee80211_radiotap.h>
  17. #include <linux/if_arp.h>
  18. #include <linux/rtnetlink.h>
  19. #include <linux/etherdevice.h>
  20. MODULE_AUTHOR("Jouni Malinen");
  21. MODULE_DESCRIPTION("Software simulator of 802.11 radio(s) for mac80211");
  22. MODULE_LICENSE("GPL");
  23. static int radios = 2;
  24. module_param(radios, int, 0444);
  25. MODULE_PARM_DESC(radios, "Number of simulated radios");
  26. struct hwsim_vif_priv {
  27. u32 magic;
  28. };
  29. #define HWSIM_VIF_MAGIC 0x69537748
  30. static inline void hwsim_check_magic(struct ieee80211_vif *vif)
  31. {
  32. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  33. WARN_ON(vp->magic != HWSIM_VIF_MAGIC);
  34. }
  35. static inline void hwsim_set_magic(struct ieee80211_vif *vif)
  36. {
  37. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  38. vp->magic = HWSIM_VIF_MAGIC;
  39. }
  40. static inline void hwsim_clear_magic(struct ieee80211_vif *vif)
  41. {
  42. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  43. vp->magic = 0;
  44. }
  45. struct hwsim_sta_priv {
  46. u32 magic;
  47. };
  48. #define HWSIM_STA_MAGIC 0x6d537748
  49. static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta)
  50. {
  51. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  52. WARN_ON(sp->magic != HWSIM_VIF_MAGIC);
  53. }
  54. static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta)
  55. {
  56. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  57. sp->magic = HWSIM_VIF_MAGIC;
  58. }
  59. static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta)
  60. {
  61. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  62. sp->magic = 0;
  63. }
  64. static struct class *hwsim_class;
  65. static struct ieee80211_hw **hwsim_radios;
  66. static int hwsim_radio_count;
  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. struct mac80211_hwsim_data {
  99. struct device *dev;
  100. struct ieee80211_supported_band band;
  101. struct ieee80211_channel channels[ARRAY_SIZE(hwsim_channels)];
  102. struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)];
  103. struct ieee80211_channel *channel;
  104. int radio_enabled;
  105. unsigned long beacon_int; /* in jiffies unit */
  106. unsigned int rx_filter;
  107. int started;
  108. struct timer_list beacon_timer;
  109. };
  110. struct hwsim_radiotap_hdr {
  111. struct ieee80211_radiotap_header hdr;
  112. u8 rt_flags;
  113. u8 rt_rate;
  114. __le16 rt_channel;
  115. __le16 rt_chbitmask;
  116. } __attribute__ ((packed));
  117. static int hwsim_mon_xmit(struct sk_buff *skb, struct net_device *dev)
  118. {
  119. /* TODO: allow packet injection */
  120. dev_kfree_skb(skb);
  121. return 0;
  122. }
  123. static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
  124. struct sk_buff *tx_skb)
  125. {
  126. struct mac80211_hwsim_data *data = hw->priv;
  127. struct sk_buff *skb;
  128. struct hwsim_radiotap_hdr *hdr;
  129. u16 flags;
  130. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
  131. struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
  132. if (!netif_running(hwsim_mon))
  133. return;
  134. skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
  135. if (skb == NULL)
  136. return;
  137. hdr = (struct hwsim_radiotap_hdr *) skb_push(skb, sizeof(*hdr));
  138. hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  139. hdr->hdr.it_pad = 0;
  140. hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
  141. hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  142. (1 << IEEE80211_RADIOTAP_RATE) |
  143. (1 << IEEE80211_RADIOTAP_CHANNEL));
  144. hdr->rt_flags = 0;
  145. hdr->rt_rate = txrate->bitrate / 5;
  146. hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
  147. flags = IEEE80211_CHAN_2GHZ;
  148. if (txrate->flags & IEEE80211_RATE_ERP_G)
  149. flags |= IEEE80211_CHAN_OFDM;
  150. else
  151. flags |= IEEE80211_CHAN_CCK;
  152. hdr->rt_chbitmask = cpu_to_le16(flags);
  153. skb->dev = hwsim_mon;
  154. skb_set_mac_header(skb, 0);
  155. skb->ip_summed = CHECKSUM_UNNECESSARY;
  156. skb->pkt_type = PACKET_OTHERHOST;
  157. skb->protocol = htons(ETH_P_802_2);
  158. memset(skb->cb, 0, sizeof(skb->cb));
  159. netif_rx(skb);
  160. }
  161. static int mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
  162. struct sk_buff *skb)
  163. {
  164. struct mac80211_hwsim_data *data = hw->priv;
  165. int i, ack = 0;
  166. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  167. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  168. struct ieee80211_rx_status rx_status;
  169. memset(&rx_status, 0, sizeof(rx_status));
  170. /* TODO: set mactime */
  171. rx_status.freq = data->channel->center_freq;
  172. rx_status.band = data->channel->band;
  173. rx_status.rate_idx = info->tx_rate_idx;
  174. /* TODO: simulate signal strength (and optional packet drop) */
  175. /* Copy skb to all enabled radios that are on the current frequency */
  176. for (i = 0; i < hwsim_radio_count; i++) {
  177. struct mac80211_hwsim_data *data2;
  178. struct sk_buff *nskb;
  179. if (hwsim_radios[i] == NULL || hwsim_radios[i] == hw)
  180. continue;
  181. data2 = hwsim_radios[i]->priv;
  182. if (!data2->started || !data2->radio_enabled ||
  183. data->channel->center_freq != data2->channel->center_freq)
  184. continue;
  185. nskb = skb_copy(skb, GFP_ATOMIC);
  186. if (nskb == NULL)
  187. continue;
  188. if (memcmp(hdr->addr1, hwsim_radios[i]->wiphy->perm_addr,
  189. ETH_ALEN) == 0)
  190. ack = 1;
  191. ieee80211_rx_irqsafe(hwsim_radios[i], nskb, &rx_status);
  192. }
  193. return ack;
  194. }
  195. static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  196. {
  197. struct mac80211_hwsim_data *data = hw->priv;
  198. int ack;
  199. struct ieee80211_tx_info *txi;
  200. mac80211_hwsim_monitor_rx(hw, skb);
  201. if (skb->len < 10) {
  202. /* Should not happen; just a sanity check for addr1 use */
  203. dev_kfree_skb(skb);
  204. return NETDEV_TX_OK;
  205. }
  206. if (!data->radio_enabled) {
  207. printk(KERN_DEBUG "%s: dropped TX frame since radio "
  208. "disabled\n", wiphy_name(hw->wiphy));
  209. dev_kfree_skb(skb);
  210. return NETDEV_TX_OK;
  211. }
  212. ack = mac80211_hwsim_tx_frame(hw, skb);
  213. txi = IEEE80211_SKB_CB(skb);
  214. hwsim_check_magic(txi->control.vif);
  215. if (txi->control.sta)
  216. hwsim_check_sta_magic(txi->control.sta);
  217. memset(&txi->status, 0, sizeof(txi->status));
  218. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK)) {
  219. if (ack)
  220. txi->flags |= IEEE80211_TX_STAT_ACK;
  221. else
  222. txi->status.excessive_retries = 1;
  223. }
  224. ieee80211_tx_status_irqsafe(hw, skb);
  225. return NETDEV_TX_OK;
  226. }
  227. static int mac80211_hwsim_start(struct ieee80211_hw *hw)
  228. {
  229. struct mac80211_hwsim_data *data = hw->priv;
  230. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  231. data->started = 1;
  232. return 0;
  233. }
  234. static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
  235. {
  236. struct mac80211_hwsim_data *data = hw->priv;
  237. data->started = 0;
  238. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  239. }
  240. static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
  241. struct ieee80211_if_init_conf *conf)
  242. {
  243. DECLARE_MAC_BUF(mac);
  244. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n",
  245. wiphy_name(hw->wiphy), __func__, conf->type,
  246. print_mac(mac, 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. DECLARE_MAC_BUF(mac);
  254. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n",
  255. wiphy_name(hw->wiphy), __func__, conf->type,
  256. print_mac(mac, conf->mac_addr));
  257. hwsim_check_magic(conf->vif);
  258. hwsim_clear_magic(conf->vif);
  259. }
  260. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  261. struct ieee80211_vif *vif)
  262. {
  263. struct ieee80211_hw *hw = arg;
  264. struct sk_buff *skb;
  265. struct ieee80211_tx_info *info;
  266. hwsim_check_magic(vif);
  267. if (vif->type != NL80211_IFTYPE_AP)
  268. return;
  269. skb = ieee80211_beacon_get(hw, vif);
  270. if (skb == NULL)
  271. return;
  272. info = IEEE80211_SKB_CB(skb);
  273. mac80211_hwsim_monitor_rx(hw, skb);
  274. mac80211_hwsim_tx_frame(hw, skb);
  275. dev_kfree_skb(skb);
  276. }
  277. static void mac80211_hwsim_beacon(unsigned long arg)
  278. {
  279. struct ieee80211_hw *hw = (struct ieee80211_hw *) arg;
  280. struct mac80211_hwsim_data *data = hw->priv;
  281. if (!data->started || !data->radio_enabled)
  282. return;
  283. ieee80211_iterate_active_interfaces_atomic(
  284. hw, mac80211_hwsim_beacon_tx, hw);
  285. data->beacon_timer.expires = jiffies + data->beacon_int;
  286. add_timer(&data->beacon_timer);
  287. }
  288. static int mac80211_hwsim_config(struct ieee80211_hw *hw,
  289. struct ieee80211_conf *conf)
  290. {
  291. struct mac80211_hwsim_data *data = hw->priv;
  292. printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d beacon_int=%d)\n",
  293. wiphy_name(hw->wiphy), __func__,
  294. conf->channel->center_freq, conf->radio_enabled,
  295. conf->beacon_int);
  296. data->channel = conf->channel;
  297. data->radio_enabled = conf->radio_enabled;
  298. data->beacon_int = 1024 * conf->beacon_int / 1000 * HZ / 1000;
  299. if (data->beacon_int < 1)
  300. data->beacon_int = 1;
  301. if (!data->started || !data->radio_enabled)
  302. del_timer(&data->beacon_timer);
  303. else
  304. mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
  305. return 0;
  306. }
  307. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  308. unsigned int changed_flags,
  309. unsigned int *total_flags,
  310. int mc_count,
  311. struct dev_addr_list *mc_list)
  312. {
  313. struct mac80211_hwsim_data *data = hw->priv;
  314. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  315. data->rx_filter = 0;
  316. if (*total_flags & FIF_PROMISC_IN_BSS)
  317. data->rx_filter |= FIF_PROMISC_IN_BSS;
  318. if (*total_flags & FIF_ALLMULTI)
  319. data->rx_filter |= FIF_ALLMULTI;
  320. *total_flags = data->rx_filter;
  321. }
  322. static int mac80211_hwsim_config_interface(struct ieee80211_hw *hw,
  323. struct ieee80211_vif *vif,
  324. struct ieee80211_if_conf *conf)
  325. {
  326. hwsim_check_magic(vif);
  327. return 0;
  328. }
  329. static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
  330. struct ieee80211_vif *vif,
  331. struct ieee80211_bss_conf *info,
  332. u32 changed)
  333. {
  334. hwsim_check_magic(vif);
  335. }
  336. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  337. struct ieee80211_vif *vif,
  338. enum sta_notify_cmd cmd,
  339. struct ieee80211_sta *sta)
  340. {
  341. hwsim_check_magic(vif);
  342. switch (cmd) {
  343. case STA_NOTIFY_ADD:
  344. hwsim_set_sta_magic(sta);
  345. break;
  346. case STA_NOTIFY_REMOVE:
  347. hwsim_clear_sta_magic(sta);
  348. break;
  349. }
  350. }
  351. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  352. struct ieee80211_sta *sta,
  353. bool set)
  354. {
  355. hwsim_check_sta_magic(sta);
  356. return 0;
  357. }
  358. static const struct ieee80211_ops mac80211_hwsim_ops =
  359. {
  360. .tx = mac80211_hwsim_tx,
  361. .start = mac80211_hwsim_start,
  362. .stop = mac80211_hwsim_stop,
  363. .add_interface = mac80211_hwsim_add_interface,
  364. .remove_interface = mac80211_hwsim_remove_interface,
  365. .config = mac80211_hwsim_config,
  366. .configure_filter = mac80211_hwsim_configure_filter,
  367. .config_interface = mac80211_hwsim_config_interface,
  368. .bss_info_changed = mac80211_hwsim_bss_info_changed,
  369. .sta_notify = mac80211_hwsim_sta_notify,
  370. .set_tim = mac80211_hwsim_set_tim,
  371. };
  372. static void mac80211_hwsim_free(void)
  373. {
  374. int i;
  375. for (i = 0; i < hwsim_radio_count; i++) {
  376. if (hwsim_radios[i]) {
  377. struct mac80211_hwsim_data *data;
  378. data = hwsim_radios[i]->priv;
  379. ieee80211_unregister_hw(hwsim_radios[i]);
  380. device_unregister(data->dev);
  381. ieee80211_free_hw(hwsim_radios[i]);
  382. }
  383. }
  384. kfree(hwsim_radios);
  385. class_destroy(hwsim_class);
  386. }
  387. static struct device_driver mac80211_hwsim_driver = {
  388. .name = "mac80211_hwsim"
  389. };
  390. static void hwsim_mon_setup(struct net_device *dev)
  391. {
  392. dev->hard_start_xmit = hwsim_mon_xmit;
  393. dev->destructor = free_netdev;
  394. ether_setup(dev);
  395. dev->tx_queue_len = 0;
  396. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  397. memset(dev->dev_addr, 0, ETH_ALEN);
  398. dev->dev_addr[0] = 0x12;
  399. }
  400. static int __init init_mac80211_hwsim(void)
  401. {
  402. int i, err = 0;
  403. u8 addr[ETH_ALEN];
  404. struct mac80211_hwsim_data *data;
  405. struct ieee80211_hw *hw;
  406. DECLARE_MAC_BUF(mac);
  407. if (radios < 1 || radios > 65535)
  408. return -EINVAL;
  409. hwsim_radio_count = radios;
  410. hwsim_radios = kcalloc(hwsim_radio_count,
  411. sizeof(struct ieee80211_hw *), GFP_KERNEL);
  412. if (hwsim_radios == NULL)
  413. return -ENOMEM;
  414. hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
  415. if (IS_ERR(hwsim_class)) {
  416. kfree(hwsim_radios);
  417. return PTR_ERR(hwsim_class);
  418. }
  419. memset(addr, 0, ETH_ALEN);
  420. addr[0] = 0x02;
  421. for (i = 0; i < hwsim_radio_count; i++) {
  422. printk(KERN_DEBUG "mac80211_hwsim: Initializing radio %d\n",
  423. i);
  424. hw = ieee80211_alloc_hw(sizeof(*data), &mac80211_hwsim_ops);
  425. if (hw == NULL) {
  426. printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw "
  427. "failed\n");
  428. err = -ENOMEM;
  429. goto failed;
  430. }
  431. hwsim_radios[i] = hw;
  432. data = hw->priv;
  433. data->dev = device_create_drvdata(hwsim_class, NULL, 0, hw,
  434. "hwsim%d", i);
  435. if (IS_ERR(data->dev)) {
  436. printk(KERN_DEBUG
  437. "mac80211_hwsim: device_create_drvdata "
  438. "failed (%ld)\n", PTR_ERR(data->dev));
  439. err = -ENOMEM;
  440. goto failed_drvdata;
  441. }
  442. data->dev->driver = &mac80211_hwsim_driver;
  443. SET_IEEE80211_DEV(hw, data->dev);
  444. addr[3] = i >> 8;
  445. addr[4] = i;
  446. SET_IEEE80211_PERM_ADDR(hw, addr);
  447. hw->channel_change_time = 1;
  448. hw->queues = 4;
  449. hw->wiphy->interface_modes =
  450. BIT(NL80211_IFTYPE_STATION) |
  451. BIT(NL80211_IFTYPE_AP);
  452. hw->ampdu_queues = 1;
  453. /* ask mac80211 to reserve space for magic */
  454. hw->vif_data_size = sizeof(struct hwsim_vif_priv);
  455. hw->sta_data_size = sizeof(struct hwsim_sta_priv);
  456. memcpy(data->channels, hwsim_channels, sizeof(hwsim_channels));
  457. memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
  458. data->band.channels = data->channels;
  459. data->band.n_channels = ARRAY_SIZE(hwsim_channels);
  460. data->band.bitrates = data->rates;
  461. data->band.n_bitrates = ARRAY_SIZE(hwsim_rates);
  462. data->band.ht_info.ht_supported = 1;
  463. data->band.ht_info.cap = IEEE80211_HT_CAP_SUP_WIDTH |
  464. IEEE80211_HT_CAP_GRN_FLD |
  465. IEEE80211_HT_CAP_SGI_40 |
  466. IEEE80211_HT_CAP_DSSSCCK40;
  467. data->band.ht_info.ampdu_factor = 0x3;
  468. data->band.ht_info.ampdu_density = 0x6;
  469. memset(data->band.ht_info.supp_mcs_set, 0,
  470. sizeof(data->band.ht_info.supp_mcs_set));
  471. data->band.ht_info.supp_mcs_set[0] = 0xff;
  472. data->band.ht_info.supp_mcs_set[1] = 0xff;
  473. data->band.ht_info.supp_mcs_set[12] =
  474. IEEE80211_HT_CAP_MCS_TX_DEFINED;
  475. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &data->band;
  476. err = ieee80211_register_hw(hw);
  477. if (err < 0) {
  478. printk(KERN_DEBUG "mac80211_hwsim: "
  479. "ieee80211_register_hw failed (%d)\n", err);
  480. goto failed_hw;
  481. }
  482. printk(KERN_DEBUG "%s: hwaddr %s registered\n",
  483. wiphy_name(hw->wiphy),
  484. print_mac(mac, hw->wiphy->perm_addr));
  485. setup_timer(&data->beacon_timer, mac80211_hwsim_beacon,
  486. (unsigned long) hw);
  487. }
  488. hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup);
  489. if (hwsim_mon == NULL)
  490. goto failed;
  491. rtnl_lock();
  492. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  493. if (err < 0)
  494. goto failed_mon;
  495. err = register_netdevice(hwsim_mon);
  496. if (err < 0)
  497. goto failed_mon;
  498. rtnl_unlock();
  499. return 0;
  500. failed_mon:
  501. rtnl_unlock();
  502. free_netdev(hwsim_mon);
  503. mac80211_hwsim_free();
  504. return err;
  505. failed_hw:
  506. device_unregister(data->dev);
  507. failed_drvdata:
  508. ieee80211_free_hw(hw);
  509. hwsim_radios[i] = NULL;
  510. failed:
  511. mac80211_hwsim_free();
  512. return err;
  513. }
  514. static void __exit exit_mac80211_hwsim(void)
  515. {
  516. printk(KERN_DEBUG "mac80211_hwsim: unregister %d radios\n",
  517. hwsim_radio_count);
  518. unregister_netdev(hwsim_mon);
  519. mac80211_hwsim_free();
  520. }
  521. module_init(init_mac80211_hwsim);
  522. module_exit(exit_mac80211_hwsim);