debugfs_netdev.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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[200];
  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[NL80211_BAND_2GHZ],
  150. HEX);
  151. IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[NL80211_BAND_5GHZ],
  152. HEX);
  153. IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz,
  154. rc_rateidx_mcs_mask[NL80211_BAND_2GHZ], HEXARRAY);
  155. IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz,
  156. rc_rateidx_mcs_mask[NL80211_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[NL80211_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[NL80211_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. static ssize_t ieee80211_if_fmt_aqm(
  406. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  407. {
  408. struct ieee80211_local *local = sdata->local;
  409. struct txq_info *txqi = to_txq_info(sdata->vif.txq);
  410. int len;
  411. spin_lock_bh(&local->fq.lock);
  412. rcu_read_lock();
  413. len = scnprintf(buf,
  414. buflen,
  415. "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
  416. "%u %u %u %u %u %u %u %u %u %u\n",
  417. txqi->txq.ac,
  418. txqi->tin.backlog_bytes,
  419. txqi->tin.backlog_packets,
  420. txqi->tin.flows,
  421. txqi->cstats.drop_count,
  422. txqi->cstats.ecn_mark,
  423. txqi->tin.overlimit,
  424. txqi->tin.collisions,
  425. txqi->tin.tx_bytes,
  426. txqi->tin.tx_packets);
  427. rcu_read_unlock();
  428. spin_unlock_bh(&local->fq.lock);
  429. return len;
  430. }
  431. IEEE80211_IF_FILE_R(aqm);
  432. /* IBSS attributes */
  433. static ssize_t ieee80211_if_fmt_tsf(
  434. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  435. {
  436. struct ieee80211_local *local = sdata->local;
  437. u64 tsf;
  438. tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
  439. return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
  440. }
  441. static ssize_t ieee80211_if_parse_tsf(
  442. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  443. {
  444. struct ieee80211_local *local = sdata->local;
  445. unsigned long long tsf;
  446. int ret;
  447. int tsf_is_delta = 0;
  448. if (strncmp(buf, "reset", 5) == 0) {
  449. if (local->ops->reset_tsf) {
  450. drv_reset_tsf(local, sdata);
  451. wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
  452. }
  453. } else {
  454. if (buflen > 10 && buf[1] == '=') {
  455. if (buf[0] == '+')
  456. tsf_is_delta = 1;
  457. else if (buf[0] == '-')
  458. tsf_is_delta = -1;
  459. else
  460. return -EINVAL;
  461. buf += 2;
  462. }
  463. ret = kstrtoull(buf, 10, &tsf);
  464. if (ret < 0)
  465. return ret;
  466. if (tsf_is_delta && local->ops->offset_tsf) {
  467. drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
  468. wiphy_info(local->hw.wiphy,
  469. "debugfs offset TSF by %018lld\n",
  470. tsf_is_delta * tsf);
  471. } else if (local->ops->set_tsf) {
  472. if (tsf_is_delta)
  473. tsf = drv_get_tsf(local, sdata) +
  474. tsf_is_delta * tsf;
  475. drv_set_tsf(local, sdata, tsf);
  476. wiphy_info(local->hw.wiphy,
  477. "debugfs set TSF to %#018llx\n", tsf);
  478. }
  479. }
  480. ieee80211_recalc_dtim(local, sdata);
  481. return buflen;
  482. }
  483. IEEE80211_IF_FILE_RW(tsf);
  484. /* WDS attributes */
  485. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  486. #ifdef CONFIG_MAC80211_MESH
  487. IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
  488. /* Mesh stats attributes */
  489. IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
  490. IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
  491. IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
  492. IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
  493. IEEE80211_IF_FILE(dropped_frames_congestion,
  494. u.mesh.mshstats.dropped_frames_congestion, DEC);
  495. IEEE80211_IF_FILE(dropped_frames_no_route,
  496. u.mesh.mshstats.dropped_frames_no_route, DEC);
  497. /* Mesh parameters */
  498. IEEE80211_IF_FILE(dot11MeshMaxRetries,
  499. u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
  500. IEEE80211_IF_FILE(dot11MeshRetryTimeout,
  501. u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
  502. IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
  503. u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
  504. IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
  505. u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
  506. IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
  507. IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
  508. IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
  509. IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
  510. u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
  511. IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
  512. u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
  513. IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
  514. u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
  515. IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
  516. u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
  517. IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
  518. u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
  519. IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
  520. u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
  521. IEEE80211_IF_FILE(path_refresh_time,
  522. u.mesh.mshcfg.path_refresh_time, DEC);
  523. IEEE80211_IF_FILE(min_discovery_timeout,
  524. u.mesh.mshcfg.min_discovery_timeout, DEC);
  525. IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
  526. u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
  527. IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
  528. u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
  529. IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
  530. u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
  531. IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
  532. IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
  533. IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
  534. IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
  535. u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
  536. IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
  537. u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
  538. IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
  539. u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
  540. IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
  541. IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
  542. u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
  543. #endif
  544. #define DEBUGFS_ADD_MODE(name, mode) \
  545. debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
  546. sdata, &name##_ops);
  547. #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
  548. static void add_common_files(struct ieee80211_sub_if_data *sdata)
  549. {
  550. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  551. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  552. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  553. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  554. DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
  555. DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
  556. DEBUGFS_ADD(hw_queues);
  557. if (sdata->local->ops->wake_tx_queue)
  558. DEBUGFS_ADD(aqm);
  559. }
  560. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  561. {
  562. DEBUGFS_ADD(bssid);
  563. DEBUGFS_ADD(aid);
  564. DEBUGFS_ADD(beacon_timeout);
  565. DEBUGFS_ADD_MODE(smps, 0600);
  566. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  567. DEBUGFS_ADD_MODE(beacon_loss, 0200);
  568. DEBUGFS_ADD_MODE(uapsd_queues, 0600);
  569. DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
  570. DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
  571. }
  572. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  573. {
  574. DEBUGFS_ADD(num_mcast_sta);
  575. DEBUGFS_ADD_MODE(smps, 0600);
  576. DEBUGFS_ADD(num_sta_ps);
  577. DEBUGFS_ADD(dtim_count);
  578. DEBUGFS_ADD(num_buffered_multicast);
  579. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  580. }
  581. static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
  582. {
  583. DEBUGFS_ADD_MODE(tsf, 0600);
  584. }
  585. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  586. {
  587. DEBUGFS_ADD(peer);
  588. }
  589. #ifdef CONFIG_MAC80211_MESH
  590. static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
  591. {
  592. DEBUGFS_ADD_MODE(tsf, 0600);
  593. DEBUGFS_ADD_MODE(estab_plinks, 0400);
  594. }
  595. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  596. {
  597. struct dentry *dir = debugfs_create_dir("mesh_stats",
  598. sdata->vif.debugfs_dir);
  599. #define MESHSTATS_ADD(name)\
  600. debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
  601. MESHSTATS_ADD(fwded_mcast);
  602. MESHSTATS_ADD(fwded_unicast);
  603. MESHSTATS_ADD(fwded_frames);
  604. MESHSTATS_ADD(dropped_frames_ttl);
  605. MESHSTATS_ADD(dropped_frames_no_route);
  606. MESHSTATS_ADD(dropped_frames_congestion);
  607. #undef MESHSTATS_ADD
  608. }
  609. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  610. {
  611. struct dentry *dir = debugfs_create_dir("mesh_config",
  612. sdata->vif.debugfs_dir);
  613. #define MESHPARAMS_ADD(name) \
  614. debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
  615. MESHPARAMS_ADD(dot11MeshMaxRetries);
  616. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  617. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  618. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  619. MESHPARAMS_ADD(dot11MeshTTL);
  620. MESHPARAMS_ADD(element_ttl);
  621. MESHPARAMS_ADD(auto_open_plinks);
  622. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  623. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  624. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  625. MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
  626. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  627. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  628. MESHPARAMS_ADD(path_refresh_time);
  629. MESHPARAMS_ADD(min_discovery_timeout);
  630. MESHPARAMS_ADD(dot11MeshHWMPRootMode);
  631. MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
  632. MESHPARAMS_ADD(dot11MeshForwarding);
  633. MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
  634. MESHPARAMS_ADD(rssi_threshold);
  635. MESHPARAMS_ADD(ht_opmode);
  636. MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
  637. MESHPARAMS_ADD(dot11MeshHWMProotInterval);
  638. MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
  639. MESHPARAMS_ADD(power_mode);
  640. MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
  641. #undef MESHPARAMS_ADD
  642. }
  643. #endif
  644. static void add_files(struct ieee80211_sub_if_data *sdata)
  645. {
  646. if (!sdata->vif.debugfs_dir)
  647. return;
  648. DEBUGFS_ADD(flags);
  649. DEBUGFS_ADD(state);
  650. DEBUGFS_ADD(txpower);
  651. DEBUGFS_ADD(user_power_level);
  652. DEBUGFS_ADD(ap_power_level);
  653. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  654. add_common_files(sdata);
  655. switch (sdata->vif.type) {
  656. case NL80211_IFTYPE_MESH_POINT:
  657. #ifdef CONFIG_MAC80211_MESH
  658. add_mesh_files(sdata);
  659. add_mesh_stats(sdata);
  660. add_mesh_config(sdata);
  661. #endif
  662. break;
  663. case NL80211_IFTYPE_STATION:
  664. add_sta_files(sdata);
  665. break;
  666. case NL80211_IFTYPE_ADHOC:
  667. add_ibss_files(sdata);
  668. break;
  669. case NL80211_IFTYPE_AP:
  670. add_ap_files(sdata);
  671. break;
  672. case NL80211_IFTYPE_WDS:
  673. add_wds_files(sdata);
  674. break;
  675. default:
  676. break;
  677. }
  678. }
  679. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  680. {
  681. char buf[10+IFNAMSIZ];
  682. sprintf(buf, "netdev:%s", sdata->name);
  683. sdata->vif.debugfs_dir = debugfs_create_dir(buf,
  684. sdata->local->hw.wiphy->debugfsdir);
  685. if (sdata->vif.debugfs_dir)
  686. sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
  687. sdata->vif.debugfs_dir);
  688. add_files(sdata);
  689. }
  690. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  691. {
  692. if (!sdata->vif.debugfs_dir)
  693. return;
  694. debugfs_remove_recursive(sdata->vif.debugfs_dir);
  695. sdata->vif.debugfs_dir = NULL;
  696. sdata->debugfs.subdir_stations = NULL;
  697. }
  698. void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
  699. {
  700. struct dentry *dir;
  701. char buf[10 + IFNAMSIZ];
  702. dir = sdata->vif.debugfs_dir;
  703. if (!dir)
  704. return;
  705. sprintf(buf, "netdev:%s", sdata->name);
  706. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  707. sdata_err(sdata,
  708. "debugfs: failed to rename debugfs dir to %s\n",
  709. buf);
  710. }