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