debugfs_netdev.c 17 KB

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