mac80211_hwsim.c 32 KB

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