debugfs_netdev.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
  136. u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
  137. #endif
  138. #define DEBUGFS_ADD(name, type) \
  139. debugfs_create_file(#name, 0400, sdata->debugfs.dir, \
  140. sdata, &name##_ops);
  141. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  142. {
  143. DEBUGFS_ADD(drop_unencrypted, sta);
  144. DEBUGFS_ADD(force_unicast_rateidx, sta);
  145. DEBUGFS_ADD(max_ratectrl_rateidx, sta);
  146. DEBUGFS_ADD(bssid, sta);
  147. DEBUGFS_ADD(aid, sta);
  148. DEBUGFS_ADD(capab, sta);
  149. }
  150. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  151. {
  152. DEBUGFS_ADD(drop_unencrypted, ap);
  153. DEBUGFS_ADD(force_unicast_rateidx, ap);
  154. DEBUGFS_ADD(max_ratectrl_rateidx, ap);
  155. DEBUGFS_ADD(num_sta_ps, ap);
  156. DEBUGFS_ADD(dtim_count, ap);
  157. DEBUGFS_ADD(num_buffered_multicast, ap);
  158. }
  159. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  160. {
  161. DEBUGFS_ADD(drop_unencrypted, wds);
  162. DEBUGFS_ADD(force_unicast_rateidx, wds);
  163. DEBUGFS_ADD(max_ratectrl_rateidx, wds);
  164. DEBUGFS_ADD(peer, wds);
  165. }
  166. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  167. {
  168. DEBUGFS_ADD(drop_unencrypted, vlan);
  169. DEBUGFS_ADD(force_unicast_rateidx, vlan);
  170. DEBUGFS_ADD(max_ratectrl_rateidx, vlan);
  171. }
  172. static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
  173. {
  174. }
  175. #ifdef CONFIG_MAC80211_MESH
  176. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  177. {
  178. struct dentry *dir = debugfs_create_dir("mesh_stats",
  179. sdata->debugfs.dir);
  180. #define MESHSTATS_ADD(name)\
  181. debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
  182. MESHSTATS_ADD(fwded_mcast);
  183. MESHSTATS_ADD(fwded_unicast);
  184. MESHSTATS_ADD(fwded_frames);
  185. MESHSTATS_ADD(dropped_frames_ttl);
  186. MESHSTATS_ADD(dropped_frames_no_route);
  187. MESHSTATS_ADD(estab_plinks);
  188. #undef MESHSTATS_ADD
  189. }
  190. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  191. {
  192. struct dentry *dir = debugfs_create_dir("mesh_config",
  193. sdata->debugfs.dir);
  194. #define MESHPARAMS_ADD(name) \
  195. debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
  196. MESHPARAMS_ADD(dot11MeshMaxRetries);
  197. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  198. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  199. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  200. MESHPARAMS_ADD(dot11MeshTTL);
  201. MESHPARAMS_ADD(auto_open_plinks);
  202. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  203. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  204. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  205. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  206. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  207. MESHPARAMS_ADD(path_refresh_time);
  208. MESHPARAMS_ADD(min_discovery_timeout);
  209. #undef MESHPARAMS_ADD
  210. }
  211. #endif
  212. static void add_files(struct ieee80211_sub_if_data *sdata)
  213. {
  214. if (!sdata->debugfs.dir)
  215. return;
  216. switch (sdata->vif.type) {
  217. case NL80211_IFTYPE_MESH_POINT:
  218. #ifdef CONFIG_MAC80211_MESH
  219. add_mesh_stats(sdata);
  220. add_mesh_config(sdata);
  221. #endif
  222. break;
  223. case NL80211_IFTYPE_STATION:
  224. add_sta_files(sdata);
  225. break;
  226. case NL80211_IFTYPE_ADHOC:
  227. /* XXX */
  228. break;
  229. case NL80211_IFTYPE_AP:
  230. add_ap_files(sdata);
  231. break;
  232. case NL80211_IFTYPE_WDS:
  233. add_wds_files(sdata);
  234. break;
  235. case NL80211_IFTYPE_MONITOR:
  236. add_monitor_files(sdata);
  237. break;
  238. case NL80211_IFTYPE_AP_VLAN:
  239. add_vlan_files(sdata);
  240. break;
  241. default:
  242. break;
  243. }
  244. }
  245. static int notif_registered;
  246. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  247. {
  248. char buf[10+IFNAMSIZ];
  249. if (!notif_registered)
  250. return;
  251. sprintf(buf, "netdev:%s", sdata->dev->name);
  252. sdata->debugfs.dir = debugfs_create_dir(buf,
  253. sdata->local->hw.wiphy->debugfsdir);
  254. add_files(sdata);
  255. }
  256. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  257. {
  258. if (!sdata->debugfs.dir)
  259. return;
  260. debugfs_remove_recursive(sdata->debugfs.dir);
  261. sdata->debugfs.dir = NULL;
  262. }
  263. static int netdev_notify(struct notifier_block *nb,
  264. unsigned long state,
  265. void *ndev)
  266. {
  267. struct net_device *dev = ndev;
  268. struct dentry *dir;
  269. struct ieee80211_sub_if_data *sdata;
  270. char buf[10+IFNAMSIZ];
  271. if (state != NETDEV_CHANGENAME)
  272. return 0;
  273. if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
  274. return 0;
  275. if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
  276. return 0;
  277. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  278. dir = sdata->debugfs.dir;
  279. if (!dir)
  280. return 0;
  281. sprintf(buf, "netdev:%s", dev->name);
  282. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  283. printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
  284. "dir to %s\n", buf);
  285. return 0;
  286. }
  287. static struct notifier_block mac80211_debugfs_netdev_notifier = {
  288. .notifier_call = netdev_notify,
  289. };
  290. void ieee80211_debugfs_netdev_init(void)
  291. {
  292. int err;
  293. err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  294. if (err) {
  295. printk(KERN_ERR
  296. "mac80211: failed to install netdev notifier,"
  297. " disabling per-netdev debugfs!\n");
  298. } else
  299. notif_registered = 1;
  300. }
  301. void ieee80211_debugfs_netdev_exit(void)
  302. {
  303. unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
  304. notif_registered = 0;
  305. }