debugfs_netdev.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
  3. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  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. #include <linux/kernel.h>
  10. #include <linux/device.h>
  11. #include <linux/if.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/rtnetlink.h>
  15. #include <linux/slab.h>
  16. #include <linux/notifier.h>
  17. #include <net/mac80211.h>
  18. #include <net/cfg80211.h>
  19. #include "ieee80211_i.h"
  20. #include "rate.h"
  21. #include "debugfs.h"
  22. #include "debugfs_netdev.h"
  23. static ssize_t ieee80211_if_read(
  24. struct ieee80211_sub_if_data *sdata,
  25. char __user *userbuf,
  26. size_t count, loff_t *ppos,
  27. ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
  28. {
  29. char buf[70];
  30. ssize_t ret = -EINVAL;
  31. read_lock(&dev_base_lock);
  32. if (sdata->dev->reg_state == NETREG_REGISTERED)
  33. ret = (*format)(sdata, buf, sizeof(buf));
  34. read_unlock(&dev_base_lock);
  35. if (ret >= 0)
  36. ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  37. return ret;
  38. }
  39. static ssize_t ieee80211_if_write(
  40. struct ieee80211_sub_if_data *sdata,
  41. const char __user *userbuf,
  42. size_t count, loff_t *ppos,
  43. ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
  44. {
  45. u8 *buf;
  46. ssize_t ret;
  47. buf = kmalloc(count, GFP_KERNEL);
  48. if (!buf)
  49. return -ENOMEM;
  50. ret = -EFAULT;
  51. if (copy_from_user(buf, userbuf, count))
  52. goto freebuf;
  53. ret = -ENODEV;
  54. rtnl_lock();
  55. if (sdata->dev->reg_state == NETREG_REGISTERED)
  56. ret = (*write)(sdata, buf, count);
  57. rtnl_unlock();
  58. freebuf:
  59. kfree(buf);
  60. return ret;
  61. }
  62. #define IEEE80211_IF_FMT(name, field, format_string) \
  63. static ssize_t ieee80211_if_fmt_##name( \
  64. const struct ieee80211_sub_if_data *sdata, char *buf, \
  65. int buflen) \
  66. { \
  67. return scnprintf(buf, buflen, format_string, sdata->field); \
  68. }
  69. #define IEEE80211_IF_FMT_DEC(name, field) \
  70. IEEE80211_IF_FMT(name, field, "%d\n")
  71. #define IEEE80211_IF_FMT_HEX(name, field) \
  72. IEEE80211_IF_FMT(name, field, "%#x\n")
  73. #define IEEE80211_IF_FMT_LHEX(name, field) \
  74. IEEE80211_IF_FMT(name, field, "%#lx\n")
  75. #define IEEE80211_IF_FMT_SIZE(name, field) \
  76. IEEE80211_IF_FMT(name, field, "%zd\n")
  77. #define IEEE80211_IF_FMT_ATOMIC(name, field) \
  78. static ssize_t ieee80211_if_fmt_##name( \
  79. const struct ieee80211_sub_if_data *sdata, \
  80. char *buf, int buflen) \
  81. { \
  82. return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
  83. }
  84. #define IEEE80211_IF_FMT_MAC(name, field) \
  85. static ssize_t ieee80211_if_fmt_##name( \
  86. const struct ieee80211_sub_if_data *sdata, char *buf, \
  87. int buflen) \
  88. { \
  89. return scnprintf(buf, buflen, "%pM\n", sdata->field); \
  90. }
  91. #define IEEE80211_IF_FMT_DEC_DIV_16(name, field) \
  92. static ssize_t ieee80211_if_fmt_##name( \
  93. const struct ieee80211_sub_if_data *sdata, \
  94. char *buf, int buflen) \
  95. { \
  96. return scnprintf(buf, buflen, "%d\n", sdata->field / 16); \
  97. }
  98. #define __IEEE80211_IF_FILE(name, _write) \
  99. static ssize_t ieee80211_if_read_##name(struct file *file, \
  100. char __user *userbuf, \
  101. size_t count, loff_t *ppos) \
  102. { \
  103. return ieee80211_if_read(file->private_data, \
  104. userbuf, count, ppos, \
  105. ieee80211_if_fmt_##name); \
  106. } \
  107. static const struct file_operations name##_ops = { \
  108. .read = ieee80211_if_read_##name, \
  109. .write = (_write), \
  110. .open = mac80211_open_file_generic, \
  111. .llseek = generic_file_llseek, \
  112. }
  113. #define __IEEE80211_IF_FILE_W(name) \
  114. static ssize_t ieee80211_if_write_##name(struct file *file, \
  115. const char __user *userbuf, \
  116. size_t count, loff_t *ppos) \
  117. { \
  118. return ieee80211_if_write(file->private_data, userbuf, count, \
  119. ppos, ieee80211_if_parse_##name); \
  120. } \
  121. __IEEE80211_IF_FILE(name, ieee80211_if_write_##name)
  122. #define IEEE80211_IF_FILE(name, field, format) \
  123. IEEE80211_IF_FMT_##format(name, field) \
  124. __IEEE80211_IF_FILE(name, NULL)
  125. /* common attributes */
  126. IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
  127. IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[IEEE80211_BAND_2GHZ],
  128. HEX);
  129. IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[IEEE80211_BAND_5GHZ],
  130. HEX);
  131. IEEE80211_IF_FILE(flags, flags, HEX);
  132. IEEE80211_IF_FILE(state, state, LHEX);
  133. IEEE80211_IF_FILE(channel_type, vif.bss_conf.channel_type, DEC);
  134. /* STA attributes */
  135. IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
  136. IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
  137. IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC);
  138. IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16);
  139. static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
  140. enum ieee80211_smps_mode smps_mode)
  141. {
  142. struct ieee80211_local *local = sdata->local;
  143. int err;
  144. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) &&
  145. smps_mode == IEEE80211_SMPS_STATIC)
  146. return -EINVAL;
  147. /* auto should be dynamic if in PS mode */
  148. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) &&
  149. (smps_mode == IEEE80211_SMPS_DYNAMIC ||
  150. smps_mode == IEEE80211_SMPS_AUTOMATIC))
  151. return -EINVAL;
  152. /* supported only on managed interfaces for now */
  153. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  154. return -EOPNOTSUPP;
  155. mutex_lock(&sdata->u.mgd.mtx);
  156. err = __ieee80211_request_smps(sdata, smps_mode);
  157. mutex_unlock(&sdata->u.mgd.mtx);
  158. return err;
  159. }
  160. static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
  161. [IEEE80211_SMPS_AUTOMATIC] = "auto",
  162. [IEEE80211_SMPS_OFF] = "off",
  163. [IEEE80211_SMPS_STATIC] = "static",
  164. [IEEE80211_SMPS_DYNAMIC] = "dynamic",
  165. };
  166. static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
  167. char *buf, int buflen)
  168. {
  169. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  170. return -EOPNOTSUPP;
  171. return snprintf(buf, buflen, "request: %s\nused: %s\n",
  172. smps_modes[sdata->u.mgd.req_smps],
  173. smps_modes[sdata->u.mgd.ap_smps]);
  174. }
  175. static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
  176. const char *buf, int buflen)
  177. {
  178. enum ieee80211_smps_mode mode;
  179. for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
  180. if (strncmp(buf, smps_modes[mode], buflen) == 0) {
  181. int err = ieee80211_set_smps(sdata, mode);
  182. if (!err)
  183. return buflen;
  184. return err;
  185. }
  186. }
  187. return -EINVAL;
  188. }
  189. __IEEE80211_IF_FILE_W(smps);
  190. static ssize_t ieee80211_if_fmt_tkip_mic_test(
  191. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  192. {
  193. return -EOPNOTSUPP;
  194. }
  195. static int hwaddr_aton(const char *txt, u8 *addr)
  196. {
  197. int i;
  198. for (i = 0; i < ETH_ALEN; i++) {
  199. int a, b;
  200. a = hex_to_bin(*txt++);
  201. if (a < 0)
  202. return -1;
  203. b = hex_to_bin(*txt++);
  204. if (b < 0)
  205. return -1;
  206. *addr++ = (a << 4) | b;
  207. if (i < 5 && *txt++ != ':')
  208. return -1;
  209. }
  210. return 0;
  211. }
  212. static ssize_t ieee80211_if_parse_tkip_mic_test(
  213. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  214. {
  215. struct ieee80211_local *local = sdata->local;
  216. u8 addr[ETH_ALEN];
  217. struct sk_buff *skb;
  218. struct ieee80211_hdr *hdr;
  219. __le16 fc;
  220. /*
  221. * Assume colon-delimited MAC address with possible white space
  222. * following.
  223. */
  224. if (buflen < 3 * ETH_ALEN - 1)
  225. return -EINVAL;
  226. if (hwaddr_aton(buf, addr) < 0)
  227. return -EINVAL;
  228. if (!ieee80211_sdata_running(sdata))
  229. return -ENOTCONN;
  230. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
  231. if (!skb)
  232. return -ENOMEM;
  233. skb_reserve(skb, local->hw.extra_tx_headroom);
  234. hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
  235. memset(hdr, 0, 24);
  236. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  237. switch (sdata->vif.type) {
  238. case NL80211_IFTYPE_AP:
  239. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  240. /* DA BSSID SA */
  241. memcpy(hdr->addr1, addr, ETH_ALEN);
  242. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  243. memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
  244. break;
  245. case NL80211_IFTYPE_STATION:
  246. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  247. /* BSSID SA DA */
  248. if (sdata->vif.bss_conf.bssid == NULL) {
  249. dev_kfree_skb(skb);
  250. return -ENOTCONN;
  251. }
  252. memcpy(hdr->addr1, sdata->vif.bss_conf.bssid, ETH_ALEN);
  253. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  254. memcpy(hdr->addr3, addr, ETH_ALEN);
  255. break;
  256. default:
  257. dev_kfree_skb(skb);
  258. return -EOPNOTSUPP;
  259. }
  260. hdr->frame_control = fc;
  261. /*
  262. * Add some length to the test frame to make it look bit more valid.
  263. * The exact contents does not matter since the recipient is required
  264. * to drop this because of the Michael MIC failure.
  265. */
  266. memset(skb_put(skb, 50), 0, 50);
  267. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
  268. ieee80211_tx_skb(sdata, skb);
  269. return buflen;
  270. }
  271. __IEEE80211_IF_FILE_W(tkip_mic_test);
  272. /* AP attributes */
  273. IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
  274. IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
  275. static ssize_t ieee80211_if_fmt_num_buffered_multicast(
  276. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  277. {
  278. return scnprintf(buf, buflen, "%u\n",
  279. skb_queue_len(&sdata->u.ap.ps_bc_buf));
  280. }
  281. __IEEE80211_IF_FILE(num_buffered_multicast, NULL);
  282. /* WDS attributes */
  283. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  284. #ifdef CONFIG_MAC80211_MESH
  285. /* Mesh stats attributes */
  286. IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
  287. IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
  288. IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
  289. IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
  290. IEEE80211_IF_FILE(dropped_frames_congestion,
  291. u.mesh.mshstats.dropped_frames_congestion, DEC);
  292. IEEE80211_IF_FILE(dropped_frames_no_route,
  293. u.mesh.mshstats.dropped_frames_no_route, DEC);
  294. IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
  295. /* Mesh parameters */
  296. IEEE80211_IF_FILE(dot11MeshMaxRetries,
  297. u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
  298. IEEE80211_IF_FILE(dot11MeshRetryTimeout,
  299. u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
  300. IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
  301. u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
  302. IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
  303. u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
  304. IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
  305. IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
  306. IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
  307. IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
  308. u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
  309. IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
  310. u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
  311. IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
  312. u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
  313. IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
  314. u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
  315. IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
  316. u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
  317. IEEE80211_IF_FILE(path_refresh_time,
  318. u.mesh.mshcfg.path_refresh_time, DEC);
  319. IEEE80211_IF_FILE(min_discovery_timeout,
  320. u.mesh.mshcfg.min_discovery_timeout, DEC);
  321. IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
  322. u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
  323. IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
  324. u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
  325. IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
  326. u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
  327. #endif
  328. #define DEBUGFS_ADD(name) \
  329. debugfs_create_file(#name, 0400, sdata->debugfs.dir, \
  330. sdata, &name##_ops);
  331. #define DEBUGFS_ADD_MODE(name, mode) \
  332. debugfs_create_file(#name, mode, sdata->debugfs.dir, \
  333. sdata, &name##_ops);
  334. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  335. {
  336. DEBUGFS_ADD(drop_unencrypted);
  337. DEBUGFS_ADD(flags);
  338. DEBUGFS_ADD(state);
  339. DEBUGFS_ADD(channel_type);
  340. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  341. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  342. DEBUGFS_ADD(bssid);
  343. DEBUGFS_ADD(aid);
  344. DEBUGFS_ADD(last_beacon);
  345. DEBUGFS_ADD(ave_beacon);
  346. DEBUGFS_ADD_MODE(smps, 0600);
  347. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  348. }
  349. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  350. {
  351. DEBUGFS_ADD(drop_unencrypted);
  352. DEBUGFS_ADD(flags);
  353. DEBUGFS_ADD(state);
  354. DEBUGFS_ADD(channel_type);
  355. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  356. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  357. DEBUGFS_ADD(num_sta_ps);
  358. DEBUGFS_ADD(dtim_count);
  359. DEBUGFS_ADD(num_buffered_multicast);
  360. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  361. }
  362. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  363. {
  364. DEBUGFS_ADD(drop_unencrypted);
  365. DEBUGFS_ADD(flags);
  366. DEBUGFS_ADD(state);
  367. DEBUGFS_ADD(channel_type);
  368. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  369. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  370. DEBUGFS_ADD(peer);
  371. }
  372. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  373. {
  374. DEBUGFS_ADD(drop_unencrypted);
  375. DEBUGFS_ADD(flags);
  376. DEBUGFS_ADD(state);
  377. DEBUGFS_ADD(channel_type);
  378. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  379. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  380. }
  381. static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
  382. {
  383. DEBUGFS_ADD(flags);
  384. DEBUGFS_ADD(state);
  385. DEBUGFS_ADD(channel_type);
  386. }
  387. #ifdef CONFIG_MAC80211_MESH
  388. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  389. {
  390. struct dentry *dir = debugfs_create_dir("mesh_stats",
  391. sdata->debugfs.dir);
  392. #define MESHSTATS_ADD(name)\
  393. debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
  394. MESHSTATS_ADD(fwded_mcast);
  395. MESHSTATS_ADD(fwded_unicast);
  396. MESHSTATS_ADD(fwded_frames);
  397. MESHSTATS_ADD(dropped_frames_ttl);
  398. MESHSTATS_ADD(dropped_frames_no_route);
  399. MESHSTATS_ADD(dropped_frames_congestion);
  400. MESHSTATS_ADD(estab_plinks);
  401. #undef MESHSTATS_ADD
  402. }
  403. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  404. {
  405. struct dentry *dir = debugfs_create_dir("mesh_config",
  406. sdata->debugfs.dir);
  407. #define MESHPARAMS_ADD(name) \
  408. debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
  409. MESHPARAMS_ADD(dot11MeshMaxRetries);
  410. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  411. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  412. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  413. MESHPARAMS_ADD(dot11MeshTTL);
  414. MESHPARAMS_ADD(element_ttl);
  415. MESHPARAMS_ADD(auto_open_plinks);
  416. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  417. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  418. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  419. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  420. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  421. MESHPARAMS_ADD(path_refresh_time);
  422. MESHPARAMS_ADD(min_discovery_timeout);
  423. MESHPARAMS_ADD(dot11MeshHWMPRootMode);
  424. MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
  425. MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
  426. #undef MESHPARAMS_ADD
  427. }
  428. #endif
  429. static void add_files(struct ieee80211_sub_if_data *sdata)
  430. {
  431. if (!sdata->debugfs.dir)
  432. return;
  433. switch (sdata->vif.type) {
  434. case NL80211_IFTYPE_MESH_POINT:
  435. #ifdef CONFIG_MAC80211_MESH
  436. add_mesh_stats(sdata);
  437. add_mesh_config(sdata);
  438. #endif
  439. break;
  440. case NL80211_IFTYPE_STATION:
  441. add_sta_files(sdata);
  442. break;
  443. case NL80211_IFTYPE_ADHOC:
  444. /* XXX */
  445. break;
  446. case NL80211_IFTYPE_AP:
  447. add_ap_files(sdata);
  448. break;
  449. case NL80211_IFTYPE_WDS:
  450. add_wds_files(sdata);
  451. break;
  452. case NL80211_IFTYPE_MONITOR:
  453. add_monitor_files(sdata);
  454. break;
  455. case NL80211_IFTYPE_AP_VLAN:
  456. add_vlan_files(sdata);
  457. break;
  458. default:
  459. break;
  460. }
  461. }
  462. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  463. {
  464. char buf[10+IFNAMSIZ];
  465. sprintf(buf, "netdev:%s", sdata->name);
  466. sdata->debugfs.dir = debugfs_create_dir(buf,
  467. sdata->local->hw.wiphy->debugfsdir);
  468. if (sdata->debugfs.dir)
  469. sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
  470. sdata->debugfs.dir);
  471. add_files(sdata);
  472. }
  473. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  474. {
  475. if (!sdata->debugfs.dir)
  476. return;
  477. debugfs_remove_recursive(sdata->debugfs.dir);
  478. sdata->debugfs.dir = NULL;
  479. }
  480. void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
  481. {
  482. struct dentry *dir;
  483. char buf[10 + IFNAMSIZ];
  484. dir = sdata->debugfs.dir;
  485. if (!dir)
  486. return;
  487. sprintf(buf, "netdev:%s", sdata->name);
  488. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  489. printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
  490. "dir to %s\n", buf);
  491. }