debugfs_netdev.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  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 = skb_put_zero(skb, 24);
  281. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  282. switch (sdata->vif.type) {
  283. case NL80211_IFTYPE_AP:
  284. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  285. /* DA BSSID SA */
  286. memcpy(hdr->addr1, addr, ETH_ALEN);
  287. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  288. memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN);
  289. break;
  290. case NL80211_IFTYPE_STATION:
  291. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  292. /* BSSID SA DA */
  293. sdata_lock(sdata);
  294. if (!sdata->u.mgd.associated) {
  295. sdata_unlock(sdata);
  296. dev_kfree_skb(skb);
  297. return -ENOTCONN;
  298. }
  299. memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN);
  300. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  301. memcpy(hdr->addr3, addr, ETH_ALEN);
  302. sdata_unlock(sdata);
  303. break;
  304. default:
  305. dev_kfree_skb(skb);
  306. return -EOPNOTSUPP;
  307. }
  308. hdr->frame_control = fc;
  309. /*
  310. * Add some length to the test frame to make it look bit more valid.
  311. * The exact contents does not matter since the recipient is required
  312. * to drop this because of the Michael MIC failure.
  313. */
  314. skb_put_zero(skb, 50);
  315. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE;
  316. ieee80211_tx_skb(sdata, skb);
  317. return buflen;
  318. }
  319. IEEE80211_IF_FILE_W(tkip_mic_test);
  320. static ssize_t ieee80211_if_parse_beacon_loss(
  321. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  322. {
  323. if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc)
  324. return -ENOTCONN;
  325. ieee80211_beacon_loss(&sdata->vif);
  326. return buflen;
  327. }
  328. IEEE80211_IF_FILE_W(beacon_loss);
  329. static ssize_t ieee80211_if_fmt_uapsd_queues(
  330. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  331. {
  332. const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  333. return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues);
  334. }
  335. static ssize_t ieee80211_if_parse_uapsd_queues(
  336. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  337. {
  338. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  339. u8 val;
  340. int ret;
  341. ret = kstrtou8(buf, 0, &val);
  342. if (ret)
  343. return ret;
  344. if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
  345. return -ERANGE;
  346. ifmgd->uapsd_queues = val;
  347. return buflen;
  348. }
  349. IEEE80211_IF_FILE_RW(uapsd_queues);
  350. static ssize_t ieee80211_if_fmt_uapsd_max_sp_len(
  351. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  352. {
  353. const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  354. return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len);
  355. }
  356. static ssize_t ieee80211_if_parse_uapsd_max_sp_len(
  357. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  358. {
  359. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  360. unsigned long val;
  361. int ret;
  362. ret = kstrtoul(buf, 0, &val);
  363. if (ret)
  364. return -EINVAL;
  365. if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
  366. return -ERANGE;
  367. ifmgd->uapsd_max_sp_len = val;
  368. return buflen;
  369. }
  370. IEEE80211_IF_FILE_RW(uapsd_max_sp_len);
  371. static ssize_t ieee80211_if_fmt_tdls_wider_bw(
  372. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  373. {
  374. const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  375. bool tdls_wider_bw;
  376. tdls_wider_bw = ieee80211_hw_check(&sdata->local->hw, TDLS_WIDER_BW) &&
  377. !ifmgd->tdls_wider_bw_prohibited;
  378. return snprintf(buf, buflen, "%d\n", tdls_wider_bw);
  379. }
  380. static ssize_t ieee80211_if_parse_tdls_wider_bw(
  381. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  382. {
  383. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  384. u8 val;
  385. int ret;
  386. ret = kstrtou8(buf, 0, &val);
  387. if (ret)
  388. return ret;
  389. ifmgd->tdls_wider_bw_prohibited = !val;
  390. return buflen;
  391. }
  392. IEEE80211_IF_FILE_RW(tdls_wider_bw);
  393. /* AP attributes */
  394. IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC);
  395. IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC);
  396. IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC);
  397. IEEE80211_IF_FILE(num_mcast_sta_vlan, u.vlan.num_mcast_sta, ATOMIC);
  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;
  410. int len;
  411. if (!sdata->vif.txq)
  412. return 0;
  413. txqi = to_txq_info(sdata->vif.txq);
  414. spin_lock_bh(&local->fq.lock);
  415. rcu_read_lock();
  416. len = scnprintf(buf,
  417. buflen,
  418. "ac backlog-bytes backlog-packets new-flows drops marks overlimit collisions tx-bytes tx-packets\n"
  419. "%u %u %u %u %u %u %u %u %u %u\n",
  420. txqi->txq.ac,
  421. txqi->tin.backlog_bytes,
  422. txqi->tin.backlog_packets,
  423. txqi->tin.flows,
  424. txqi->cstats.drop_count,
  425. txqi->cstats.ecn_mark,
  426. txqi->tin.overlimit,
  427. txqi->tin.collisions,
  428. txqi->tin.tx_bytes,
  429. txqi->tin.tx_packets);
  430. rcu_read_unlock();
  431. spin_unlock_bh(&local->fq.lock);
  432. return len;
  433. }
  434. IEEE80211_IF_FILE_R(aqm);
  435. IEEE80211_IF_FILE(multicast_to_unicast, u.ap.multicast_to_unicast, HEX);
  436. /* IBSS attributes */
  437. static ssize_t ieee80211_if_fmt_tsf(
  438. const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
  439. {
  440. struct ieee80211_local *local = sdata->local;
  441. u64 tsf;
  442. tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata);
  443. return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf);
  444. }
  445. static ssize_t ieee80211_if_parse_tsf(
  446. struct ieee80211_sub_if_data *sdata, const char *buf, int buflen)
  447. {
  448. struct ieee80211_local *local = sdata->local;
  449. unsigned long long tsf;
  450. int ret;
  451. int tsf_is_delta = 0;
  452. if (strncmp(buf, "reset", 5) == 0) {
  453. if (local->ops->reset_tsf) {
  454. drv_reset_tsf(local, sdata);
  455. wiphy_info(local->hw.wiphy, "debugfs reset TSF\n");
  456. }
  457. } else {
  458. if (buflen > 10 && buf[1] == '=') {
  459. if (buf[0] == '+')
  460. tsf_is_delta = 1;
  461. else if (buf[0] == '-')
  462. tsf_is_delta = -1;
  463. else
  464. return -EINVAL;
  465. buf += 2;
  466. }
  467. ret = kstrtoull(buf, 10, &tsf);
  468. if (ret < 0)
  469. return ret;
  470. if (tsf_is_delta && local->ops->offset_tsf) {
  471. drv_offset_tsf(local, sdata, tsf_is_delta * tsf);
  472. wiphy_info(local->hw.wiphy,
  473. "debugfs offset TSF by %018lld\n",
  474. tsf_is_delta * tsf);
  475. } else if (local->ops->set_tsf) {
  476. if (tsf_is_delta)
  477. tsf = drv_get_tsf(local, sdata) +
  478. tsf_is_delta * tsf;
  479. drv_set_tsf(local, sdata, tsf);
  480. wiphy_info(local->hw.wiphy,
  481. "debugfs set TSF to %#018llx\n", tsf);
  482. }
  483. }
  484. ieee80211_recalc_dtim(local, sdata);
  485. return buflen;
  486. }
  487. IEEE80211_IF_FILE_RW(tsf);
  488. /* WDS attributes */
  489. IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
  490. #ifdef CONFIG_MAC80211_MESH
  491. IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC);
  492. /* Mesh stats attributes */
  493. IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC);
  494. IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC);
  495. IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC);
  496. IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC);
  497. IEEE80211_IF_FILE(dropped_frames_congestion,
  498. u.mesh.mshstats.dropped_frames_congestion, DEC);
  499. IEEE80211_IF_FILE(dropped_frames_no_route,
  500. u.mesh.mshstats.dropped_frames_no_route, DEC);
  501. /* Mesh parameters */
  502. IEEE80211_IF_FILE(dot11MeshMaxRetries,
  503. u.mesh.mshcfg.dot11MeshMaxRetries, DEC);
  504. IEEE80211_IF_FILE(dot11MeshRetryTimeout,
  505. u.mesh.mshcfg.dot11MeshRetryTimeout, DEC);
  506. IEEE80211_IF_FILE(dot11MeshConfirmTimeout,
  507. u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC);
  508. IEEE80211_IF_FILE(dot11MeshHoldingTimeout,
  509. u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC);
  510. IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC);
  511. IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC);
  512. IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC);
  513. IEEE80211_IF_FILE(dot11MeshMaxPeerLinks,
  514. u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC);
  515. IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout,
  516. u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC);
  517. IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval,
  518. u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC);
  519. IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval,
  520. u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC);
  521. IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime,
  522. u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC);
  523. IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries,
  524. u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC);
  525. IEEE80211_IF_FILE(path_refresh_time,
  526. u.mesh.mshcfg.path_refresh_time, DEC);
  527. IEEE80211_IF_FILE(min_discovery_timeout,
  528. u.mesh.mshcfg.min_discovery_timeout, DEC);
  529. IEEE80211_IF_FILE(dot11MeshHWMPRootMode,
  530. u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC);
  531. IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol,
  532. u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC);
  533. IEEE80211_IF_FILE(dot11MeshHWMPRannInterval,
  534. u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC);
  535. IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC);
  536. IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC);
  537. IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC);
  538. IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout,
  539. u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC);
  540. IEEE80211_IF_FILE(dot11MeshHWMProotInterval,
  541. u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC);
  542. IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval,
  543. u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC);
  544. IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC);
  545. IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration,
  546. u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC);
  547. #endif
  548. #define DEBUGFS_ADD_MODE(name, mode) \
  549. debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \
  550. sdata, &name##_ops);
  551. #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400)
  552. static void add_common_files(struct ieee80211_sub_if_data *sdata)
  553. {
  554. DEBUGFS_ADD(rc_rateidx_mask_2ghz);
  555. DEBUGFS_ADD(rc_rateidx_mask_5ghz);
  556. DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz);
  557. DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz);
  558. DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_2ghz);
  559. DEBUGFS_ADD(rc_rateidx_vht_mcs_mask_5ghz);
  560. DEBUGFS_ADD(hw_queues);
  561. if (sdata->local->ops->wake_tx_queue &&
  562. sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
  563. sdata->vif.type != NL80211_IFTYPE_NAN)
  564. DEBUGFS_ADD(aqm);
  565. }
  566. static void add_sta_files(struct ieee80211_sub_if_data *sdata)
  567. {
  568. DEBUGFS_ADD(bssid);
  569. DEBUGFS_ADD(aid);
  570. DEBUGFS_ADD(beacon_timeout);
  571. DEBUGFS_ADD_MODE(smps, 0600);
  572. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  573. DEBUGFS_ADD_MODE(beacon_loss, 0200);
  574. DEBUGFS_ADD_MODE(uapsd_queues, 0600);
  575. DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600);
  576. DEBUGFS_ADD_MODE(tdls_wider_bw, 0600);
  577. }
  578. static void add_ap_files(struct ieee80211_sub_if_data *sdata)
  579. {
  580. DEBUGFS_ADD(num_mcast_sta);
  581. DEBUGFS_ADD_MODE(smps, 0600);
  582. DEBUGFS_ADD(num_sta_ps);
  583. DEBUGFS_ADD(dtim_count);
  584. DEBUGFS_ADD(num_buffered_multicast);
  585. DEBUGFS_ADD_MODE(tkip_mic_test, 0200);
  586. DEBUGFS_ADD_MODE(multicast_to_unicast, 0600);
  587. }
  588. static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
  589. {
  590. /* add num_mcast_sta_vlan using name num_mcast_sta */
  591. debugfs_create_file("num_mcast_sta", 0400, sdata->vif.debugfs_dir,
  592. sdata, &num_mcast_sta_vlan_ops);
  593. }
  594. static void add_ibss_files(struct ieee80211_sub_if_data *sdata)
  595. {
  596. DEBUGFS_ADD_MODE(tsf, 0600);
  597. }
  598. static void add_wds_files(struct ieee80211_sub_if_data *sdata)
  599. {
  600. DEBUGFS_ADD(peer);
  601. }
  602. #ifdef CONFIG_MAC80211_MESH
  603. static void add_mesh_files(struct ieee80211_sub_if_data *sdata)
  604. {
  605. DEBUGFS_ADD_MODE(tsf, 0600);
  606. DEBUGFS_ADD_MODE(estab_plinks, 0400);
  607. }
  608. static void add_mesh_stats(struct ieee80211_sub_if_data *sdata)
  609. {
  610. struct dentry *dir = debugfs_create_dir("mesh_stats",
  611. sdata->vif.debugfs_dir);
  612. #define MESHSTATS_ADD(name)\
  613. debugfs_create_file(#name, 0400, dir, sdata, &name##_ops);
  614. MESHSTATS_ADD(fwded_mcast);
  615. MESHSTATS_ADD(fwded_unicast);
  616. MESHSTATS_ADD(fwded_frames);
  617. MESHSTATS_ADD(dropped_frames_ttl);
  618. MESHSTATS_ADD(dropped_frames_no_route);
  619. MESHSTATS_ADD(dropped_frames_congestion);
  620. #undef MESHSTATS_ADD
  621. }
  622. static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
  623. {
  624. struct dentry *dir = debugfs_create_dir("mesh_config",
  625. sdata->vif.debugfs_dir);
  626. #define MESHPARAMS_ADD(name) \
  627. debugfs_create_file(#name, 0600, dir, sdata, &name##_ops);
  628. MESHPARAMS_ADD(dot11MeshMaxRetries);
  629. MESHPARAMS_ADD(dot11MeshRetryTimeout);
  630. MESHPARAMS_ADD(dot11MeshConfirmTimeout);
  631. MESHPARAMS_ADD(dot11MeshHoldingTimeout);
  632. MESHPARAMS_ADD(dot11MeshTTL);
  633. MESHPARAMS_ADD(element_ttl);
  634. MESHPARAMS_ADD(auto_open_plinks);
  635. MESHPARAMS_ADD(dot11MeshMaxPeerLinks);
  636. MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout);
  637. MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval);
  638. MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval);
  639. MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime);
  640. MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries);
  641. MESHPARAMS_ADD(path_refresh_time);
  642. MESHPARAMS_ADD(min_discovery_timeout);
  643. MESHPARAMS_ADD(dot11MeshHWMPRootMode);
  644. MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
  645. MESHPARAMS_ADD(dot11MeshForwarding);
  646. MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
  647. MESHPARAMS_ADD(rssi_threshold);
  648. MESHPARAMS_ADD(ht_opmode);
  649. MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout);
  650. MESHPARAMS_ADD(dot11MeshHWMProotInterval);
  651. MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval);
  652. MESHPARAMS_ADD(power_mode);
  653. MESHPARAMS_ADD(dot11MeshAwakeWindowDuration);
  654. #undef MESHPARAMS_ADD
  655. }
  656. #endif
  657. static void add_files(struct ieee80211_sub_if_data *sdata)
  658. {
  659. if (!sdata->vif.debugfs_dir)
  660. return;
  661. DEBUGFS_ADD(flags);
  662. DEBUGFS_ADD(state);
  663. DEBUGFS_ADD(txpower);
  664. DEBUGFS_ADD(user_power_level);
  665. DEBUGFS_ADD(ap_power_level);
  666. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  667. add_common_files(sdata);
  668. switch (sdata->vif.type) {
  669. case NL80211_IFTYPE_MESH_POINT:
  670. #ifdef CONFIG_MAC80211_MESH
  671. add_mesh_files(sdata);
  672. add_mesh_stats(sdata);
  673. add_mesh_config(sdata);
  674. #endif
  675. break;
  676. case NL80211_IFTYPE_STATION:
  677. add_sta_files(sdata);
  678. break;
  679. case NL80211_IFTYPE_ADHOC:
  680. add_ibss_files(sdata);
  681. break;
  682. case NL80211_IFTYPE_AP:
  683. add_ap_files(sdata);
  684. break;
  685. case NL80211_IFTYPE_AP_VLAN:
  686. add_vlan_files(sdata);
  687. break;
  688. case NL80211_IFTYPE_WDS:
  689. add_wds_files(sdata);
  690. break;
  691. default:
  692. break;
  693. }
  694. }
  695. void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
  696. {
  697. char buf[10+IFNAMSIZ];
  698. sprintf(buf, "netdev:%s", sdata->name);
  699. sdata->vif.debugfs_dir = debugfs_create_dir(buf,
  700. sdata->local->hw.wiphy->debugfsdir);
  701. if (sdata->vif.debugfs_dir)
  702. sdata->debugfs.subdir_stations = debugfs_create_dir("stations",
  703. sdata->vif.debugfs_dir);
  704. add_files(sdata);
  705. }
  706. void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
  707. {
  708. if (!sdata->vif.debugfs_dir)
  709. return;
  710. debugfs_remove_recursive(sdata->vif.debugfs_dir);
  711. sdata->vif.debugfs_dir = NULL;
  712. sdata->debugfs.subdir_stations = NULL;
  713. }
  714. void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
  715. {
  716. struct dentry *dir;
  717. char buf[10 + IFNAMSIZ];
  718. dir = sdata->vif.debugfs_dir;
  719. if (IS_ERR_OR_NULL(dir))
  720. return;
  721. sprintf(buf, "netdev:%s", sdata->name);
  722. if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
  723. sdata_err(sdata,
  724. "debugfs: failed to rename debugfs dir to %s\n",
  725. buf);
  726. }