debugfs_netdev.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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/notifier.h>
  16. #include <net/mac80211.h>
  17. #include <net/cfg80211.h>
  18. #include "ieee80211_i.h"
  19. #include "rate.h"
  20. #include "debugfs.h"
  21. #include "debugfs_netdev.h"
  22. static ssize_t ieee80211_if_read(
  23. struct ieee80211_sub_if_data *sdata,
  24. char __user *userbuf,
  25. size_t count, loff_t *ppos,
  26. ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
  27. {
  28. char buf[70];
  29. ssize_t ret = -EINVAL;
  30. read_lock(&dev_base_lock);
  31. if (sdata->dev->reg_state == NETREG_REGISTERED)
  32. ret = (*format)(sdata, buf, sizeof(buf));
  33. read_unlock(&dev_base_lock);
  34. if (ret != -EINVAL)
  35. ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  36. return ret;
  37. }
  38. #ifdef CONFIG_MAC80211_MESH
  39. static ssize_t ieee80211_if_write(
  40. struct ieee80211_sub_if_data *sdata,
  41. char const __user *userbuf,
  42. size_t count, loff_t *ppos,
  43. int (*format)(struct ieee80211_sub_if_data *, char *))
  44. {
  45. char buf[10];
  46. int buf_size;
  47. memset(buf, 0x00, sizeof(buf));
  48. buf_size = min(count, (sizeof(buf)-1));
  49. if (copy_from_user(buf, userbuf, buf_size))
  50. return count;
  51. read_lock(&dev_base_lock);
  52. if (sdata->dev->reg_state == NETREG_REGISTERED)
  53. (*format)(sdata, buf);
  54. read_unlock(&dev_base_lock);
  55. return count;
  56. }
  57. #endif
  58. #define IEEE80211_IF_FMT(name, field, format_string) \
  59. static ssize_t ieee80211_if_fmt_##name( \
  60. const struct ieee80211_sub_if_data *sdata, char *buf, \
  61. int buflen) \
  62. { \
  63. return scnprintf(buf, buflen, format_string, sdata->field); \
  64. }
  65. #define IEEE80211_IF_WFMT(name, field, type) \
  66. static int ieee80211_if_wfmt_##name( \
  67. struct ieee80211_sub_if_data *sdata, char *buf) \
  68. { \
  69. unsigned long tmp; \
  70. char *endp; \
  71. \
  72. tmp = simple_strtoul(buf, &endp, 0); \
  73. if ((endp == buf) || ((type)tmp != tmp)) \
  74. return -EINVAL; \
  75. sdata->field = tmp; \
  76. return 0; \
  77. }
  78. #define IEEE80211_IF_FMT_DEC(name, field) \
  79. IEEE80211_IF_FMT(name, field, "%d\n")
  80. #define IEEE80211_IF_FMT_HEX(name, field) \
  81. IEEE80211_IF_FMT(name, field, "%#x\n")
  82. #define IEEE80211_IF_FMT_SIZE(name, field) \
  83. IEEE80211_IF_FMT(name, field, "%zd\n")
  84. #define IEEE80211_IF_FMT_ATOMIC(name, field) \
  85. static ssize_t ieee80211_if_fmt_##name( \
  86. const struct ieee80211_sub_if_data *sdata, \
  87. char *buf, int buflen) \
  88. { \
  89. return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
  90. }
  91. #define IEEE80211_IF_FMT_MAC(name, field) \
  92. static ssize_t ieee80211_if_fmt_##name( \
  93. const struct ieee80211_sub_if_data *sdata, char *buf, \
  94. int buflen) \
  95. { \
  96. DECLARE_MAC_BUF(mac); \
  97. return scnprintf(buf, buflen, "%s\n", print_mac(mac, sdata->field));\
  98. }
  99. #define __IEEE80211_IF_FILE(name) \
  100. static ssize_t ieee80211_if_read_##name(struct file *file, \
  101. char __user *userbuf, \
  102. size_t count, loff_t *ppos) \
  103. { \
  104. return ieee80211_if_read(file->private_data, \
  105. userbuf, count, ppos, \
  106. ieee80211_if_fmt_##name); \
  107. } \
  108. static const struct file_operations name##_ops = { \
  109. .read = ieee80211_if_read_##name, \
  110. .open = mac80211_open_file_generic, \
  111. }
  112. #define IEEE80211_IF_FILE(name, field, format) \
  113. IEEE80211_IF_FMT_##format(name, field) \
  114. __IEEE80211_IF_FILE(name)
  115. #define __IEEE80211_IF_WFILE(name) \
  116. static ssize_t ieee80211_if_read_##name(struct file *file, \
  117. char __user *userbuf, \
  118. size_t count, loff_t *ppos) \
  119. { \
  120. return ieee80211_if_read(file->private_data, \
  121. userbuf, count, ppos, \
  122. ieee80211_if_fmt_##name); \
  123. } \
  124. static ssize_t ieee80211_if_write_##name(struct file *file, \
  125. const char __user *userbuf, \
  126. size_t count, loff_t *ppos) \
  127. { \
  128. return ieee80211_if_write(file->private_data, \
  129. userbuf, count, ppos, \
  130. ieee80211_if_wfmt_##name); \
  131. } \
  132. static const struct file_operations name##_ops = { \
  133. .read = ieee80211_if_read_##name, \
  134. .write = ieee80211_if_write_##name, \
  135. .open = mac80211_open_file_generic, \
  136. }
  137. #define IEEE80211_IF_WFILE(name, field, format, type) \
  138. IEEE80211_IF_FMT_##format(name, field) \
  139. IEEE80211_IF_WFMT(name, field, type) \
  140. __IEEE80211_IF_WFILE(name)
  141. /* common attributes */
  142. IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
  143. IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
  144. IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
  145. /* STA/IBSS attributes */
  146. IEEE80211_IF_FILE(state, u.sta.state, DEC);
  147. IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
  148. IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
  149. IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
  150. IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
  151. IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
  152. IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
  153. IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
  154. IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
  155. IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
  156. IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
  157. IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
  158. IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
  159. IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
  160. static ssize_t ieee80211_if_fmt_flags(
  161. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  162. {
  163. return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
  164. sdata->u.sta.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
  165. sdata->u.sta.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
  166. sdata->u.sta.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
  167. sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
  168. sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
  169. sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
  170. sdata->bss_conf.use_cts_prot ? "CTS prot\n" : "");
  171. }
  172. __IEEE80211_IF_FILE(flags);
  173. /* AP attributes */
  174. IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
  175. IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
  176. IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
  177. static ssize_t ieee80211_if_fmt_num_buffered_multicast(
  178. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  179. {
  180. return scnprintf(buf, buflen, "%u\n",
  181. skb_queue_len(&sdata->u.ap.ps_bc_buf));
  182. }
  183. __IEEE80211_IF_FILE(num_buffered_multicast);
  184. /* WDS attributes */
  185. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  186. #ifdef CONFIG_MAC80211_MESH
  187. /* Mesh stats attributes */
  188. IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC);
  189. IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC);
  190. IEEE80211_IF_FILE(dropped_frames_no_route,
  191. u.sta.mshstats.dropped_frames_no_route, DEC);
  192. IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC);
  193. /* Mesh parameters */
  194. IEEE80211_IF_WFILE(dot11MeshMaxRetries,
  195. u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8);
  196. IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
  197. u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16);
  198. IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
  199. u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
  200. IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
  201. u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
  202. IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8);
  203. IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, u8);
  204. IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
  205. u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
  206. IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
  207. u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
  208. IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
  209. u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
  210. IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
  211. u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
  212. IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
  213. u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
  214. IEEE80211_IF_WFILE(path_refresh_time,
  215. u.sta.mshcfg.path_refresh_time, DEC, u32);
  216. IEEE80211_IF_WFILE(min_discovery_timeout,
  217. u.sta.mshcfg.min_discovery_timeout, DEC, u16);
  218. #endif
  219. #define DEBUGFS_ADD(name, type)\
  220. sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
  221. sdata->debugfsdir, sdata, &name##_ops);
  222. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  223. {
  224. DEBUGFS_ADD(drop_unencrypted, sta);
  225. DEBUGFS_ADD(force_unicast_rateidx, sta);
  226. DEBUGFS_ADD(max_ratectrl_rateidx, sta);
  227. DEBUGFS_ADD(state, sta);
  228. DEBUGFS_ADD(bssid, sta);
  229. DEBUGFS_ADD(prev_bssid, sta);
  230. DEBUGFS_ADD(ssid_len, sta);
  231. DEBUGFS_ADD(aid, sta);
  232. DEBUGFS_ADD(ap_capab, sta);
  233. DEBUGFS_ADD(capab, sta);
  234. DEBUGFS_ADD(extra_ie_len, sta);
  235. DEBUGFS_ADD(auth_tries, sta);
  236. DEBUGFS_ADD(assoc_tries, sta);
  237. DEBUGFS_ADD(auth_algs, sta);
  238. DEBUGFS_ADD(auth_alg, sta);
  239. DEBUGFS_ADD(auth_transaction, sta);
  240. DEBUGFS_ADD(flags, sta);
  241. DEBUGFS_ADD(num_beacons_sta, sta);
  242. }
  243. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  244. {
  245. DEBUGFS_ADD(drop_unencrypted, ap);
  246. DEBUGFS_ADD(force_unicast_rateidx, ap);
  247. DEBUGFS_ADD(max_ratectrl_rateidx, ap);
  248. DEBUGFS_ADD(num_sta_ps, ap);
  249. DEBUGFS_ADD(dtim_count, ap);
  250. DEBUGFS_ADD(num_beacons, ap);
  251. DEBUGFS_ADD(num_buffered_multicast, ap);
  252. }
  253. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  254. {
  255. DEBUGFS_ADD(drop_unencrypted, wds);
  256. DEBUGFS_ADD(force_unicast_rateidx, wds);
  257. DEBUGFS_ADD(max_ratectrl_rateidx, wds);
  258. DEBUGFS_ADD(peer, wds);
  259. }
  260. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  261. {
  262. DEBUGFS_ADD(drop_unencrypted, vlan);
  263. DEBUGFS_ADD(force_unicast_rateidx, vlan);
  264. DEBUGFS_ADD(max_ratectrl_rateidx, vlan);
  265. }
  266. static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
  267. {
  268. }
  269. #ifdef CONFIG_MAC80211_MESH
  270. #define MESHSTATS_ADD(name)\
  271. sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
  272. sdata->mesh_stats_dir, sdata, &name##_ops);
  273. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  274. {
  275. sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
  276. sdata->debugfsdir);
  277. MESHSTATS_ADD(fwded_frames);
  278. MESHSTATS_ADD(dropped_frames_ttl);
  279. MESHSTATS_ADD(dropped_frames_no_route);
  280. MESHSTATS_ADD(estab_plinks);
  281. }
  282. #define MESHPARAMS_ADD(name)\
  283. sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
  284. sdata->mesh_config_dir, sdata, &name##_ops);
  285. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  286. {
  287. sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
  288. sdata->debugfsdir);
  289. MESHPARAMS_ADD(dot11MeshMaxRetries);
  290. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  291. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  292. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  293. MESHPARAMS_ADD(dot11MeshTTL);
  294. MESHPARAMS_ADD(auto_open_plinks);
  295. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  296. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  297. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  298. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  299. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  300. MESHPARAMS_ADD(path_refresh_time);
  301. MESHPARAMS_ADD(min_discovery_timeout);
  302. }
  303. #endif
  304. static void add_files(struct ieee80211_sub_if_data *sdata)
  305. {
  306. if (!sdata->debugfsdir)
  307. return;
  308. switch (sdata->vif.type) {
  309. case IEEE80211_IF_TYPE_MESH_POINT:
  310. #ifdef CONFIG_MAC80211_MESH
  311. add_mesh_stats(sdata);
  312. add_mesh_config(sdata);
  313. #endif
  314. /* fall through */
  315. case IEEE80211_IF_TYPE_STA:
  316. case IEEE80211_IF_TYPE_IBSS:
  317. add_sta_files(sdata);
  318. break;
  319. case IEEE80211_IF_TYPE_AP:
  320. add_ap_files(sdata);
  321. break;
  322. case IEEE80211_IF_TYPE_WDS:
  323. add_wds_files(sdata);
  324. break;
  325. case IEEE80211_IF_TYPE_MNTR:
  326. add_monitor_files(sdata);
  327. break;
  328. case IEEE80211_IF_TYPE_VLAN:
  329. add_vlan_files(sdata);
  330. break;
  331. default:
  332. break;
  333. }
  334. }
  335. #define DEBUGFS_DEL(name, type) \
  336. do { \
  337. debugfs_remove(sdata->debugfs.type.name); \
  338. sdata->debugfs.type.name = NULL; \
  339. } while (0)
  340. static void del_sta_files(struct ieee80211_sub_if_data *sdata)
  341. {
  342. DEBUGFS_DEL(drop_unencrypted, sta);
  343. DEBUGFS_DEL(force_unicast_rateidx, sta);
  344. DEBUGFS_DEL(max_ratectrl_rateidx, sta);
  345. DEBUGFS_DEL(state, sta);
  346. DEBUGFS_DEL(bssid, sta);
  347. DEBUGFS_DEL(prev_bssid, sta);
  348. DEBUGFS_DEL(ssid_len, sta);
  349. DEBUGFS_DEL(aid, sta);
  350. DEBUGFS_DEL(ap_capab, sta);
  351. DEBUGFS_DEL(capab, sta);
  352. DEBUGFS_DEL(extra_ie_len, sta);
  353. DEBUGFS_DEL(auth_tries, sta);
  354. DEBUGFS_DEL(assoc_tries, sta);
  355. DEBUGFS_DEL(auth_algs, sta);
  356. DEBUGFS_DEL(auth_alg, sta);
  357. DEBUGFS_DEL(auth_transaction, sta);
  358. DEBUGFS_DEL(flags, sta);
  359. DEBUGFS_DEL(num_beacons_sta, sta);
  360. }
  361. static void del_ap_files(struct ieee80211_sub_if_data *sdata)
  362. {
  363. DEBUGFS_DEL(drop_unencrypted, ap);
  364. DEBUGFS_DEL(force_unicast_rateidx, ap);
  365. DEBUGFS_DEL(max_ratectrl_rateidx, ap);
  366. DEBUGFS_DEL(num_sta_ps, ap);
  367. DEBUGFS_DEL(dtim_count, ap);
  368. DEBUGFS_DEL(num_beacons, ap);
  369. DEBUGFS_DEL(num_buffered_multicast, ap);
  370. }
  371. static void del_wds_files(struct ieee80211_sub_if_data *sdata)
  372. {
  373. DEBUGFS_DEL(drop_unencrypted, wds);
  374. DEBUGFS_DEL(force_unicast_rateidx, wds);
  375. DEBUGFS_DEL(max_ratectrl_rateidx, wds);
  376. DEBUGFS_DEL(peer, wds);
  377. }
  378. static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
  379. {
  380. DEBUGFS_DEL(drop_unencrypted, vlan);
  381. DEBUGFS_DEL(force_unicast_rateidx, vlan);
  382. DEBUGFS_DEL(max_ratectrl_rateidx, vlan);
  383. }
  384. static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
  385. {
  386. }
  387. #ifdef CONFIG_MAC80211_MESH
  388. #define MESHSTATS_DEL(name) \
  389. do { \
  390. debugfs_remove(sdata->mesh_stats.name); \
  391. sdata->mesh_stats.name = NULL; \
  392. } while (0)
  393. static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
  394. {
  395. MESHSTATS_DEL(fwded_frames);
  396. MESHSTATS_DEL(dropped_frames_ttl);
  397. MESHSTATS_DEL(dropped_frames_no_route);
  398. MESHSTATS_DEL(estab_plinks);
  399. debugfs_remove(sdata->mesh_stats_dir);
  400. sdata->mesh_stats_dir = NULL;
  401. }
  402. #define MESHPARAMS_DEL(name) \
  403. do { \
  404. debugfs_remove(sdata->mesh_config.name); \
  405. sdata->mesh_config.name = NULL; \
  406. } while (0)
  407. static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
  408. {
  409. MESHPARAMS_DEL(dot11MeshMaxRetries);
  410. MESHPARAMS_DEL(dot11MeshRetryTimeout);
  411. MESHPARAMS_DEL(dot11MeshConfirmTimeout);
  412. MESHPARAMS_DEL(dot11MeshHoldingTimeout);
  413. MESHPARAMS_DEL(dot11MeshTTL);
  414. MESHPARAMS_DEL(auto_open_plinks);
  415. MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
  416. MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
  417. MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
  418. MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
  419. MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
  420. MESHPARAMS_DEL(path_refresh_time);
  421. MESHPARAMS_DEL(min_discovery_timeout);
  422. debugfs_remove(sdata->mesh_config_dir);
  423. sdata->mesh_config_dir = NULL;
  424. }
  425. #endif
  426. static void del_files(struct ieee80211_sub_if_data *sdata)
  427. {
  428. if (!sdata->debugfsdir)
  429. return;
  430. switch (sdata->vif.type) {
  431. case IEEE80211_IF_TYPE_MESH_POINT:
  432. #ifdef CONFIG_MAC80211_MESH
  433. del_mesh_stats(sdata);
  434. del_mesh_config(sdata);
  435. #endif
  436. /* fall through */
  437. case IEEE80211_IF_TYPE_STA:
  438. case IEEE80211_IF_TYPE_IBSS:
  439. del_sta_files(sdata);
  440. break;
  441. case IEEE80211_IF_TYPE_AP:
  442. del_ap_files(sdata);
  443. break;
  444. case IEEE80211_IF_TYPE_WDS:
  445. del_wds_files(sdata);
  446. break;
  447. case IEEE80211_IF_TYPE_MNTR:
  448. del_monitor_files(sdata);
  449. break;
  450. case IEEE80211_IF_TYPE_VLAN:
  451. del_vlan_files(sdata);
  452. break;
  453. default:
  454. break;
  455. }
  456. }
  457. static int notif_registered;
  458. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  459. {
  460. char buf[10+IFNAMSIZ];
  461. if (!notif_registered)
  462. return;
  463. sprintf(buf, "netdev:%s", sdata->dev->name);
  464. sdata->debugfsdir = debugfs_create_dir(buf,
  465. sdata->local->hw.wiphy->debugfsdir);
  466. add_files(sdata);
  467. }
  468. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  469. {
  470. del_files(sdata);
  471. debugfs_remove(sdata->debugfsdir);
  472. sdata->debugfsdir = NULL;
  473. }
  474. static int netdev_notify(struct notifier_block *nb,
  475. unsigned long state,
  476. void *ndev)
  477. {
  478. struct net_device *dev = ndev;
  479. struct dentry *dir;
  480. struct ieee80211_sub_if_data *sdata;
  481. char buf[10+IFNAMSIZ];
  482. if (state != NETDEV_CHANGENAME)
  483. return 0;
  484. if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
  485. return 0;
  486. if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  487. return 0;
  488. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  489. sprintf(buf, "netdev:%s", dev->name);
  490. dir = sdata->debugfsdir;
  491. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  492. printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
  493. "dir to %s\n", buf);
  494. return 0;
  495. }
  496. static struct notifier_block mac80211_debugfs_netdev_notifier = {
  497. .notifier_call = netdev_notify,
  498. };
  499. void ieee80211_debugfs_netdev_init(void)
  500. {
  501. int err;
  502. err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  503. if (err) {
  504. printk(KERN_ERR
  505. "mac80211: failed to install netdev notifier,"
  506. " disabling per-netdev debugfs!\n");
  507. } else
  508. notif_registered = 1;
  509. }
  510. void ieee80211_debugfs_netdev_exit(void)
  511. {
  512. unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  513. notif_registered = 0;
  514. }