debugfs_netdev.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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(channel_use, channel_use, DEC);
  143. IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
  144. /* STA/IBSS attributes */
  145. IEEE80211_IF_FILE(state, u.sta.state, DEC);
  146. IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
  147. IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
  148. IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
  149. IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
  150. IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
  151. IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
  152. IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
  153. IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
  154. IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
  155. IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
  156. IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
  157. IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
  158. IEEE80211_IF_FILE(num_beacons_sta, u.sta.num_beacons, DEC);
  159. static ssize_t ieee80211_if_fmt_flags(
  160. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  161. {
  162. return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
  163. sdata->u.sta.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
  164. sdata->u.sta.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
  165. sdata->u.sta.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
  166. sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
  167. sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
  168. sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
  169. sdata->bss_conf.use_cts_prot ? "CTS prot\n" : "");
  170. }
  171. __IEEE80211_IF_FILE(flags);
  172. /* AP attributes */
  173. IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
  174. IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
  175. IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
  176. IEEE80211_IF_FILE(force_unicast_rateidx, u.ap.force_unicast_rateidx, DEC);
  177. IEEE80211_IF_FILE(max_ratectrl_rateidx, u.ap.max_ratectrl_rateidx, DEC);
  178. static ssize_t ieee80211_if_fmt_num_buffered_multicast(
  179. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  180. {
  181. return scnprintf(buf, buflen, "%u\n",
  182. skb_queue_len(&sdata->u.ap.ps_bc_buf));
  183. }
  184. __IEEE80211_IF_FILE(num_buffered_multicast);
  185. /* WDS attributes */
  186. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  187. #ifdef CONFIG_MAC80211_MESH
  188. /* Mesh stats attributes */
  189. IEEE80211_IF_FILE(fwded_frames, u.sta.mshstats.fwded_frames, DEC);
  190. IEEE80211_IF_FILE(dropped_frames_ttl, u.sta.mshstats.dropped_frames_ttl, DEC);
  191. IEEE80211_IF_FILE(dropped_frames_no_route,
  192. u.sta.mshstats.dropped_frames_no_route, DEC);
  193. IEEE80211_IF_FILE(estab_plinks, u.sta.mshstats.estab_plinks, ATOMIC);
  194. /* Mesh parameters */
  195. IEEE80211_IF_WFILE(dot11MeshMaxRetries,
  196. u.sta.mshcfg.dot11MeshMaxRetries, DEC, u8);
  197. IEEE80211_IF_WFILE(dot11MeshRetryTimeout,
  198. u.sta.mshcfg.dot11MeshRetryTimeout, DEC, u16);
  199. IEEE80211_IF_WFILE(dot11MeshConfirmTimeout,
  200. u.sta.mshcfg.dot11MeshConfirmTimeout, DEC, u16);
  201. IEEE80211_IF_WFILE(dot11MeshHoldingTimeout,
  202. u.sta.mshcfg.dot11MeshHoldingTimeout, DEC, u16);
  203. IEEE80211_IF_WFILE(dot11MeshTTL, u.sta.mshcfg.dot11MeshTTL, DEC, u8);
  204. IEEE80211_IF_WFILE(auto_open_plinks, u.sta.mshcfg.auto_open_plinks, DEC, u8);
  205. IEEE80211_IF_WFILE(dot11MeshMaxPeerLinks,
  206. u.sta.mshcfg.dot11MeshMaxPeerLinks, DEC, u16);
  207. IEEE80211_IF_WFILE(dot11MeshHWMPactivePathTimeout,
  208. u.sta.mshcfg.dot11MeshHWMPactivePathTimeout, DEC, u32);
  209. IEEE80211_IF_WFILE(dot11MeshHWMPpreqMinInterval,
  210. u.sta.mshcfg.dot11MeshHWMPpreqMinInterval, DEC, u16);
  211. IEEE80211_IF_WFILE(dot11MeshHWMPnetDiameterTraversalTime,
  212. u.sta.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC, u16);
  213. IEEE80211_IF_WFILE(dot11MeshHWMPmaxPREQretries,
  214. u.sta.mshcfg.dot11MeshHWMPmaxPREQretries, DEC, u8);
  215. IEEE80211_IF_WFILE(path_refresh_time,
  216. u.sta.mshcfg.path_refresh_time, DEC, u32);
  217. IEEE80211_IF_WFILE(min_discovery_timeout,
  218. u.sta.mshcfg.min_discovery_timeout, DEC, u16);
  219. #endif
  220. #define DEBUGFS_ADD(name, type)\
  221. sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
  222. sdata->debugfsdir, sdata, &name##_ops);
  223. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  224. {
  225. DEBUGFS_ADD(channel_use, sta);
  226. DEBUGFS_ADD(drop_unencrypted, 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(channel_use, ap);
  246. DEBUGFS_ADD(drop_unencrypted, ap);
  247. DEBUGFS_ADD(num_sta_ps, ap);
  248. DEBUGFS_ADD(dtim_count, ap);
  249. DEBUGFS_ADD(num_beacons, ap);
  250. DEBUGFS_ADD(force_unicast_rateidx, ap);
  251. DEBUGFS_ADD(max_ratectrl_rateidx, ap);
  252. DEBUGFS_ADD(num_buffered_multicast, ap);
  253. }
  254. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  255. {
  256. DEBUGFS_ADD(channel_use, wds);
  257. DEBUGFS_ADD(drop_unencrypted, wds);
  258. DEBUGFS_ADD(peer, wds);
  259. }
  260. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  261. {
  262. DEBUGFS_ADD(channel_use, vlan);
  263. DEBUGFS_ADD(drop_unencrypted, vlan);
  264. }
  265. static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
  266. {
  267. }
  268. #ifdef CONFIG_MAC80211_MESH
  269. #define MESHSTATS_ADD(name)\
  270. sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
  271. sdata->mesh_stats_dir, sdata, &name##_ops);
  272. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  273. {
  274. sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
  275. sdata->debugfsdir);
  276. MESHSTATS_ADD(fwded_frames);
  277. MESHSTATS_ADD(dropped_frames_ttl);
  278. MESHSTATS_ADD(dropped_frames_no_route);
  279. MESHSTATS_ADD(estab_plinks);
  280. }
  281. #define MESHPARAMS_ADD(name)\
  282. sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
  283. sdata->mesh_config_dir, sdata, &name##_ops);
  284. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  285. {
  286. sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
  287. sdata->debugfsdir);
  288. MESHPARAMS_ADD(dot11MeshMaxRetries);
  289. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  290. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  291. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  292. MESHPARAMS_ADD(dot11MeshTTL);
  293. MESHPARAMS_ADD(auto_open_plinks);
  294. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  295. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  296. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  297. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  298. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  299. MESHPARAMS_ADD(path_refresh_time);
  300. MESHPARAMS_ADD(min_discovery_timeout);
  301. }
  302. #endif
  303. static void add_files(struct ieee80211_sub_if_data *sdata)
  304. {
  305. if (!sdata->debugfsdir)
  306. return;
  307. switch (sdata->vif.type) {
  308. case IEEE80211_IF_TYPE_MESH_POINT:
  309. #ifdef CONFIG_MAC80211_MESH
  310. add_mesh_stats(sdata);
  311. add_mesh_config(sdata);
  312. #endif
  313. /* fall through */
  314. case IEEE80211_IF_TYPE_STA:
  315. case IEEE80211_IF_TYPE_IBSS:
  316. add_sta_files(sdata);
  317. break;
  318. case IEEE80211_IF_TYPE_AP:
  319. add_ap_files(sdata);
  320. break;
  321. case IEEE80211_IF_TYPE_WDS:
  322. add_wds_files(sdata);
  323. break;
  324. case IEEE80211_IF_TYPE_MNTR:
  325. add_monitor_files(sdata);
  326. break;
  327. case IEEE80211_IF_TYPE_VLAN:
  328. add_vlan_files(sdata);
  329. break;
  330. default:
  331. break;
  332. }
  333. }
  334. #define DEBUGFS_DEL(name, type) \
  335. do { \
  336. debugfs_remove(sdata->debugfs.type.name); \
  337. sdata->debugfs.type.name = NULL; \
  338. } while (0)
  339. static void del_sta_files(struct ieee80211_sub_if_data *sdata)
  340. {
  341. DEBUGFS_DEL(channel_use, sta);
  342. DEBUGFS_DEL(drop_unencrypted, sta);
  343. DEBUGFS_DEL(state, sta);
  344. DEBUGFS_DEL(bssid, sta);
  345. DEBUGFS_DEL(prev_bssid, sta);
  346. DEBUGFS_DEL(ssid_len, sta);
  347. DEBUGFS_DEL(aid, sta);
  348. DEBUGFS_DEL(ap_capab, sta);
  349. DEBUGFS_DEL(capab, sta);
  350. DEBUGFS_DEL(extra_ie_len, sta);
  351. DEBUGFS_DEL(auth_tries, sta);
  352. DEBUGFS_DEL(assoc_tries, sta);
  353. DEBUGFS_DEL(auth_algs, sta);
  354. DEBUGFS_DEL(auth_alg, sta);
  355. DEBUGFS_DEL(auth_transaction, sta);
  356. DEBUGFS_DEL(flags, sta);
  357. DEBUGFS_DEL(num_beacons_sta, sta);
  358. }
  359. static void del_ap_files(struct ieee80211_sub_if_data *sdata)
  360. {
  361. DEBUGFS_DEL(channel_use, ap);
  362. DEBUGFS_DEL(drop_unencrypted, ap);
  363. DEBUGFS_DEL(num_sta_ps, ap);
  364. DEBUGFS_DEL(dtim_count, ap);
  365. DEBUGFS_DEL(num_beacons, ap);
  366. DEBUGFS_DEL(force_unicast_rateidx, ap);
  367. DEBUGFS_DEL(max_ratectrl_rateidx, ap);
  368. DEBUGFS_DEL(num_buffered_multicast, ap);
  369. }
  370. static void del_wds_files(struct ieee80211_sub_if_data *sdata)
  371. {
  372. DEBUGFS_DEL(channel_use, wds);
  373. DEBUGFS_DEL(drop_unencrypted, wds);
  374. DEBUGFS_DEL(peer, wds);
  375. }
  376. static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
  377. {
  378. DEBUGFS_DEL(channel_use, vlan);
  379. DEBUGFS_DEL(drop_unencrypted, vlan);
  380. }
  381. static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
  382. {
  383. }
  384. #ifdef CONFIG_MAC80211_MESH
  385. #define MESHSTATS_DEL(name) \
  386. do { \
  387. debugfs_remove(sdata->mesh_stats.name); \
  388. sdata->mesh_stats.name = NULL; \
  389. } while (0)
  390. static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
  391. {
  392. MESHSTATS_DEL(fwded_frames);
  393. MESHSTATS_DEL(dropped_frames_ttl);
  394. MESHSTATS_DEL(dropped_frames_no_route);
  395. MESHSTATS_DEL(estab_plinks);
  396. debugfs_remove(sdata->mesh_stats_dir);
  397. sdata->mesh_stats_dir = NULL;
  398. }
  399. #define MESHPARAMS_DEL(name) \
  400. do { \
  401. debugfs_remove(sdata->mesh_config.name); \
  402. sdata->mesh_config.name = NULL; \
  403. } while (0)
  404. static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
  405. {
  406. MESHPARAMS_DEL(dot11MeshMaxRetries);
  407. MESHPARAMS_DEL(dot11MeshRetryTimeout);
  408. MESHPARAMS_DEL(dot11MeshConfirmTimeout);
  409. MESHPARAMS_DEL(dot11MeshHoldingTimeout);
  410. MESHPARAMS_DEL(dot11MeshTTL);
  411. MESHPARAMS_DEL(auto_open_plinks);
  412. MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
  413. MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
  414. MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
  415. MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
  416. MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
  417. MESHPARAMS_DEL(path_refresh_time);
  418. MESHPARAMS_DEL(min_discovery_timeout);
  419. debugfs_remove(sdata->mesh_config_dir);
  420. sdata->mesh_config_dir = NULL;
  421. }
  422. #endif
  423. static void del_files(struct ieee80211_sub_if_data *sdata, int type)
  424. {
  425. if (!sdata->debugfsdir)
  426. return;
  427. switch (type) {
  428. case IEEE80211_IF_TYPE_MESH_POINT:
  429. #ifdef CONFIG_MAC80211_MESH
  430. del_mesh_stats(sdata);
  431. del_mesh_config(sdata);
  432. #endif
  433. /* fall through */
  434. case IEEE80211_IF_TYPE_STA:
  435. case IEEE80211_IF_TYPE_IBSS:
  436. del_sta_files(sdata);
  437. break;
  438. case IEEE80211_IF_TYPE_AP:
  439. del_ap_files(sdata);
  440. break;
  441. case IEEE80211_IF_TYPE_WDS:
  442. del_wds_files(sdata);
  443. break;
  444. case IEEE80211_IF_TYPE_MNTR:
  445. del_monitor_files(sdata);
  446. break;
  447. case IEEE80211_IF_TYPE_VLAN:
  448. del_vlan_files(sdata);
  449. break;
  450. default:
  451. break;
  452. }
  453. }
  454. static int notif_registered;
  455. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  456. {
  457. char buf[10+IFNAMSIZ];
  458. if (!notif_registered)
  459. return;
  460. sprintf(buf, "netdev:%s", sdata->dev->name);
  461. sdata->debugfsdir = debugfs_create_dir(buf,
  462. sdata->local->hw.wiphy->debugfsdir);
  463. }
  464. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  465. {
  466. del_files(sdata, sdata->vif.type);
  467. debugfs_remove(sdata->debugfsdir);
  468. sdata->debugfsdir = NULL;
  469. }
  470. void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
  471. int oldtype)
  472. {
  473. del_files(sdata, oldtype);
  474. add_files(sdata);
  475. }
  476. static int netdev_notify(struct notifier_block * nb,
  477. unsigned long state,
  478. void *ndev)
  479. {
  480. struct net_device *dev = ndev;
  481. struct dentry *dir;
  482. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  483. char buf[10+IFNAMSIZ];
  484. if (state != NETDEV_CHANGENAME)
  485. return 0;
  486. if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
  487. return 0;
  488. if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  489. return 0;
  490. sprintf(buf, "netdev:%s", dev->name);
  491. dir = sdata->debugfsdir;
  492. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  493. printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
  494. "dir to %s\n", buf);
  495. return 0;
  496. }
  497. static struct notifier_block mac80211_debugfs_netdev_notifier = {
  498. .notifier_call = netdev_notify,
  499. };
  500. void ieee80211_debugfs_netdev_init(void)
  501. {
  502. int err;
  503. err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  504. if (err) {
  505. printk(KERN_ERR
  506. "mac80211: failed to install netdev notifier,"
  507. " disabling per-netdev debugfs!\n");
  508. } else
  509. notif_registered = 1;
  510. }
  511. void ieee80211_debugfs_netdev_exit(void)
  512. {
  513. unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  514. notif_registered = 0;
  515. }