debugfs_netdev.c 23 KB

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