mac80211_hwsim.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  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. * - RX filtering based on filter configuration (data->rx_filter)
  13. */
  14. #include <linux/list.h>
  15. #include <linux/spinlock.h>
  16. #include <net/mac80211.h>
  17. #include <net/ieee80211_radiotap.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/debugfs.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. /**
  29. * enum hwsim_regtest - the type of regulatory tests we offer
  30. *
  31. * These are the different values you can use for the regtest
  32. * module parameter. This is useful to help test world roaming
  33. * and the driver regulatory_hint() call and combinations of these.
  34. * If you want to do specific alpha2 regulatory domain tests simply
  35. * use the userspace regulatory request as that will be respected as
  36. * well without the need of this module parameter. This is designed
  37. * only for testing the driver regulatory request, world roaming
  38. * and all possible combinations.
  39. *
  40. * @HWSIM_REGTEST_DISABLED: No regulatory tests are performed,
  41. * this is the default value.
  42. * @HWSIM_REGTEST_DRIVER_REG_FOLLOW: Used for testing the driver regulatory
  43. * hint, only one driver regulatory hint will be sent as such the
  44. * secondary radios are expected to follow.
  45. * @HWSIM_REGTEST_DRIVER_REG_ALL: Used for testing the driver regulatory
  46. * request with all radios reporting the same regulatory domain.
  47. * @HWSIM_REGTEST_DIFF_COUNTRY: Used for testing the drivers calling
  48. * different regulatory domains requests. Expected behaviour is for
  49. * an intersection to occur but each device will still use their
  50. * respective regulatory requested domains. Subsequent radios will
  51. * use the resulting intersection.
  52. * @HWSIM_REGTEST_WORLD_ROAM: Used for testing the world roaming. We acomplish
  53. * this by using a custom beacon-capable regulatory domain for the first
  54. * radio. All other device world roam.
  55. * @HWSIM_REGTEST_CUSTOM_WORLD: Used for testing the custom world regulatory
  56. * domain requests. All radios will adhere to this custom world regulatory
  57. * domain.
  58. * @HWSIM_REGTEST_CUSTOM_WORLD_2: Used for testing 2 custom world regulatory
  59. * domain requests. The first radio will adhere to the first custom world
  60. * regulatory domain, the second one to the second custom world regulatory
  61. * domain. All other devices will world roam.
  62. * @HWSIM_REGTEST_STRICT_FOLLOW_: Used for testing strict regulatory domain
  63. * settings, only the first radio will send a regulatory domain request
  64. * and use strict settings. The rest of the radios are expected to follow.
  65. * @HWSIM_REGTEST_STRICT_ALL: Used for testing strict regulatory domain
  66. * settings. All radios will adhere to this.
  67. * @HWSIM_REGTEST_STRICT_AND_DRIVER_REG: Used for testing strict regulatory
  68. * domain settings, combined with secondary driver regulatory domain
  69. * settings. The first radio will get a strict regulatory domain setting
  70. * using the first driver regulatory request and the second radio will use
  71. * non-strict settings using the second driver regulatory request. All
  72. * other devices should follow the intersection created between the
  73. * first two.
  74. * @HWSIM_REGTEST_ALL: Used for testing every possible mix. You will need
  75. * at least 6 radios for a complete test. We will test in this order:
  76. * 1 - driver custom world regulatory domain
  77. * 2 - second custom world regulatory domain
  78. * 3 - first driver regulatory domain request
  79. * 4 - second driver regulatory domain request
  80. * 5 - strict regulatory domain settings using the third driver regulatory
  81. * domain request
  82. * 6 and on - should follow the intersection of the 3rd, 4rth and 5th radio
  83. * regulatory requests.
  84. */
  85. enum hwsim_regtest {
  86. HWSIM_REGTEST_DISABLED = 0,
  87. HWSIM_REGTEST_DRIVER_REG_FOLLOW = 1,
  88. HWSIM_REGTEST_DRIVER_REG_ALL = 2,
  89. HWSIM_REGTEST_DIFF_COUNTRY = 3,
  90. HWSIM_REGTEST_WORLD_ROAM = 4,
  91. HWSIM_REGTEST_CUSTOM_WORLD = 5,
  92. HWSIM_REGTEST_CUSTOM_WORLD_2 = 6,
  93. HWSIM_REGTEST_STRICT_FOLLOW = 7,
  94. HWSIM_REGTEST_STRICT_ALL = 8,
  95. HWSIM_REGTEST_STRICT_AND_DRIVER_REG = 9,
  96. HWSIM_REGTEST_ALL = 10,
  97. };
  98. /* Set to one of the HWSIM_REGTEST_* values above */
  99. static int regtest = HWSIM_REGTEST_DISABLED;
  100. module_param(regtest, int, 0444);
  101. MODULE_PARM_DESC(regtest, "The type of regulatory test we want to run");
  102. static const char *hwsim_alpha2s[] = {
  103. "FI",
  104. "AL",
  105. "US",
  106. "DE",
  107. "JP",
  108. "AL",
  109. };
  110. static const struct ieee80211_regdomain hwsim_world_regdom_custom_01 = {
  111. .n_reg_rules = 4,
  112. .alpha2 = "99",
  113. .reg_rules = {
  114. REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
  115. REG_RULE(2484-10, 2484+10, 40, 0, 20, 0),
  116. REG_RULE(5150-10, 5240+10, 40, 0, 30, 0),
  117. REG_RULE(5745-10, 5825+10, 40, 0, 30, 0),
  118. }
  119. };
  120. static const struct ieee80211_regdomain hwsim_world_regdom_custom_02 = {
  121. .n_reg_rules = 2,
  122. .alpha2 = "99",
  123. .reg_rules = {
  124. REG_RULE(2412-10, 2462+10, 40, 0, 20, 0),
  125. REG_RULE(5725-10, 5850+10, 40, 0, 30,
  126. NL80211_RRF_PASSIVE_SCAN | NL80211_RRF_NO_IBSS),
  127. }
  128. };
  129. struct hwsim_vif_priv {
  130. u32 magic;
  131. u8 bssid[ETH_ALEN];
  132. bool assoc;
  133. u16 aid;
  134. };
  135. #define HWSIM_VIF_MAGIC 0x69537748
  136. static inline void hwsim_check_magic(struct ieee80211_vif *vif)
  137. {
  138. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  139. WARN_ON(vp->magic != HWSIM_VIF_MAGIC);
  140. }
  141. static inline void hwsim_set_magic(struct ieee80211_vif *vif)
  142. {
  143. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  144. vp->magic = HWSIM_VIF_MAGIC;
  145. }
  146. static inline void hwsim_clear_magic(struct ieee80211_vif *vif)
  147. {
  148. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  149. vp->magic = 0;
  150. }
  151. struct hwsim_sta_priv {
  152. u32 magic;
  153. };
  154. #define HWSIM_STA_MAGIC 0x6d537748
  155. static inline void hwsim_check_sta_magic(struct ieee80211_sta *sta)
  156. {
  157. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  158. WARN_ON(sp->magic != HWSIM_STA_MAGIC);
  159. }
  160. static inline void hwsim_set_sta_magic(struct ieee80211_sta *sta)
  161. {
  162. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  163. sp->magic = HWSIM_STA_MAGIC;
  164. }
  165. static inline void hwsim_clear_sta_magic(struct ieee80211_sta *sta)
  166. {
  167. struct hwsim_sta_priv *sp = (void *)sta->drv_priv;
  168. sp->magic = 0;
  169. }
  170. static struct class *hwsim_class;
  171. static struct net_device *hwsim_mon; /* global monitor netdev */
  172. #define CHAN2G(_freq) { \
  173. .band = IEEE80211_BAND_2GHZ, \
  174. .center_freq = (_freq), \
  175. .hw_value = (_freq), \
  176. .max_power = 20, \
  177. }
  178. #define CHAN5G(_freq) { \
  179. .band = IEEE80211_BAND_5GHZ, \
  180. .center_freq = (_freq), \
  181. .hw_value = (_freq), \
  182. .max_power = 20, \
  183. }
  184. static const struct ieee80211_channel hwsim_channels_2ghz[] = {
  185. CHAN2G(2412), /* Channel 1 */
  186. CHAN2G(2417), /* Channel 2 */
  187. CHAN2G(2422), /* Channel 3 */
  188. CHAN2G(2427), /* Channel 4 */
  189. CHAN2G(2432), /* Channel 5 */
  190. CHAN2G(2437), /* Channel 6 */
  191. CHAN2G(2442), /* Channel 7 */
  192. CHAN2G(2447), /* Channel 8 */
  193. CHAN2G(2452), /* Channel 9 */
  194. CHAN2G(2457), /* Channel 10 */
  195. CHAN2G(2462), /* Channel 11 */
  196. CHAN2G(2467), /* Channel 12 */
  197. CHAN2G(2472), /* Channel 13 */
  198. CHAN2G(2484), /* Channel 14 */
  199. };
  200. static const struct ieee80211_channel hwsim_channels_5ghz[] = {
  201. CHAN5G(5180), /* Channel 36 */
  202. CHAN5G(5200), /* Channel 40 */
  203. CHAN5G(5220), /* Channel 44 */
  204. CHAN5G(5240), /* Channel 48 */
  205. CHAN5G(5260), /* Channel 52 */
  206. CHAN5G(5280), /* Channel 56 */
  207. CHAN5G(5300), /* Channel 60 */
  208. CHAN5G(5320), /* Channel 64 */
  209. CHAN5G(5500), /* Channel 100 */
  210. CHAN5G(5520), /* Channel 104 */
  211. CHAN5G(5540), /* Channel 108 */
  212. CHAN5G(5560), /* Channel 112 */
  213. CHAN5G(5580), /* Channel 116 */
  214. CHAN5G(5600), /* Channel 120 */
  215. CHAN5G(5620), /* Channel 124 */
  216. CHAN5G(5640), /* Channel 128 */
  217. CHAN5G(5660), /* Channel 132 */
  218. CHAN5G(5680), /* Channel 136 */
  219. CHAN5G(5700), /* Channel 140 */
  220. CHAN5G(5745), /* Channel 149 */
  221. CHAN5G(5765), /* Channel 153 */
  222. CHAN5G(5785), /* Channel 157 */
  223. CHAN5G(5805), /* Channel 161 */
  224. CHAN5G(5825), /* Channel 165 */
  225. };
  226. static const struct ieee80211_rate hwsim_rates[] = {
  227. { .bitrate = 10 },
  228. { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  229. { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  230. { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  231. { .bitrate = 60 },
  232. { .bitrate = 90 },
  233. { .bitrate = 120 },
  234. { .bitrate = 180 },
  235. { .bitrate = 240 },
  236. { .bitrate = 360 },
  237. { .bitrate = 480 },
  238. { .bitrate = 540 }
  239. };
  240. static spinlock_t hwsim_radio_lock;
  241. static struct list_head hwsim_radios;
  242. struct mac80211_hwsim_data {
  243. struct list_head list;
  244. struct ieee80211_hw *hw;
  245. struct device *dev;
  246. struct ieee80211_supported_band bands[2];
  247. struct ieee80211_channel channels_2ghz[ARRAY_SIZE(hwsim_channels_2ghz)];
  248. struct ieee80211_channel channels_5ghz[ARRAY_SIZE(hwsim_channels_5ghz)];
  249. struct ieee80211_rate rates[ARRAY_SIZE(hwsim_rates)];
  250. struct ieee80211_channel *channel;
  251. unsigned long beacon_int; /* in jiffies unit */
  252. unsigned int rx_filter;
  253. int started;
  254. struct timer_list beacon_timer;
  255. enum ps_mode {
  256. PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
  257. } ps;
  258. bool ps_poll_pending;
  259. struct dentry *debugfs;
  260. struct dentry *debugfs_ps;
  261. /*
  262. * Only radios in the same group can communicate together (the
  263. * channel has to match too). Each bit represents a group. A
  264. * radio can be in more then one group.
  265. */
  266. u64 group;
  267. struct dentry *debugfs_group;
  268. };
  269. struct hwsim_radiotap_hdr {
  270. struct ieee80211_radiotap_header hdr;
  271. u8 rt_flags;
  272. u8 rt_rate;
  273. __le16 rt_channel;
  274. __le16 rt_chbitmask;
  275. } __attribute__ ((packed));
  276. static int hwsim_mon_xmit(struct sk_buff *skb, struct net_device *dev)
  277. {
  278. /* TODO: allow packet injection */
  279. dev_kfree_skb(skb);
  280. return 0;
  281. }
  282. static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
  283. struct sk_buff *tx_skb)
  284. {
  285. struct mac80211_hwsim_data *data = hw->priv;
  286. struct sk_buff *skb;
  287. struct hwsim_radiotap_hdr *hdr;
  288. u16 flags;
  289. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
  290. struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
  291. if (!netif_running(hwsim_mon))
  292. return;
  293. skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
  294. if (skb == NULL)
  295. return;
  296. hdr = (struct hwsim_radiotap_hdr *) skb_push(skb, sizeof(*hdr));
  297. hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  298. hdr->hdr.it_pad = 0;
  299. hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
  300. hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  301. (1 << IEEE80211_RADIOTAP_RATE) |
  302. (1 << IEEE80211_RADIOTAP_CHANNEL));
  303. hdr->rt_flags = 0;
  304. hdr->rt_rate = txrate->bitrate / 5;
  305. hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
  306. flags = IEEE80211_CHAN_2GHZ;
  307. if (txrate->flags & IEEE80211_RATE_ERP_G)
  308. flags |= IEEE80211_CHAN_OFDM;
  309. else
  310. flags |= IEEE80211_CHAN_CCK;
  311. hdr->rt_chbitmask = cpu_to_le16(flags);
  312. skb->dev = hwsim_mon;
  313. skb_set_mac_header(skb, 0);
  314. skb->ip_summed = CHECKSUM_UNNECESSARY;
  315. skb->pkt_type = PACKET_OTHERHOST;
  316. skb->protocol = htons(ETH_P_802_2);
  317. memset(skb->cb, 0, sizeof(skb->cb));
  318. netif_rx(skb);
  319. }
  320. static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
  321. struct sk_buff *skb)
  322. {
  323. switch (data->ps) {
  324. case PS_DISABLED:
  325. return true;
  326. case PS_ENABLED:
  327. return false;
  328. case PS_AUTO_POLL:
  329. /* TODO: accept (some) Beacons by default and other frames only
  330. * if pending PS-Poll has been sent */
  331. return true;
  332. case PS_MANUAL_POLL:
  333. /* Allow unicast frames to own address if there is a pending
  334. * PS-Poll */
  335. if (data->ps_poll_pending &&
  336. memcmp(data->hw->wiphy->perm_addr, skb->data + 4,
  337. ETH_ALEN) == 0) {
  338. data->ps_poll_pending = false;
  339. return true;
  340. }
  341. return false;
  342. }
  343. return true;
  344. }
  345. static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
  346. struct sk_buff *skb)
  347. {
  348. struct mac80211_hwsim_data *data = hw->priv, *data2;
  349. bool ack = false;
  350. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  351. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  352. struct ieee80211_rx_status rx_status;
  353. memset(&rx_status, 0, sizeof(rx_status));
  354. /* TODO: set mactime */
  355. rx_status.freq = data->channel->center_freq;
  356. rx_status.band = data->channel->band;
  357. rx_status.rate_idx = info->control.rates[0].idx;
  358. /* TODO: simulate signal strength (and optional packet drop) */
  359. if (data->ps != PS_DISABLED)
  360. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  361. /* Copy skb to all enabled radios that are on the current frequency */
  362. spin_lock(&hwsim_radio_lock);
  363. list_for_each_entry(data2, &hwsim_radios, list) {
  364. struct sk_buff *nskb;
  365. if (data == data2)
  366. continue;
  367. if (!data2->started || !hwsim_ps_rx_ok(data2, skb) ||
  368. !data->channel || !data2->channel ||
  369. data->channel->center_freq != data2->channel->center_freq ||
  370. !(data->group & data2->group))
  371. continue;
  372. nskb = skb_copy(skb, GFP_ATOMIC);
  373. if (nskb == NULL)
  374. continue;
  375. if (memcmp(hdr->addr1, data2->hw->wiphy->perm_addr,
  376. ETH_ALEN) == 0)
  377. ack = true;
  378. ieee80211_rx_irqsafe(data2->hw, nskb, &rx_status);
  379. }
  380. spin_unlock(&hwsim_radio_lock);
  381. return ack;
  382. }
  383. static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  384. {
  385. bool ack;
  386. struct ieee80211_tx_info *txi;
  387. mac80211_hwsim_monitor_rx(hw, skb);
  388. if (skb->len < 10) {
  389. /* Should not happen; just a sanity check for addr1 use */
  390. dev_kfree_skb(skb);
  391. return NETDEV_TX_OK;
  392. }
  393. ack = mac80211_hwsim_tx_frame(hw, skb);
  394. txi = IEEE80211_SKB_CB(skb);
  395. if (txi->control.vif)
  396. hwsim_check_magic(txi->control.vif);
  397. if (txi->control.sta)
  398. hwsim_check_sta_magic(txi->control.sta);
  399. ieee80211_tx_info_clear_status(txi);
  400. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack)
  401. txi->flags |= IEEE80211_TX_STAT_ACK;
  402. ieee80211_tx_status_irqsafe(hw, skb);
  403. return NETDEV_TX_OK;
  404. }
  405. static int mac80211_hwsim_start(struct ieee80211_hw *hw)
  406. {
  407. struct mac80211_hwsim_data *data = hw->priv;
  408. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  409. data->started = 1;
  410. return 0;
  411. }
  412. static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
  413. {
  414. struct mac80211_hwsim_data *data = hw->priv;
  415. data->started = 0;
  416. del_timer(&data->beacon_timer);
  417. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  418. }
  419. static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
  420. struct ieee80211_if_init_conf *conf)
  421. {
  422. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%pM)\n",
  423. wiphy_name(hw->wiphy), __func__, conf->type,
  424. conf->mac_addr);
  425. hwsim_set_magic(conf->vif);
  426. return 0;
  427. }
  428. static void mac80211_hwsim_remove_interface(
  429. struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf)
  430. {
  431. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%pM)\n",
  432. wiphy_name(hw->wiphy), __func__, conf->type,
  433. conf->mac_addr);
  434. hwsim_check_magic(conf->vif);
  435. hwsim_clear_magic(conf->vif);
  436. }
  437. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  438. struct ieee80211_vif *vif)
  439. {
  440. struct ieee80211_hw *hw = arg;
  441. struct sk_buff *skb;
  442. struct ieee80211_tx_info *info;
  443. hwsim_check_magic(vif);
  444. if (vif->type != NL80211_IFTYPE_AP &&
  445. vif->type != NL80211_IFTYPE_MESH_POINT)
  446. return;
  447. skb = ieee80211_beacon_get(hw, vif);
  448. if (skb == NULL)
  449. return;
  450. info = IEEE80211_SKB_CB(skb);
  451. mac80211_hwsim_monitor_rx(hw, skb);
  452. mac80211_hwsim_tx_frame(hw, skb);
  453. dev_kfree_skb(skb);
  454. }
  455. static void mac80211_hwsim_beacon(unsigned long arg)
  456. {
  457. struct ieee80211_hw *hw = (struct ieee80211_hw *) arg;
  458. struct mac80211_hwsim_data *data = hw->priv;
  459. if (!data->started)
  460. return;
  461. ieee80211_iterate_active_interfaces_atomic(
  462. hw, mac80211_hwsim_beacon_tx, hw);
  463. data->beacon_timer.expires = jiffies + data->beacon_int;
  464. add_timer(&data->beacon_timer);
  465. }
  466. static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
  467. {
  468. struct mac80211_hwsim_data *data = hw->priv;
  469. struct ieee80211_conf *conf = &hw->conf;
  470. printk(KERN_DEBUG "%s:%s (freq=%d idle=%d ps=%d)\n",
  471. wiphy_name(hw->wiphy), __func__,
  472. conf->channel->center_freq,
  473. !!(conf->flags & IEEE80211_CONF_IDLE),
  474. !!(conf->flags & IEEE80211_CONF_PS));
  475. data->channel = conf->channel;
  476. if (!data->started || !data->beacon_int)
  477. del_timer(&data->beacon_timer);
  478. else
  479. mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
  480. return 0;
  481. }
  482. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  483. unsigned int changed_flags,
  484. unsigned int *total_flags,
  485. int mc_count,
  486. struct dev_addr_list *mc_list)
  487. {
  488. struct mac80211_hwsim_data *data = hw->priv;
  489. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  490. data->rx_filter = 0;
  491. if (*total_flags & FIF_PROMISC_IN_BSS)
  492. data->rx_filter |= FIF_PROMISC_IN_BSS;
  493. if (*total_flags & FIF_ALLMULTI)
  494. data->rx_filter |= FIF_ALLMULTI;
  495. *total_flags = data->rx_filter;
  496. }
  497. static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
  498. struct ieee80211_vif *vif,
  499. struct ieee80211_bss_conf *info,
  500. u32 changed)
  501. {
  502. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  503. struct mac80211_hwsim_data *data = hw->priv;
  504. hwsim_check_magic(vif);
  505. printk(KERN_DEBUG "%s:%s(changed=0x%x)\n",
  506. wiphy_name(hw->wiphy), __func__, changed);
  507. if (changed & BSS_CHANGED_BSSID) {
  508. printk(KERN_DEBUG "%s:%s: BSSID changed: %pM\n",
  509. wiphy_name(hw->wiphy), __func__,
  510. info->bssid);
  511. memcpy(vp->bssid, info->bssid, ETH_ALEN);
  512. }
  513. if (changed & BSS_CHANGED_ASSOC) {
  514. printk(KERN_DEBUG " %s: ASSOC: assoc=%d aid=%d\n",
  515. wiphy_name(hw->wiphy), info->assoc, info->aid);
  516. vp->assoc = info->assoc;
  517. vp->aid = info->aid;
  518. }
  519. if (changed & BSS_CHANGED_BEACON_INT) {
  520. printk(KERN_DEBUG " %s: BCNINT: %d\n",
  521. wiphy_name(hw->wiphy), info->beacon_int);
  522. data->beacon_int = 1024 * info->beacon_int / 1000 * HZ / 1000;
  523. if (WARN_ON(!data->beacon_int))
  524. data->beacon_int = 1;
  525. }
  526. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  527. printk(KERN_DEBUG " %s: ERP_CTS_PROT: %d\n",
  528. wiphy_name(hw->wiphy), info->use_cts_prot);
  529. }
  530. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  531. printk(KERN_DEBUG " %s: ERP_PREAMBLE: %d\n",
  532. wiphy_name(hw->wiphy), info->use_short_preamble);
  533. }
  534. if (changed & BSS_CHANGED_ERP_SLOT) {
  535. printk(KERN_DEBUG " %s: ERP_SLOT: %d\n",
  536. wiphy_name(hw->wiphy), info->use_short_slot);
  537. }
  538. if (changed & BSS_CHANGED_HT) {
  539. printk(KERN_DEBUG " %s: HT: op_mode=0x%x\n",
  540. wiphy_name(hw->wiphy),
  541. info->ht_operation_mode);
  542. }
  543. if (changed & BSS_CHANGED_BASIC_RATES) {
  544. printk(KERN_DEBUG " %s: BASIC_RATES: 0x%llx\n",
  545. wiphy_name(hw->wiphy),
  546. (unsigned long long) info->basic_rates);
  547. }
  548. }
  549. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  550. struct ieee80211_vif *vif,
  551. enum sta_notify_cmd cmd,
  552. struct ieee80211_sta *sta)
  553. {
  554. hwsim_check_magic(vif);
  555. switch (cmd) {
  556. case STA_NOTIFY_ADD:
  557. hwsim_set_sta_magic(sta);
  558. break;
  559. case STA_NOTIFY_REMOVE:
  560. hwsim_clear_sta_magic(sta);
  561. break;
  562. case STA_NOTIFY_SLEEP:
  563. case STA_NOTIFY_AWAKE:
  564. /* TODO: make good use of these flags */
  565. break;
  566. }
  567. }
  568. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  569. struct ieee80211_sta *sta,
  570. bool set)
  571. {
  572. hwsim_check_sta_magic(sta);
  573. return 0;
  574. }
  575. static int mac80211_hwsim_conf_tx(
  576. struct ieee80211_hw *hw, u16 queue,
  577. const struct ieee80211_tx_queue_params *params)
  578. {
  579. printk(KERN_DEBUG "%s:%s (queue=%d txop=%d cw_min=%d cw_max=%d "
  580. "aifs=%d)\n",
  581. wiphy_name(hw->wiphy), __func__, queue,
  582. params->txop, params->cw_min, params->cw_max, params->aifs);
  583. return 0;
  584. }
  585. static const struct ieee80211_ops mac80211_hwsim_ops =
  586. {
  587. .tx = mac80211_hwsim_tx,
  588. .start = mac80211_hwsim_start,
  589. .stop = mac80211_hwsim_stop,
  590. .add_interface = mac80211_hwsim_add_interface,
  591. .remove_interface = mac80211_hwsim_remove_interface,
  592. .config = mac80211_hwsim_config,
  593. .configure_filter = mac80211_hwsim_configure_filter,
  594. .bss_info_changed = mac80211_hwsim_bss_info_changed,
  595. .sta_notify = mac80211_hwsim_sta_notify,
  596. .set_tim = mac80211_hwsim_set_tim,
  597. .conf_tx = mac80211_hwsim_conf_tx,
  598. };
  599. static void mac80211_hwsim_free(void)
  600. {
  601. struct list_head tmplist, *i, *tmp;
  602. struct mac80211_hwsim_data *data;
  603. INIT_LIST_HEAD(&tmplist);
  604. spin_lock_bh(&hwsim_radio_lock);
  605. list_for_each_safe(i, tmp, &hwsim_radios)
  606. list_move(i, &tmplist);
  607. spin_unlock_bh(&hwsim_radio_lock);
  608. list_for_each_entry(data, &tmplist, list) {
  609. debugfs_remove(data->debugfs_group);
  610. debugfs_remove(data->debugfs_ps);
  611. debugfs_remove(data->debugfs);
  612. ieee80211_unregister_hw(data->hw);
  613. device_unregister(data->dev);
  614. ieee80211_free_hw(data->hw);
  615. }
  616. class_destroy(hwsim_class);
  617. }
  618. static struct device_driver mac80211_hwsim_driver = {
  619. .name = "mac80211_hwsim"
  620. };
  621. static const struct net_device_ops hwsim_netdev_ops = {
  622. .ndo_start_xmit = hwsim_mon_xmit,
  623. .ndo_change_mtu = eth_change_mtu,
  624. .ndo_set_mac_address = eth_mac_addr,
  625. .ndo_validate_addr = eth_validate_addr,
  626. };
  627. static void hwsim_mon_setup(struct net_device *dev)
  628. {
  629. dev->netdev_ops = &hwsim_netdev_ops;
  630. dev->destructor = free_netdev;
  631. ether_setup(dev);
  632. dev->tx_queue_len = 0;
  633. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  634. memset(dev->dev_addr, 0, ETH_ALEN);
  635. dev->dev_addr[0] = 0x12;
  636. }
  637. static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif)
  638. {
  639. struct mac80211_hwsim_data *data = dat;
  640. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  641. DECLARE_MAC_BUF(buf);
  642. struct sk_buff *skb;
  643. struct ieee80211_pspoll *pspoll;
  644. if (!vp->assoc)
  645. return;
  646. printk(KERN_DEBUG "%s:%s: send PS-Poll to %pM for aid %d\n",
  647. wiphy_name(data->hw->wiphy), __func__, vp->bssid, vp->aid);
  648. skb = dev_alloc_skb(sizeof(*pspoll));
  649. if (!skb)
  650. return;
  651. pspoll = (void *) skb_put(skb, sizeof(*pspoll));
  652. pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  653. IEEE80211_STYPE_PSPOLL |
  654. IEEE80211_FCTL_PM);
  655. pspoll->aid = cpu_to_le16(0xc000 | vp->aid);
  656. memcpy(pspoll->bssid, vp->bssid, ETH_ALEN);
  657. memcpy(pspoll->ta, mac, ETH_ALEN);
  658. if (!mac80211_hwsim_tx_frame(data->hw, skb))
  659. printk(KERN_DEBUG "%s: PS-Poll frame not ack'ed\n", __func__);
  660. dev_kfree_skb(skb);
  661. }
  662. static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac,
  663. struct ieee80211_vif *vif, int ps)
  664. {
  665. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  666. DECLARE_MAC_BUF(buf);
  667. struct sk_buff *skb;
  668. struct ieee80211_hdr *hdr;
  669. if (!vp->assoc)
  670. return;
  671. printk(KERN_DEBUG "%s:%s: send data::nullfunc to %pM ps=%d\n",
  672. wiphy_name(data->hw->wiphy), __func__, vp->bssid, ps);
  673. skb = dev_alloc_skb(sizeof(*hdr));
  674. if (!skb)
  675. return;
  676. hdr = (void *) skb_put(skb, sizeof(*hdr) - ETH_ALEN);
  677. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  678. IEEE80211_STYPE_NULLFUNC |
  679. (ps ? IEEE80211_FCTL_PM : 0));
  680. hdr->duration_id = cpu_to_le16(0);
  681. memcpy(hdr->addr1, vp->bssid, ETH_ALEN);
  682. memcpy(hdr->addr2, mac, ETH_ALEN);
  683. memcpy(hdr->addr3, vp->bssid, ETH_ALEN);
  684. if (!mac80211_hwsim_tx_frame(data->hw, skb))
  685. printk(KERN_DEBUG "%s: nullfunc frame not ack'ed\n", __func__);
  686. dev_kfree_skb(skb);
  687. }
  688. static void hwsim_send_nullfunc_ps(void *dat, u8 *mac,
  689. struct ieee80211_vif *vif)
  690. {
  691. struct mac80211_hwsim_data *data = dat;
  692. hwsim_send_nullfunc(data, mac, vif, 1);
  693. }
  694. static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac,
  695. struct ieee80211_vif *vif)
  696. {
  697. struct mac80211_hwsim_data *data = dat;
  698. hwsim_send_nullfunc(data, mac, vif, 0);
  699. }
  700. static int hwsim_fops_ps_read(void *dat, u64 *val)
  701. {
  702. struct mac80211_hwsim_data *data = dat;
  703. *val = data->ps;
  704. return 0;
  705. }
  706. static int hwsim_fops_ps_write(void *dat, u64 val)
  707. {
  708. struct mac80211_hwsim_data *data = dat;
  709. enum ps_mode old_ps;
  710. if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL &&
  711. val != PS_MANUAL_POLL)
  712. return -EINVAL;
  713. old_ps = data->ps;
  714. data->ps = val;
  715. if (val == PS_MANUAL_POLL) {
  716. ieee80211_iterate_active_interfaces(data->hw,
  717. hwsim_send_ps_poll, data);
  718. data->ps_poll_pending = true;
  719. } else if (old_ps == PS_DISABLED && val != PS_DISABLED) {
  720. ieee80211_iterate_active_interfaces(data->hw,
  721. hwsim_send_nullfunc_ps,
  722. data);
  723. } else if (old_ps != PS_DISABLED && val == PS_DISABLED) {
  724. ieee80211_iterate_active_interfaces(data->hw,
  725. hwsim_send_nullfunc_no_ps,
  726. data);
  727. }
  728. return 0;
  729. }
  730. DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,
  731. "%llu\n");
  732. static int hwsim_fops_group_read(void *dat, u64 *val)
  733. {
  734. struct mac80211_hwsim_data *data = dat;
  735. *val = data->group;
  736. return 0;
  737. }
  738. static int hwsim_fops_group_write(void *dat, u64 val)
  739. {
  740. struct mac80211_hwsim_data *data = dat;
  741. data->group = val;
  742. return 0;
  743. }
  744. DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group,
  745. hwsim_fops_group_read, hwsim_fops_group_write,
  746. "%llx\n");
  747. static int __init init_mac80211_hwsim(void)
  748. {
  749. int i, err = 0;
  750. u8 addr[ETH_ALEN];
  751. struct mac80211_hwsim_data *data;
  752. struct ieee80211_hw *hw;
  753. enum ieee80211_band band;
  754. if (radios < 1 || radios > 100)
  755. return -EINVAL;
  756. spin_lock_init(&hwsim_radio_lock);
  757. INIT_LIST_HEAD(&hwsim_radios);
  758. hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
  759. if (IS_ERR(hwsim_class))
  760. return PTR_ERR(hwsim_class);
  761. memset(addr, 0, ETH_ALEN);
  762. addr[0] = 0x02;
  763. for (i = 0; i < radios; i++) {
  764. printk(KERN_DEBUG "mac80211_hwsim: Initializing radio %d\n",
  765. i);
  766. hw = ieee80211_alloc_hw(sizeof(*data), &mac80211_hwsim_ops);
  767. if (!hw) {
  768. printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw "
  769. "failed\n");
  770. err = -ENOMEM;
  771. goto failed;
  772. }
  773. data = hw->priv;
  774. data->hw = hw;
  775. data->dev = device_create(hwsim_class, NULL, 0, hw,
  776. "hwsim%d", i);
  777. if (IS_ERR(data->dev)) {
  778. printk(KERN_DEBUG
  779. "mac80211_hwsim: device_create "
  780. "failed (%ld)\n", PTR_ERR(data->dev));
  781. err = -ENOMEM;
  782. goto failed_drvdata;
  783. }
  784. data->dev->driver = &mac80211_hwsim_driver;
  785. SET_IEEE80211_DEV(hw, data->dev);
  786. addr[3] = i >> 8;
  787. addr[4] = i;
  788. SET_IEEE80211_PERM_ADDR(hw, addr);
  789. hw->channel_change_time = 1;
  790. hw->queues = 4;
  791. hw->wiphy->interface_modes =
  792. BIT(NL80211_IFTYPE_STATION) |
  793. BIT(NL80211_IFTYPE_AP) |
  794. BIT(NL80211_IFTYPE_MESH_POINT);
  795. hw->flags = IEEE80211_HW_MFP_CAPABLE;
  796. /* ask mac80211 to reserve space for magic */
  797. hw->vif_data_size = sizeof(struct hwsim_vif_priv);
  798. hw->sta_data_size = sizeof(struct hwsim_sta_priv);
  799. memcpy(data->channels_2ghz, hwsim_channels_2ghz,
  800. sizeof(hwsim_channels_2ghz));
  801. memcpy(data->channels_5ghz, hwsim_channels_5ghz,
  802. sizeof(hwsim_channels_5ghz));
  803. memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
  804. for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
  805. struct ieee80211_supported_band *sband = &data->bands[band];
  806. switch (band) {
  807. case IEEE80211_BAND_2GHZ:
  808. sband->channels = data->channels_2ghz;
  809. sband->n_channels =
  810. ARRAY_SIZE(hwsim_channels_2ghz);
  811. break;
  812. case IEEE80211_BAND_5GHZ:
  813. sband->channels = data->channels_5ghz;
  814. sband->n_channels =
  815. ARRAY_SIZE(hwsim_channels_5ghz);
  816. break;
  817. default:
  818. break;
  819. }
  820. sband->bitrates = data->rates;
  821. sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
  822. sband->ht_cap.ht_supported = true;
  823. sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  824. IEEE80211_HT_CAP_GRN_FLD |
  825. IEEE80211_HT_CAP_SGI_40 |
  826. IEEE80211_HT_CAP_DSSSCCK40;
  827. sband->ht_cap.ampdu_factor = 0x3;
  828. sband->ht_cap.ampdu_density = 0x6;
  829. memset(&sband->ht_cap.mcs, 0,
  830. sizeof(sband->ht_cap.mcs));
  831. sband->ht_cap.mcs.rx_mask[0] = 0xff;
  832. sband->ht_cap.mcs.rx_mask[1] = 0xff;
  833. sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  834. hw->wiphy->bands[band] = sband;
  835. }
  836. /* By default all radios are belonging to the first group */
  837. data->group = 1;
  838. /* Work to be done prior to ieee80211_register_hw() */
  839. switch (regtest) {
  840. case HWSIM_REGTEST_DISABLED:
  841. case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
  842. case HWSIM_REGTEST_DRIVER_REG_ALL:
  843. case HWSIM_REGTEST_DIFF_COUNTRY:
  844. /*
  845. * Nothing to be done for driver regulatory domain
  846. * hints prior to ieee80211_register_hw()
  847. */
  848. break;
  849. case HWSIM_REGTEST_WORLD_ROAM:
  850. if (i == 0) {
  851. hw->wiphy->custom_regulatory = true;
  852. wiphy_apply_custom_regulatory(hw->wiphy,
  853. &hwsim_world_regdom_custom_01);
  854. }
  855. break;
  856. case HWSIM_REGTEST_CUSTOM_WORLD:
  857. hw->wiphy->custom_regulatory = true;
  858. wiphy_apply_custom_regulatory(hw->wiphy,
  859. &hwsim_world_regdom_custom_01);
  860. break;
  861. case HWSIM_REGTEST_CUSTOM_WORLD_2:
  862. if (i == 0) {
  863. hw->wiphy->custom_regulatory = true;
  864. wiphy_apply_custom_regulatory(hw->wiphy,
  865. &hwsim_world_regdom_custom_01);
  866. } else if (i == 1) {
  867. hw->wiphy->custom_regulatory = true;
  868. wiphy_apply_custom_regulatory(hw->wiphy,
  869. &hwsim_world_regdom_custom_02);
  870. }
  871. break;
  872. case HWSIM_REGTEST_STRICT_ALL:
  873. hw->wiphy->strict_regulatory = true;
  874. break;
  875. case HWSIM_REGTEST_STRICT_FOLLOW:
  876. case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
  877. if (i == 0)
  878. hw->wiphy->strict_regulatory = true;
  879. break;
  880. case HWSIM_REGTEST_ALL:
  881. if (i == 0) {
  882. hw->wiphy->custom_regulatory = true;
  883. wiphy_apply_custom_regulatory(hw->wiphy,
  884. &hwsim_world_regdom_custom_01);
  885. } else if (i == 1) {
  886. hw->wiphy->custom_regulatory = true;
  887. wiphy_apply_custom_regulatory(hw->wiphy,
  888. &hwsim_world_regdom_custom_02);
  889. } else if (i == 4)
  890. hw->wiphy->strict_regulatory = true;
  891. break;
  892. default:
  893. break;
  894. }
  895. /* give the regulatory workqueue a chance to run */
  896. if (regtest)
  897. schedule_timeout_interruptible(1);
  898. err = ieee80211_register_hw(hw);
  899. if (err < 0) {
  900. printk(KERN_DEBUG "mac80211_hwsim: "
  901. "ieee80211_register_hw failed (%d)\n", err);
  902. goto failed_hw;
  903. }
  904. /* Work to be done after to ieee80211_register_hw() */
  905. switch (regtest) {
  906. case HWSIM_REGTEST_WORLD_ROAM:
  907. case HWSIM_REGTEST_DISABLED:
  908. break;
  909. case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
  910. if (!i)
  911. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  912. break;
  913. case HWSIM_REGTEST_DRIVER_REG_ALL:
  914. case HWSIM_REGTEST_STRICT_ALL:
  915. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  916. break;
  917. case HWSIM_REGTEST_DIFF_COUNTRY:
  918. if (i < ARRAY_SIZE(hwsim_alpha2s))
  919. regulatory_hint(hw->wiphy, hwsim_alpha2s[i]);
  920. break;
  921. case HWSIM_REGTEST_CUSTOM_WORLD:
  922. case HWSIM_REGTEST_CUSTOM_WORLD_2:
  923. /*
  924. * Nothing to be done for custom world regulatory
  925. * domains after to ieee80211_register_hw
  926. */
  927. break;
  928. case HWSIM_REGTEST_STRICT_FOLLOW:
  929. if (i == 0)
  930. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  931. break;
  932. case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
  933. if (i == 0)
  934. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  935. else if (i == 1)
  936. regulatory_hint(hw->wiphy, hwsim_alpha2s[1]);
  937. break;
  938. case HWSIM_REGTEST_ALL:
  939. if (i == 2)
  940. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  941. else if (i == 3)
  942. regulatory_hint(hw->wiphy, hwsim_alpha2s[1]);
  943. else if (i == 4)
  944. regulatory_hint(hw->wiphy, hwsim_alpha2s[2]);
  945. break;
  946. default:
  947. break;
  948. }
  949. printk(KERN_DEBUG "%s: hwaddr %pM registered\n",
  950. wiphy_name(hw->wiphy),
  951. hw->wiphy->perm_addr);
  952. data->debugfs = debugfs_create_dir("hwsim",
  953. hw->wiphy->debugfsdir);
  954. data->debugfs_ps = debugfs_create_file("ps", 0666,
  955. data->debugfs, data,
  956. &hwsim_fops_ps);
  957. data->debugfs_group = debugfs_create_file("group", 0666,
  958. data->debugfs, data,
  959. &hwsim_fops_group);
  960. setup_timer(&data->beacon_timer, mac80211_hwsim_beacon,
  961. (unsigned long) hw);
  962. list_add_tail(&data->list, &hwsim_radios);
  963. }
  964. hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup);
  965. if (hwsim_mon == NULL)
  966. goto failed;
  967. rtnl_lock();
  968. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  969. if (err < 0)
  970. goto failed_mon;
  971. err = register_netdevice(hwsim_mon);
  972. if (err < 0)
  973. goto failed_mon;
  974. rtnl_unlock();
  975. return 0;
  976. failed_mon:
  977. rtnl_unlock();
  978. free_netdev(hwsim_mon);
  979. mac80211_hwsim_free();
  980. return err;
  981. failed_hw:
  982. device_unregister(data->dev);
  983. failed_drvdata:
  984. ieee80211_free_hw(hw);
  985. failed:
  986. mac80211_hwsim_free();
  987. return err;
  988. }
  989. static void __exit exit_mac80211_hwsim(void)
  990. {
  991. printk(KERN_DEBUG "mac80211_hwsim: unregister radios\n");
  992. unregister_netdev(hwsim_mon);
  993. mac80211_hwsim_free();
  994. }
  995. module_init(init_mac80211_hwsim);
  996. module_exit(exit_mac80211_hwsim);