Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 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> |
Johannes Berg | 28656a1 | 2012-11-05 20:24:38 +0100 | [diff] [blame] | 13 | #include <linux/if_ether.h> |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 18 | #include <linux/notifier.h> |
| 19 | #include <net/mac80211.h> |
| 20 | #include <net/cfg80211.h> |
| 21 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 22 | #include "rate.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 23 | #include "debugfs.h" |
| 24 | #include "debugfs_netdev.h" |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 25 | #include "driver-ops.h" |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 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); |
Arik Nemtsov | 923eaf3 | 2014-05-26 14:40:51 +0300 | [diff] [blame] | 37 | ret = (*format)(sdata, buf, sizeof(buf)); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 38 | read_unlock(&dev_base_lock); |
Luis Carlos Cobo | 73bb3e4 | 2008-03-31 15:10:22 -0700 | [diff] [blame] | 39 | |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 40 | if (ret >= 0) |
Luis Carlos Cobo | 73bb3e4 | 2008-03-31 15:10:22 -0700 | [diff] [blame] | 41 | ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret); |
| 42 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 43 | return ret; |
| 44 | } |
| 45 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 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 | { |
Eliad Peller | ada577c | 2012-03-14 16:15:02 +0200 | [diff] [blame] | 52 | char buf[64]; |
Eric Dumazet | 51f5f8c | 2010-03-10 17:13:36 +0100 | [diff] [blame] | 53 | ssize_t ret; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 54 | |
Eliad Peller | ada577c | 2012-03-14 16:15:02 +0200 | [diff] [blame] | 55 | if (count >= sizeof(buf)) |
| 56 | return -E2BIG; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 57 | |
| 58 | if (copy_from_user(buf, userbuf, count)) |
Eliad Peller | ada577c | 2012-03-14 16:15:02 +0200 | [diff] [blame] | 59 | return -EFAULT; |
| 60 | buf[count] = '\0'; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 61 | |
Eric Dumazet | 51f5f8c | 2010-03-10 17:13:36 +0100 | [diff] [blame] | 62 | ret = -ENODEV; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 63 | rtnl_lock(); |
Arik Nemtsov | 923eaf3 | 2014-05-26 14:40:51 +0300 | [diff] [blame] | 64 | ret = (*write)(sdata, buf, count); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 65 | rtnl_unlock(); |
| 66 | |
| 67 | return ret; |
| 68 | } |
| 69 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 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") |
Ben Greear | 4914b3b | 2011-01-27 22:09:34 -0800 | [diff] [blame] | 81 | #define IEEE80211_IF_FMT_LHEX(name, field) \ |
| 82 | IEEE80211_IF_FMT(name, field, "%#lx\n") |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 83 | #define IEEE80211_IF_FMT_SIZE(name, field) \ |
| 84 | IEEE80211_IF_FMT(name, field, "%zd\n") |
| 85 | |
Simon Wunderlich | 1946841 | 2012-01-28 17:25:33 +0100 | [diff] [blame] | 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 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 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 | { \ |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 114 | return scnprintf(buf, buflen, "%pM\n", sdata->field); \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 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 | |
Ben Greear | 78e443e | 2013-03-25 11:19:34 -0700 | [diff] [blame] | 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 | |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 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) \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 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); \ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 152 | #define _IEEE80211_IF_FILE_W_FN(name) \ |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 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); \ |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 159 | } |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 160 | |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 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) |
| 168 | |
| 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) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 174 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 175 | #define IEEE80211_IF_FILE(name, field, format) \ |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 176 | IEEE80211_IF_FMT_##format(name, field) \ |
| 177 | IEEE80211_IF_FILE_R(name) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 178 | |
| 179 | /* common attributes */ |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 180 | IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC); |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 181 | IEEE80211_IF_FILE(rc_rateidx_mask_2ghz, rc_rateidx_mask[IEEE80211_BAND_2GHZ], |
| 182 | HEX); |
| 183 | IEEE80211_IF_FILE(rc_rateidx_mask_5ghz, rc_rateidx_mask[IEEE80211_BAND_5GHZ], |
| 184 | HEX); |
Simon Wunderlich | 1946841 | 2012-01-28 17:25:33 +0100 | [diff] [blame] | 185 | IEEE80211_IF_FILE(rc_rateidx_mcs_mask_2ghz, |
| 186 | rc_rateidx_mcs_mask[IEEE80211_BAND_2GHZ], HEXARRAY); |
| 187 | IEEE80211_IF_FILE(rc_rateidx_mcs_mask_5ghz, |
| 188 | rc_rateidx_mcs_mask[IEEE80211_BAND_5GHZ], HEXARRAY); |
| 189 | |
Ben Greear | 4914b3b | 2011-01-27 22:09:34 -0800 | [diff] [blame] | 190 | IEEE80211_IF_FILE(flags, flags, HEX); |
| 191 | IEEE80211_IF_FILE(state, state, LHEX); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 192 | IEEE80211_IF_FILE(txpower, vif.bss_conf.txpower, DEC); |
| 193 | IEEE80211_IF_FILE(ap_power_level, ap_power_level, DEC); |
| 194 | IEEE80211_IF_FILE(user_power_level, user_power_level, DEC); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 195 | |
Johannes Berg | 0864331 | 2012-11-08 15:29:28 +0100 | [diff] [blame] | 196 | static ssize_t |
| 197 | ieee80211_if_fmt_hw_queues(const struct ieee80211_sub_if_data *sdata, |
| 198 | char *buf, int buflen) |
| 199 | { |
| 200 | int len; |
| 201 | |
| 202 | len = scnprintf(buf, buflen, "AC queues: VO:%d VI:%d BE:%d BK:%d\n", |
| 203 | sdata->vif.hw_queue[IEEE80211_AC_VO], |
| 204 | sdata->vif.hw_queue[IEEE80211_AC_VI], |
| 205 | sdata->vif.hw_queue[IEEE80211_AC_BE], |
| 206 | sdata->vif.hw_queue[IEEE80211_AC_BK]); |
| 207 | |
| 208 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 209 | len += scnprintf(buf + len, buflen - len, "cab queue: %d\n", |
| 210 | sdata->vif.cab_queue); |
| 211 | |
| 212 | return len; |
| 213 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 214 | IEEE80211_IF_FILE_R(hw_queues); |
Johannes Berg | 0864331 | 2012-11-08 15:29:28 +0100 | [diff] [blame] | 215 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 216 | /* STA attributes */ |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 217 | IEEE80211_IF_FILE(bssid, u.mgd.bssid, MAC); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 218 | IEEE80211_IF_FILE(aid, u.mgd.aid, DEC); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 219 | IEEE80211_IF_FILE(last_beacon, u.mgd.last_beacon_signal, DEC); |
| 220 | IEEE80211_IF_FILE(ave_beacon, u.mgd.ave_beacon_signal, DEC_DIV_16); |
Ben Greear | 78e443e | 2013-03-25 11:19:34 -0700 | [diff] [blame] | 221 | IEEE80211_IF_FILE(beacon_timeout, u.mgd.beacon_timeout, JIFFIES_TO_MS); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 222 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 223 | static int ieee80211_set_smps(struct ieee80211_sub_if_data *sdata, |
| 224 | enum ieee80211_smps_mode smps_mode) |
| 225 | { |
| 226 | struct ieee80211_local *local = sdata->local; |
| 227 | int err; |
| 228 | |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 229 | if (!(local->hw.wiphy->features & NL80211_FEATURE_STATIC_SMPS) && |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 230 | smps_mode == IEEE80211_SMPS_STATIC) |
| 231 | return -EINVAL; |
| 232 | |
| 233 | /* auto should be dynamic if in PS mode */ |
Eliad Peller | 0d8614b | 2014-09-10 14:07:36 +0300 | [diff] [blame] | 234 | if (!(local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS) && |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 235 | (smps_mode == IEEE80211_SMPS_DYNAMIC || |
| 236 | smps_mode == IEEE80211_SMPS_AUTOMATIC)) |
| 237 | return -EINVAL; |
| 238 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 239 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 240 | sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 241 | return -EOPNOTSUPP; |
| 242 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 243 | sdata_lock(sdata); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 244 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 245 | err = __ieee80211_request_smps_mgd(sdata, smps_mode); |
| 246 | else |
| 247 | err = __ieee80211_request_smps_ap(sdata, smps_mode); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 248 | sdata_unlock(sdata); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 249 | |
| 250 | return err; |
| 251 | } |
| 252 | |
| 253 | static const char *smps_modes[IEEE80211_SMPS_NUM_MODES] = { |
| 254 | [IEEE80211_SMPS_AUTOMATIC] = "auto", |
| 255 | [IEEE80211_SMPS_OFF] = "off", |
| 256 | [IEEE80211_SMPS_STATIC] = "static", |
| 257 | [IEEE80211_SMPS_DYNAMIC] = "dynamic", |
| 258 | }; |
| 259 | |
| 260 | static ssize_t ieee80211_if_fmt_smps(const struct ieee80211_sub_if_data *sdata, |
| 261 | char *buf, int buflen) |
| 262 | { |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 263 | if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 264 | return snprintf(buf, buflen, "request: %s\nused: %s\n", |
| 265 | smps_modes[sdata->u.mgd.req_smps], |
| 266 | smps_modes[sdata->smps_mode]); |
| 267 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 268 | return snprintf(buf, buflen, "request: %s\nused: %s\n", |
| 269 | smps_modes[sdata->u.ap.req_smps], |
| 270 | smps_modes[sdata->smps_mode]); |
| 271 | return -EINVAL; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static ssize_t ieee80211_if_parse_smps(struct ieee80211_sub_if_data *sdata, |
| 275 | const char *buf, int buflen) |
| 276 | { |
| 277 | enum ieee80211_smps_mode mode; |
| 278 | |
| 279 | for (mode = 0; mode < IEEE80211_SMPS_NUM_MODES; mode++) { |
| 280 | if (strncmp(buf, smps_modes[mode], buflen) == 0) { |
| 281 | int err = ieee80211_set_smps(sdata, mode); |
| 282 | if (!err) |
| 283 | return buflen; |
| 284 | return err; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return -EINVAL; |
| 289 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 290 | IEEE80211_IF_FILE_RW(smps); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 291 | |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 292 | static ssize_t ieee80211_if_parse_tkip_mic_test( |
| 293 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
| 294 | { |
| 295 | struct ieee80211_local *local = sdata->local; |
| 296 | u8 addr[ETH_ALEN]; |
| 297 | struct sk_buff *skb; |
| 298 | struct ieee80211_hdr *hdr; |
| 299 | __le16 fc; |
| 300 | |
Johannes Berg | 28656a1 | 2012-11-05 20:24:38 +0100 | [diff] [blame] | 301 | if (!mac_pton(buf, addr)) |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 302 | return -EINVAL; |
| 303 | |
| 304 | if (!ieee80211_sdata_running(sdata)) |
| 305 | return -ENOTCONN; |
| 306 | |
| 307 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 100); |
| 308 | if (!skb) |
| 309 | return -ENOMEM; |
| 310 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 311 | |
| 312 | hdr = (struct ieee80211_hdr *) skb_put(skb, 24); |
| 313 | memset(hdr, 0, 24); |
| 314 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); |
| 315 | |
| 316 | switch (sdata->vif.type) { |
| 317 | case NL80211_IFTYPE_AP: |
| 318 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); |
| 319 | /* DA BSSID SA */ |
| 320 | memcpy(hdr->addr1, addr, ETH_ALEN); |
| 321 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
| 322 | memcpy(hdr->addr3, sdata->vif.addr, ETH_ALEN); |
| 323 | break; |
| 324 | case NL80211_IFTYPE_STATION: |
| 325 | fc |= cpu_to_le16(IEEE80211_FCTL_TODS); |
| 326 | /* BSSID SA DA */ |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 327 | sdata_lock(sdata); |
Johannes Berg | 41c97a2 | 2012-11-05 20:27:57 +0100 | [diff] [blame] | 328 | if (!sdata->u.mgd.associated) { |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 329 | sdata_unlock(sdata); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 330 | dev_kfree_skb(skb); |
| 331 | return -ENOTCONN; |
| 332 | } |
Johannes Berg | 41c97a2 | 2012-11-05 20:27:57 +0100 | [diff] [blame] | 333 | memcpy(hdr->addr1, sdata->u.mgd.associated->bssid, ETH_ALEN); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 334 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
| 335 | memcpy(hdr->addr3, addr, ETH_ALEN); |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 336 | sdata_unlock(sdata); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 337 | break; |
| 338 | default: |
| 339 | dev_kfree_skb(skb); |
| 340 | return -EOPNOTSUPP; |
| 341 | } |
| 342 | hdr->frame_control = fc; |
| 343 | |
| 344 | /* |
| 345 | * Add some length to the test frame to make it look bit more valid. |
| 346 | * The exact contents does not matter since the recipient is required |
| 347 | * to drop this because of the Michael MIC failure. |
| 348 | */ |
| 349 | memset(skb_put(skb, 50), 0, 50); |
| 350 | |
| 351 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_TKIP_MIC_FAILURE; |
| 352 | |
| 353 | ieee80211_tx_skb(sdata, skb); |
| 354 | |
| 355 | return buflen; |
| 356 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 357 | IEEE80211_IF_FILE_W(tkip_mic_test); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 358 | |
Eliad Peller | 802ee9e | 2014-02-11 12:36:18 +0200 | [diff] [blame] | 359 | static ssize_t ieee80211_if_parse_beacon_loss( |
| 360 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
| 361 | { |
| 362 | if (!ieee80211_sdata_running(sdata) || !sdata->vif.bss_conf.assoc) |
| 363 | return -ENOTCONN; |
| 364 | |
| 365 | ieee80211_beacon_loss(&sdata->vif); |
| 366 | |
| 367 | return buflen; |
| 368 | } |
| 369 | IEEE80211_IF_FILE_W(beacon_loss); |
| 370 | |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 371 | static ssize_t ieee80211_if_fmt_uapsd_queues( |
| 372 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
| 373 | { |
| 374 | const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 375 | |
| 376 | return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_queues); |
| 377 | } |
| 378 | |
| 379 | static ssize_t ieee80211_if_parse_uapsd_queues( |
| 380 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
| 381 | { |
| 382 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 383 | u8 val; |
| 384 | int ret; |
| 385 | |
| 386 | ret = kstrtou8(buf, 0, &val); |
| 387 | if (ret) |
| 388 | return ret; |
| 389 | |
| 390 | if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) |
| 391 | return -ERANGE; |
| 392 | |
| 393 | ifmgd->uapsd_queues = val; |
| 394 | |
| 395 | return buflen; |
| 396 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 397 | IEEE80211_IF_FILE_RW(uapsd_queues); |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 398 | |
| 399 | static ssize_t ieee80211_if_fmt_uapsd_max_sp_len( |
| 400 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
| 401 | { |
| 402 | const struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 403 | |
| 404 | return snprintf(buf, buflen, "0x%x\n", ifmgd->uapsd_max_sp_len); |
| 405 | } |
| 406 | |
| 407 | static ssize_t ieee80211_if_parse_uapsd_max_sp_len( |
| 408 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
| 409 | { |
| 410 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 411 | unsigned long val; |
| 412 | int ret; |
| 413 | |
| 414 | ret = kstrtoul(buf, 0, &val); |
| 415 | if (ret) |
| 416 | return -EINVAL; |
| 417 | |
| 418 | if (val & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) |
| 419 | return -ERANGE; |
| 420 | |
| 421 | ifmgd->uapsd_max_sp_len = val; |
| 422 | |
| 423 | return buflen; |
| 424 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 425 | IEEE80211_IF_FILE_RW(uapsd_max_sp_len); |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 426 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 427 | /* AP attributes */ |
Felix Fietkau | 030ef8f | 2012-04-23 19:49:02 +0200 | [diff] [blame] | 428 | IEEE80211_IF_FILE(num_mcast_sta, u.ap.num_mcast_sta, ATOMIC); |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 429 | IEEE80211_IF_FILE(num_sta_ps, u.ap.ps.num_sta_ps, ATOMIC); |
| 430 | IEEE80211_IF_FILE(dtim_count, u.ap.ps.dtim_count, DEC); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 431 | |
| 432 | static ssize_t ieee80211_if_fmt_num_buffered_multicast( |
| 433 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
| 434 | { |
| 435 | return scnprintf(buf, buflen, "%u\n", |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 436 | skb_queue_len(&sdata->u.ap.ps.bc_buf)); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 437 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 438 | IEEE80211_IF_FILE_R(num_buffered_multicast); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 439 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 440 | /* IBSS attributes */ |
| 441 | static ssize_t ieee80211_if_fmt_tsf( |
| 442 | const struct ieee80211_sub_if_data *sdata, char *buf, int buflen) |
| 443 | { |
| 444 | struct ieee80211_local *local = sdata->local; |
| 445 | u64 tsf; |
| 446 | |
| 447 | tsf = drv_get_tsf(local, (struct ieee80211_sub_if_data *)sdata); |
| 448 | |
| 449 | return scnprintf(buf, buflen, "0x%016llx\n", (unsigned long long) tsf); |
| 450 | } |
| 451 | |
| 452 | static ssize_t ieee80211_if_parse_tsf( |
| 453 | struct ieee80211_sub_if_data *sdata, const char *buf, int buflen) |
| 454 | { |
| 455 | struct ieee80211_local *local = sdata->local; |
| 456 | unsigned long long tsf; |
| 457 | int ret; |
Javier Cardona | 9bdd3a6 | 2012-03-31 11:31:31 -0700 | [diff] [blame] | 458 | int tsf_is_delta = 0; |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 459 | |
| 460 | if (strncmp(buf, "reset", 5) == 0) { |
| 461 | if (local->ops->reset_tsf) { |
| 462 | drv_reset_tsf(local, sdata); |
| 463 | wiphy_info(local->hw.wiphy, "debugfs reset TSF\n"); |
| 464 | } |
| 465 | } else { |
Javier Cardona | 9bdd3a6 | 2012-03-31 11:31:31 -0700 | [diff] [blame] | 466 | if (buflen > 10 && buf[1] == '=') { |
| 467 | if (buf[0] == '+') |
| 468 | tsf_is_delta = 1; |
| 469 | else if (buf[0] == '-') |
| 470 | tsf_is_delta = -1; |
| 471 | else |
| 472 | return -EINVAL; |
| 473 | buf += 2; |
| 474 | } |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 475 | ret = kstrtoull(buf, 10, &tsf); |
| 476 | if (ret < 0) |
Johannes Berg | 6fc1da9 | 2012-11-05 20:30:39 +0100 | [diff] [blame] | 477 | return ret; |
Javier Cardona | 9bdd3a6 | 2012-03-31 11:31:31 -0700 | [diff] [blame] | 478 | if (tsf_is_delta) |
| 479 | tsf = drv_get_tsf(local, sdata) + tsf_is_delta * tsf; |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 480 | if (local->ops->set_tsf) { |
| 481 | drv_set_tsf(local, sdata, tsf); |
| 482 | wiphy_info(local->hw.wiphy, |
| 483 | "debugfs set TSF to %#018llx\n", tsf); |
| 484 | } |
| 485 | } |
| 486 | |
Thomas Pedersen | 057d5f4 | 2013-12-19 10:25:15 -0800 | [diff] [blame] | 487 | ieee80211_recalc_dtim(local, sdata); |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 488 | return buflen; |
| 489 | } |
Johannes Berg | 4cd3c4e | 2014-01-06 15:47:15 +0100 | [diff] [blame] | 490 | IEEE80211_IF_FILE_RW(tsf); |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 491 | |
| 492 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 493 | /* WDS attributes */ |
| 494 | IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC); |
| 495 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 496 | #ifdef CONFIG_MAC80211_MESH |
Ashok Nagarajan | d4a5a48 | 2013-05-13 17:08:04 -0700 | [diff] [blame] | 497 | IEEE80211_IF_FILE(estab_plinks, u.mesh.estab_plinks, ATOMIC); |
| 498 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 499 | /* Mesh stats attributes */ |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 500 | IEEE80211_IF_FILE(fwded_mcast, u.mesh.mshstats.fwded_mcast, DEC); |
| 501 | IEEE80211_IF_FILE(fwded_unicast, u.mesh.mshstats.fwded_unicast, DEC); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 502 | IEEE80211_IF_FILE(fwded_frames, u.mesh.mshstats.fwded_frames, DEC); |
| 503 | IEEE80211_IF_FILE(dropped_frames_ttl, u.mesh.mshstats.dropped_frames_ttl, DEC); |
Javier Cardona | cfee66b | 2011-09-06 13:05:21 -0700 | [diff] [blame] | 504 | IEEE80211_IF_FILE(dropped_frames_congestion, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 505 | u.mesh.mshstats.dropped_frames_congestion, DEC); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 506 | IEEE80211_IF_FILE(dropped_frames_no_route, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 507 | u.mesh.mshstats.dropped_frames_no_route, DEC); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 508 | |
| 509 | /* Mesh parameters */ |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 510 | IEEE80211_IF_FILE(dot11MeshMaxRetries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 511 | u.mesh.mshcfg.dot11MeshMaxRetries, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 512 | IEEE80211_IF_FILE(dot11MeshRetryTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 513 | u.mesh.mshcfg.dot11MeshRetryTimeout, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 514 | IEEE80211_IF_FILE(dot11MeshConfirmTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 515 | u.mesh.mshcfg.dot11MeshConfirmTimeout, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 516 | IEEE80211_IF_FILE(dot11MeshHoldingTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 517 | u.mesh.mshcfg.dot11MeshHoldingTimeout, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 518 | IEEE80211_IF_FILE(dot11MeshTTL, u.mesh.mshcfg.dot11MeshTTL, DEC); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 519 | IEEE80211_IF_FILE(element_ttl, u.mesh.mshcfg.element_ttl, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 520 | IEEE80211_IF_FILE(auto_open_plinks, u.mesh.mshcfg.auto_open_plinks, DEC); |
| 521 | IEEE80211_IF_FILE(dot11MeshMaxPeerLinks, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 522 | u.mesh.mshcfg.dot11MeshMaxPeerLinks, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 523 | IEEE80211_IF_FILE(dot11MeshHWMPactivePathTimeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 524 | u.mesh.mshcfg.dot11MeshHWMPactivePathTimeout, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 525 | IEEE80211_IF_FILE(dot11MeshHWMPpreqMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 526 | u.mesh.mshcfg.dot11MeshHWMPpreqMinInterval, DEC); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 527 | IEEE80211_IF_FILE(dot11MeshHWMPperrMinInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 528 | u.mesh.mshcfg.dot11MeshHWMPperrMinInterval, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 529 | IEEE80211_IF_FILE(dot11MeshHWMPnetDiameterTraversalTime, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 530 | u.mesh.mshcfg.dot11MeshHWMPnetDiameterTraversalTime, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 531 | IEEE80211_IF_FILE(dot11MeshHWMPmaxPREQretries, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 532 | u.mesh.mshcfg.dot11MeshHWMPmaxPREQretries, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 533 | IEEE80211_IF_FILE(path_refresh_time, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 534 | u.mesh.mshcfg.path_refresh_time, DEC); |
Johannes Berg | 36ff382 | 2008-10-07 12:04:31 +0200 | [diff] [blame] | 535 | IEEE80211_IF_FILE(min_discovery_timeout, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 536 | u.mesh.mshcfg.min_discovery_timeout, DEC); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 537 | IEEE80211_IF_FILE(dot11MeshHWMPRootMode, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 538 | u.mesh.mshcfg.dot11MeshHWMPRootMode, DEC); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 539 | IEEE80211_IF_FILE(dot11MeshGateAnnouncementProtocol, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 540 | u.mesh.mshcfg.dot11MeshGateAnnouncementProtocol, DEC); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 541 | IEEE80211_IF_FILE(dot11MeshHWMPRannInterval, |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 542 | u.mesh.mshcfg.dot11MeshHWMPRannInterval, DEC); |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 543 | IEEE80211_IF_FILE(dot11MeshForwarding, u.mesh.mshcfg.dot11MeshForwarding, DEC); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 544 | IEEE80211_IF_FILE(rssi_threshold, u.mesh.mshcfg.rssi_threshold, DEC); |
Ashok Nagarajan | 4416f5d | 2012-05-07 21:00:32 -0700 | [diff] [blame] | 545 | IEEE80211_IF_FILE(ht_opmode, u.mesh.mshcfg.ht_opmode, DEC); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 546 | IEEE80211_IF_FILE(dot11MeshHWMPactivePathToRootTimeout, |
| 547 | u.mesh.mshcfg.dot11MeshHWMPactivePathToRootTimeout, DEC); |
| 548 | IEEE80211_IF_FILE(dot11MeshHWMProotInterval, |
| 549 | u.mesh.mshcfg.dot11MeshHWMProotInterval, DEC); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 550 | IEEE80211_IF_FILE(dot11MeshHWMPconfirmationInterval, |
| 551 | u.mesh.mshcfg.dot11MeshHWMPconfirmationInterval, DEC); |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 552 | IEEE80211_IF_FILE(power_mode, u.mesh.mshcfg.power_mode, DEC); |
| 553 | IEEE80211_IF_FILE(dot11MeshAwakeWindowDuration, |
| 554 | u.mesh.mshcfg.dot11MeshAwakeWindowDuration, DEC); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 555 | #endif |
| 556 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 557 | #define DEBUGFS_ADD_MODE(name, mode) \ |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 558 | debugfs_create_file(#name, mode, sdata->vif.debugfs_dir, \ |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 559 | sdata, &name##_ops); |
| 560 | |
Felix Fietkau | fcb2c9e | 2012-03-18 22:58:05 +0100 | [diff] [blame] | 561 | #define DEBUGFS_ADD(name) DEBUGFS_ADD_MODE(name, 0400) |
| 562 | |
| 563 | static void add_common_files(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 564 | { |
Johannes Berg | 2d46d7c | 2010-01-10 17:12:41 +0100 | [diff] [blame] | 565 | DEBUGFS_ADD(drop_unencrypted); |
| 566 | DEBUGFS_ADD(rc_rateidx_mask_2ghz); |
| 567 | DEBUGFS_ADD(rc_rateidx_mask_5ghz); |
Simon Wunderlich | 1946841 | 2012-01-28 17:25:33 +0100 | [diff] [blame] | 568 | DEBUGFS_ADD(rc_rateidx_mcs_mask_2ghz); |
| 569 | DEBUGFS_ADD(rc_rateidx_mcs_mask_5ghz); |
Johannes Berg | 0864331 | 2012-11-08 15:29:28 +0100 | [diff] [blame] | 570 | DEBUGFS_ADD(hw_queues); |
Felix Fietkau | fcb2c9e | 2012-03-18 22:58:05 +0100 | [diff] [blame] | 571 | } |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 572 | |
Felix Fietkau | fcb2c9e | 2012-03-18 22:58:05 +0100 | [diff] [blame] | 573 | static void add_sta_files(struct ieee80211_sub_if_data *sdata) |
| 574 | { |
Johannes Berg | 2d46d7c | 2010-01-10 17:12:41 +0100 | [diff] [blame] | 575 | DEBUGFS_ADD(bssid); |
| 576 | DEBUGFS_ADD(aid); |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 577 | DEBUGFS_ADD(last_beacon); |
| 578 | DEBUGFS_ADD(ave_beacon); |
Ben Greear | 78e443e | 2013-03-25 11:19:34 -0700 | [diff] [blame] | 579 | DEBUGFS_ADD(beacon_timeout); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 580 | DEBUGFS_ADD_MODE(smps, 0600); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 581 | DEBUGFS_ADD_MODE(tkip_mic_test, 0200); |
Eliad Peller | 802ee9e | 2014-02-11 12:36:18 +0200 | [diff] [blame] | 582 | DEBUGFS_ADD_MODE(beacon_loss, 0200); |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 583 | DEBUGFS_ADD_MODE(uapsd_queues, 0600); |
| 584 | DEBUGFS_ADD_MODE(uapsd_max_sp_len, 0600); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | static void add_ap_files(struct ieee80211_sub_if_data *sdata) |
| 588 | { |
Felix Fietkau | 030ef8f | 2012-04-23 19:49:02 +0200 | [diff] [blame] | 589 | DEBUGFS_ADD(num_mcast_sta); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 590 | DEBUGFS_ADD_MODE(smps, 0600); |
Johannes Berg | 2d46d7c | 2010-01-10 17:12:41 +0100 | [diff] [blame] | 591 | DEBUGFS_ADD(num_sta_ps); |
| 592 | DEBUGFS_ADD(dtim_count); |
| 593 | DEBUGFS_ADD(num_buffered_multicast); |
Jouni Malinen | 681d119 | 2011-02-03 18:35:19 +0200 | [diff] [blame] | 594 | DEBUGFS_ADD_MODE(tkip_mic_test, 0200); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 597 | static void add_ibss_files(struct ieee80211_sub_if_data *sdata) |
| 598 | { |
| 599 | DEBUGFS_ADD_MODE(tsf, 0600); |
| 600 | } |
| 601 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 602 | static void add_wds_files(struct ieee80211_sub_if_data *sdata) |
| 603 | { |
Johannes Berg | 2d46d7c | 2010-01-10 17:12:41 +0100 | [diff] [blame] | 604 | DEBUGFS_ADD(peer); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 605 | } |
| 606 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 607 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 608 | |
Javier Cardona | 12ce8ba | 2012-03-05 17:20:38 -0800 | [diff] [blame] | 609 | static void add_mesh_files(struct ieee80211_sub_if_data *sdata) |
| 610 | { |
| 611 | DEBUGFS_ADD_MODE(tsf, 0600); |
Ashok Nagarajan | d4a5a48 | 2013-05-13 17:08:04 -0700 | [diff] [blame] | 612 | DEBUGFS_ADD_MODE(estab_plinks, 0400); |
Javier Cardona | 12ce8ba | 2012-03-05 17:20:38 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 615 | static void add_mesh_stats(struct ieee80211_sub_if_data *sdata) |
| 616 | { |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 617 | struct dentry *dir = debugfs_create_dir("mesh_stats", |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 618 | sdata->vif.debugfs_dir); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 619 | #define MESHSTATS_ADD(name)\ |
| 620 | debugfs_create_file(#name, 0400, dir, sdata, &name##_ops); |
| 621 | |
Daniel Walker | c8a61a7 | 2009-08-18 10:59:00 -0700 | [diff] [blame] | 622 | MESHSTATS_ADD(fwded_mcast); |
| 623 | MESHSTATS_ADD(fwded_unicast); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 624 | MESHSTATS_ADD(fwded_frames); |
| 625 | MESHSTATS_ADD(dropped_frames_ttl); |
| 626 | MESHSTATS_ADD(dropped_frames_no_route); |
Javier Cardona | cfee66b | 2011-09-06 13:05:21 -0700 | [diff] [blame] | 627 | MESHSTATS_ADD(dropped_frames_congestion); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 628 | #undef MESHSTATS_ADD |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 629 | } |
| 630 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 631 | static void add_mesh_config(struct ieee80211_sub_if_data *sdata) |
| 632 | { |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 633 | struct dentry *dir = debugfs_create_dir("mesh_config", |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 634 | sdata->vif.debugfs_dir); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 635 | |
| 636 | #define MESHPARAMS_ADD(name) \ |
| 637 | debugfs_create_file(#name, 0600, dir, sdata, &name##_ops); |
| 638 | |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 639 | MESHPARAMS_ADD(dot11MeshMaxRetries); |
| 640 | MESHPARAMS_ADD(dot11MeshRetryTimeout); |
| 641 | MESHPARAMS_ADD(dot11MeshConfirmTimeout); |
| 642 | MESHPARAMS_ADD(dot11MeshHoldingTimeout); |
| 643 | MESHPARAMS_ADD(dot11MeshTTL); |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 644 | MESHPARAMS_ADD(element_ttl); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 645 | MESHPARAMS_ADD(auto_open_plinks); |
| 646 | MESHPARAMS_ADD(dot11MeshMaxPeerLinks); |
| 647 | MESHPARAMS_ADD(dot11MeshHWMPactivePathTimeout); |
| 648 | MESHPARAMS_ADD(dot11MeshHWMPpreqMinInterval); |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 649 | MESHPARAMS_ADD(dot11MeshHWMPperrMinInterval); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 650 | MESHPARAMS_ADD(dot11MeshHWMPnetDiameterTraversalTime); |
| 651 | MESHPARAMS_ADD(dot11MeshHWMPmaxPREQretries); |
| 652 | MESHPARAMS_ADD(path_refresh_time); |
| 653 | MESHPARAMS_ADD(min_discovery_timeout); |
Javier Cardona | 699403d | 2011-08-09 16:45:09 -0700 | [diff] [blame] | 654 | MESHPARAMS_ADD(dot11MeshHWMPRootMode); |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 655 | MESHPARAMS_ADD(dot11MeshHWMPRannInterval); |
Chun-Yeow Yeoh | 8c06e8c | 2012-05-31 18:17:30 +0800 | [diff] [blame] | 656 | MESHPARAMS_ADD(dot11MeshForwarding); |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 657 | MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol); |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 658 | MESHPARAMS_ADD(rssi_threshold); |
Ashok Nagarajan | 4416f5d | 2012-05-07 21:00:32 -0700 | [diff] [blame] | 659 | MESHPARAMS_ADD(ht_opmode); |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 660 | MESHPARAMS_ADD(dot11MeshHWMPactivePathToRootTimeout); |
| 661 | MESHPARAMS_ADD(dot11MeshHWMProotInterval); |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 662 | MESHPARAMS_ADD(dot11MeshHWMPconfirmationInterval); |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 663 | MESHPARAMS_ADD(power_mode); |
| 664 | MESHPARAMS_ADD(dot11MeshAwakeWindowDuration); |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 665 | #undef MESHPARAMS_ADD |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 666 | } |
| 667 | #endif |
| 668 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 669 | static void add_files(struct ieee80211_sub_if_data *sdata) |
| 670 | { |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 671 | if (!sdata->vif.debugfs_dir) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 672 | return; |
| 673 | |
Felix Fietkau | fcb2c9e | 2012-03-18 22:58:05 +0100 | [diff] [blame] | 674 | DEBUGFS_ADD(flags); |
| 675 | DEBUGFS_ADD(state); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 676 | DEBUGFS_ADD(txpower); |
| 677 | DEBUGFS_ADD(user_power_level); |
| 678 | DEBUGFS_ADD(ap_power_level); |
Felix Fietkau | fcb2c9e | 2012-03-18 22:58:05 +0100 | [diff] [blame] | 679 | |
| 680 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) |
| 681 | add_common_files(sdata); |
| 682 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 683 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 684 | case NL80211_IFTYPE_MESH_POINT: |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 685 | #ifdef CONFIG_MAC80211_MESH |
Javier Cardona | 12ce8ba | 2012-03-05 17:20:38 -0800 | [diff] [blame] | 686 | add_mesh_files(sdata); |
Luis Carlos Cobo | 9f42f60 | 2008-02-23 15:17:16 +0100 | [diff] [blame] | 687 | add_mesh_stats(sdata); |
| 688 | add_mesh_config(sdata); |
| 689 | #endif |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 690 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 691 | case NL80211_IFTYPE_STATION: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 692 | add_sta_files(sdata); |
| 693 | break; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 694 | case NL80211_IFTYPE_ADHOC: |
Eliad Peller | 37a41b4 | 2011-09-21 14:06:11 +0300 | [diff] [blame] | 695 | add_ibss_files(sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 696 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 697 | case NL80211_IFTYPE_AP: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 698 | add_ap_files(sdata); |
| 699 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 700 | case NL80211_IFTYPE_WDS: |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 701 | add_wds_files(sdata); |
| 702 | break; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 703 | default: |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 708 | void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata) |
| 709 | { |
| 710 | char buf[10+IFNAMSIZ]; |
| 711 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 712 | sprintf(buf, "netdev:%s", sdata->name); |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 713 | sdata->vif.debugfs_dir = debugfs_create_dir(buf, |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 714 | sdata->local->hw.wiphy->debugfsdir); |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 715 | if (sdata->vif.debugfs_dir) |
Ben Greear | 295bafb | 2010-09-22 20:29:01 -0700 | [diff] [blame] | 716 | sdata->debugfs.subdir_stations = debugfs_create_dir("stations", |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 717 | sdata->vif.debugfs_dir); |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 718 | add_files(sdata); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata) |
| 722 | { |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 723 | if (!sdata->vif.debugfs_dir) |
Johannes Berg | 7bcfaf2 | 2009-10-27 12:59:03 +0100 | [diff] [blame] | 724 | return; |
| 725 | |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 726 | debugfs_remove_recursive(sdata->vif.debugfs_dir); |
| 727 | sdata->vif.debugfs_dir = NULL; |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 728 | } |
| 729 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 730 | void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 731 | { |
Johannes Berg | 7c8081e | 2007-06-21 18:30:19 +0200 | [diff] [blame] | 732 | struct dentry *dir; |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 733 | char buf[10 + IFNAMSIZ]; |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 734 | |
Stanislaw Gruszka | ddbfe86 | 2013-03-08 14:46:14 +0100 | [diff] [blame] | 735 | dir = sdata->vif.debugfs_dir; |
Johannes Berg | c74e90a | 2008-10-08 10:18:36 +0200 | [diff] [blame] | 736 | |
| 737 | if (!dir) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 738 | return; |
Johannes Berg | c74e90a | 2008-10-08 10:18:36 +0200 | [diff] [blame] | 739 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 740 | sprintf(buf, "netdev:%s", sdata->name); |
Johannes Berg | 7c8081e | 2007-06-21 18:30:19 +0200 | [diff] [blame] | 741 | if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf)) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 742 | sdata_err(sdata, |
| 743 | "debugfs: failed to rename debugfs dir to %s\n", |
| 744 | buf); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 745 | } |