debugfs_netdev.c 21 KB

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