debugfs_netdev.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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/slab.h>
  16. #include <linux/notifier.h>
  17. #include <net/mac80211.h>
  18. #include <net/cfg80211.h>
  19. #include "ieee80211_i.h"
  20. #include "rate.h"
  21. #include "debugfs.h"
  22. #include "debugfs_netdev.h"
  23. #include "driver-ops.h"
  24. static ssize_t ieee80211_if_read(
  25. struct ieee80211_sub_if_data *sdata,
  26. char __user *userbuf,
  27. size_t count, loff_t *ppos,
  28. ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
  29. {
  30. char buf[70];
  31. ssize_t ret = -EINVAL;
  32. read_lock(&dev_base_lock);
  33. ret = (*format)(sdata, buf, sizeof(buf));
  34. read_unlock(&dev_base_lock);
  35. if (ret >= 0)
  36. ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
  37. return ret;
  38. }
  39. static ssize_t ieee80211_if_write(
  40. struct ieee80211_sub_if_data *sdata,
  41. const char __user *userbuf,
  42. size_t count, loff_t *ppos,
  43. ssize_t (*write)(struct ieee80211_sub_if_data *, const char *, int))
  44. {
  45. char buf[64];
  46. ssize_t ret;
  47. if (count >= sizeof(buf))
  48. return -E2BIG;
  49. if (copy_from_user(buf, userbuf, count))
  50. return -EFAULT;
  51. buf[count] = '\0';
  52. ret = -ENODEV;
  53. rtnl_lock();
  54. ret = (*write)(sdata, buf, count);
  55. rtnl_unlock();
  56. return ret;
  57. }
  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_FMT_DEC(name, field) \
  66. IEEE80211_IF_FMT(name, field, "%d\n")
  67. #define IEEE80211_IF_FMT_HEX(name, field) \
  68. IEEE80211_IF_FMT(name, field, "%#x\n")
  69. #define IEEE80211_IF_FMT_LHEX(name, field) \
  70. IEEE80211_IF_FMT(name, field, "%#lx\n")
  71. #define IEEE80211_IF_FMT_SIZE(name, field) \
  72. IEEE80211_IF_FMT(name, field, "%zd\n")
  73. #define IEEE80211_IF_FMT_HEXARRAY(name, field) \
  74. static ssize_t ieee80211_if_fmt_##name( \
  75. const struct ieee80211_sub_if_data *sdata, \
  76. char *buf, int buflen) \
  77. { \
  78. char *p = buf; \
  79. int i; \
  80. for (i = 0; i < sizeof(sdata->field); i++) { \
  81. p += scnprintf(p, buflen + buf - p, "%.2x ", \
  82. sdata->field[i]); \
  83. } \
  84. p += scnprintf(p, buflen + buf - p, "\n"); \
  85. return p - buf; \
  86. }
  87. #define IEEE80211_IF_FMT_ATOMIC(name, field) \
  88. static ssize_t ieee80211_if_fmt_##name( \
  89. const struct ieee80211_sub_if_data *sdata, \
  90. char *buf, int buflen) \
  91. { \
  92. return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
  93. }
  94. #define IEEE80211_IF_FMT_MAC(name, field) \
  95. static ssize_t ieee80211_if_fmt_##name( \
  96. const struct ieee80211_sub_if_data *sdata, char *buf, \
  97. int buflen) \
  98. { \
  99. return scnprintf(buf, buflen, "%pM\n", sdata->field); \
  100. }
  101. #define IEEE80211_IF_FMT_DEC_DIV_16(name, field) \
  102. static ssize_t ieee80211_if_fmt_##name( \
  103. const struct ieee80211_sub_if_data *sdata, \
  104. char *buf, int buflen) \
  105. { \
  106. return scnprintf(buf, buflen, "%d\n", sdata->field / 16); \
  107. }
  108. #define __IEEE80211_IF_FILE(name, _write) \
  109. static ssize_t ieee80211_if_read_##name(struct file *file, \
  110. char __user *userbuf, \
  111. size_t count, loff_t *ppos) \
  112. { \
  113. return ieee80211_if_read(file->private_data, \
  114. userbuf, count, ppos, \
  115. ieee80211_if_fmt_##name); \
  116. } \
  117. static const struct file_operations name##_ops = { \
  118. .read = ieee80211_if_read_##name, \
  119. .write = (_write), \
  120. .open = simple_open, \
  121. .llseek = generic_file_llseek, \
  122. }
  123. #define __IEEE80211_IF_FILE_W(name) \
  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, userbuf, count, \
  129. ppos, ieee80211_if_parse_##name); \
  130. } \
  131. __IEEE80211_IF_FILE(name, ieee80211_if_write_##name)
  132. #define IEEE80211_IF_FILE(name, field, format) \
  133. IEEE80211_IF_FMT_##format(name, field) \
  134. __IEEE80211_IF_FILE(name, NULL)
  135. /* common attributes */
  136. IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
  137. IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[IEEE80211_BAND_2GHZ],
  138. HEX);
  139. IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[IEEE80211_BAND_5GHZ],
  140. HEX);
  141. IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
  142. rc_rateidx_mcs_mask[IEEE80211_BAND_2GHZ], HEXARRAY);
  143. IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
  144. rc_rateidx_mcs_mask[IEEE80211_BAND_5GHZ], HEXARRAY);
  145. IEEE80211_IF_FILE(flags, flags, HEX);
  146. IEEE80211_IF_FILE(state, state, LHEX);
  147. IEEE80211_IF_FILE(channel_type, vif.bss_conf.channel_type, DEC);
  148. /* STA attributes */
  149. IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC);
  150. IEEE80211_IF_FILE(aid, u.mgd.aid, DEC);
  151. IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC);
  152. IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16);
  153. static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata,
  154. enum ieee80211_smps_mode smps_mode)
  155. {
  156. struct ieee80211_local *local = sdata->local;
  157. int err;
  158. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_STATIC_SMPS) &&
  159. smps_mode == IEEE80211_SMPS_STATIC)
  160. return -EINVAL;
  161. /* auto should be dynamic if in PS mode */
  162. if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) &&
  163. (smps_mode == IEEE80211_SMPS_DYNAMIC ||
  164. smps_mode == IEEE80211_SMPS_AUTOMATIC))
  165. return -EINVAL;
  166. /* supported only on managed interfaces for now */
  167. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  168. return -EOPNOTSUPP;
  169. mutex_lock(&sdata->u.mgd.mtx);
  170. err = __ieee80211_request_smps(sdata, smps_mode);
  171. mutex_unlock(&sdata->u.mgd.mtx);
  172. return err;
  173. }
  174. static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = {
  175. [IEEE80211_SMPS_AUTOMATIC] = "auto",
  176. [IEEE80211_SMPS_OFF] = "off",
  177. [IEEE80211_SMPS_STATIC] = "static",
  178. [IEEE80211_SMPS_DYNAMIC] = "dynamic",
  179. };
  180. static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata,
  181. char *buf, int buflen)
  182. {
  183. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  184. return -EOPNOTSUPP;
  185. return snprintf(buf, buflen, "request: %s\nused: %s\n",
  186. smps_modes[sdata->u.mgd.req_smps],
  187. smps_modes[sdata->u.mgd.ap_smps]);
  188. }
  189. static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata,
  190. const char *buf, int buflen)
  191. {
  192. enum ieee80211_smps_mode mode;
  193. for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) {
  194. if (strncmp(buf, smps_modes[mode], buflen) == 0) {
  195. int err = ieee80211_set_smps(sdata, mode);
  196. if (!err)
  197. return buflen;
  198. return err;
  199. }
  200. }
  201. return -EINVAL;
  202. }
  203. __IEEE80211_IF_FILE_W(smps);
  204. static ssize_t ieee80211_if_fmt_tkip_mic_test(
  205. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  206. {
  207. return -EOPNOTSUPP;
  208. }
  209. static int hwaddr_aton(const char *txt, u8 *addr)
  210. {
  211. int i;
  212. for (i = 0; i < ETH_ALEN; i++) {
  213. int a, b;
  214. a = hex_to_bin(*txt++);
  215. if (a < 0)
  216. return -1;
  217. b = hex_to_bin(*txt++);
  218. if (b < 0)
  219. return -1;
  220. *addr++ = (a << 4) | b;
  221. if (i < 5 && *txt++ != ':')
  222. return -1;
  223. }
  224. return 0;
  225. }
  226. static ssize_t ieee80211_if_parse_tkip_mic_test(
  227. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  228. {
  229. struct ieee80211_local *local = sdata->local;
  230. u8 addr[ETH_ALEN];
  231. struct sk_buff *skb;
  232. struct ieee80211_hdr *hdr;
  233. __le16 fc;
  234. /*
  235. * Assume colon-delimited MAC address with possible white space
  236. * following.
  237. */
  238. if (buflen < 3 * ETH_ALEN - 1)
  239. return -EINVAL;
  240. if (hwaddr_aton(buf, addr) < 0)
  241. return -EINVAL;
  242. if (!ieee80211_sdata_running(sdata))
  243. return -ENOTCONN;
  244. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100);
  245. if (!skb)
  246. return -ENOMEM;
  247. skb_reserve(skb, local->hw.extra_tx_headroom);
  248. hdr = (struct ieee80211_hdr *) skb_put(skb, 24);
  249. memset(hdr, 0, 24);
  250. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  251. switch (sdata->vif.type) {
  252. case NL80211_IFTYPE_AP:
  253. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  254. /* DA BSSID SA */
  255. memcpy(hdr->addr1, addr, ETH_ALEN);
  256. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  257. memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
  258. break;
  259. case NL80211_IFTYPE_STATION:
  260. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  261. /* BSSID SA DA */
  262. if (sdata->vif.bss_conf.bssid == NULL) {
  263. dev_kfree_skb(skb);
  264. return -ENOTCONN;
  265. }
  266. memcpy(hdr->addr1, sdata->vif.bss_conf.bssid, ETH_ALEN);
  267. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  268. memcpy(hdr->addr3, addr, ETH_ALEN);
  269. break;
  270. default:
  271. dev_kfree_skb(skb);
  272. return -EOPNOTSUPP;
  273. }
  274. hdr->frame_control = fc;
  275. /*
  276. * Add some length to the test frame to make it look bit more valid.
  277. * The exact contents does not matter since the recipient is required
  278. * to drop this because of the Michael MIC failure.
  279. */
  280. memset(skb_put(skb, 50), 0, 50);
  281. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
  282. ieee80211_tx_skb(sdata, skb);
  283. return buflen;
  284. }
  285. __IEEE80211_IF_FILE_W(tkip_mic_test);
  286. static ssize_t ieee80211_if_fmt_uapsd_queues(
  287. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  288. {
  289. const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  290. return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
  291. }
  292. static ssize_t ieee80211_if_parse_uapsd_queues(
  293. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  294. {
  295. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  296. u8 val;
  297. int ret;
  298. ret = kstrtou8(buf, 0, &val);
  299. if (ret)
  300. return ret;
  301. if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  302. return -ERANGE;
  303. ifmgd->uapsd_queues = val;
  304. return buflen;
  305. }
  306. __IEEE80211_IF_FILE_W(uapsd_queues);
  307. static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
  308. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  309. {
  310. const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  311. return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
  312. }
  313. static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
  314. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  315. {
  316. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  317. unsigned long val;
  318. int ret;
  319. ret = kstrtoul(buf, 0, &val);
  320. if (ret)
  321. return -EINVAL;
  322. if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  323. return -ERANGE;
  324. ifmgd->uapsd_max_sp_len = val;
  325. return buflen;
  326. }
  327. __IEEE80211_IF_FILE_W(uapsd_max_sp_len);
  328. /* AP attributes */
  329. IEEE80211_IF_FILE(num_sta_authorized, u.ap.num_sta_authorized, ATOMIC);
  330. IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
  331. IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
  332. static ssize_t ieee80211_if_fmt_num_buffered_multicast(
  333. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  334. {
  335. return scnprintf(buf, buflen, "%u\n",
  336. skb_queue_len(&sdata->u.ap.ps_bc_buf));
  337. }
  338. __IEEE80211_IF_FILE(num_buffered_multicast, NULL);
  339. /* IBSS attributes */
  340. static ssize_t ieee80211_if_fmt_tsf(
  341. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  342. {
  343. struct ieee80211_local *local = sdata->local;
  344. u64 tsf;
  345. tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
  346. return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
  347. }
  348. static ssize_t ieee80211_if_parse_tsf(
  349. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  350. {
  351. struct ieee80211_local *local = sdata->local;
  352. unsigned long long tsf;
  353. int ret;
  354. if (strncmp(buf, "reset", 5) == 0) {
  355. if (local->ops->reset_tsf) {
  356. drv_reset_tsf(local, sdata);
  357. wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
  358. }
  359. } else {
  360. ret = kstrtoull(buf, 10, &tsf);
  361. if (ret < 0)
  362. return -EINVAL;
  363. if (local->ops->set_tsf) {
  364. drv_set_tsf(local, sdata, tsf);
  365. wiphy_info(local->hw.wiphy,
  366. "debugfs set TSF to %#018llx\n", tsf);
  367. }
  368. }
  369. return buflen;
  370. }
  371. __IEEE80211_IF_FILE_W(tsf);
  372. /* WDS attributes */
  373. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  374. #ifdef CONFIG_MAC80211_MESH
  375. /* Mesh stats attributes */
  376. IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
  377. IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
  378. IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
  379. IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
  380. IEEE80211_IF_FILE(dropped_frames_congestion,
  381. u.mesh.mshstats.dropped_frames_congestion, DEC);
  382. IEEE80211_IF_FILE(dropped_frames_no_route,
  383. u.mesh.mshstats.dropped_frames_no_route, DEC);
  384. IEEE80211_IF_FILE(estab_plinks, u.mesh.mshstats.estab_plinks, ATOMIC);
  385. /* Mesh parameters */
  386. IEEE80211_IF_FILE(dot11MeshMaxRetries,
  387. u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
  388. IEEE80211_IF_FILE(dot11MeshRetryTimeout,
  389. u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
  390. IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
  391. u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
  392. IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
  393. u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
  394. IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
  395. IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
  396. IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
  397. IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
  398. u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
  399. IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
  400. u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
  401. IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
  402. u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
  403. IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
  404. u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
  405. IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
  406. u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
  407. IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
  408. u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
  409. IEEE80211_IF_FILE(path_refresh_time,
  410. u.mesh.mshcfg.path_refresh_time, DEC);
  411. IEEE80211_IF_FILE(min_discovery_timeout,
  412. u.mesh.mshcfg.min_discovery_timeout, DEC);
  413. IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
  414. u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
  415. IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
  416. u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
  417. IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
  418. u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
  419. IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
  420. IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
  421. #endif
  422. #define DEBUGFS_ADD(name) \
  423. debugfs_create_file(#name, 0400, sdata->debugfs.dir, \
  424. sdata, &name##_ops);
  425. #define DEBUGFS_ADD_MODE(name, mode) \
  426. debugfs_create_file(#name, mode, sdata->debugfs.dir, \
  427. sdata, &name##_ops);
  428. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  429. {
  430. DEBUGFS_ADD(drop_unencrypted);
  431. DEBUGFS_ADD(flags);
  432. DEBUGFS_ADD(state);
  433. DEBUGFS_ADD(channel_type);
  434. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  435. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  436. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  437. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  438. DEBUGFS_ADD(bssid);
  439. DEBUGFS_ADD(aid);
  440. DEBUGFS_ADD(last_beacon);
  441. DEBUGFS_ADD(ave_beacon);
  442. DEBUGFS_ADD_MODE(smps, 0600);
  443. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  444. DEBUGFS_ADD_MODE(uapsd_queues, 0600);
  445. DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
  446. }
  447. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  448. {
  449. DEBUGFS_ADD(drop_unencrypted);
  450. DEBUGFS_ADD(flags);
  451. DEBUGFS_ADD(state);
  452. DEBUGFS_ADD(channel_type);
  453. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  454. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  455. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  456. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  457. DEBUGFS_ADD(num_sta_authorized);
  458. DEBUGFS_ADD(num_sta_ps);
  459. DEBUGFS_ADD(dtim_count);
  460. DEBUGFS_ADD(num_buffered_multicast);
  461. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  462. }
  463. static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
  464. {
  465. DEBUGFS_ADD(channel_type);
  466. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  467. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  468. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  469. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  470. DEBUGFS_ADD_MODE(tsf, 0600);
  471. }
  472. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  473. {
  474. DEBUGFS_ADD(drop_unencrypted);
  475. DEBUGFS_ADD(flags);
  476. DEBUGFS_ADD(state);
  477. DEBUGFS_ADD(channel_type);
  478. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  479. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  480. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  481. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  482. DEBUGFS_ADD(peer);
  483. }
  484. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  485. {
  486. DEBUGFS_ADD(drop_unencrypted);
  487. DEBUGFS_ADD(flags);
  488. DEBUGFS_ADD(state);
  489. DEBUGFS_ADD(channel_type);
  490. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  491. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  492. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  493. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  494. }
  495. static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
  496. {
  497. DEBUGFS_ADD(flags);
  498. DEBUGFS_ADD(state);
  499. DEBUGFS_ADD(channel_type);
  500. }
  501. #ifdef CONFIG_MAC80211_MESH
  502. static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
  503. {
  504. DEBUGFS_ADD_MODE(tsf, 0600);
  505. }
  506. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  507. {
  508. struct dentry *dir = debugfs_create_dir("mesh_stats",
  509. sdata->debugfs.dir);
  510. #define MESHSTATS_ADD(name)\
  511. debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
  512. MESHSTATS_ADD(fwded_mcast);
  513. MESHSTATS_ADD(fwded_unicast);
  514. MESHSTATS_ADD(fwded_frames);
  515. MESHSTATS_ADD(dropped_frames_ttl);
  516. MESHSTATS_ADD(dropped_frames_no_route);
  517. MESHSTATS_ADD(dropped_frames_congestion);
  518. MESHSTATS_ADD(estab_plinks);
  519. #undef MESHSTATS_ADD
  520. }
  521. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  522. {
  523. struct dentry *dir = debugfs_create_dir("mesh_config",
  524. sdata->debugfs.dir);
  525. #define MESHPARAMS_ADD(name) \
  526. debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
  527. MESHPARAMS_ADD(dot11MeshMaxRetries);
  528. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  529. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  530. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  531. MESHPARAMS_ADD(dot11MeshTTL);
  532. MESHPARAMS_ADD(element_ttl);
  533. MESHPARAMS_ADD(auto_open_plinks);
  534. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  535. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  536. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  537. MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
  538. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  539. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  540. MESHPARAMS_ADD(path_refresh_time);
  541. MESHPARAMS_ADD(min_discovery_timeout);
  542. MESHPARAMS_ADD(dot11MeshHWMPRootMode);
  543. MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
  544. MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
  545. MESHPARAMS_ADD(rssi_threshold);
  546. #undef MESHPARAMS_ADD
  547. }
  548. #endif
  549. static void add_files(struct ieee80211_sub_if_data *sdata)
  550. {
  551. if (!sdata->debugfs.dir)
  552. return;
  553. switch (sdata->vif.type) {
  554. case NL80211_IFTYPE_MESH_POINT:
  555. #ifdef CONFIG_MAC80211_MESH
  556. add_mesh_files(sdata);
  557. add_mesh_stats(sdata);
  558. add_mesh_config(sdata);
  559. #endif
  560. break;
  561. case NL80211_IFTYPE_STATION:
  562. add_sta_files(sdata);
  563. break;
  564. case NL80211_IFTYPE_ADHOC:
  565. add_ibss_files(sdata);
  566. break;
  567. case NL80211_IFTYPE_AP:
  568. add_ap_files(sdata);
  569. break;
  570. case NL80211_IFTYPE_WDS:
  571. add_wds_files(sdata);
  572. break;
  573. case NL80211_IFTYPE_MONITOR:
  574. add_monitor_files(sdata);
  575. break;
  576. case NL80211_IFTYPE_AP_VLAN:
  577. add_vlan_files(sdata);
  578. break;
  579. default:
  580. break;
  581. }
  582. }
  583. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  584. {
  585. char buf[10+IFNAMSIZ];
  586. sprintf(buf, "netdev:%s", sdata->name);
  587. sdata->debugfs.dir = debugfs_create_dir(buf,
  588. sdata->local->hw.wiphy->debugfsdir);
  589. if (sdata->debugfs.dir)
  590. sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
  591. sdata->debugfs.dir);
  592. add_files(sdata);
  593. }
  594. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  595. {
  596. if (!sdata->debugfs.dir)
  597. return;
  598. debugfs_remove_recursive(sdata->debugfs.dir);
  599. sdata->debugfs.dir = NULL;
  600. sdata->debugfs.subdir_stations = NULL;
  601. }
  602. void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
  603. {
  604. struct dentry *dir;
  605. char buf[10 + IFNAMSIZ];
  606. dir = sdata->debugfs.dir;
  607. if (!dir)
  608. return;
  609. sprintf(buf, "netdev:%s", sdata->name);
  610. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  611. printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
  612. "dir to %s\n", buf);
  613. }