debugfs_netdev.c 16 KB

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