mac80211_hwsim.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  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. int radio_enabled;
  252. unsigned long beacon_int; /* in jiffies unit */
  253. unsigned int rx_filter;
  254. int started;
  255. struct timer_list beacon_timer;
  256. enum ps_mode {
  257. PS_DISABLED, PS_ENABLED, PS_AUTO_POLL, PS_MANUAL_POLL
  258. } ps;
  259. bool ps_poll_pending;
  260. struct dentry *debugfs;
  261. struct dentry *debugfs_ps;
  262. /*
  263. * Only radios in the same group can communicate together (the
  264. * channel has to match too). Each bit represents a group. A
  265. * radio can be in more then one group.
  266. */
  267. u64 group;
  268. struct dentry *debugfs_group;
  269. };
  270. struct hwsim_radiotap_hdr {
  271. struct ieee80211_radiotap_header hdr;
  272. u8 rt_flags;
  273. u8 rt_rate;
  274. __le16 rt_channel;
  275. __le16 rt_chbitmask;
  276. } __attribute__ ((packed));
  277. static int hwsim_mon_xmit(struct sk_buff *skb, struct net_device *dev)
  278. {
  279. /* TODO: allow packet injection */
  280. dev_kfree_skb(skb);
  281. return 0;
  282. }
  283. static void mac80211_hwsim_monitor_rx(struct ieee80211_hw *hw,
  284. struct sk_buff *tx_skb)
  285. {
  286. struct mac80211_hwsim_data *data = hw->priv;
  287. struct sk_buff *skb;
  288. struct hwsim_radiotap_hdr *hdr;
  289. u16 flags;
  290. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx_skb);
  291. struct ieee80211_rate *txrate = ieee80211_get_tx_rate(hw, info);
  292. if (!netif_running(hwsim_mon))
  293. return;
  294. skb = skb_copy_expand(tx_skb, sizeof(*hdr), 0, GFP_ATOMIC);
  295. if (skb == NULL)
  296. return;
  297. hdr = (struct hwsim_radiotap_hdr *) skb_push(skb, sizeof(*hdr));
  298. hdr->hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  299. hdr->hdr.it_pad = 0;
  300. hdr->hdr.it_len = cpu_to_le16(sizeof(*hdr));
  301. hdr->hdr.it_present = cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
  302. (1 << IEEE80211_RADIOTAP_RATE) |
  303. (1 << IEEE80211_RADIOTAP_CHANNEL));
  304. hdr->rt_flags = 0;
  305. hdr->rt_rate = txrate->bitrate / 5;
  306. hdr->rt_channel = cpu_to_le16(data->channel->center_freq);
  307. flags = IEEE80211_CHAN_2GHZ;
  308. if (txrate->flags & IEEE80211_RATE_ERP_G)
  309. flags |= IEEE80211_CHAN_OFDM;
  310. else
  311. flags |= IEEE80211_CHAN_CCK;
  312. hdr->rt_chbitmask = cpu_to_le16(flags);
  313. skb->dev = hwsim_mon;
  314. skb_set_mac_header(skb, 0);
  315. skb->ip_summed = CHECKSUM_UNNECESSARY;
  316. skb->pkt_type = PACKET_OTHERHOST;
  317. skb->protocol = htons(ETH_P_802_2);
  318. memset(skb->cb, 0, sizeof(skb->cb));
  319. netif_rx(skb);
  320. }
  321. static bool hwsim_ps_rx_ok(struct mac80211_hwsim_data *data,
  322. struct sk_buff *skb)
  323. {
  324. switch (data->ps) {
  325. case PS_DISABLED:
  326. return true;
  327. case PS_ENABLED:
  328. return false;
  329. case PS_AUTO_POLL:
  330. /* TODO: accept (some) Beacons by default and other frames only
  331. * if pending PS-Poll has been sent */
  332. return true;
  333. case PS_MANUAL_POLL:
  334. /* Allow unicast frames to own address if there is a pending
  335. * PS-Poll */
  336. if (data->ps_poll_pending &&
  337. memcmp(data->hw->wiphy->perm_addr, skb->data + 4,
  338. ETH_ALEN) == 0) {
  339. data->ps_poll_pending = false;
  340. return true;
  341. }
  342. return false;
  343. }
  344. return true;
  345. }
  346. static bool mac80211_hwsim_tx_frame(struct ieee80211_hw *hw,
  347. struct sk_buff *skb)
  348. {
  349. struct mac80211_hwsim_data *data = hw->priv, *data2;
  350. bool ack = false;
  351. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  352. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  353. struct ieee80211_rx_status rx_status;
  354. memset(&rx_status, 0, sizeof(rx_status));
  355. /* TODO: set mactime */
  356. rx_status.freq = data->channel->center_freq;
  357. rx_status.band = data->channel->band;
  358. rx_status.rate_idx = info->control.rates[0].idx;
  359. /* TODO: simulate signal strength (and optional packet drop) */
  360. if (data->ps != PS_DISABLED)
  361. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  362. /* Copy skb to all enabled radios that are on the current frequency */
  363. spin_lock(&hwsim_radio_lock);
  364. list_for_each_entry(data2, &hwsim_radios, list) {
  365. struct sk_buff *nskb;
  366. if (data == data2)
  367. continue;
  368. if (!data2->started || !data2->radio_enabled ||
  369. !hwsim_ps_rx_ok(data2, skb) ||
  370. data->channel->center_freq != data2->channel->center_freq ||
  371. !(data->group & data2->group))
  372. continue;
  373. nskb = skb_copy(skb, GFP_ATOMIC);
  374. if (nskb == NULL)
  375. continue;
  376. if (memcmp(hdr->addr1, data2->hw->wiphy->perm_addr,
  377. ETH_ALEN) == 0)
  378. ack = true;
  379. ieee80211_rx_irqsafe(data2->hw, nskb, &rx_status);
  380. }
  381. spin_unlock(&hwsim_radio_lock);
  382. return ack;
  383. }
  384. static int mac80211_hwsim_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  385. {
  386. struct mac80211_hwsim_data *data = hw->priv;
  387. bool ack;
  388. struct ieee80211_tx_info *txi;
  389. mac80211_hwsim_monitor_rx(hw, skb);
  390. if (skb->len < 10) {
  391. /* Should not happen; just a sanity check for addr1 use */
  392. dev_kfree_skb(skb);
  393. return NETDEV_TX_OK;
  394. }
  395. if (!data->radio_enabled) {
  396. printk(KERN_DEBUG "%s: dropped TX frame since radio "
  397. "disabled\n", wiphy_name(hw->wiphy));
  398. dev_kfree_skb(skb);
  399. return NETDEV_TX_OK;
  400. }
  401. ack = mac80211_hwsim_tx_frame(hw, skb);
  402. txi = IEEE80211_SKB_CB(skb);
  403. if (txi->control.vif)
  404. hwsim_check_magic(txi->control.vif);
  405. if (txi->control.sta)
  406. hwsim_check_sta_magic(txi->control.sta);
  407. ieee80211_tx_info_clear_status(txi);
  408. if (!(txi->flags & IEEE80211_TX_CTL_NO_ACK) && ack)
  409. txi->flags |= IEEE80211_TX_STAT_ACK;
  410. ieee80211_tx_status_irqsafe(hw, skb);
  411. return NETDEV_TX_OK;
  412. }
  413. static int mac80211_hwsim_start(struct ieee80211_hw *hw)
  414. {
  415. struct mac80211_hwsim_data *data = hw->priv;
  416. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  417. data->started = 1;
  418. return 0;
  419. }
  420. static void mac80211_hwsim_stop(struct ieee80211_hw *hw)
  421. {
  422. struct mac80211_hwsim_data *data = hw->priv;
  423. data->started = 0;
  424. del_timer(&data->beacon_timer);
  425. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  426. }
  427. static int mac80211_hwsim_add_interface(struct ieee80211_hw *hw,
  428. struct ieee80211_if_init_conf *conf)
  429. {
  430. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%pM)\n",
  431. wiphy_name(hw->wiphy), __func__, conf->type,
  432. conf->mac_addr);
  433. hwsim_set_magic(conf->vif);
  434. return 0;
  435. }
  436. static void mac80211_hwsim_remove_interface(
  437. struct ieee80211_hw *hw, struct ieee80211_if_init_conf *conf)
  438. {
  439. printk(KERN_DEBUG "%s:%s (type=%d mac_addr=%pM)\n",
  440. wiphy_name(hw->wiphy), __func__, conf->type,
  441. conf->mac_addr);
  442. hwsim_check_magic(conf->vif);
  443. hwsim_clear_magic(conf->vif);
  444. }
  445. static void mac80211_hwsim_beacon_tx(void *arg, u8 *mac,
  446. struct ieee80211_vif *vif)
  447. {
  448. struct ieee80211_hw *hw = arg;
  449. struct sk_buff *skb;
  450. struct ieee80211_tx_info *info;
  451. hwsim_check_magic(vif);
  452. if (vif->type != NL80211_IFTYPE_AP &&
  453. vif->type != NL80211_IFTYPE_MESH_POINT)
  454. return;
  455. skb = ieee80211_beacon_get(hw, vif);
  456. if (skb == NULL)
  457. return;
  458. info = IEEE80211_SKB_CB(skb);
  459. mac80211_hwsim_monitor_rx(hw, skb);
  460. mac80211_hwsim_tx_frame(hw, skb);
  461. dev_kfree_skb(skb);
  462. }
  463. static void mac80211_hwsim_beacon(unsigned long arg)
  464. {
  465. struct ieee80211_hw *hw = (struct ieee80211_hw *) arg;
  466. struct mac80211_hwsim_data *data = hw->priv;
  467. if (!data->started || !data->radio_enabled)
  468. return;
  469. ieee80211_iterate_active_interfaces_atomic(
  470. hw, mac80211_hwsim_beacon_tx, hw);
  471. data->beacon_timer.expires = jiffies + data->beacon_int;
  472. add_timer(&data->beacon_timer);
  473. }
  474. static int mac80211_hwsim_config(struct ieee80211_hw *hw, u32 changed)
  475. {
  476. struct mac80211_hwsim_data *data = hw->priv;
  477. struct ieee80211_conf *conf = &hw->conf;
  478. printk(KERN_DEBUG "%s:%s (freq=%d radio_enabled=%d idle=%d ps=%d)\n",
  479. wiphy_name(hw->wiphy), __func__,
  480. conf->channel->center_freq, conf->radio_enabled,
  481. !!(conf->flags & IEEE80211_CONF_IDLE),
  482. !!(conf->flags & IEEE80211_CONF_PS));
  483. data->channel = conf->channel;
  484. data->radio_enabled = conf->radio_enabled;
  485. if (!data->started || !data->radio_enabled || !data->beacon_int)
  486. del_timer(&data->beacon_timer);
  487. else
  488. mod_timer(&data->beacon_timer, jiffies + data->beacon_int);
  489. return 0;
  490. }
  491. static void mac80211_hwsim_configure_filter(struct ieee80211_hw *hw,
  492. unsigned int changed_flags,
  493. unsigned int *total_flags,
  494. int mc_count,
  495. struct dev_addr_list *mc_list)
  496. {
  497. struct mac80211_hwsim_data *data = hw->priv;
  498. printk(KERN_DEBUG "%s:%s\n", wiphy_name(hw->wiphy), __func__);
  499. data->rx_filter = 0;
  500. if (*total_flags & FIF_PROMISC_IN_BSS)
  501. data->rx_filter |= FIF_PROMISC_IN_BSS;
  502. if (*total_flags & FIF_ALLMULTI)
  503. data->rx_filter |= FIF_ALLMULTI;
  504. *total_flags = data->rx_filter;
  505. }
  506. static void mac80211_hwsim_bss_info_changed(struct ieee80211_hw *hw,
  507. struct ieee80211_vif *vif,
  508. struct ieee80211_bss_conf *info,
  509. u32 changed)
  510. {
  511. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  512. struct mac80211_hwsim_data *data = hw->priv;
  513. hwsim_check_magic(vif);
  514. printk(KERN_DEBUG "%s:%s(changed=0x%x)\n",
  515. wiphy_name(hw->wiphy), __func__, changed);
  516. if (changed & BSS_CHANGED_BSSID) {
  517. printk(KERN_DEBUG "%s:%s: BSSID changed: %pM\n",
  518. wiphy_name(hw->wiphy), __func__,
  519. info->bssid);
  520. memcpy(vp->bssid, info->bssid, ETH_ALEN);
  521. }
  522. if (changed & BSS_CHANGED_ASSOC) {
  523. printk(KERN_DEBUG " %s: ASSOC: assoc=%d aid=%d\n",
  524. wiphy_name(hw->wiphy), info->assoc, info->aid);
  525. vp->assoc = info->assoc;
  526. vp->aid = info->aid;
  527. }
  528. if (changed & BSS_CHANGED_BEACON_INT) {
  529. printk(KERN_DEBUG " %s: BCNINT: %d\n",
  530. wiphy_name(hw->wiphy), info->beacon_int);
  531. data->beacon_int = 1024 * info->beacon_int / 1000 * HZ / 1000;
  532. if (WARN_ON(!data->beacon_int))
  533. data->beacon_int = 1;
  534. }
  535. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  536. printk(KERN_DEBUG " %s: ERP_CTS_PROT: %d\n",
  537. wiphy_name(hw->wiphy), info->use_cts_prot);
  538. }
  539. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  540. printk(KERN_DEBUG " %s: ERP_PREAMBLE: %d\n",
  541. wiphy_name(hw->wiphy), info->use_short_preamble);
  542. }
  543. if (changed & BSS_CHANGED_ERP_SLOT) {
  544. printk(KERN_DEBUG " %s: ERP_SLOT: %d\n",
  545. wiphy_name(hw->wiphy), info->use_short_slot);
  546. }
  547. if (changed & BSS_CHANGED_HT) {
  548. printk(KERN_DEBUG " %s: HT: op_mode=0x%x\n",
  549. wiphy_name(hw->wiphy),
  550. info->ht_operation_mode);
  551. }
  552. if (changed & BSS_CHANGED_BASIC_RATES) {
  553. printk(KERN_DEBUG " %s: BASIC_RATES: 0x%llx\n",
  554. wiphy_name(hw->wiphy),
  555. (unsigned long long) info->basic_rates);
  556. }
  557. }
  558. static void mac80211_hwsim_sta_notify(struct ieee80211_hw *hw,
  559. struct ieee80211_vif *vif,
  560. enum sta_notify_cmd cmd,
  561. struct ieee80211_sta *sta)
  562. {
  563. hwsim_check_magic(vif);
  564. switch (cmd) {
  565. case STA_NOTIFY_ADD:
  566. hwsim_set_sta_magic(sta);
  567. break;
  568. case STA_NOTIFY_REMOVE:
  569. hwsim_clear_sta_magic(sta);
  570. break;
  571. case STA_NOTIFY_SLEEP:
  572. case STA_NOTIFY_AWAKE:
  573. /* TODO: make good use of these flags */
  574. break;
  575. }
  576. }
  577. static int mac80211_hwsim_set_tim(struct ieee80211_hw *hw,
  578. struct ieee80211_sta *sta,
  579. bool set)
  580. {
  581. hwsim_check_sta_magic(sta);
  582. return 0;
  583. }
  584. static int mac80211_hwsim_conf_tx(
  585. struct ieee80211_hw *hw, u16 queue,
  586. const struct ieee80211_tx_queue_params *params)
  587. {
  588. printk(KERN_DEBUG "%s:%s (queue=%d txop=%d cw_min=%d cw_max=%d "
  589. "aifs=%d)\n",
  590. wiphy_name(hw->wiphy), __func__, queue,
  591. params->txop, params->cw_min, params->cw_max, params->aifs);
  592. return 0;
  593. }
  594. static const struct ieee80211_ops mac80211_hwsim_ops =
  595. {
  596. .tx = mac80211_hwsim_tx,
  597. .start = mac80211_hwsim_start,
  598. .stop = mac80211_hwsim_stop,
  599. .add_interface = mac80211_hwsim_add_interface,
  600. .remove_interface = mac80211_hwsim_remove_interface,
  601. .config = mac80211_hwsim_config,
  602. .configure_filter = mac80211_hwsim_configure_filter,
  603. .bss_info_changed = mac80211_hwsim_bss_info_changed,
  604. .sta_notify = mac80211_hwsim_sta_notify,
  605. .set_tim = mac80211_hwsim_set_tim,
  606. .conf_tx = mac80211_hwsim_conf_tx,
  607. };
  608. static void mac80211_hwsim_free(void)
  609. {
  610. struct list_head tmplist, *i, *tmp;
  611. struct mac80211_hwsim_data *data;
  612. INIT_LIST_HEAD(&tmplist);
  613. spin_lock_bh(&hwsim_radio_lock);
  614. list_for_each_safe(i, tmp, &hwsim_radios)
  615. list_move(i, &tmplist);
  616. spin_unlock_bh(&hwsim_radio_lock);
  617. list_for_each_entry(data, &tmplist, list) {
  618. debugfs_remove(data->debugfs_group);
  619. debugfs_remove(data->debugfs_ps);
  620. debugfs_remove(data->debugfs);
  621. ieee80211_unregister_hw(data->hw);
  622. device_unregister(data->dev);
  623. ieee80211_free_hw(data->hw);
  624. }
  625. class_destroy(hwsim_class);
  626. }
  627. static struct device_driver mac80211_hwsim_driver = {
  628. .name = "mac80211_hwsim"
  629. };
  630. static const struct net_device_ops hwsim_netdev_ops = {
  631. .ndo_start_xmit = hwsim_mon_xmit,
  632. .ndo_change_mtu = eth_change_mtu,
  633. .ndo_set_mac_address = eth_mac_addr,
  634. .ndo_validate_addr = eth_validate_addr,
  635. };
  636. static void hwsim_mon_setup(struct net_device *dev)
  637. {
  638. dev->netdev_ops = &hwsim_netdev_ops;
  639. dev->destructor = free_netdev;
  640. ether_setup(dev);
  641. dev->tx_queue_len = 0;
  642. dev->type = ARPHRD_IEEE80211_RADIOTAP;
  643. memset(dev->dev_addr, 0, ETH_ALEN);
  644. dev->dev_addr[0] = 0x12;
  645. }
  646. static void hwsim_send_ps_poll(void *dat, u8 *mac, struct ieee80211_vif *vif)
  647. {
  648. struct mac80211_hwsim_data *data = dat;
  649. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  650. DECLARE_MAC_BUF(buf);
  651. struct sk_buff *skb;
  652. struct ieee80211_pspoll *pspoll;
  653. if (!vp->assoc)
  654. return;
  655. printk(KERN_DEBUG "%s:%s: send PS-Poll to %pM for aid %d\n",
  656. wiphy_name(data->hw->wiphy), __func__, vp->bssid, vp->aid);
  657. skb = dev_alloc_skb(sizeof(*pspoll));
  658. if (!skb)
  659. return;
  660. pspoll = (void *) skb_put(skb, sizeof(*pspoll));
  661. pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  662. IEEE80211_STYPE_PSPOLL |
  663. IEEE80211_FCTL_PM);
  664. pspoll->aid = cpu_to_le16(0xc000 | vp->aid);
  665. memcpy(pspoll->bssid, vp->bssid, ETH_ALEN);
  666. memcpy(pspoll->ta, mac, ETH_ALEN);
  667. if (data->radio_enabled &&
  668. !mac80211_hwsim_tx_frame(data->hw, skb))
  669. printk(KERN_DEBUG "%s: PS-Poll frame not ack'ed\n", __func__);
  670. dev_kfree_skb(skb);
  671. }
  672. static void hwsim_send_nullfunc(struct mac80211_hwsim_data *data, u8 *mac,
  673. struct ieee80211_vif *vif, int ps)
  674. {
  675. struct hwsim_vif_priv *vp = (void *)vif->drv_priv;
  676. DECLARE_MAC_BUF(buf);
  677. struct sk_buff *skb;
  678. struct ieee80211_hdr *hdr;
  679. if (!vp->assoc)
  680. return;
  681. printk(KERN_DEBUG "%s:%s: send data::nullfunc to %pM ps=%d\n",
  682. wiphy_name(data->hw->wiphy), __func__, vp->bssid, ps);
  683. skb = dev_alloc_skb(sizeof(*hdr));
  684. if (!skb)
  685. return;
  686. hdr = (void *) skb_put(skb, sizeof(*hdr) - ETH_ALEN);
  687. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  688. IEEE80211_STYPE_NULLFUNC |
  689. (ps ? IEEE80211_FCTL_PM : 0));
  690. hdr->duration_id = cpu_to_le16(0);
  691. memcpy(hdr->addr1, vp->bssid, ETH_ALEN);
  692. memcpy(hdr->addr2, mac, ETH_ALEN);
  693. memcpy(hdr->addr3, vp->bssid, ETH_ALEN);
  694. if (data->radio_enabled &&
  695. !mac80211_hwsim_tx_frame(data->hw, skb))
  696. printk(KERN_DEBUG "%s: nullfunc frame not ack'ed\n", __func__);
  697. dev_kfree_skb(skb);
  698. }
  699. static void hwsim_send_nullfunc_ps(void *dat, u8 *mac,
  700. struct ieee80211_vif *vif)
  701. {
  702. struct mac80211_hwsim_data *data = dat;
  703. hwsim_send_nullfunc(data, mac, vif, 1);
  704. }
  705. static void hwsim_send_nullfunc_no_ps(void *dat, u8 *mac,
  706. struct ieee80211_vif *vif)
  707. {
  708. struct mac80211_hwsim_data *data = dat;
  709. hwsim_send_nullfunc(data, mac, vif, 0);
  710. }
  711. static int hwsim_fops_ps_read(void *dat, u64 *val)
  712. {
  713. struct mac80211_hwsim_data *data = dat;
  714. *val = data->ps;
  715. return 0;
  716. }
  717. static int hwsim_fops_ps_write(void *dat, u64 val)
  718. {
  719. struct mac80211_hwsim_data *data = dat;
  720. enum ps_mode old_ps;
  721. if (val != PS_DISABLED && val != PS_ENABLED && val != PS_AUTO_POLL &&
  722. val != PS_MANUAL_POLL)
  723. return -EINVAL;
  724. old_ps = data->ps;
  725. data->ps = val;
  726. if (val == PS_MANUAL_POLL) {
  727. ieee80211_iterate_active_interfaces(data->hw,
  728. hwsim_send_ps_poll, data);
  729. data->ps_poll_pending = true;
  730. } else if (old_ps == PS_DISABLED && val != PS_DISABLED) {
  731. ieee80211_iterate_active_interfaces(data->hw,
  732. hwsim_send_nullfunc_ps,
  733. data);
  734. } else if (old_ps != PS_DISABLED && val == PS_DISABLED) {
  735. ieee80211_iterate_active_interfaces(data->hw,
  736. hwsim_send_nullfunc_no_ps,
  737. data);
  738. }
  739. return 0;
  740. }
  741. DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_ps, hwsim_fops_ps_read, hwsim_fops_ps_write,
  742. "%llu\n");
  743. static int hwsim_fops_group_read(void *dat, u64 *val)
  744. {
  745. struct mac80211_hwsim_data *data = dat;
  746. *val = data->group;
  747. return 0;
  748. }
  749. static int hwsim_fops_group_write(void *dat, u64 val)
  750. {
  751. struct mac80211_hwsim_data *data = dat;
  752. data->group = val;
  753. return 0;
  754. }
  755. DEFINE_SIMPLE_ATTRIBUTE(hwsim_fops_group,
  756. hwsim_fops_group_read, hwsim_fops_group_write,
  757. "%llx\n");
  758. static int __init init_mac80211_hwsim(void)
  759. {
  760. int i, err = 0;
  761. u8 addr[ETH_ALEN];
  762. struct mac80211_hwsim_data *data;
  763. struct ieee80211_hw *hw;
  764. enum ieee80211_band band;
  765. if (radios < 1 || radios > 100)
  766. return -EINVAL;
  767. spin_lock_init(&hwsim_radio_lock);
  768. INIT_LIST_HEAD(&hwsim_radios);
  769. hwsim_class = class_create(THIS_MODULE, "mac80211_hwsim");
  770. if (IS_ERR(hwsim_class))
  771. return PTR_ERR(hwsim_class);
  772. memset(addr, 0, ETH_ALEN);
  773. addr[0] = 0x02;
  774. for (i = 0; i < radios; i++) {
  775. printk(KERN_DEBUG "mac80211_hwsim: Initializing radio %d\n",
  776. i);
  777. hw = ieee80211_alloc_hw(sizeof(*data), &mac80211_hwsim_ops);
  778. if (!hw) {
  779. printk(KERN_DEBUG "mac80211_hwsim: ieee80211_alloc_hw "
  780. "failed\n");
  781. err = -ENOMEM;
  782. goto failed;
  783. }
  784. data = hw->priv;
  785. data->hw = hw;
  786. data->dev = device_create(hwsim_class, NULL, 0, hw,
  787. "hwsim%d", i);
  788. if (IS_ERR(data->dev)) {
  789. printk(KERN_DEBUG
  790. "mac80211_hwsim: device_create "
  791. "failed (%ld)\n", PTR_ERR(data->dev));
  792. err = -ENOMEM;
  793. goto failed_drvdata;
  794. }
  795. data->dev->driver = &mac80211_hwsim_driver;
  796. SET_IEEE80211_DEV(hw, data->dev);
  797. addr[3] = i >> 8;
  798. addr[4] = i;
  799. SET_IEEE80211_PERM_ADDR(hw, addr);
  800. hw->channel_change_time = 1;
  801. hw->queues = 4;
  802. hw->wiphy->interface_modes =
  803. BIT(NL80211_IFTYPE_STATION) |
  804. BIT(NL80211_IFTYPE_AP) |
  805. BIT(NL80211_IFTYPE_MESH_POINT);
  806. hw->flags = IEEE80211_HW_MFP_CAPABLE;
  807. /* ask mac80211 to reserve space for magic */
  808. hw->vif_data_size = sizeof(struct hwsim_vif_priv);
  809. hw->sta_data_size = sizeof(struct hwsim_sta_priv);
  810. memcpy(data->channels_2ghz, hwsim_channels_2ghz,
  811. sizeof(hwsim_channels_2ghz));
  812. memcpy(data->channels_5ghz, hwsim_channels_5ghz,
  813. sizeof(hwsim_channels_5ghz));
  814. memcpy(data->rates, hwsim_rates, sizeof(hwsim_rates));
  815. for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
  816. struct ieee80211_supported_band *sband = &data->bands[band];
  817. switch (band) {
  818. case IEEE80211_BAND_2GHZ:
  819. sband->channels = data->channels_2ghz;
  820. sband->n_channels =
  821. ARRAY_SIZE(hwsim_channels_2ghz);
  822. break;
  823. case IEEE80211_BAND_5GHZ:
  824. sband->channels = data->channels_5ghz;
  825. sband->n_channels =
  826. ARRAY_SIZE(hwsim_channels_5ghz);
  827. break;
  828. default:
  829. break;
  830. }
  831. sband->bitrates = data->rates;
  832. sband->n_bitrates = ARRAY_SIZE(hwsim_rates);
  833. sband->ht_cap.ht_supported = true;
  834. sband->ht_cap.cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  835. IEEE80211_HT_CAP_GRN_FLD |
  836. IEEE80211_HT_CAP_SGI_40 |
  837. IEEE80211_HT_CAP_DSSSCCK40;
  838. sband->ht_cap.ampdu_factor = 0x3;
  839. sband->ht_cap.ampdu_density = 0x6;
  840. memset(&sband->ht_cap.mcs, 0,
  841. sizeof(sband->ht_cap.mcs));
  842. sband->ht_cap.mcs.rx_mask[0] = 0xff;
  843. sband->ht_cap.mcs.rx_mask[1] = 0xff;
  844. sband->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  845. hw->wiphy->bands[band] = sband;
  846. }
  847. /* By default all radios are belonging to the first group */
  848. data->group = 1;
  849. /* Work to be done prior to ieee80211_register_hw() */
  850. switch (regtest) {
  851. case HWSIM_REGTEST_DISABLED:
  852. case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
  853. case HWSIM_REGTEST_DRIVER_REG_ALL:
  854. case HWSIM_REGTEST_DIFF_COUNTRY:
  855. /*
  856. * Nothing to be done for driver regulatory domain
  857. * hints prior to ieee80211_register_hw()
  858. */
  859. break;
  860. case HWSIM_REGTEST_WORLD_ROAM:
  861. if (i == 0) {
  862. hw->wiphy->custom_regulatory = true;
  863. wiphy_apply_custom_regulatory(hw->wiphy,
  864. &hwsim_world_regdom_custom_01);
  865. }
  866. break;
  867. case HWSIM_REGTEST_CUSTOM_WORLD:
  868. hw->wiphy->custom_regulatory = true;
  869. wiphy_apply_custom_regulatory(hw->wiphy,
  870. &hwsim_world_regdom_custom_01);
  871. break;
  872. case HWSIM_REGTEST_CUSTOM_WORLD_2:
  873. if (i == 0) {
  874. hw->wiphy->custom_regulatory = true;
  875. wiphy_apply_custom_regulatory(hw->wiphy,
  876. &hwsim_world_regdom_custom_01);
  877. } else if (i == 1) {
  878. hw->wiphy->custom_regulatory = true;
  879. wiphy_apply_custom_regulatory(hw->wiphy,
  880. &hwsim_world_regdom_custom_02);
  881. }
  882. break;
  883. case HWSIM_REGTEST_STRICT_ALL:
  884. hw->wiphy->strict_regulatory = true;
  885. break;
  886. case HWSIM_REGTEST_STRICT_FOLLOW:
  887. case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
  888. if (i == 0)
  889. hw->wiphy->strict_regulatory = true;
  890. break;
  891. case HWSIM_REGTEST_ALL:
  892. if (i == 0) {
  893. hw->wiphy->custom_regulatory = true;
  894. wiphy_apply_custom_regulatory(hw->wiphy,
  895. &hwsim_world_regdom_custom_01);
  896. } else if (i == 1) {
  897. hw->wiphy->custom_regulatory = true;
  898. wiphy_apply_custom_regulatory(hw->wiphy,
  899. &hwsim_world_regdom_custom_02);
  900. } else if (i == 4)
  901. hw->wiphy->strict_regulatory = true;
  902. break;
  903. default:
  904. break;
  905. }
  906. /* give the regulatory workqueue a chance to run */
  907. if (regtest)
  908. schedule_timeout_interruptible(1);
  909. err = ieee80211_register_hw(hw);
  910. if (err < 0) {
  911. printk(KERN_DEBUG "mac80211_hwsim: "
  912. "ieee80211_register_hw failed (%d)\n", err);
  913. goto failed_hw;
  914. }
  915. /* Work to be done after to ieee80211_register_hw() */
  916. switch (regtest) {
  917. case HWSIM_REGTEST_WORLD_ROAM:
  918. case HWSIM_REGTEST_DISABLED:
  919. break;
  920. case HWSIM_REGTEST_DRIVER_REG_FOLLOW:
  921. if (!i)
  922. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  923. break;
  924. case HWSIM_REGTEST_DRIVER_REG_ALL:
  925. case HWSIM_REGTEST_STRICT_ALL:
  926. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  927. break;
  928. case HWSIM_REGTEST_DIFF_COUNTRY:
  929. if (i < ARRAY_SIZE(hwsim_alpha2s))
  930. regulatory_hint(hw->wiphy, hwsim_alpha2s[i]);
  931. break;
  932. case HWSIM_REGTEST_CUSTOM_WORLD:
  933. case HWSIM_REGTEST_CUSTOM_WORLD_2:
  934. /*
  935. * Nothing to be done for custom world regulatory
  936. * domains after to ieee80211_register_hw
  937. */
  938. break;
  939. case HWSIM_REGTEST_STRICT_FOLLOW:
  940. if (i == 0)
  941. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  942. break;
  943. case HWSIM_REGTEST_STRICT_AND_DRIVER_REG:
  944. if (i == 0)
  945. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  946. else if (i == 1)
  947. regulatory_hint(hw->wiphy, hwsim_alpha2s[1]);
  948. break;
  949. case HWSIM_REGTEST_ALL:
  950. if (i == 2)
  951. regulatory_hint(hw->wiphy, hwsim_alpha2s[0]);
  952. else if (i == 3)
  953. regulatory_hint(hw->wiphy, hwsim_alpha2s[1]);
  954. else if (i == 4)
  955. regulatory_hint(hw->wiphy, hwsim_alpha2s[2]);
  956. break;
  957. default:
  958. break;
  959. }
  960. printk(KERN_DEBUG "%s: hwaddr %pM registered\n",
  961. wiphy_name(hw->wiphy),
  962. hw->wiphy->perm_addr);
  963. data->debugfs = debugfs_create_dir("hwsim",
  964. hw->wiphy->debugfsdir);
  965. data->debugfs_ps = debugfs_create_file("ps", 0666,
  966. data->debugfs, data,
  967. &hwsim_fops_ps);
  968. data->debugfs_group = debugfs_create_file("group", 0666,
  969. data->debugfs, data,
  970. &hwsim_fops_group);
  971. setup_timer(&data->beacon_timer, mac80211_hwsim_beacon,
  972. (unsigned long) hw);
  973. list_add_tail(&data->list, &hwsim_radios);
  974. }
  975. hwsim_mon = alloc_netdev(0, "hwsim%d", hwsim_mon_setup);
  976. if (hwsim_mon == NULL)
  977. goto failed;
  978. rtnl_lock();
  979. err = dev_alloc_name(hwsim_mon, hwsim_mon->name);
  980. if (err < 0)
  981. goto failed_mon;
  982. err = register_netdevice(hwsim_mon);
  983. if (err < 0)
  984. goto failed_mon;
  985. rtnl_unlock();
  986. return 0;
  987. failed_mon:
  988. rtnl_unlock();
  989. free_netdev(hwsim_mon);
  990. mac80211_hwsim_free();
  991. return err;
  992. failed_hw:
  993. device_unregister(data->dev);
  994. failed_drvdata:
  995. ieee80211_free_hw(hw);
  996. failed:
  997. mac80211_hwsim_free();
  998. return err;
  999. }
  1000. static void __exit exit_mac80211_hwsim(void)
  1001. {
  1002. printk(KERN_DEBUG "mac80211_hwsim: unregister radios\n");
  1003. unregister_netdev(hwsim_mon);
  1004. mac80211_hwsim_free();
  1005. }
  1006. module_init(init_mac80211_hwsim);
  1007. module_exit(exit_mac80211_hwsim);