debugfs_netdev.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. #define IEEE80211_IF_FMT(name, field, format_string) \
  39. static ssize_t ieee80211_if_fmt_##name( \
  40. const struct ieee80211_sub_if_data *sdata, char *buf, \
  41. int buflen) \
  42. { \
  43. return scnprintf(buf, buflen, format_string, sdata->field); \
  44. }
  45. #define IEEE80211_IF_FMT_DEC(name, field) \
  46. IEEE80211_IF_FMT(name, field, "%d\n")
  47. #define IEEE80211_IF_FMT_HEX(name, field) \
  48. IEEE80211_IF_FMT(name, field, "%#x\n")
  49. #define IEEE80211_IF_FMT_SIZE(name, field) \
  50. IEEE80211_IF_FMT(name, field, "%zd\n")
  51. #define IEEE80211_IF_FMT_ATOMIC(name, field) \
  52. static ssize_t ieee80211_if_fmt_##name( \
  53. const struct ieee80211_sub_if_data *sdata, \
  54. char *buf, int buflen) \
  55. { \
  56. return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
  57. }
  58. #define IEEE80211_IF_FMT_MAC(name, field) \
  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, "%pM\n", sdata->field); \
  64. }
  65. #define __IEEE80211_IF_FILE(name) \
  66. static ssize_t ieee80211_if_read_##name(struct file *file, \
  67. char __user *userbuf, \
  68. size_t count, loff_t *ppos) \
  69. { \
  70. return ieee80211_if_read(file->private_data, \
  71. userbuf, count, ppos, \
  72. ieee80211_if_fmt_##name); \
  73. } \
  74. static const struct file_operations name##_ops = { \
  75. .read = ieee80211_if_read_##name, \
  76. .open = mac80211_open_file_generic, \
  77. }
  78. #define IEEE80211_IF_FILE(name, field, format) \
  79. IEEE80211_IF_FMT_##format(name, field) \
  80. __IEEE80211_IF_FILE(name)
  81. /* common attributes */
  82. IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
  83. IEEE80211_IF_FILE(force_unicast_rateidx, force_unicast_rateidx, DEC);
  84. IEEE80211_IF_FILE(max_ratectrl_rateidx, max_ratectrl_rateidx, DEC);
  85. /* STA attributes */
  86. IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
  87. IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
  88. IEEE80211_IF_FILE(capab, u.mgd.capab, HEX);
  89. /* AP attributes */
  90. IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
  91. IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
  92. static ssize_t ieee80211_if_fmt_num_buffered_multicast(
  93. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  94. {
  95. return scnprintf(buf, buflen, "%u\n",
  96. skb_queue_len(&sdata->u.ap.ps_bc_buf));
  97. }
  98. __IEEE80211_IF_FILE(num_buffered_multicast);
  99. /* WDS attributes */
  100. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  101. #ifdef CONFIG_MAC80211_MESH
  102. /* Mesh stats attributes */
  103. IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
  104. IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
  105. IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
  106. IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
  107. IEEE80211_IF_FILE(dropped_frames_no_route,
  108. u.mesh.mshstats.dropped_frames_no_route, DEC);
  109. IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
  110. /* Mesh parameters */
  111. IEEE80211_IF_FILE(dot11MeshMaxRetries,
  112. u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
  113. IEEE80211_IF_FILE(dot11MeshRetryTimeout,
  114. u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
  115. IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
  116. u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
  117. IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
  118. u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
  119. IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
  120. IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
  121. IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
  122. u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
  123. IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
  124. u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
  125. IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
  126. u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
  127. IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
  128. u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
  129. IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
  130. u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
  131. IEEE80211_IF_FILE(path_refresh_time,
  132. u.mesh.mshcfg.path_refresh_time, DEC);
  133. IEEE80211_IF_FILE(min_discovery_timeout,
  134. u.mesh.mshcfg.min_discovery_timeout, DEC);
  135. #endif
  136. #define DEBUGFS_ADD(name, type)\
  137. sdata->debugfs.type.name = debugfs_create_file(#name, 0400,\
  138. sdata->debugfsdir, sdata, &name##_ops);
  139. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  140. {
  141. DEBUGFS_ADD(drop_unencrypted, sta);
  142. DEBUGFS_ADD(force_unicast_rateidx, sta);
  143. DEBUGFS_ADD(max_ratectrl_rateidx, sta);
  144. DEBUGFS_ADD(bssid, sta);
  145. DEBUGFS_ADD(aid, sta);
  146. DEBUGFS_ADD(capab, sta);
  147. }
  148. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  149. {
  150. DEBUGFS_ADD(drop_unencrypted, ap);
  151. DEBUGFS_ADD(force_unicast_rateidx, ap);
  152. DEBUGFS_ADD(max_ratectrl_rateidx, ap);
  153. DEBUGFS_ADD(num_sta_ps, ap);
  154. DEBUGFS_ADD(dtim_count, ap);
  155. DEBUGFS_ADD(num_buffered_multicast, ap);
  156. }
  157. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  158. {
  159. DEBUGFS_ADD(drop_unencrypted, wds);
  160. DEBUGFS_ADD(force_unicast_rateidx, wds);
  161. DEBUGFS_ADD(max_ratectrl_rateidx, wds);
  162. DEBUGFS_ADD(peer, wds);
  163. }
  164. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  165. {
  166. DEBUGFS_ADD(drop_unencrypted, vlan);
  167. DEBUGFS_ADD(force_unicast_rateidx, vlan);
  168. DEBUGFS_ADD(max_ratectrl_rateidx, vlan);
  169. }
  170. static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
  171. {
  172. }
  173. #ifdef CONFIG_MAC80211_MESH
  174. #define MESHSTATS_ADD(name)\
  175. sdata->mesh_stats.name = debugfs_create_file(#name, 0400,\
  176. sdata->mesh_stats_dir, sdata, &name##_ops);
  177. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  178. {
  179. sdata->mesh_stats_dir = debugfs_create_dir("mesh_stats",
  180. sdata->debugfsdir);
  181. MESHSTATS_ADD(fwded_mcast);
  182. MESHSTATS_ADD(fwded_unicast);
  183. MESHSTATS_ADD(fwded_frames);
  184. MESHSTATS_ADD(dropped_frames_ttl);
  185. MESHSTATS_ADD(dropped_frames_no_route);
  186. MESHSTATS_ADD(estab_plinks);
  187. }
  188. #define MESHPARAMS_ADD(name)\
  189. sdata->mesh_config.name = debugfs_create_file(#name, 0600,\
  190. sdata->mesh_config_dir, sdata, &name##_ops);
  191. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  192. {
  193. sdata->mesh_config_dir = debugfs_create_dir("mesh_config",
  194. sdata->debugfsdir);
  195. MESHPARAMS_ADD(dot11MeshMaxRetries);
  196. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  197. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  198. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  199. MESHPARAMS_ADD(dot11MeshTTL);
  200. MESHPARAMS_ADD(auto_open_plinks);
  201. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  202. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  203. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  204. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  205. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  206. MESHPARAMS_ADD(path_refresh_time);
  207. MESHPARAMS_ADD(min_discovery_timeout);
  208. }
  209. #endif
  210. static void add_files(struct ieee80211_sub_if_data *sdata)
  211. {
  212. if (!sdata->debugfsdir)
  213. return;
  214. switch (sdata->vif.type) {
  215. case NL80211_IFTYPE_MESH_POINT:
  216. #ifdef CONFIG_MAC80211_MESH
  217. add_mesh_stats(sdata);
  218. add_mesh_config(sdata);
  219. #endif
  220. break;
  221. case NL80211_IFTYPE_STATION:
  222. add_sta_files(sdata);
  223. break;
  224. case NL80211_IFTYPE_ADHOC:
  225. /* XXX */
  226. break;
  227. case NL80211_IFTYPE_AP:
  228. add_ap_files(sdata);
  229. break;
  230. case NL80211_IFTYPE_WDS:
  231. add_wds_files(sdata);
  232. break;
  233. case NL80211_IFTYPE_MONITOR:
  234. add_monitor_files(sdata);
  235. break;
  236. case NL80211_IFTYPE_AP_VLAN:
  237. add_vlan_files(sdata);
  238. break;
  239. default:
  240. break;
  241. }
  242. }
  243. #define DEBUGFS_DEL(name, type) \
  244. do { \
  245. debugfs_remove(sdata->debugfs.type.name); \
  246. sdata->debugfs.type.name = NULL; \
  247. } while (0)
  248. static void del_sta_files(struct ieee80211_sub_if_data *sdata)
  249. {
  250. DEBUGFS_DEL(drop_unencrypted, sta);
  251. DEBUGFS_DEL(force_unicast_rateidx, sta);
  252. DEBUGFS_DEL(max_ratectrl_rateidx, sta);
  253. DEBUGFS_DEL(bssid, sta);
  254. DEBUGFS_DEL(aid, sta);
  255. DEBUGFS_DEL(capab, sta);
  256. }
  257. static void del_ap_files(struct ieee80211_sub_if_data *sdata)
  258. {
  259. DEBUGFS_DEL(drop_unencrypted, ap);
  260. DEBUGFS_DEL(force_unicast_rateidx, ap);
  261. DEBUGFS_DEL(max_ratectrl_rateidx, ap);
  262. DEBUGFS_DEL(num_sta_ps, ap);
  263. DEBUGFS_DEL(dtim_count, ap);
  264. DEBUGFS_DEL(num_buffered_multicast, ap);
  265. }
  266. static void del_wds_files(struct ieee80211_sub_if_data *sdata)
  267. {
  268. DEBUGFS_DEL(drop_unencrypted, wds);
  269. DEBUGFS_DEL(force_unicast_rateidx, wds);
  270. DEBUGFS_DEL(max_ratectrl_rateidx, wds);
  271. DEBUGFS_DEL(peer, wds);
  272. }
  273. static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
  274. {
  275. DEBUGFS_DEL(drop_unencrypted, vlan);
  276. DEBUGFS_DEL(force_unicast_rateidx, vlan);
  277. DEBUGFS_DEL(max_ratectrl_rateidx, vlan);
  278. }
  279. static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
  280. {
  281. }
  282. #ifdef CONFIG_MAC80211_MESH
  283. #define MESHSTATS_DEL(name) \
  284. do { \
  285. debugfs_remove(sdata->mesh_stats.name); \
  286. sdata->mesh_stats.name = NULL; \
  287. } while (0)
  288. static void del_mesh_stats(struct ieee80211_sub_if_data *sdata)
  289. {
  290. MESHSTATS_DEL(fwded_mcast);
  291. MESHSTATS_DEL(fwded_unicast);
  292. MESHSTATS_DEL(fwded_frames);
  293. MESHSTATS_DEL(dropped_frames_ttl);
  294. MESHSTATS_DEL(dropped_frames_no_route);
  295. MESHSTATS_DEL(estab_plinks);
  296. debugfs_remove(sdata->mesh_stats_dir);
  297. sdata->mesh_stats_dir = NULL;
  298. }
  299. #define MESHPARAMS_DEL(name) \
  300. do { \
  301. debugfs_remove(sdata->mesh_config.name); \
  302. sdata->mesh_config.name = NULL; \
  303. } while (0)
  304. static void del_mesh_config(struct ieee80211_sub_if_data *sdata)
  305. {
  306. MESHPARAMS_DEL(dot11MeshMaxRetries);
  307. MESHPARAMS_DEL(dot11MeshRetryTimeout);
  308. MESHPARAMS_DEL(dot11MeshConfirmTimeout);
  309. MESHPARAMS_DEL(dot11MeshHoldingTimeout);
  310. MESHPARAMS_DEL(dot11MeshTTL);
  311. MESHPARAMS_DEL(auto_open_plinks);
  312. MESHPARAMS_DEL(dot11MeshMaxPeerLinks);
  313. MESHPARAMS_DEL(dot11MeshHWMPactivePathTimeout);
  314. MESHPARAMS_DEL(dot11MeshHWMPpreqMinInterval);
  315. MESHPARAMS_DEL(dot11MeshHWMPnetDiameterTraversalTime);
  316. MESHPARAMS_DEL(dot11MeshHWMPmaxPREQretries);
  317. MESHPARAMS_DEL(path_refresh_time);
  318. MESHPARAMS_DEL(min_discovery_timeout);
  319. debugfs_remove(sdata->mesh_config_dir);
  320. sdata->mesh_config_dir = NULL;
  321. }
  322. #endif
  323. static void del_files(struct ieee80211_sub_if_data *sdata)
  324. {
  325. if (!sdata->debugfsdir)
  326. return;
  327. switch (sdata->vif.type) {
  328. case NL80211_IFTYPE_MESH_POINT:
  329. #ifdef CONFIG_MAC80211_MESH
  330. del_mesh_stats(sdata);
  331. del_mesh_config(sdata);
  332. #endif
  333. break;
  334. case NL80211_IFTYPE_STATION:
  335. del_sta_files(sdata);
  336. break;
  337. case NL80211_IFTYPE_ADHOC:
  338. /* XXX */
  339. break;
  340. case NL80211_IFTYPE_AP:
  341. del_ap_files(sdata);
  342. break;
  343. case NL80211_IFTYPE_WDS:
  344. del_wds_files(sdata);
  345. break;
  346. case NL80211_IFTYPE_MONITOR:
  347. del_monitor_files(sdata);
  348. break;
  349. case NL80211_IFTYPE_AP_VLAN:
  350. del_vlan_files(sdata);
  351. break;
  352. default:
  353. break;
  354. }
  355. }
  356. static int notif_registered;
  357. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  358. {
  359. char buf[10+IFNAMSIZ];
  360. if (!notif_registered)
  361. return;
  362. sprintf(buf, "netdev:%s", sdata->dev->name);
  363. sdata->debugfsdir = debugfs_create_dir(buf,
  364. sdata->local->hw.wiphy->debugfsdir);
  365. add_files(sdata);
  366. }
  367. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  368. {
  369. del_files(sdata);
  370. debugfs_remove(sdata->debugfsdir);
  371. sdata->debugfsdir = NULL;
  372. }
  373. static int netdev_notify(struct notifier_block *nb,
  374. unsigned long state,
  375. void *ndev)
  376. {
  377. struct net_device *dev = ndev;
  378. struct dentry *dir;
  379. struct ieee80211_sub_if_data *sdata;
  380. char buf[10+IFNAMSIZ];
  381. if (state != NETDEV_CHANGENAME)
  382. return 0;
  383. if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
  384. return 0;
  385. if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  386. return 0;
  387. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  388. dir = sdata->debugfsdir;
  389. if (!dir)
  390. return 0;
  391. sprintf(buf, "netdev:%s", dev->name);
  392. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  393. printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
  394. "dir to %s\n", buf);
  395. return 0;
  396. }
  397. static struct notifier_block mac80211_debugfs_netdev_notifier = {
  398. .notifier_call = netdev_notify,
  399. };
  400. void ieee80211_debugfs_netdev_init(void)
  401. {
  402. int err;
  403. err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  404. if (err) {
  405. printk(KERN_ERR
  406. "mac80211: failed to install netdev notifier,"
  407. " disabling per-netdev debugfs!\n");
  408. } else
  409. notif_registered = 1;
  410. }
  411. void ieee80211_debugfs_netdev_exit(void)
  412. {
  413. unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  414. notif_registered = 0;
  415. }