mac80211_hwsim.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. if (txi->control.vif)
  215. hwsim_check_magic(txi->control.vif);
  216. if (txi->control.sta)
  217. hwsim_check_sta_magic(txi->control.sta);
  218. memset(&txi->status, 0, sizeof(txi->status));
  219. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK)) {
  220. if (ack)
  221. txi->flags |= IEEE80211_TX_STAT_ACK;
  222. else
  223. txi->status.excessive_retries = 1;
  224. }
  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. DECLARE_MAC_BUF(mac);
  245. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n",
  246. wiphy_name(hw->wiphy), __func__, conf->type,
  247. print_mac(mac, conf->mac_addr));
  248. hwsim_set_magic(conf->vif);
  249. return 0;
  250. }
  251. static void mac80211_hwsim_remove_interface(
  252. struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf)
  253. {
  254. DECLARE_MAC_BUF(mac);
  255. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%s)\n",
  256. wiphy_name(hw->wiphy), __func__, conf->type,
  257. print_mac(mac, conf->mac_addr));
  258. hwsim_check_magic(conf->vif);
  259. hwsim_clear_magic(conf->vif);
  260. }
  261. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  262. struct ieee80211_vif *vif)
  263. {
  264. struct ieee80211_hw *hw = arg;
  265. struct sk_buff *skb;
  266. struct ieee80211_tx_info *info;
  267. hwsim_check_magic(vif);
  268. if (vif->type != NL80211_IFTYPE_AP)
  269. return;
  270. skb = ieee80211_beacon_get(hw, vif);
  271. if (skb == NULL)
  272. return;
  273. info = IEEE80211_SKB_CB(skb);
  274. mac80211_hwsim_monitor_rx(hw, skb);
  275. mac80211_hwsim_tx_frame(hw, skb);
  276. dev_kfree_skb(skb);
  277. }
  278. static void mac80211_hwsim_beacon(unsigned long arg)
  279. {
  280. struct ieee80211_hw *hw = (struct ieee80211_hw *) arg;
  281. struct mac80211_hwsim_data *data = hw->priv;
  282. if (!data->started || !data->radio_enabled)
  283. return;
  284. ieee80211_iterate_active_interfaces_atomic(
  285. hw, mac80211_hwsim_beacon_tx, hw);
  286. data->beacon_timer.expires = jiffies + data->beacon_int;
  287. add_timer(&data->beacon_timer);
  288. }
  289. static int mac80211_hwsim_config(struct ieee80211_hw *hw,
  290. struct ieee80211_conf *conf)
  291. {
  292. struct mac80211_hwsim_data *data = hw->priv;
  293. printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d beacon_int=%d)\n",
  294. wiphy_name(hw->wiphy), __func__,
  295. conf->channel->center_freq, conf->radio_enabled,
  296. conf->beacon_int);
  297. data->channel = conf->channel;
  298. data->radio_enabled = conf->radio_enabled;
  299. data->beacon_int = 1024 * conf->beacon_int / 1000 * HZ / 1000;
  300. if (data->beacon_int < 1)
  301. data->beacon_int = 1;
  302. if (!data->started || !data->radio_enabled)
  303. del_timer(&data->beacon_timer);
  304. else
  305. mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
  306. return 0;
  307. }
  308. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  309. unsigned int changed_flags,
  310. unsigned int *total_flags,
  311. int mc_count,
  312. struct dev_addr_list *mc_list)
  313. {
  314. struct mac80211_hwsim_data *data = hw->priv;
  315. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  316. data->rx_filter = 0;
  317. if (*total_flags & FIF_PROMISC_IN_BSS)
  318. data->rx_filter |= FIF_PROMISC_IN_BSS;
  319. if (*total_flags & FIF_ALLMULTI)
  320. data->rx_filter |= FIF_ALLMULTI;
  321. *total_flags = data->rx_filter;
  322. }
  323. static int mac80211_hwsim_config_interface(struct ieee80211_hw *hw,
  324. struct ieee80211_vif *vif,
  325. struct ieee80211_if_conf *conf)
  326. {
  327. hwsim_check_magic(vif);
  328. return 0;
  329. }
  330. static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
  331. struct ieee80211_vif *vif,
  332. struct ieee80211_bss_conf *info,
  333. u32 changed)
  334. {
  335. hwsim_check_magic(vif);
  336. }
  337. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  338. struct ieee80211_vif *vif,
  339. enum sta_notify_cmd cmd,
  340. struct ieee80211_sta *sta)
  341. {
  342. hwsim_check_magic(vif);
  343. switch (cmd) {
  344. case STA_NOTIFY_ADD:
  345. hwsim_set_sta_magic(sta);
  346. break;
  347. case STA_NOTIFY_REMOVE:
  348. hwsim_clear_sta_magic(sta);
  349. break;
  350. }
  351. }
  352. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  353. struct ieee80211_sta *sta,
  354. bool set)
  355. {
  356. hwsim_check_sta_magic(sta);
  357. return 0;
  358. }
  359. static const struct ieee80211_ops mac80211_hwsim_ops =
  360. {
  361. .tx = mac80211_hwsim_tx,
  362. .start = mac80211_hwsim_start,
  363. .stop = mac80211_hwsim_stop,
  364. .add_interface = mac80211_hwsim_add_interface,
  365. .remove_interface = mac80211_hwsim_remove_interface,
  366. .config = mac80211_hwsim_config,
  367. .configure_filter = mac80211_hwsim_configure_filter,
  368. .config_interface = mac80211_hwsim_config_interface,
  369. .bss_info_changed = mac80211_hwsim_bss_info_changed,
  370. .sta_notify = mac80211_hwsim_sta_notify,
  371. .set_tim = mac80211_hwsim_set_tim,
  372. };
  373. static void mac80211_hwsim_free(void)
  374. {
  375. int i;
  376. for (i = 0; i < hwsim_radio_count; i++) {
  377. if (hwsim_radios[i]) {
  378. struct mac80211_hwsim_data *data;
  379. data = hwsim_radios[i]->priv;
  380. ieee80211_unregister_hw(hwsim_radios[i]);
  381. device_unregister(data->dev);
  382. ieee80211_free_hw(hwsim_radios[i]);
  383. }
  384. }
  385. kfree(hwsim_radios);
  386. class_destroy(hwsim_class);
  387. }
  388. static struct device_driver mac80211_hwsim_driver = {
  389. .name = "mac80211_hwsim"
  390. };
  391. static void hwsim_mon_setup(struct net_device *dev)
  392. {
  393. dev->hard_start_xmit = hwsim_mon_xmit;
  394. dev->destructor = free_netdev;
  395. ether_setup(dev);
  396. dev->tx_queue_len = 0;
  397. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  398. memset(dev->dev_addr, 0, ETH_ALEN);
  399. dev->dev_addr[0] = 0x12;
  400. }
  401. static int __init init_mac80211_hwsim(void)
  402. {
  403. int i, err = 0;
  404. u8 addr[ETH_ALEN];
  405. struct mac80211_hwsim_data *data;
  406. struct ieee80211_hw *hw;
  407. DECLARE_MAC_BUF(mac);
  408. if (radios < 1 || radios > 65535)
  409. return -EINVAL;
  410. hwsim_radio_count = radios;
  411. hwsim_radios = kcalloc(hwsim_radio_count,
  412. sizeof(struct ieee80211_hw *), GFP_KERNEL);
  413. if (hwsim_radios == NULL)
  414. return -ENOMEM;
  415. hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
  416. if (IS_ERR(hwsim_class)) {
  417. kfree(hwsim_radios);
  418. return PTR_ERR(hwsim_class);
  419. }
  420. memset(addr, 0, ETH_ALEN);
  421. addr[0] = 0x02;
  422. for (i = 0; i < hwsim_radio_count; 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 == NULL) {
  427. printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw "
  428. "failed\n");
  429. err = -ENOMEM;
  430. goto failed;
  431. }
  432. hwsim_radios[i] = hw;
  433. data = hw->priv;
  434. data->dev = device_create_drvdata(hwsim_class, NULL, 0, hw,
  435. "hwsim%d", i);
  436. if (IS_ERR(data->dev)) {
  437. printk(KERN_DEBUG
  438. "mac80211_hwsim: device_create_drvdata "
  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. }
  489. hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup);
  490. if (hwsim_mon == NULL)
  491. goto failed;
  492. rtnl_lock();
  493. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  494. if (err < 0)
  495. goto failed_mon;
  496. err = register_netdevice(hwsim_mon);
  497. if (err < 0)
  498. goto failed_mon;
  499. rtnl_unlock();
  500. return 0;
  501. failed_mon:
  502. rtnl_unlock();
  503. free_netdev(hwsim_mon);
  504. mac80211_hwsim_free();
  505. return err;
  506. failed_hw:
  507. device_unregister(data->dev);
  508. failed_drvdata:
  509. ieee80211_free_hw(hw);
  510. hwsim_radios[i] = NULL;
  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 %d radios\n",
  518. hwsim_radio_count);
  519. unregister_netdev(hwsim_mon);
  520. mac80211_hwsim_free();
  521. }
  522. module_init(init_mac80211_hwsim);
  523. module_exit(exit_mac80211_hwsim);