Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
11 | #include <linux/list.h> |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/ieee80211.h> | |
14 | #include <linux/nl80211.h> | |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/netlink.h> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
55682965 JB |
22 | #include "core.h" |
23 | #include "nl80211.h" | |
b2e1b302 | 24 | #include "reg.h" |
55682965 | 25 | |
5fb628e9 JM |
26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, | |
28 | struct genl_info *info, | |
29 | struct cfg80211_crypto_settings *settings, | |
30 | int cipher_limit); | |
31 | ||
4c476991 JB |
32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
33 | struct genl_info *info); | |
34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
35 | struct genl_info *info); | |
36 | ||
55682965 JB |
37 | /* the netlink family */ |
38 | static struct genl_family nl80211_fam = { | |
39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
40 | .name = "nl80211", /* have users key off the name instead */ | |
41 | .hdrsize = 0, /* no private header */ | |
42 | .version = 1, /* no particular meaning now */ | |
43 | .maxattr = NL80211_ATTR_MAX, | |
463d0183 | 44 | .netnsok = true, |
4c476991 JB |
45 | .pre_doit = nl80211_pre_doit, |
46 | .post_doit = nl80211_post_doit, | |
55682965 JB |
47 | }; |
48 | ||
79c97e97 | 49 | /* internal helper: get rdev and dev */ |
00918d33 JB |
50 | static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs, |
51 | struct cfg80211_registered_device **rdev, | |
52 | struct net_device **dev) | |
55682965 JB |
53 | { |
54 | int ifindex; | |
55 | ||
bba95fef | 56 | if (!attrs[NL80211_ATTR_IFINDEX]) |
55682965 JB |
57 | return -EINVAL; |
58 | ||
bba95fef | 59 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
00918d33 | 60 | *dev = dev_get_by_index(netns, ifindex); |
55682965 JB |
61 | if (!*dev) |
62 | return -ENODEV; | |
63 | ||
00918d33 | 64 | *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex); |
79c97e97 | 65 | if (IS_ERR(*rdev)) { |
55682965 | 66 | dev_put(*dev); |
79c97e97 | 67 | return PTR_ERR(*rdev); |
55682965 JB |
68 | } |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
a9455408 | 73 | static struct cfg80211_registered_device * |
878d9ec7 | 74 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 75 | { |
7fee4778 JB |
76 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
77 | struct net_device *netdev; | |
a9455408 JB |
78 | |
79 | assert_cfg80211_lock(); | |
80 | ||
878d9ec7 JB |
81 | if (!attrs[NL80211_ATTR_WIPHY] && |
82 | !attrs[NL80211_ATTR_IFINDEX]) | |
7fee4778 JB |
83 | return ERR_PTR(-EINVAL); |
84 | ||
878d9ec7 | 85 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 86 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 87 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 88 | |
878d9ec7 JB |
89 | if (attrs[NL80211_ATTR_IFINDEX]) { |
90 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
4f7eff10 | 91 | netdev = dev_get_by_index(netns, ifindex); |
7fee4778 JB |
92 | if (netdev) { |
93 | if (netdev->ieee80211_ptr) | |
94 | tmp = wiphy_to_dev( | |
95 | netdev->ieee80211_ptr->wiphy); | |
96 | else | |
97 | tmp = NULL; | |
98 | ||
99 | dev_put(netdev); | |
100 | ||
101 | /* not wireless device -- return error */ | |
102 | if (!tmp) | |
103 | return ERR_PTR(-EINVAL); | |
104 | ||
105 | /* mismatch -- return error */ | |
106 | if (rdev && tmp != rdev) | |
107 | return ERR_PTR(-EINVAL); | |
108 | ||
109 | rdev = tmp; | |
a9455408 | 110 | } |
a9455408 | 111 | } |
a9455408 | 112 | |
4f7eff10 JB |
113 | if (!rdev) |
114 | return ERR_PTR(-ENODEV); | |
a9455408 | 115 | |
4f7eff10 JB |
116 | if (netns != wiphy_net(&rdev->wiphy)) |
117 | return ERR_PTR(-ENODEV); | |
118 | ||
119 | return rdev; | |
a9455408 JB |
120 | } |
121 | ||
122 | /* | |
123 | * This function returns a pointer to the driver | |
124 | * that the genl_info item that is passed refers to. | |
125 | * If successful, it returns non-NULL and also locks | |
126 | * the driver's mutex! | |
127 | * | |
128 | * This means that you need to call cfg80211_unlock_rdev() | |
129 | * before being allowed to acquire &cfg80211_mutex! | |
130 | * | |
131 | * This is necessary because we need to lock the global | |
132 | * mutex to get an item off the list safely, and then | |
133 | * we lock the rdev mutex so it doesn't go away under us. | |
134 | * | |
135 | * We don't want to keep cfg80211_mutex locked | |
136 | * for all the time in order to allow requests on | |
137 | * other interfaces to go through at the same time. | |
138 | * | |
139 | * The result of this can be a PTR_ERR and hence must | |
140 | * be checked with IS_ERR() for errors. | |
141 | */ | |
142 | static struct cfg80211_registered_device * | |
4f7eff10 | 143 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 JB |
144 | { |
145 | struct cfg80211_registered_device *rdev; | |
146 | ||
147 | mutex_lock(&cfg80211_mutex); | |
878d9ec7 | 148 | rdev = __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
149 | |
150 | /* if it is not an error we grab the lock on | |
151 | * it to assure it won't be going away while | |
152 | * we operate on it */ | |
153 | if (!IS_ERR(rdev)) | |
154 | mutex_lock(&rdev->mtx); | |
155 | ||
156 | mutex_unlock(&cfg80211_mutex); | |
157 | ||
158 | return rdev; | |
159 | } | |
160 | ||
55682965 | 161 | /* policy for the attributes */ |
b54452b0 | 162 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
163 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
164 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 165 | .len = 20-1 }, |
31888487 | 166 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
72bdcf34 | 167 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 168 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
b9a5f8ca JM |
169 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
170 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
171 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
172 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 173 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
174 | |
175 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
176 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
177 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 178 | |
e007b857 EP |
179 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
180 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 181 | |
b9454e83 | 182 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
183 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
184 | .len = WLAN_MAX_KEY_LEN }, | |
185 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
186 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
187 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 188 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 189 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
190 | |
191 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
192 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
193 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
194 | .len = IEEE80211_MAX_DATA_LEN }, | |
195 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
196 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
197 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
198 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
199 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
200 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
201 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 202 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 203 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 204 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 205 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 206 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 207 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 208 | |
b2e1b302 LR |
209 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
210 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
211 | ||
9f1ba906 JM |
212 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
213 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
214 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
215 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
216 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 217 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 218 | |
24bdd9f4 | 219 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 220 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 221 | |
6c739419 | 222 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
223 | |
224 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
225 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
226 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
227 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
228 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
229 | |
230 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
231 | .len = IEEE80211_MAX_SSID_LEN }, | |
232 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 234 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 235 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 236 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
237 | [NL80211_ATTR_STA_FLAGS2] = { |
238 | .len = sizeof(struct nl80211_sta_flag_update), | |
239 | }, | |
3f77316c | 240 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
241 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
242 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
243 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
244 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
245 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 246 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 247 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
248 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
249 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
250 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
251 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 252 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
253 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
254 | .len = IEEE80211_MAX_DATA_LEN }, | |
255 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 256 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 257 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 258 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 259 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
260 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
261 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 262 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
263 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
264 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 265 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 266 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 267 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 268 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 269 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 270 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 271 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 272 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 273 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
274 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
275 | .len = IEEE80211_MAX_DATA_LEN }, | |
276 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
277 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 278 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 279 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 280 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
281 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
282 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
283 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
284 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
285 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 286 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
287 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
288 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 289 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
290 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
291 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
292 | .len = NL80211_HT_CAPABILITY_LEN | |
293 | }, | |
1d9d9213 | 294 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 295 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 296 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
55682965 JB |
297 | }; |
298 | ||
e31b8213 | 299 | /* policy for the key attributes */ |
b54452b0 | 300 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 301 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
302 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
303 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 304 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
305 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
306 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 307 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
308 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
309 | }; | |
310 | ||
311 | /* policy for the key default flags */ | |
312 | static const struct nla_policy | |
313 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
314 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
315 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
316 | }; |
317 | ||
ff1b6e69 JB |
318 | /* policy for WoWLAN attributes */ |
319 | static const struct nla_policy | |
320 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
321 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
322 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
323 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
324 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
325 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
326 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
327 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
328 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
ff1b6e69 JB |
329 | }; |
330 | ||
e5497d76 JB |
331 | /* policy for GTK rekey offload attributes */ |
332 | static const struct nla_policy | |
333 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
334 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
335 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
336 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
337 | }; | |
338 | ||
a1f1c21c LC |
339 | static const struct nla_policy |
340 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 341 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 342 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 343 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
344 | }; |
345 | ||
a043897a HS |
346 | /* ifidx get helper */ |
347 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
348 | { | |
349 | int res; | |
350 | ||
351 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
352 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
353 | nl80211_policy); | |
354 | if (res) | |
355 | return res; | |
356 | ||
357 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
358 | return -EINVAL; | |
359 | ||
360 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
361 | if (!res) | |
362 | return -EINVAL; | |
363 | return res; | |
364 | } | |
365 | ||
67748893 JB |
366 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
367 | struct netlink_callback *cb, | |
368 | struct cfg80211_registered_device **rdev, | |
369 | struct net_device **dev) | |
370 | { | |
371 | int ifidx = cb->args[0]; | |
372 | int err; | |
373 | ||
374 | if (!ifidx) | |
375 | ifidx = nl80211_get_ifidx(cb); | |
376 | if (ifidx < 0) | |
377 | return ifidx; | |
378 | ||
379 | cb->args[0] = ifidx; | |
380 | ||
381 | rtnl_lock(); | |
382 | ||
383 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
384 | if (!*dev) { | |
385 | err = -ENODEV; | |
386 | goto out_rtnl; | |
387 | } | |
388 | ||
389 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3cc25e51 FF |
390 | if (IS_ERR(*rdev)) { |
391 | err = PTR_ERR(*rdev); | |
67748893 JB |
392 | goto out_rtnl; |
393 | } | |
394 | ||
395 | return 0; | |
396 | out_rtnl: | |
397 | rtnl_unlock(); | |
398 | return err; | |
399 | } | |
400 | ||
401 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | |
402 | { | |
403 | cfg80211_unlock_rdev(rdev); | |
404 | rtnl_unlock(); | |
405 | } | |
406 | ||
f4a11bb0 JB |
407 | /* IE validation */ |
408 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
409 | { | |
410 | const u8 *pos; | |
411 | int len; | |
412 | ||
413 | if (!attr) | |
414 | return true; | |
415 | ||
416 | pos = nla_data(attr); | |
417 | len = nla_len(attr); | |
418 | ||
419 | while (len) { | |
420 | u8 elemlen; | |
421 | ||
422 | if (len < 2) | |
423 | return false; | |
424 | len -= 2; | |
425 | ||
426 | elemlen = pos[1]; | |
427 | if (elemlen > len) | |
428 | return false; | |
429 | ||
430 | len -= elemlen; | |
431 | pos += 2 + elemlen; | |
432 | } | |
433 | ||
434 | return true; | |
435 | } | |
436 | ||
55682965 JB |
437 | /* message building helper */ |
438 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, | |
439 | int flags, u8 cmd) | |
440 | { | |
441 | /* since there is no private header just add the generic one */ | |
442 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); | |
443 | } | |
444 | ||
5dab3b8a LR |
445 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
446 | struct ieee80211_channel *chan) | |
447 | { | |
9360ffd1 DM |
448 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
449 | chan->center_freq)) | |
450 | goto nla_put_failure; | |
5dab3b8a | 451 | |
9360ffd1 DM |
452 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
453 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
454 | goto nla_put_failure; | |
455 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
456 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
457 | goto nla_put_failure; | |
458 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
459 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
460 | goto nla_put_failure; | |
461 | if ((chan->flags & IEEE80211_CHAN_RADAR) && | |
462 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
463 | goto nla_put_failure; | |
5dab3b8a | 464 | |
9360ffd1 DM |
465 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
466 | DBM_TO_MBM(chan->max_power))) | |
467 | goto nla_put_failure; | |
5dab3b8a LR |
468 | |
469 | return 0; | |
470 | ||
471 | nla_put_failure: | |
472 | return -ENOBUFS; | |
473 | } | |
474 | ||
55682965 JB |
475 | /* netlink command implementations */ |
476 | ||
b9454e83 JB |
477 | struct key_parse { |
478 | struct key_params p; | |
479 | int idx; | |
e31b8213 | 480 | int type; |
b9454e83 | 481 | bool def, defmgmt; |
dbd2fd65 | 482 | bool def_uni, def_multi; |
b9454e83 JB |
483 | }; |
484 | ||
485 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
486 | { | |
487 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
488 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
489 | nl80211_key_policy); | |
490 | if (err) | |
491 | return err; | |
492 | ||
493 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
494 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
495 | ||
dbd2fd65 JB |
496 | if (k->def) { |
497 | k->def_uni = true; | |
498 | k->def_multi = true; | |
499 | } | |
500 | if (k->defmgmt) | |
501 | k->def_multi = true; | |
502 | ||
b9454e83 JB |
503 | if (tb[NL80211_KEY_IDX]) |
504 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
505 | ||
506 | if (tb[NL80211_KEY_DATA]) { | |
507 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
508 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
509 | } | |
510 | ||
511 | if (tb[NL80211_KEY_SEQ]) { | |
512 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
513 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
514 | } | |
515 | ||
516 | if (tb[NL80211_KEY_CIPHER]) | |
517 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
518 | ||
e31b8213 JB |
519 | if (tb[NL80211_KEY_TYPE]) { |
520 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
521 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
522 | return -EINVAL; | |
523 | } | |
524 | ||
dbd2fd65 JB |
525 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
526 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
527 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
528 | tb[NL80211_KEY_DEFAULT_TYPES], | |
529 | nl80211_key_default_policy); | |
dbd2fd65 JB |
530 | if (err) |
531 | return err; | |
532 | ||
533 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
534 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
535 | } | |
536 | ||
b9454e83 JB |
537 | return 0; |
538 | } | |
539 | ||
540 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
541 | { | |
542 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
543 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
544 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
545 | } | |
546 | ||
547 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
548 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
549 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
550 | } | |
551 | ||
552 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
553 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
554 | ||
555 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
556 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
557 | ||
558 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
559 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
560 | ||
dbd2fd65 JB |
561 | if (k->def) { |
562 | k->def_uni = true; | |
563 | k->def_multi = true; | |
564 | } | |
565 | if (k->defmgmt) | |
566 | k->def_multi = true; | |
567 | ||
e31b8213 JB |
568 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
569 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
570 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
571 | return -EINVAL; | |
572 | } | |
573 | ||
dbd2fd65 JB |
574 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
575 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
576 | int err = nla_parse_nested( | |
577 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
578 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
579 | nl80211_key_default_policy); | |
580 | if (err) | |
581 | return err; | |
582 | ||
583 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
584 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
585 | } | |
586 | ||
b9454e83 JB |
587 | return 0; |
588 | } | |
589 | ||
590 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
591 | { | |
592 | int err; | |
593 | ||
594 | memset(k, 0, sizeof(*k)); | |
595 | k->idx = -1; | |
e31b8213 | 596 | k->type = -1; |
b9454e83 JB |
597 | |
598 | if (info->attrs[NL80211_ATTR_KEY]) | |
599 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
600 | else | |
601 | err = nl80211_parse_key_old(info, k); | |
602 | ||
603 | if (err) | |
604 | return err; | |
605 | ||
606 | if (k->def && k->defmgmt) | |
607 | return -EINVAL; | |
608 | ||
dbd2fd65 JB |
609 | if (k->defmgmt) { |
610 | if (k->def_uni || !k->def_multi) | |
611 | return -EINVAL; | |
612 | } | |
613 | ||
b9454e83 JB |
614 | if (k->idx != -1) { |
615 | if (k->defmgmt) { | |
616 | if (k->idx < 4 || k->idx > 5) | |
617 | return -EINVAL; | |
618 | } else if (k->def) { | |
619 | if (k->idx < 0 || k->idx > 3) | |
620 | return -EINVAL; | |
621 | } else { | |
622 | if (k->idx < 0 || k->idx > 5) | |
623 | return -EINVAL; | |
624 | } | |
625 | } | |
626 | ||
627 | return 0; | |
628 | } | |
629 | ||
fffd0934 JB |
630 | static struct cfg80211_cached_keys * |
631 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
632 | struct nlattr *keys) | |
633 | { | |
634 | struct key_parse parse; | |
635 | struct nlattr *key; | |
636 | struct cfg80211_cached_keys *result; | |
637 | int rem, err, def = 0; | |
638 | ||
639 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
640 | if (!result) | |
641 | return ERR_PTR(-ENOMEM); | |
642 | ||
643 | result->def = -1; | |
644 | result->defmgmt = -1; | |
645 | ||
646 | nla_for_each_nested(key, keys, rem) { | |
647 | memset(&parse, 0, sizeof(parse)); | |
648 | parse.idx = -1; | |
649 | ||
650 | err = nl80211_parse_key_new(key, &parse); | |
651 | if (err) | |
652 | goto error; | |
653 | err = -EINVAL; | |
654 | if (!parse.p.key) | |
655 | goto error; | |
656 | if (parse.idx < 0 || parse.idx > 4) | |
657 | goto error; | |
658 | if (parse.def) { | |
659 | if (def) | |
660 | goto error; | |
661 | def = 1; | |
662 | result->def = parse.idx; | |
dbd2fd65 JB |
663 | if (!parse.def_uni || !parse.def_multi) |
664 | goto error; | |
fffd0934 JB |
665 | } else if (parse.defmgmt) |
666 | goto error; | |
667 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 668 | parse.idx, false, NULL); |
fffd0934 JB |
669 | if (err) |
670 | goto error; | |
671 | result->params[parse.idx].cipher = parse.p.cipher; | |
672 | result->params[parse.idx].key_len = parse.p.key_len; | |
673 | result->params[parse.idx].key = result->data[parse.idx]; | |
674 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
675 | } | |
676 | ||
677 | return result; | |
678 | error: | |
679 | kfree(result); | |
680 | return ERR_PTR(err); | |
681 | } | |
682 | ||
683 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
684 | { | |
685 | ASSERT_WDEV_LOCK(wdev); | |
686 | ||
fffd0934 JB |
687 | switch (wdev->iftype) { |
688 | case NL80211_IFTYPE_AP: | |
689 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 690 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 691 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
692 | break; |
693 | case NL80211_IFTYPE_ADHOC: | |
694 | if (!wdev->current_bss) | |
695 | return -ENOLINK; | |
696 | break; | |
697 | case NL80211_IFTYPE_STATION: | |
074ac8df | 698 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
699 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
700 | return -ENOLINK; | |
701 | break; | |
702 | default: | |
703 | return -EINVAL; | |
704 | } | |
705 | ||
706 | return 0; | |
707 | } | |
708 | ||
7527a782 JB |
709 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
710 | { | |
711 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
712 | int i; | |
713 | ||
714 | if (!nl_modes) | |
715 | goto nla_put_failure; | |
716 | ||
717 | i = 0; | |
718 | while (ifmodes) { | |
9360ffd1 DM |
719 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
720 | goto nla_put_failure; | |
7527a782 JB |
721 | ifmodes >>= 1; |
722 | i++; | |
723 | } | |
724 | ||
725 | nla_nest_end(msg, nl_modes); | |
726 | return 0; | |
727 | ||
728 | nla_put_failure: | |
729 | return -ENOBUFS; | |
730 | } | |
731 | ||
732 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
733 | struct sk_buff *msg) | |
734 | { | |
735 | struct nlattr *nl_combis; | |
736 | int i, j; | |
737 | ||
738 | nl_combis = nla_nest_start(msg, | |
739 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
740 | if (!nl_combis) | |
741 | goto nla_put_failure; | |
742 | ||
743 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
744 | const struct ieee80211_iface_combination *c; | |
745 | struct nlattr *nl_combi, *nl_limits; | |
746 | ||
747 | c = &wiphy->iface_combinations[i]; | |
748 | ||
749 | nl_combi = nla_nest_start(msg, i + 1); | |
750 | if (!nl_combi) | |
751 | goto nla_put_failure; | |
752 | ||
753 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
754 | if (!nl_limits) | |
755 | goto nla_put_failure; | |
756 | ||
757 | for (j = 0; j < c->n_limits; j++) { | |
758 | struct nlattr *nl_limit; | |
759 | ||
760 | nl_limit = nla_nest_start(msg, j + 1); | |
761 | if (!nl_limit) | |
762 | goto nla_put_failure; | |
9360ffd1 DM |
763 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
764 | c->limits[j].max)) | |
765 | goto nla_put_failure; | |
7527a782 JB |
766 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
767 | c->limits[j].types)) | |
768 | goto nla_put_failure; | |
769 | nla_nest_end(msg, nl_limit); | |
770 | } | |
771 | ||
772 | nla_nest_end(msg, nl_limits); | |
773 | ||
9360ffd1 DM |
774 | if (c->beacon_int_infra_match && |
775 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
776 | goto nla_put_failure; | |
777 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
778 | c->num_different_channels) || | |
779 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
780 | c->max_interfaces)) | |
781 | goto nla_put_failure; | |
7527a782 JB |
782 | |
783 | nla_nest_end(msg, nl_combi); | |
784 | } | |
785 | ||
786 | nla_nest_end(msg, nl_combis); | |
787 | ||
788 | return 0; | |
789 | nla_put_failure: | |
790 | return -ENOBUFS; | |
791 | } | |
792 | ||
55682965 JB |
793 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
794 | struct cfg80211_registered_device *dev) | |
795 | { | |
796 | void *hdr; | |
ee688b00 JB |
797 | struct nlattr *nl_bands, *nl_band; |
798 | struct nlattr *nl_freqs, *nl_freq; | |
799 | struct nlattr *nl_rates, *nl_rate; | |
8fdc621d | 800 | struct nlattr *nl_cmds; |
ee688b00 JB |
801 | enum ieee80211_band band; |
802 | struct ieee80211_channel *chan; | |
803 | struct ieee80211_rate *rate; | |
804 | int i; | |
2e161f78 JB |
805 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
806 | dev->wiphy.mgmt_stypes; | |
55682965 JB |
807 | |
808 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | |
809 | if (!hdr) | |
810 | return -1; | |
811 | ||
9360ffd1 DM |
812 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
813 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || | |
814 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
815 | cfg80211_rdev_list_generation) || | |
816 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
817 | dev->wiphy.retry_short) || | |
818 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
819 | dev->wiphy.retry_long) || | |
820 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
821 | dev->wiphy.frag_threshold) || | |
822 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
823 | dev->wiphy.rts_threshold) || | |
824 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
825 | dev->wiphy.coverage_class) || | |
826 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
827 | dev->wiphy.max_scan_ssids) || | |
828 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
829 | dev->wiphy.max_sched_scan_ssids) || | |
830 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
831 | dev->wiphy.max_scan_ie_len) || | |
832 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
833 | dev->wiphy.max_sched_scan_ie_len) || | |
834 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
835 | dev->wiphy.max_match_sets)) | |
836 | goto nla_put_failure; | |
837 | ||
838 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
839 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
840 | goto nla_put_failure; | |
841 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && | |
842 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
843 | goto nla_put_failure; | |
844 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
845 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
846 | goto nla_put_failure; | |
847 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
848 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
849 | goto nla_put_failure; | |
850 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
851 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
852 | goto nla_put_failure; | |
853 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
854 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
855 | goto nla_put_failure; | |
856 | ||
857 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
858 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
859 | dev->wiphy.cipher_suites)) | |
860 | goto nla_put_failure; | |
861 | ||
862 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, | |
863 | dev->wiphy.max_num_pmkids)) | |
864 | goto nla_put_failure; | |
865 | ||
866 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
867 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
868 | goto nla_put_failure; | |
869 | ||
870 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, | |
871 | dev->wiphy.available_antennas_tx) || | |
872 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
873 | dev->wiphy.available_antennas_rx)) | |
874 | goto nla_put_failure; | |
875 | ||
876 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && | |
877 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
878 | dev->wiphy.probe_resp_offload)) | |
879 | goto nla_put_failure; | |
87bbbe22 | 880 | |
7f531e03 BR |
881 | if ((dev->wiphy.available_antennas_tx || |
882 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { | |
afe0cbf8 BR |
883 | u32 tx_ant = 0, rx_ant = 0; |
884 | int res; | |
885 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); | |
886 | if (!res) { | |
9360ffd1 DM |
887 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
888 | tx_ant) || | |
889 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, | |
890 | rx_ant)) | |
891 | goto nla_put_failure; | |
afe0cbf8 BR |
892 | } |
893 | } | |
894 | ||
7527a782 JB |
895 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
896 | dev->wiphy.interface_modes)) | |
f59ac048 LR |
897 | goto nla_put_failure; |
898 | ||
ee688b00 JB |
899 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
900 | if (!nl_bands) | |
901 | goto nla_put_failure; | |
902 | ||
903 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
904 | if (!dev->wiphy.bands[band]) | |
905 | continue; | |
906 | ||
907 | nl_band = nla_nest_start(msg, band); | |
908 | if (!nl_band) | |
909 | goto nla_put_failure; | |
910 | ||
d51626df | 911 | /* add HT info */ |
9360ffd1 DM |
912 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
913 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
914 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
915 | &dev->wiphy.bands[band]->ht_cap.mcs) || | |
916 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
917 | dev->wiphy.bands[band]->ht_cap.cap) || | |
918 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
919 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || | |
920 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
921 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) | |
922 | goto nla_put_failure; | |
d51626df | 923 | |
bf0c111e MP |
924 | /* add VHT info */ |
925 | if (dev->wiphy.bands[band]->vht_cap.vht_supported && | |
926 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
927 | sizeof(dev->wiphy.bands[band]->vht_cap.vht_mcs), | |
928 | &dev->wiphy.bands[band]->vht_cap.vht_mcs) || | |
929 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
930 | dev->wiphy.bands[band]->vht_cap.cap))) | |
931 | goto nla_put_failure; | |
932 | ||
ee688b00 JB |
933 | /* add frequencies */ |
934 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
935 | if (!nl_freqs) | |
936 | goto nla_put_failure; | |
937 | ||
938 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
939 | nl_freq = nla_nest_start(msg, i); | |
940 | if (!nl_freq) | |
941 | goto nla_put_failure; | |
942 | ||
943 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
944 | |
945 | if (nl80211_msg_put_channel(msg, chan)) | |
946 | goto nla_put_failure; | |
e2f367f2 | 947 | |
ee688b00 JB |
948 | nla_nest_end(msg, nl_freq); |
949 | } | |
950 | ||
951 | nla_nest_end(msg, nl_freqs); | |
952 | ||
953 | /* add bitrates */ | |
954 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
955 | if (!nl_rates) | |
956 | goto nla_put_failure; | |
957 | ||
958 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
959 | nl_rate = nla_nest_start(msg, i); | |
960 | if (!nl_rate) | |
961 | goto nla_put_failure; | |
962 | ||
963 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
9360ffd1 DM |
964 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
965 | rate->bitrate)) | |
966 | goto nla_put_failure; | |
967 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
968 | nla_put_flag(msg, | |
969 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
970 | goto nla_put_failure; | |
ee688b00 JB |
971 | |
972 | nla_nest_end(msg, nl_rate); | |
973 | } | |
974 | ||
975 | nla_nest_end(msg, nl_rates); | |
976 | ||
977 | nla_nest_end(msg, nl_band); | |
978 | } | |
979 | nla_nest_end(msg, nl_bands); | |
980 | ||
8fdc621d JB |
981 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
982 | if (!nl_cmds) | |
983 | goto nla_put_failure; | |
984 | ||
985 | i = 0; | |
986 | #define CMD(op, n) \ | |
987 | do { \ | |
988 | if (dev->ops->op) { \ | |
989 | i++; \ | |
9360ffd1 DM |
990 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
991 | goto nla_put_failure; \ | |
8fdc621d JB |
992 | } \ |
993 | } while (0) | |
994 | ||
995 | CMD(add_virtual_intf, NEW_INTERFACE); | |
996 | CMD(change_virtual_intf, SET_INTERFACE); | |
997 | CMD(add_key, NEW_KEY); | |
8860020e | 998 | CMD(start_ap, START_AP); |
8fdc621d JB |
999 | CMD(add_station, NEW_STATION); |
1000 | CMD(add_mpath, NEW_MPATH); | |
24bdd9f4 | 1001 | CMD(update_mesh_config, SET_MESH_CONFIG); |
8fdc621d | 1002 | CMD(change_bss, SET_BSS); |
636a5d36 JM |
1003 | CMD(auth, AUTHENTICATE); |
1004 | CMD(assoc, ASSOCIATE); | |
1005 | CMD(deauth, DEAUTHENTICATE); | |
1006 | CMD(disassoc, DISASSOCIATE); | |
04a773ad | 1007 | CMD(join_ibss, JOIN_IBSS); |
29cbe68c | 1008 | CMD(join_mesh, JOIN_MESH); |
67fbb16b SO |
1009 | CMD(set_pmksa, SET_PMKSA); |
1010 | CMD(del_pmksa, DEL_PMKSA); | |
1011 | CMD(flush_pmksa, FLUSH_PMKSA); | |
7c4ef712 JB |
1012 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
1013 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
13ae75b1 | 1014 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
2e161f78 | 1015 | CMD(mgmt_tx, FRAME); |
f7ca38df | 1016 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
5be83de5 | 1017 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
463d0183 | 1018 | i++; |
9360ffd1 DM |
1019 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
1020 | goto nla_put_failure; | |
463d0183 | 1021 | } |
e8c9bd5b | 1022 | if (dev->ops->set_monitor_channel || dev->ops->start_ap || |
cc1d2806 | 1023 | dev->ops->join_mesh) { |
aa430da4 JB |
1024 | i++; |
1025 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1026 | goto nla_put_failure; | |
1027 | } | |
e8347eba | 1028 | CMD(set_wds_peer, SET_WDS_PEER); |
109086ce AN |
1029 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
1030 | CMD(tdls_mgmt, TDLS_MGMT); | |
1031 | CMD(tdls_oper, TDLS_OPER); | |
1032 | } | |
807f8a8c LC |
1033 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
1034 | CMD(sched_scan_start, START_SCHED_SCAN); | |
7f6cf311 | 1035 | CMD(probe_client, PROBE_CLIENT); |
1d9d9213 | 1036 | CMD(set_noack_map, SET_NOACK_MAP); |
5e760230 JB |
1037 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
1038 | i++; | |
9360ffd1 DM |
1039 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
1040 | goto nla_put_failure; | |
5e760230 | 1041 | } |
8fdc621d | 1042 | |
4745fc09 KV |
1043 | #ifdef CONFIG_NL80211_TESTMODE |
1044 | CMD(testmode_cmd, TESTMODE); | |
1045 | #endif | |
1046 | ||
8fdc621d | 1047 | #undef CMD |
b23aa676 | 1048 | |
6829c878 | 1049 | if (dev->ops->connect || dev->ops->auth) { |
b23aa676 | 1050 | i++; |
9360ffd1 DM |
1051 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
1052 | goto nla_put_failure; | |
b23aa676 SO |
1053 | } |
1054 | ||
6829c878 | 1055 | if (dev->ops->disconnect || dev->ops->deauth) { |
b23aa676 | 1056 | i++; |
9360ffd1 DM |
1057 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
1058 | goto nla_put_failure; | |
b23aa676 SO |
1059 | } |
1060 | ||
8fdc621d JB |
1061 | nla_nest_end(msg, nl_cmds); |
1062 | ||
7c4ef712 | 1063 | if (dev->ops->remain_on_channel && |
9360ffd1 DM |
1064 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
1065 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1066 | dev->wiphy.max_remain_on_channel_duration)) | |
1067 | goto nla_put_failure; | |
a293911d | 1068 | |
9360ffd1 DM |
1069 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
1070 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
1071 | goto nla_put_failure; | |
f7ca38df | 1072 | |
2e161f78 JB |
1073 | if (mgmt_stypes) { |
1074 | u16 stypes; | |
1075 | struct nlattr *nl_ftypes, *nl_ifs; | |
1076 | enum nl80211_iftype ift; | |
1077 | ||
1078 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | |
1079 | if (!nl_ifs) | |
1080 | goto nla_put_failure; | |
1081 | ||
1082 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
1083 | nl_ftypes = nla_nest_start(msg, ift); | |
1084 | if (!nl_ftypes) | |
1085 | goto nla_put_failure; | |
1086 | i = 0; | |
1087 | stypes = mgmt_stypes[ift].tx; | |
1088 | while (stypes) { | |
9360ffd1 DM |
1089 | if ((stypes & 1) && |
1090 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1091 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1092 | goto nla_put_failure; | |
2e161f78 JB |
1093 | stypes >>= 1; |
1094 | i++; | |
1095 | } | |
1096 | nla_nest_end(msg, nl_ftypes); | |
1097 | } | |
1098 | ||
74b70a4e JB |
1099 | nla_nest_end(msg, nl_ifs); |
1100 | ||
2e161f78 JB |
1101 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1102 | if (!nl_ifs) | |
1103 | goto nla_put_failure; | |
1104 | ||
1105 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
1106 | nl_ftypes = nla_nest_start(msg, ift); | |
1107 | if (!nl_ftypes) | |
1108 | goto nla_put_failure; | |
1109 | i = 0; | |
1110 | stypes = mgmt_stypes[ift].rx; | |
1111 | while (stypes) { | |
9360ffd1 DM |
1112 | if ((stypes & 1) && |
1113 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1114 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1115 | goto nla_put_failure; | |
2e161f78 JB |
1116 | stypes >>= 1; |
1117 | i++; | |
1118 | } | |
1119 | nla_nest_end(msg, nl_ftypes); | |
1120 | } | |
1121 | nla_nest_end(msg, nl_ifs); | |
1122 | } | |
1123 | ||
dfb89c56 | 1124 | #ifdef CONFIG_PM |
ff1b6e69 JB |
1125 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
1126 | struct nlattr *nl_wowlan; | |
1127 | ||
1128 | nl_wowlan = nla_nest_start(msg, | |
1129 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | |
1130 | if (!nl_wowlan) | |
1131 | goto nla_put_failure; | |
1132 | ||
9360ffd1 DM |
1133 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
1134 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
1135 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
1136 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
1137 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
1138 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
1139 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
1140 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
1141 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
1142 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
1143 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
1144 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1145 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1146 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1147 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1148 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1149 | goto nla_put_failure; | |
ff1b6e69 JB |
1150 | if (dev->wiphy.wowlan.n_patterns) { |
1151 | struct nl80211_wowlan_pattern_support pat = { | |
1152 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1153 | .min_pattern_len = | |
1154 | dev->wiphy.wowlan.pattern_min_len, | |
1155 | .max_pattern_len = | |
1156 | dev->wiphy.wowlan.pattern_max_len, | |
1157 | }; | |
9360ffd1 DM |
1158 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1159 | sizeof(pat), &pat)) | |
1160 | goto nla_put_failure; | |
ff1b6e69 JB |
1161 | } |
1162 | ||
1163 | nla_nest_end(msg, nl_wowlan); | |
1164 | } | |
dfb89c56 | 1165 | #endif |
ff1b6e69 | 1166 | |
7527a782 JB |
1167 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
1168 | dev->wiphy.software_iftypes)) | |
1169 | goto nla_put_failure; | |
1170 | ||
1171 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) | |
1172 | goto nla_put_failure; | |
1173 | ||
9360ffd1 DM |
1174 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
1175 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1176 | dev->wiphy.ap_sme_capa)) | |
1177 | goto nla_put_failure; | |
562a7480 | 1178 | |
9360ffd1 DM |
1179 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
1180 | dev->wiphy.features)) | |
1181 | goto nla_put_failure; | |
1f074bd8 | 1182 | |
9360ffd1 DM |
1183 | if (dev->wiphy.ht_capa_mod_mask && |
1184 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1185 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1186 | dev->wiphy.ht_capa_mod_mask)) | |
1187 | goto nla_put_failure; | |
7e7c8926 | 1188 | |
55682965 JB |
1189 | return genlmsg_end(msg, hdr); |
1190 | ||
1191 | nla_put_failure: | |
bc3ed28c TG |
1192 | genlmsg_cancel(msg, hdr); |
1193 | return -EMSGSIZE; | |
55682965 JB |
1194 | } |
1195 | ||
1196 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1197 | { | |
1198 | int idx = 0; | |
1199 | int start = cb->args[0]; | |
1200 | struct cfg80211_registered_device *dev; | |
1201 | ||
a1794390 | 1202 | mutex_lock(&cfg80211_mutex); |
79c97e97 | 1203 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1204 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1205 | continue; | |
b4637271 | 1206 | if (++idx <= start) |
55682965 JB |
1207 | continue; |
1208 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, | |
1209 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
b4637271 JV |
1210 | dev) < 0) { |
1211 | idx--; | |
55682965 | 1212 | break; |
b4637271 | 1213 | } |
55682965 | 1214 | } |
a1794390 | 1215 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1216 | |
1217 | cb->args[0] = idx; | |
1218 | ||
1219 | return skb->len; | |
1220 | } | |
1221 | ||
1222 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1223 | { | |
1224 | struct sk_buff *msg; | |
4c476991 | 1225 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1226 | |
fd2120ca | 1227 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1228 | if (!msg) |
4c476991 | 1229 | return -ENOMEM; |
55682965 | 1230 | |
4c476991 JB |
1231 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
1232 | nlmsg_free(msg); | |
1233 | return -ENOBUFS; | |
1234 | } | |
55682965 | 1235 | |
134e6375 | 1236 | return genlmsg_reply(msg, info); |
55682965 JB |
1237 | } |
1238 | ||
31888487 JM |
1239 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1240 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1241 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1242 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1243 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1244 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1245 | }; | |
1246 | ||
1247 | static int parse_txq_params(struct nlattr *tb[], | |
1248 | struct ieee80211_txq_params *txq_params) | |
1249 | { | |
a3304b0a | 1250 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1251 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1252 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1253 | return -EINVAL; | |
1254 | ||
a3304b0a | 1255 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1256 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1257 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1258 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1259 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1260 | ||
a3304b0a JB |
1261 | if (txq_params->ac >= NL80211_NUM_ACS) |
1262 | return -EINVAL; | |
1263 | ||
31888487 JM |
1264 | return 0; |
1265 | } | |
1266 | ||
f444de05 JB |
1267 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1268 | { | |
1269 | /* | |
cc1d2806 JB |
1270 | * You can only set the channel explicitly for WDS interfaces, |
1271 | * all others have their channel managed via their respective | |
1272 | * "establish a connection" command (connect, join, ...) | |
1273 | * | |
1274 | * For AP/GO and mesh mode, the channel can be set with the | |
1275 | * channel userspace API, but is only stored and passed to the | |
1276 | * low-level driver when the AP starts or the mesh is joined. | |
1277 | * This is for backward compatibility, userspace can also give | |
1278 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1279 | * |
1280 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1281 | * whatever else is going on, so they have their own special |
1282 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1283 | */ |
1284 | return !wdev || | |
1285 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1286 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1287 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1288 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1289 | } |
1290 | ||
cd6c6598 JB |
1291 | static bool nl80211_valid_channel_type(struct genl_info *info, |
1292 | enum nl80211_channel_type *channel_type) | |
1293 | { | |
1294 | enum nl80211_channel_type tmp; | |
1295 | ||
1296 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) | |
1297 | return false; | |
1298 | ||
1299 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1300 | if (tmp != NL80211_CHAN_NO_HT && | |
1301 | tmp != NL80211_CHAN_HT20 && | |
1302 | tmp != NL80211_CHAN_HT40PLUS && | |
1303 | tmp != NL80211_CHAN_HT40MINUS) | |
1304 | return false; | |
1305 | ||
1306 | if (channel_type) | |
1307 | *channel_type = tmp; | |
1308 | ||
1309 | return true; | |
1310 | } | |
1311 | ||
f444de05 JB |
1312 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1313 | struct wireless_dev *wdev, | |
1314 | struct genl_info *info) | |
1315 | { | |
aa430da4 | 1316 | struct ieee80211_channel *channel; |
f444de05 JB |
1317 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
1318 | u32 freq; | |
1319 | int result; | |
e8c9bd5b JB |
1320 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
1321 | ||
1322 | if (wdev) | |
1323 | iftype = wdev->iftype; | |
f444de05 JB |
1324 | |
1325 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1326 | return -EINVAL; | |
1327 | ||
1328 | if (!nl80211_can_set_dev_channel(wdev)) | |
1329 | return -EOPNOTSUPP; | |
1330 | ||
cd6c6598 JB |
1331 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
1332 | !nl80211_valid_channel_type(info, &channel_type)) | |
1333 | return -EINVAL; | |
f444de05 JB |
1334 | |
1335 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1336 | ||
1337 | mutex_lock(&rdev->devlist_mtx); | |
e8c9bd5b | 1338 | switch (iftype) { |
aa430da4 JB |
1339 | case NL80211_IFTYPE_AP: |
1340 | case NL80211_IFTYPE_P2P_GO: | |
1341 | if (wdev->beacon_interval) { | |
1342 | result = -EBUSY; | |
1343 | break; | |
1344 | } | |
1345 | channel = rdev_freq_to_chan(rdev, freq, channel_type); | |
1346 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, | |
1347 | channel, | |
1348 | channel_type)) { | |
1349 | result = -EINVAL; | |
1350 | break; | |
1351 | } | |
1352 | wdev->preset_chan = channel; | |
1353 | wdev->preset_chantype = channel_type; | |
1354 | result = 0; | |
1355 | break; | |
cc1d2806 JB |
1356 | case NL80211_IFTYPE_MESH_POINT: |
1357 | result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type); | |
1358 | break; | |
e8c9bd5b JB |
1359 | case NL80211_IFTYPE_MONITOR: |
1360 | result = cfg80211_set_monitor_channel(rdev, freq, channel_type); | |
1361 | break; | |
aa430da4 | 1362 | default: |
e8c9bd5b | 1363 | result = -EINVAL; |
f444de05 JB |
1364 | } |
1365 | mutex_unlock(&rdev->devlist_mtx); | |
1366 | ||
1367 | return result; | |
1368 | } | |
1369 | ||
1370 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1371 | { | |
4c476991 JB |
1372 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1373 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1374 | |
4c476991 | 1375 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1376 | } |
1377 | ||
e8347eba BJ |
1378 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1379 | { | |
43b19952 JB |
1380 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1381 | struct net_device *dev = info->user_ptr[1]; | |
1382 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1383 | const u8 *bssid; |
e8347eba BJ |
1384 | |
1385 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1386 | return -EINVAL; | |
1387 | ||
43b19952 JB |
1388 | if (netif_running(dev)) |
1389 | return -EBUSY; | |
e8347eba | 1390 | |
43b19952 JB |
1391 | if (!rdev->ops->set_wds_peer) |
1392 | return -EOPNOTSUPP; | |
e8347eba | 1393 | |
43b19952 JB |
1394 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1395 | return -EOPNOTSUPP; | |
e8347eba BJ |
1396 | |
1397 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
43b19952 | 1398 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
e8347eba BJ |
1399 | } |
1400 | ||
1401 | ||
55682965 JB |
1402 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1403 | { | |
1404 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1405 | struct net_device *netdev = NULL; |
1406 | struct wireless_dev *wdev; | |
a1e567c8 | 1407 | int result = 0, rem_txq_params = 0; |
31888487 | 1408 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1409 | u32 changed; |
1410 | u8 retry_short = 0, retry_long = 0; | |
1411 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1412 | u8 coverage_class = 0; |
55682965 | 1413 | |
f444de05 JB |
1414 | /* |
1415 | * Try to find the wiphy and netdev. Normally this | |
1416 | * function shouldn't need the netdev, but this is | |
1417 | * done for backward compatibility -- previously | |
1418 | * setting the channel was done per wiphy, but now | |
1419 | * it is per netdev. Previous userland like hostapd | |
1420 | * also passed a netdev to set_wiphy, so that it is | |
1421 | * possible to let that go to the right netdev! | |
1422 | */ | |
4bbf4d56 JB |
1423 | mutex_lock(&cfg80211_mutex); |
1424 | ||
f444de05 JB |
1425 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1426 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1427 | ||
1428 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1429 | if (netdev && netdev->ieee80211_ptr) { | |
1430 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1431 | mutex_lock(&rdev->mtx); | |
1432 | } else | |
1433 | netdev = NULL; | |
4bbf4d56 JB |
1434 | } |
1435 | ||
f444de05 | 1436 | if (!netdev) { |
878d9ec7 JB |
1437 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
1438 | info->attrs); | |
f444de05 JB |
1439 | if (IS_ERR(rdev)) { |
1440 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1441 | return PTR_ERR(rdev); |
f444de05 JB |
1442 | } |
1443 | wdev = NULL; | |
1444 | netdev = NULL; | |
1445 | result = 0; | |
1446 | ||
1447 | mutex_lock(&rdev->mtx); | |
cc1d2806 | 1448 | } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) |
f444de05 JB |
1449 | wdev = netdev->ieee80211_ptr; |
1450 | else | |
1451 | wdev = NULL; | |
1452 | ||
1453 | /* | |
1454 | * end workaround code, by now the rdev is available | |
1455 | * and locked, and wdev may or may not be NULL. | |
1456 | */ | |
4bbf4d56 JB |
1457 | |
1458 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1459 | result = cfg80211_dev_rename( |
1460 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1461 | |
1462 | mutex_unlock(&cfg80211_mutex); | |
1463 | ||
1464 | if (result) | |
1465 | goto bad_res; | |
31888487 JM |
1466 | |
1467 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1468 | struct ieee80211_txq_params txq_params; | |
1469 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1470 | ||
1471 | if (!rdev->ops->set_txq_params) { | |
1472 | result = -EOPNOTSUPP; | |
1473 | goto bad_res; | |
1474 | } | |
1475 | ||
f70f01c2 EP |
1476 | if (!netdev) { |
1477 | result = -EINVAL; | |
1478 | goto bad_res; | |
1479 | } | |
1480 | ||
133a3ff2 JB |
1481 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1482 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1483 | result = -EINVAL; | |
1484 | goto bad_res; | |
1485 | } | |
1486 | ||
2b5f8b0b JB |
1487 | if (!netif_running(netdev)) { |
1488 | result = -ENETDOWN; | |
1489 | goto bad_res; | |
1490 | } | |
1491 | ||
31888487 JM |
1492 | nla_for_each_nested(nl_txq_params, |
1493 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1494 | rem_txq_params) { | |
1495 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1496 | nla_data(nl_txq_params), | |
1497 | nla_len(nl_txq_params), | |
1498 | txq_params_policy); | |
1499 | result = parse_txq_params(tb, &txq_params); | |
1500 | if (result) | |
1501 | goto bad_res; | |
1502 | ||
1503 | result = rdev->ops->set_txq_params(&rdev->wiphy, | |
f70f01c2 | 1504 | netdev, |
31888487 JM |
1505 | &txq_params); |
1506 | if (result) | |
1507 | goto bad_res; | |
1508 | } | |
1509 | } | |
55682965 | 1510 | |
72bdcf34 | 1511 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
f444de05 | 1512 | result = __nl80211_set_channel(rdev, wdev, info); |
72bdcf34 JM |
1513 | if (result) |
1514 | goto bad_res; | |
1515 | } | |
1516 | ||
98d2ff8b JO |
1517 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
1518 | enum nl80211_tx_power_setting type; | |
1519 | int idx, mbm = 0; | |
1520 | ||
1521 | if (!rdev->ops->set_tx_power) { | |
60ea385f | 1522 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1523 | goto bad_res; |
1524 | } | |
1525 | ||
1526 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1527 | type = nla_get_u32(info->attrs[idx]); | |
1528 | ||
1529 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1530 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1531 | result = -EINVAL; | |
1532 | goto bad_res; | |
1533 | } | |
1534 | ||
1535 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1536 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1537 | mbm = nla_get_u32(info->attrs[idx]); | |
1538 | } | |
1539 | ||
1540 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); | |
1541 | if (result) | |
1542 | goto bad_res; | |
1543 | } | |
1544 | ||
afe0cbf8 BR |
1545 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1546 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1547 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1548 | if ((!rdev->wiphy.available_antennas_tx && |
1549 | !rdev->wiphy.available_antennas_rx) || | |
1550 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1551 | result = -EOPNOTSUPP; |
1552 | goto bad_res; | |
1553 | } | |
1554 | ||
1555 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1556 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
1557 | ||
a7ffac95 | 1558 | /* reject antenna configurations which don't match the |
7f531e03 BR |
1559 | * available antenna masks, except for the "all" mask */ |
1560 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
1561 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
1562 | result = -EINVAL; |
1563 | goto bad_res; | |
1564 | } | |
1565 | ||
7f531e03 BR |
1566 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
1567 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 1568 | |
afe0cbf8 BR |
1569 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
1570 | if (result) | |
1571 | goto bad_res; | |
1572 | } | |
1573 | ||
b9a5f8ca JM |
1574 | changed = 0; |
1575 | ||
1576 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
1577 | retry_short = nla_get_u8( | |
1578 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
1579 | if (retry_short == 0) { | |
1580 | result = -EINVAL; | |
1581 | goto bad_res; | |
1582 | } | |
1583 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
1584 | } | |
1585 | ||
1586 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
1587 | retry_long = nla_get_u8( | |
1588 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
1589 | if (retry_long == 0) { | |
1590 | result = -EINVAL; | |
1591 | goto bad_res; | |
1592 | } | |
1593 | changed |= WIPHY_PARAM_RETRY_LONG; | |
1594 | } | |
1595 | ||
1596 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
1597 | frag_threshold = nla_get_u32( | |
1598 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
1599 | if (frag_threshold < 256) { | |
1600 | result = -EINVAL; | |
1601 | goto bad_res; | |
1602 | } | |
1603 | if (frag_threshold != (u32) -1) { | |
1604 | /* | |
1605 | * Fragments (apart from the last one) are required to | |
1606 | * have even length. Make the fragmentation code | |
1607 | * simpler by stripping LSB should someone try to use | |
1608 | * odd threshold value. | |
1609 | */ | |
1610 | frag_threshold &= ~0x1; | |
1611 | } | |
1612 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
1613 | } | |
1614 | ||
1615 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
1616 | rts_threshold = nla_get_u32( | |
1617 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
1618 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
1619 | } | |
1620 | ||
81077e82 LT |
1621 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
1622 | coverage_class = nla_get_u8( | |
1623 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
1624 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
1625 | } | |
1626 | ||
b9a5f8ca JM |
1627 | if (changed) { |
1628 | u8 old_retry_short, old_retry_long; | |
1629 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 1630 | u8 old_coverage_class; |
b9a5f8ca JM |
1631 | |
1632 | if (!rdev->ops->set_wiphy_params) { | |
1633 | result = -EOPNOTSUPP; | |
1634 | goto bad_res; | |
1635 | } | |
1636 | ||
1637 | old_retry_short = rdev->wiphy.retry_short; | |
1638 | old_retry_long = rdev->wiphy.retry_long; | |
1639 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
1640 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 1641 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
1642 | |
1643 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1644 | rdev->wiphy.retry_short = retry_short; | |
1645 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1646 | rdev->wiphy.retry_long = retry_long; | |
1647 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
1648 | rdev->wiphy.frag_threshold = frag_threshold; | |
1649 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
1650 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
1651 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
1652 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca JM |
1653 | |
1654 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); | |
1655 | if (result) { | |
1656 | rdev->wiphy.retry_short = old_retry_short; | |
1657 | rdev->wiphy.retry_long = old_retry_long; | |
1658 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
1659 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 1660 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
1661 | } |
1662 | } | |
72bdcf34 | 1663 | |
306d6112 | 1664 | bad_res: |
4bbf4d56 | 1665 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
1666 | if (netdev) |
1667 | dev_put(netdev); | |
55682965 JB |
1668 | return result; |
1669 | } | |
1670 | ||
1671 | ||
1672 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
d726405a | 1673 | struct cfg80211_registered_device *rdev, |
55682965 JB |
1674 | struct net_device *dev) |
1675 | { | |
1676 | void *hdr; | |
1677 | ||
1678 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); | |
1679 | if (!hdr) | |
1680 | return -1; | |
1681 | ||
9360ffd1 DM |
1682 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
1683 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
1684 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) || | |
1685 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
1686 | dev->ieee80211_ptr->iftype) || | |
1687 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1688 | rdev->devlist_generation ^ | |
1689 | (cfg80211_rdev_list_generation << 2))) | |
1690 | goto nla_put_failure; | |
f5ea9120 | 1691 | |
d91df0e3 PF |
1692 | if (rdev->ops->get_channel) { |
1693 | struct ieee80211_channel *chan; | |
1694 | enum nl80211_channel_type channel_type; | |
1695 | ||
1696 | chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type); | |
59ef43e6 JL |
1697 | if (chan && |
1698 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, | |
1699 | chan->center_freq) || | |
1700 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
1701 | channel_type))) | |
1702 | goto nla_put_failure; | |
d91df0e3 PF |
1703 | } |
1704 | ||
55682965 JB |
1705 | return genlmsg_end(msg, hdr); |
1706 | ||
1707 | nla_put_failure: | |
bc3ed28c TG |
1708 | genlmsg_cancel(msg, hdr); |
1709 | return -EMSGSIZE; | |
55682965 JB |
1710 | } |
1711 | ||
1712 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
1713 | { | |
1714 | int wp_idx = 0; | |
1715 | int if_idx = 0; | |
1716 | int wp_start = cb->args[0]; | |
1717 | int if_start = cb->args[1]; | |
f5ea9120 | 1718 | struct cfg80211_registered_device *rdev; |
55682965 JB |
1719 | struct wireless_dev *wdev; |
1720 | ||
a1794390 | 1721 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
1722 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1723 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1724 | continue; |
bba95fef JB |
1725 | if (wp_idx < wp_start) { |
1726 | wp_idx++; | |
55682965 | 1727 | continue; |
bba95fef | 1728 | } |
55682965 JB |
1729 | if_idx = 0; |
1730 | ||
f5ea9120 JB |
1731 | mutex_lock(&rdev->devlist_mtx); |
1732 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
bba95fef JB |
1733 | if (if_idx < if_start) { |
1734 | if_idx++; | |
55682965 | 1735 | continue; |
bba95fef | 1736 | } |
55682965 JB |
1737 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
1738 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
f5ea9120 JB |
1739 | rdev, wdev->netdev) < 0) { |
1740 | mutex_unlock(&rdev->devlist_mtx); | |
bba95fef JB |
1741 | goto out; |
1742 | } | |
1743 | if_idx++; | |
55682965 | 1744 | } |
f5ea9120 | 1745 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
1746 | |
1747 | wp_idx++; | |
55682965 | 1748 | } |
bba95fef | 1749 | out: |
a1794390 | 1750 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1751 | |
1752 | cb->args[0] = wp_idx; | |
1753 | cb->args[1] = if_idx; | |
1754 | ||
1755 | return skb->len; | |
1756 | } | |
1757 | ||
1758 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
1759 | { | |
1760 | struct sk_buff *msg; | |
4c476991 JB |
1761 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
1762 | struct net_device *netdev = info->user_ptr[1]; | |
55682965 | 1763 | |
fd2120ca | 1764 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1765 | if (!msg) |
4c476991 | 1766 | return -ENOMEM; |
55682965 | 1767 | |
d726405a | 1768 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
4c476991 JB |
1769 | dev, netdev) < 0) { |
1770 | nlmsg_free(msg); | |
1771 | return -ENOBUFS; | |
1772 | } | |
55682965 | 1773 | |
134e6375 | 1774 | return genlmsg_reply(msg, info); |
55682965 JB |
1775 | } |
1776 | ||
66f7ac50 MW |
1777 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
1778 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
1779 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
1780 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
1781 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
1782 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
1783 | }; | |
1784 | ||
1785 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
1786 | { | |
1787 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
1788 | int flag; | |
1789 | ||
1790 | *mntrflags = 0; | |
1791 | ||
1792 | if (!nla) | |
1793 | return -EINVAL; | |
1794 | ||
1795 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
1796 | nla, mntr_flags_policy)) | |
1797 | return -EINVAL; | |
1798 | ||
1799 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
1800 | if (flags[flag]) | |
1801 | *mntrflags |= (1<<flag); | |
1802 | ||
1803 | return 0; | |
1804 | } | |
1805 | ||
9bc383de | 1806 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
1807 | struct net_device *netdev, u8 use_4addr, |
1808 | enum nl80211_iftype iftype) | |
9bc383de | 1809 | { |
ad4bb6f8 | 1810 | if (!use_4addr) { |
f350a0a8 | 1811 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 1812 | return -EBUSY; |
9bc383de | 1813 | return 0; |
ad4bb6f8 | 1814 | } |
9bc383de JB |
1815 | |
1816 | switch (iftype) { | |
1817 | case NL80211_IFTYPE_AP_VLAN: | |
1818 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
1819 | return 0; | |
1820 | break; | |
1821 | case NL80211_IFTYPE_STATION: | |
1822 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
1823 | return 0; | |
1824 | break; | |
1825 | default: | |
1826 | break; | |
1827 | } | |
1828 | ||
1829 | return -EOPNOTSUPP; | |
1830 | } | |
1831 | ||
55682965 JB |
1832 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
1833 | { | |
4c476991 | 1834 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 1835 | struct vif_params params; |
e36d56b6 | 1836 | int err; |
04a773ad | 1837 | enum nl80211_iftype otype, ntype; |
4c476991 | 1838 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 1839 | u32 _flags, *flags = NULL; |
ac7f9cfa | 1840 | bool change = false; |
55682965 | 1841 | |
2ec600d6 LCC |
1842 | memset(¶ms, 0, sizeof(params)); |
1843 | ||
04a773ad | 1844 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 1845 | |
723b038d | 1846 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 1847 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 1848 | if (otype != ntype) |
ac7f9cfa | 1849 | change = true; |
4c476991 JB |
1850 | if (ntype > NL80211_IFTYPE_MAX) |
1851 | return -EINVAL; | |
723b038d JB |
1852 | } |
1853 | ||
92ffe055 | 1854 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
1855 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
1856 | ||
4c476991 JB |
1857 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
1858 | return -EINVAL; | |
29cbe68c JB |
1859 | if (netif_running(dev)) |
1860 | return -EBUSY; | |
1861 | ||
1862 | wdev_lock(wdev); | |
1863 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
1864 | IEEE80211_MAX_MESH_ID_LEN); | |
1865 | wdev->mesh_id_up_len = | |
1866 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1867 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
1868 | wdev->mesh_id_up_len); | |
1869 | wdev_unlock(wdev); | |
2ec600d6 LCC |
1870 | } |
1871 | ||
8b787643 FF |
1872 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
1873 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
1874 | change = true; | |
ad4bb6f8 | 1875 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 1876 | if (err) |
4c476991 | 1877 | return err; |
8b787643 FF |
1878 | } else { |
1879 | params.use_4addr = -1; | |
1880 | } | |
1881 | ||
92ffe055 | 1882 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
1883 | if (ntype != NL80211_IFTYPE_MONITOR) |
1884 | return -EINVAL; | |
92ffe055 JB |
1885 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
1886 | &_flags); | |
ac7f9cfa | 1887 | if (err) |
4c476991 | 1888 | return err; |
ac7f9cfa JB |
1889 | |
1890 | flags = &_flags; | |
1891 | change = true; | |
92ffe055 | 1892 | } |
3b85875a | 1893 | |
ac7f9cfa | 1894 | if (change) |
3d54d255 | 1895 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
1896 | else |
1897 | err = 0; | |
60719ffd | 1898 | |
9bc383de JB |
1899 | if (!err && params.use_4addr != -1) |
1900 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
1901 | ||
55682965 JB |
1902 | return err; |
1903 | } | |
1904 | ||
1905 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
1906 | { | |
4c476991 | 1907 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 1908 | struct vif_params params; |
f9e10ce4 | 1909 | struct net_device *dev; |
55682965 JB |
1910 | int err; |
1911 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 1912 | u32 flags; |
55682965 | 1913 | |
2ec600d6 LCC |
1914 | memset(¶ms, 0, sizeof(params)); |
1915 | ||
55682965 JB |
1916 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
1917 | return -EINVAL; | |
1918 | ||
1919 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
1920 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
1921 | if (type > NL80211_IFTYPE_MAX) | |
1922 | return -EINVAL; | |
1923 | } | |
1924 | ||
79c97e97 | 1925 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
1926 | !(rdev->wiphy.interface_modes & (1 << type))) |
1927 | return -EOPNOTSUPP; | |
55682965 | 1928 | |
9bc383de | 1929 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 1930 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 1931 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 1932 | if (err) |
4c476991 | 1933 | return err; |
9bc383de | 1934 | } |
8b787643 | 1935 | |
66f7ac50 MW |
1936 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
1937 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
1938 | &flags); | |
f9e10ce4 | 1939 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
66f7ac50 | 1940 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
2ec600d6 | 1941 | type, err ? NULL : &flags, ¶ms); |
f9e10ce4 JB |
1942 | if (IS_ERR(dev)) |
1943 | return PTR_ERR(dev); | |
2ec600d6 | 1944 | |
29cbe68c JB |
1945 | if (type == NL80211_IFTYPE_MESH_POINT && |
1946 | info->attrs[NL80211_ATTR_MESH_ID]) { | |
1947 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1948 | ||
1949 | wdev_lock(wdev); | |
1950 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
1951 | IEEE80211_MAX_MESH_ID_LEN); | |
1952 | wdev->mesh_id_up_len = | |
1953 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1954 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
1955 | wdev->mesh_id_up_len); | |
1956 | wdev_unlock(wdev); | |
1957 | } | |
1958 | ||
f9e10ce4 | 1959 | return 0; |
55682965 JB |
1960 | } |
1961 | ||
1962 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
1963 | { | |
4c476991 JB |
1964 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1965 | struct net_device *dev = info->user_ptr[1]; | |
55682965 | 1966 | |
4c476991 JB |
1967 | if (!rdev->ops->del_virtual_intf) |
1968 | return -EOPNOTSUPP; | |
55682965 | 1969 | |
4c476991 | 1970 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
55682965 JB |
1971 | } |
1972 | ||
1d9d9213 SW |
1973 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
1974 | { | |
1975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
1976 | struct net_device *dev = info->user_ptr[1]; | |
1977 | u16 noack_map; | |
1978 | ||
1979 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
1980 | return -EINVAL; | |
1981 | ||
1982 | if (!rdev->ops->set_noack_map) | |
1983 | return -EOPNOTSUPP; | |
1984 | ||
1985 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
1986 | ||
1987 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); | |
1988 | } | |
1989 | ||
41ade00f JB |
1990 | struct get_key_cookie { |
1991 | struct sk_buff *msg; | |
1992 | int error; | |
b9454e83 | 1993 | int idx; |
41ade00f JB |
1994 | }; |
1995 | ||
1996 | static void get_key_callback(void *c, struct key_params *params) | |
1997 | { | |
b9454e83 | 1998 | struct nlattr *key; |
41ade00f JB |
1999 | struct get_key_cookie *cookie = c; |
2000 | ||
9360ffd1 DM |
2001 | if ((params->key && |
2002 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2003 | params->key_len, params->key)) || | |
2004 | (params->seq && | |
2005 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2006 | params->seq_len, params->seq)) || | |
2007 | (params->cipher && | |
2008 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2009 | params->cipher))) | |
2010 | goto nla_put_failure; | |
41ade00f | 2011 | |
b9454e83 JB |
2012 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2013 | if (!key) | |
2014 | goto nla_put_failure; | |
2015 | ||
9360ffd1 DM |
2016 | if ((params->key && |
2017 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2018 | params->key_len, params->key)) || | |
2019 | (params->seq && | |
2020 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2021 | params->seq_len, params->seq)) || | |
2022 | (params->cipher && | |
2023 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2024 | params->cipher))) | |
2025 | goto nla_put_failure; | |
b9454e83 | 2026 | |
9360ffd1 DM |
2027 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2028 | goto nla_put_failure; | |
b9454e83 JB |
2029 | |
2030 | nla_nest_end(cookie->msg, key); | |
2031 | ||
41ade00f JB |
2032 | return; |
2033 | nla_put_failure: | |
2034 | cookie->error = 1; | |
2035 | } | |
2036 | ||
2037 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2038 | { | |
4c476991 | 2039 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2040 | int err; |
4c476991 | 2041 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2042 | u8 key_idx = 0; |
e31b8213 JB |
2043 | const u8 *mac_addr = NULL; |
2044 | bool pairwise; | |
41ade00f JB |
2045 | struct get_key_cookie cookie = { |
2046 | .error = 0, | |
2047 | }; | |
2048 | void *hdr; | |
2049 | struct sk_buff *msg; | |
2050 | ||
2051 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2052 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2053 | ||
3cfcf6ac | 2054 | if (key_idx > 5) |
41ade00f JB |
2055 | return -EINVAL; |
2056 | ||
2057 | if (info->attrs[NL80211_ATTR_MAC]) | |
2058 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2059 | ||
e31b8213 JB |
2060 | pairwise = !!mac_addr; |
2061 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2062 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2063 | if (kt >= NUM_NL80211_KEYTYPES) | |
2064 | return -EINVAL; | |
2065 | if (kt != NL80211_KEYTYPE_GROUP && | |
2066 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2067 | return -EINVAL; | |
2068 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2069 | } | |
2070 | ||
4c476991 JB |
2071 | if (!rdev->ops->get_key) |
2072 | return -EOPNOTSUPP; | |
41ade00f | 2073 | |
fd2120ca | 2074 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2075 | if (!msg) |
2076 | return -ENOMEM; | |
41ade00f JB |
2077 | |
2078 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2079 | NL80211_CMD_NEW_KEY); | |
4c476991 JB |
2080 | if (IS_ERR(hdr)) |
2081 | return PTR_ERR(hdr); | |
41ade00f JB |
2082 | |
2083 | cookie.msg = msg; | |
b9454e83 | 2084 | cookie.idx = key_idx; |
41ade00f | 2085 | |
9360ffd1 DM |
2086 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2087 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2088 | goto nla_put_failure; | |
2089 | if (mac_addr && | |
2090 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2091 | goto nla_put_failure; | |
41ade00f | 2092 | |
e31b8213 JB |
2093 | if (pairwise && mac_addr && |
2094 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2095 | return -ENOENT; | |
2096 | ||
2097 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, | |
2098 | mac_addr, &cookie, get_key_callback); | |
41ade00f JB |
2099 | |
2100 | if (err) | |
6c95e2a2 | 2101 | goto free_msg; |
41ade00f JB |
2102 | |
2103 | if (cookie.error) | |
2104 | goto nla_put_failure; | |
2105 | ||
2106 | genlmsg_end(msg, hdr); | |
4c476991 | 2107 | return genlmsg_reply(msg, info); |
41ade00f JB |
2108 | |
2109 | nla_put_failure: | |
2110 | err = -ENOBUFS; | |
6c95e2a2 | 2111 | free_msg: |
41ade00f | 2112 | nlmsg_free(msg); |
41ade00f JB |
2113 | return err; |
2114 | } | |
2115 | ||
2116 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2117 | { | |
4c476991 | 2118 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2119 | struct key_parse key; |
41ade00f | 2120 | int err; |
4c476991 | 2121 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2122 | |
b9454e83 JB |
2123 | err = nl80211_parse_key(info, &key); |
2124 | if (err) | |
2125 | return err; | |
41ade00f | 2126 | |
b9454e83 | 2127 | if (key.idx < 0) |
41ade00f JB |
2128 | return -EINVAL; |
2129 | ||
b9454e83 JB |
2130 | /* only support setting default key */ |
2131 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2132 | return -EINVAL; |
2133 | ||
dbd2fd65 | 2134 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2135 | |
dbd2fd65 JB |
2136 | if (key.def) { |
2137 | if (!rdev->ops->set_default_key) { | |
2138 | err = -EOPNOTSUPP; | |
2139 | goto out; | |
2140 | } | |
41ade00f | 2141 | |
dbd2fd65 JB |
2142 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2143 | if (err) | |
2144 | goto out; | |
2145 | ||
dbd2fd65 JB |
2146 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
2147 | key.def_uni, key.def_multi); | |
2148 | ||
2149 | if (err) | |
2150 | goto out; | |
fffd0934 | 2151 | |
3d23e349 | 2152 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2153 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2154 | #endif | |
2155 | } else { | |
2156 | if (key.def_uni || !key.def_multi) { | |
2157 | err = -EINVAL; | |
2158 | goto out; | |
2159 | } | |
2160 | ||
2161 | if (!rdev->ops->set_default_mgmt_key) { | |
2162 | err = -EOPNOTSUPP; | |
2163 | goto out; | |
2164 | } | |
2165 | ||
2166 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2167 | if (err) | |
2168 | goto out; | |
2169 | ||
2170 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, | |
2171 | dev, key.idx); | |
2172 | if (err) | |
2173 | goto out; | |
2174 | ||
2175 | #ifdef CONFIG_CFG80211_WEXT | |
2176 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2177 | #endif |
dbd2fd65 JB |
2178 | } |
2179 | ||
2180 | out: | |
fffd0934 | 2181 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2182 | |
41ade00f JB |
2183 | return err; |
2184 | } | |
2185 | ||
2186 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2187 | { | |
4c476991 | 2188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2189 | int err; |
4c476991 | 2190 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2191 | struct key_parse key; |
e31b8213 | 2192 | const u8 *mac_addr = NULL; |
41ade00f | 2193 | |
b9454e83 JB |
2194 | err = nl80211_parse_key(info, &key); |
2195 | if (err) | |
2196 | return err; | |
41ade00f | 2197 | |
b9454e83 | 2198 | if (!key.p.key) |
41ade00f JB |
2199 | return -EINVAL; |
2200 | ||
41ade00f JB |
2201 | if (info->attrs[NL80211_ATTR_MAC]) |
2202 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2203 | ||
e31b8213 JB |
2204 | if (key.type == -1) { |
2205 | if (mac_addr) | |
2206 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2207 | else | |
2208 | key.type = NL80211_KEYTYPE_GROUP; | |
2209 | } | |
2210 | ||
2211 | /* for now */ | |
2212 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2213 | key.type != NL80211_KEYTYPE_GROUP) | |
2214 | return -EINVAL; | |
2215 | ||
4c476991 JB |
2216 | if (!rdev->ops->add_key) |
2217 | return -EOPNOTSUPP; | |
25e47c18 | 2218 | |
e31b8213 JB |
2219 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2220 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2221 | mac_addr)) | |
4c476991 | 2222 | return -EINVAL; |
41ade00f | 2223 | |
fffd0934 JB |
2224 | wdev_lock(dev->ieee80211_ptr); |
2225 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2226 | if (!err) | |
2227 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, | |
e31b8213 | 2228 | key.type == NL80211_KEYTYPE_PAIRWISE, |
fffd0934 JB |
2229 | mac_addr, &key.p); |
2230 | wdev_unlock(dev->ieee80211_ptr); | |
41ade00f | 2231 | |
41ade00f JB |
2232 | return err; |
2233 | } | |
2234 | ||
2235 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2236 | { | |
4c476991 | 2237 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2238 | int err; |
4c476991 | 2239 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2240 | u8 *mac_addr = NULL; |
b9454e83 | 2241 | struct key_parse key; |
41ade00f | 2242 | |
b9454e83 JB |
2243 | err = nl80211_parse_key(info, &key); |
2244 | if (err) | |
2245 | return err; | |
41ade00f JB |
2246 | |
2247 | if (info->attrs[NL80211_ATTR_MAC]) | |
2248 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2249 | ||
e31b8213 JB |
2250 | if (key.type == -1) { |
2251 | if (mac_addr) | |
2252 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2253 | else | |
2254 | key.type = NL80211_KEYTYPE_GROUP; | |
2255 | } | |
2256 | ||
2257 | /* for now */ | |
2258 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2259 | key.type != NL80211_KEYTYPE_GROUP) | |
2260 | return -EINVAL; | |
2261 | ||
4c476991 JB |
2262 | if (!rdev->ops->del_key) |
2263 | return -EOPNOTSUPP; | |
41ade00f | 2264 | |
fffd0934 JB |
2265 | wdev_lock(dev->ieee80211_ptr); |
2266 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2267 | |
2268 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2269 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2270 | err = -ENOENT; | |
2271 | ||
fffd0934 | 2272 | if (!err) |
e31b8213 JB |
2273 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
2274 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2275 | mac_addr); | |
41ade00f | 2276 | |
3d23e349 | 2277 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2278 | if (!err) { |
b9454e83 | 2279 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2280 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2281 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2282 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2283 | } | |
2284 | #endif | |
fffd0934 | 2285 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2286 | |
41ade00f JB |
2287 | return err; |
2288 | } | |
2289 | ||
8860020e JB |
2290 | static int nl80211_parse_beacon(struct genl_info *info, |
2291 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2292 | { |
8860020e | 2293 | bool haveinfo = false; |
ed1b6cc7 | 2294 | |
9946ecfb JM |
2295 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2296 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2297 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2298 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2299 | return -EINVAL; |
2300 | ||
8860020e | 2301 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2302 | |
ed1b6cc7 | 2303 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2304 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2305 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2306 | if (!bcn->head_len) | |
2307 | return -EINVAL; | |
2308 | haveinfo = true; | |
ed1b6cc7 JB |
2309 | } |
2310 | ||
2311 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2312 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2313 | bcn->tail_len = | |
ed1b6cc7 | 2314 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2315 | haveinfo = true; |
ed1b6cc7 JB |
2316 | } |
2317 | ||
4c476991 JB |
2318 | if (!haveinfo) |
2319 | return -EINVAL; | |
3b85875a | 2320 | |
9946ecfb | 2321 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2322 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2323 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2324 | } |
2325 | ||
2326 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2327 | bcn->proberesp_ies = |
9946ecfb | 2328 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2329 | bcn->proberesp_ies_len = |
9946ecfb JM |
2330 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2331 | } | |
2332 | ||
2333 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2334 | bcn->assocresp_ies = |
9946ecfb | 2335 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2336 | bcn->assocresp_ies_len = |
9946ecfb JM |
2337 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2338 | } | |
2339 | ||
00f740e1 | 2340 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2341 | bcn->probe_resp = |
00f740e1 | 2342 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2343 | bcn->probe_resp_len = |
00f740e1 AN |
2344 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2345 | } | |
2346 | ||
8860020e JB |
2347 | return 0; |
2348 | } | |
2349 | ||
46c1dd0c FF |
2350 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
2351 | struct cfg80211_ap_settings *params) | |
2352 | { | |
2353 | struct wireless_dev *wdev; | |
2354 | bool ret = false; | |
2355 | ||
2356 | mutex_lock(&rdev->devlist_mtx); | |
2357 | ||
2358 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
2359 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
2360 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
2361 | continue; | |
2362 | ||
2363 | if (!wdev->preset_chan) | |
2364 | continue; | |
2365 | ||
2366 | params->channel = wdev->preset_chan; | |
2367 | params->channel_type = wdev->preset_chantype; | |
2368 | ret = true; | |
2369 | break; | |
2370 | } | |
2371 | ||
2372 | mutex_unlock(&rdev->devlist_mtx); | |
2373 | ||
2374 | return ret; | |
2375 | } | |
2376 | ||
8860020e JB |
2377 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
2378 | { | |
2379 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2380 | struct net_device *dev = info->user_ptr[1]; | |
2381 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2382 | struct cfg80211_ap_settings params; | |
2383 | int err; | |
2384 | ||
2385 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2386 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2387 | return -EOPNOTSUPP; | |
2388 | ||
2389 | if (!rdev->ops->start_ap) | |
2390 | return -EOPNOTSUPP; | |
2391 | ||
2392 | if (wdev->beacon_interval) | |
2393 | return -EALREADY; | |
2394 | ||
2395 | memset(¶ms, 0, sizeof(params)); | |
2396 | ||
2397 | /* these are required for START_AP */ | |
2398 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
2399 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
2400 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
2401 | return -EINVAL; | |
2402 | ||
2403 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
2404 | if (err) | |
2405 | return err; | |
2406 | ||
2407 | params.beacon_interval = | |
2408 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
2409 | params.dtim_period = | |
2410 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
2411 | ||
2412 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
2413 | if (err) | |
2414 | return err; | |
2415 | ||
2416 | /* | |
2417 | * In theory, some of these attributes should be required here | |
2418 | * but since they were not used when the command was originally | |
2419 | * added, keep them optional for old user space programs to let | |
2420 | * them continue to work with drivers that do not need the | |
2421 | * additional information -- drivers must check! | |
2422 | */ | |
2423 | if (info->attrs[NL80211_ATTR_SSID]) { | |
2424 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
2425 | params.ssid_len = | |
2426 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
2427 | if (params.ssid_len == 0 || | |
2428 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
2429 | return -EINVAL; | |
2430 | } | |
2431 | ||
2432 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
2433 | params.hidden_ssid = nla_get_u32( | |
2434 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
2435 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
2436 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
2437 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
2438 | return -EINVAL; | |
2439 | } | |
2440 | ||
2441 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
2442 | ||
2443 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
2444 | params.auth_type = nla_get_u32( | |
2445 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
2446 | if (!nl80211_valid_auth_type(params.auth_type)) | |
2447 | return -EINVAL; | |
2448 | } else | |
2449 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
2450 | ||
2451 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
2452 | NL80211_MAX_NR_CIPHER_SUITES); | |
2453 | if (err) | |
2454 | return err; | |
2455 | ||
1b658f11 VT |
2456 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
2457 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
2458 | return -EOPNOTSUPP; | |
2459 | params.inactivity_timeout = nla_get_u16( | |
2460 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
2461 | } | |
2462 | ||
aa430da4 JB |
2463 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
2464 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
2465 | ||
2466 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && | |
2467 | !nl80211_valid_channel_type(info, &channel_type)) | |
2468 | return -EINVAL; | |
2469 | ||
2470 | params.channel = rdev_freq_to_chan(rdev, | |
2471 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), | |
2472 | channel_type); | |
2473 | if (!params.channel) | |
2474 | return -EINVAL; | |
2475 | params.channel_type = channel_type; | |
2476 | } else if (wdev->preset_chan) { | |
2477 | params.channel = wdev->preset_chan; | |
2478 | params.channel_type = wdev->preset_chantype; | |
46c1dd0c | 2479 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
2480 | return -EINVAL; |
2481 | ||
2482 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, | |
2483 | params.channel_type)) | |
2484 | return -EINVAL; | |
2485 | ||
8860020e | 2486 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
46c1dd0c FF |
2487 | if (!err) { |
2488 | wdev->preset_chan = params.channel; | |
2489 | wdev->preset_chantype = params.channel_type; | |
8860020e | 2490 | wdev->beacon_interval = params.beacon_interval; |
46c1dd0c | 2491 | } |
56d1893d | 2492 | return err; |
ed1b6cc7 JB |
2493 | } |
2494 | ||
8860020e JB |
2495 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
2496 | { | |
2497 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2498 | struct net_device *dev = info->user_ptr[1]; | |
2499 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2500 | struct cfg80211_beacon_data params; | |
2501 | int err; | |
2502 | ||
2503 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2504 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2505 | return -EOPNOTSUPP; | |
2506 | ||
2507 | if (!rdev->ops->change_beacon) | |
2508 | return -EOPNOTSUPP; | |
2509 | ||
2510 | if (!wdev->beacon_interval) | |
2511 | return -EINVAL; | |
2512 | ||
2513 | err = nl80211_parse_beacon(info, ¶ms); | |
2514 | if (err) | |
2515 | return err; | |
2516 | ||
2517 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); | |
2518 | } | |
2519 | ||
2520 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 2521 | { |
4c476991 JB |
2522 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2523 | struct net_device *dev = info->user_ptr[1]; | |
56d1893d JB |
2524 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2525 | int err; | |
ed1b6cc7 | 2526 | |
8860020e | 2527 | if (!rdev->ops->stop_ap) |
4c476991 | 2528 | return -EOPNOTSUPP; |
ed1b6cc7 | 2529 | |
074ac8df | 2530 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
2531 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2532 | return -EOPNOTSUPP; | |
3b85875a | 2533 | |
8860020e JB |
2534 | if (!wdev->beacon_interval) |
2535 | return -ENOENT; | |
2536 | ||
2537 | err = rdev->ops->stop_ap(&rdev->wiphy, dev); | |
56d1893d JB |
2538 | if (!err) |
2539 | wdev->beacon_interval = 0; | |
2540 | return err; | |
ed1b6cc7 JB |
2541 | } |
2542 | ||
5727ef1b JB |
2543 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
2544 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
2545 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
2546 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 2547 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 2548 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 2549 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
2550 | }; |
2551 | ||
eccb8e8f | 2552 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 2553 | enum nl80211_iftype iftype, |
eccb8e8f | 2554 | struct station_parameters *params) |
5727ef1b JB |
2555 | { |
2556 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 2557 | struct nlattr *nla; |
5727ef1b JB |
2558 | int flag; |
2559 | ||
eccb8e8f JB |
2560 | /* |
2561 | * Try parsing the new attribute first so userspace | |
2562 | * can specify both for older kernels. | |
2563 | */ | |
2564 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
2565 | if (nla) { | |
2566 | struct nl80211_sta_flag_update *sta_flags; | |
2567 | ||
2568 | sta_flags = nla_data(nla); | |
2569 | params->sta_flags_mask = sta_flags->mask; | |
2570 | params->sta_flags_set = sta_flags->set; | |
2571 | if ((params->sta_flags_mask | | |
2572 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
2573 | return -EINVAL; | |
2574 | return 0; | |
2575 | } | |
2576 | ||
2577 | /* if present, parse the old attribute */ | |
5727ef1b | 2578 | |
eccb8e8f | 2579 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
2580 | if (!nla) |
2581 | return 0; | |
2582 | ||
2583 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
2584 | nla, sta_flags_policy)) | |
2585 | return -EINVAL; | |
2586 | ||
bdd3ae3d JB |
2587 | /* |
2588 | * Only allow certain flags for interface types so that | |
2589 | * other attributes are silently ignored. Remember that | |
2590 | * this is backward compatibility code with old userspace | |
2591 | * and shouldn't be hit in other cases anyway. | |
2592 | */ | |
2593 | switch (iftype) { | |
2594 | case NL80211_IFTYPE_AP: | |
2595 | case NL80211_IFTYPE_AP_VLAN: | |
2596 | case NL80211_IFTYPE_P2P_GO: | |
2597 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2598 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
2599 | BIT(NL80211_STA_FLAG_WME) | | |
2600 | BIT(NL80211_STA_FLAG_MFP); | |
2601 | break; | |
2602 | case NL80211_IFTYPE_P2P_CLIENT: | |
2603 | case NL80211_IFTYPE_STATION: | |
2604 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2605 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
2606 | break; | |
2607 | case NL80211_IFTYPE_MESH_POINT: | |
2608 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
2609 | BIT(NL80211_STA_FLAG_MFP) | | |
2610 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
2611 | default: | |
2612 | return -EINVAL; | |
2613 | } | |
5727ef1b | 2614 | |
3383b5a6 JB |
2615 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
2616 | if (flags[flag]) { | |
eccb8e8f | 2617 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 2618 | |
3383b5a6 JB |
2619 | /* no longer support new API additions in old API */ |
2620 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
2621 | return -EINVAL; | |
2622 | } | |
2623 | } | |
2624 | ||
5727ef1b JB |
2625 | return 0; |
2626 | } | |
2627 | ||
c8dcfd8a FF |
2628 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
2629 | int attr) | |
2630 | { | |
2631 | struct nlattr *rate; | |
2632 | u16 bitrate; | |
2633 | ||
2634 | rate = nla_nest_start(msg, attr); | |
2635 | if (!rate) | |
2636 | goto nla_put_failure; | |
2637 | ||
2638 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
2639 | bitrate = cfg80211_calculate_bitrate(info); | |
9360ffd1 DM |
2640 | if ((bitrate > 0 && |
2641 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) || | |
2642 | ((info->flags & RATE_INFO_FLAGS_MCS) && | |
2643 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || | |
2644 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && | |
2645 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || | |
2646 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && | |
2647 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) | |
2648 | goto nla_put_failure; | |
c8dcfd8a FF |
2649 | |
2650 | nla_nest_end(msg, rate); | |
2651 | return true; | |
2652 | ||
2653 | nla_put_failure: | |
2654 | return false; | |
2655 | } | |
2656 | ||
fd5b74dc | 2657 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
66266b3a JL |
2658 | int flags, |
2659 | struct cfg80211_registered_device *rdev, | |
2660 | struct net_device *dev, | |
98b62183 | 2661 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
2662 | { |
2663 | void *hdr; | |
f4263c98 | 2664 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc JB |
2665 | |
2666 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2667 | if (!hdr) | |
2668 | return -1; | |
2669 | ||
9360ffd1 DM |
2670 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2671 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
2672 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
2673 | goto nla_put_failure; | |
f5ea9120 | 2674 | |
2ec600d6 LCC |
2675 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
2676 | if (!sinfoattr) | |
fd5b74dc | 2677 | goto nla_put_failure; |
9360ffd1 DM |
2678 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
2679 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
2680 | sinfo->connected_time)) | |
2681 | goto nla_put_failure; | |
2682 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
2683 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
2684 | sinfo->inactive_time)) | |
2685 | goto nla_put_failure; | |
2686 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && | |
2687 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, | |
2688 | sinfo->rx_bytes)) | |
2689 | goto nla_put_failure; | |
2690 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && | |
2691 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, | |
2692 | sinfo->tx_bytes)) | |
2693 | goto nla_put_failure; | |
2694 | if ((sinfo->filled & STATION_INFO_LLID) && | |
2695 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
2696 | goto nla_put_failure; | |
2697 | if ((sinfo->filled & STATION_INFO_PLID) && | |
2698 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
2699 | goto nla_put_failure; | |
2700 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
2701 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
2702 | sinfo->plink_state)) | |
2703 | goto nla_put_failure; | |
66266b3a JL |
2704 | switch (rdev->wiphy.signal_type) { |
2705 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
2706 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
2707 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
2708 | sinfo->signal)) | |
2709 | goto nla_put_failure; | |
2710 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
2711 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
2712 | sinfo->signal_avg)) | |
2713 | goto nla_put_failure; | |
66266b3a JL |
2714 | break; |
2715 | default: | |
2716 | break; | |
2717 | } | |
420e7fab | 2718 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
2719 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
2720 | NL80211_STA_INFO_TX_BITRATE)) | |
2721 | goto nla_put_failure; | |
2722 | } | |
2723 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
2724 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
2725 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 2726 | goto nla_put_failure; |
420e7fab | 2727 | } |
9360ffd1 DM |
2728 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
2729 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
2730 | sinfo->rx_packets)) | |
2731 | goto nla_put_failure; | |
2732 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
2733 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
2734 | sinfo->tx_packets)) | |
2735 | goto nla_put_failure; | |
2736 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
2737 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
2738 | sinfo->tx_retries)) | |
2739 | goto nla_put_failure; | |
2740 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
2741 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
2742 | sinfo->tx_failed)) | |
2743 | goto nla_put_failure; | |
2744 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
2745 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
2746 | sinfo->beacon_loss_count)) | |
2747 | goto nla_put_failure; | |
f4263c98 PS |
2748 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
2749 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
2750 | if (!bss_param) | |
2751 | goto nla_put_failure; | |
2752 | ||
9360ffd1 DM |
2753 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
2754 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
2755 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
2756 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
2757 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
2758 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
2759 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
2760 | sinfo->bss_param.dtim_period) || | |
2761 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
2762 | sinfo->bss_param.beacon_interval)) | |
2763 | goto nla_put_failure; | |
f4263c98 PS |
2764 | |
2765 | nla_nest_end(msg, bss_param); | |
2766 | } | |
9360ffd1 DM |
2767 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
2768 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
2769 | sizeof(struct nl80211_sta_flag_update), | |
2770 | &sinfo->sta_flags)) | |
2771 | goto nla_put_failure; | |
7eab0f64 JL |
2772 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
2773 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
2774 | sinfo->t_offset)) | |
2775 | goto nla_put_failure; | |
2ec600d6 | 2776 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 2777 | |
9360ffd1 DM |
2778 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
2779 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
2780 | sinfo->assoc_req_ies)) | |
2781 | goto nla_put_failure; | |
50d3dfb7 | 2782 | |
fd5b74dc JB |
2783 | return genlmsg_end(msg, hdr); |
2784 | ||
2785 | nla_put_failure: | |
bc3ed28c TG |
2786 | genlmsg_cancel(msg, hdr); |
2787 | return -EMSGSIZE; | |
fd5b74dc JB |
2788 | } |
2789 | ||
2ec600d6 | 2790 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 2791 | struct netlink_callback *cb) |
2ec600d6 | 2792 | { |
2ec600d6 LCC |
2793 | struct station_info sinfo; |
2794 | struct cfg80211_registered_device *dev; | |
bba95fef | 2795 | struct net_device *netdev; |
2ec600d6 | 2796 | u8 mac_addr[ETH_ALEN]; |
bba95fef | 2797 | int sta_idx = cb->args[1]; |
2ec600d6 | 2798 | int err; |
2ec600d6 | 2799 | |
67748893 JB |
2800 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
2801 | if (err) | |
2802 | return err; | |
bba95fef JB |
2803 | |
2804 | if (!dev->ops->dump_station) { | |
eec60b03 | 2805 | err = -EOPNOTSUPP; |
bba95fef JB |
2806 | goto out_err; |
2807 | } | |
2808 | ||
bba95fef | 2809 | while (1) { |
f612cedf | 2810 | memset(&sinfo, 0, sizeof(sinfo)); |
bba95fef JB |
2811 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
2812 | mac_addr, &sinfo); | |
2813 | if (err == -ENOENT) | |
2814 | break; | |
2815 | if (err) | |
3b85875a | 2816 | goto out_err; |
bba95fef JB |
2817 | |
2818 | if (nl80211_send_station(skb, | |
2819 | NETLINK_CB(cb->skb).pid, | |
2820 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
66266b3a | 2821 | dev, netdev, mac_addr, |
bba95fef JB |
2822 | &sinfo) < 0) |
2823 | goto out; | |
2824 | ||
2825 | sta_idx++; | |
2826 | } | |
2827 | ||
2828 | ||
2829 | out: | |
2830 | cb->args[1] = sta_idx; | |
2831 | err = skb->len; | |
bba95fef | 2832 | out_err: |
67748893 | 2833 | nl80211_finish_netdev_dump(dev); |
bba95fef JB |
2834 | |
2835 | return err; | |
2ec600d6 | 2836 | } |
fd5b74dc | 2837 | |
5727ef1b JB |
2838 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
2839 | { | |
4c476991 JB |
2840 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2841 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 2842 | struct station_info sinfo; |
fd5b74dc JB |
2843 | struct sk_buff *msg; |
2844 | u8 *mac_addr = NULL; | |
4c476991 | 2845 | int err; |
fd5b74dc | 2846 | |
2ec600d6 | 2847 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
2848 | |
2849 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2850 | return -EINVAL; | |
2851 | ||
2852 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2853 | ||
4c476991 JB |
2854 | if (!rdev->ops->get_station) |
2855 | return -EOPNOTSUPP; | |
3b85875a | 2856 | |
4c476991 | 2857 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
fd5b74dc | 2858 | if (err) |
4c476991 | 2859 | return err; |
2ec600d6 | 2860 | |
fd2120ca | 2861 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 2862 | if (!msg) |
4c476991 | 2863 | return -ENOMEM; |
fd5b74dc JB |
2864 | |
2865 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | |
66266b3a | 2866 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
2867 | nlmsg_free(msg); |
2868 | return -ENOBUFS; | |
2869 | } | |
3b85875a | 2870 | |
4c476991 | 2871 | return genlmsg_reply(msg, info); |
5727ef1b JB |
2872 | } |
2873 | ||
2874 | /* | |
c258d2de | 2875 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 2876 | */ |
80b99899 JB |
2877 | static struct net_device *get_vlan(struct genl_info *info, |
2878 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 2879 | { |
463d0183 | 2880 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
2881 | struct net_device *v; |
2882 | int ret; | |
2883 | ||
2884 | if (!vlanattr) | |
2885 | return NULL; | |
2886 | ||
2887 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
2888 | if (!v) | |
2889 | return ERR_PTR(-ENODEV); | |
2890 | ||
2891 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
2892 | ret = -EINVAL; | |
2893 | goto error; | |
5727ef1b | 2894 | } |
80b99899 JB |
2895 | |
2896 | if (!netif_running(v)) { | |
2897 | ret = -ENETDOWN; | |
2898 | goto error; | |
2899 | } | |
2900 | ||
2901 | return v; | |
2902 | error: | |
2903 | dev_put(v); | |
2904 | return ERR_PTR(ret); | |
5727ef1b JB |
2905 | } |
2906 | ||
2907 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
2908 | { | |
4c476991 | 2909 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2910 | int err; |
4c476991 | 2911 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2912 | struct station_parameters params; |
2913 | u8 *mac_addr = NULL; | |
2914 | ||
2915 | memset(¶ms, 0, sizeof(params)); | |
2916 | ||
2917 | params.listen_interval = -1; | |
57cf8043 | 2918 | params.plink_state = -1; |
5727ef1b JB |
2919 | |
2920 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
2921 | return -EINVAL; | |
2922 | ||
2923 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2924 | return -EINVAL; | |
2925 | ||
2926 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2927 | ||
2928 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
2929 | params.supported_rates = | |
2930 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2931 | params.supported_rates_len = | |
2932 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2933 | } | |
2934 | ||
2935 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
2936 | params.listen_interval = | |
2937 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
2938 | ||
36aedc90 JM |
2939 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2940 | params.ht_capa = | |
2941 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
2942 | ||
bdd90d5e JB |
2943 | if (!rdev->ops->change_station) |
2944 | return -EOPNOTSUPP; | |
2945 | ||
bdd3ae3d | 2946 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
2947 | return -EINVAL; |
2948 | ||
2ec600d6 LCC |
2949 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2950 | params.plink_action = | |
2951 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2952 | ||
9c3990aa JC |
2953 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
2954 | params.plink_state = | |
2955 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | |
2956 | ||
a97f4424 JB |
2957 | switch (dev->ieee80211_ptr->iftype) { |
2958 | case NL80211_IFTYPE_AP: | |
2959 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 2960 | case NL80211_IFTYPE_P2P_GO: |
a97f4424 JB |
2961 | /* disallow mesh-specific things */ |
2962 | if (params.plink_action) | |
bdd90d5e JB |
2963 | return -EINVAL; |
2964 | ||
2965 | /* TDLS can't be set, ... */ | |
2966 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
2967 | return -EINVAL; | |
2968 | /* | |
2969 | * ... but don't bother the driver with it. This works around | |
2970 | * a hostapd/wpa_supplicant issue -- it always includes the | |
2971 | * TLDS_PEER flag in the mask even for AP mode. | |
2972 | */ | |
2973 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
2974 | ||
2975 | /* accept only the listed bits */ | |
2976 | if (params.sta_flags_mask & | |
2977 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2978 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
2979 | BIT(NL80211_STA_FLAG_WME) | | |
2980 | BIT(NL80211_STA_FLAG_MFP))) | |
2981 | return -EINVAL; | |
2982 | ||
2983 | /* must be last in here for error handling */ | |
2984 | params.vlan = get_vlan(info, rdev); | |
2985 | if (IS_ERR(params.vlan)) | |
2986 | return PTR_ERR(params.vlan); | |
a97f4424 | 2987 | break; |
074ac8df | 2988 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 2989 | case NL80211_IFTYPE_STATION: |
bdd90d5e JB |
2990 | /* |
2991 | * Don't allow userspace to change the TDLS_PEER flag, | |
2992 | * but silently ignore attempts to change it since we | |
2993 | * don't have state here to verify that it doesn't try | |
2994 | * to change the flag. | |
2995 | */ | |
2996 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
267335d6 AQ |
2997 | /* fall through */ |
2998 | case NL80211_IFTYPE_ADHOC: | |
2999 | /* disallow things sta doesn't support */ | |
3000 | if (params.plink_action) | |
3001 | return -EINVAL; | |
3002 | if (params.ht_capa) | |
3003 | return -EINVAL; | |
3004 | if (params.listen_interval >= 0) | |
3005 | return -EINVAL; | |
bdd90d5e JB |
3006 | /* reject any changes other than AUTHORIZED */ |
3007 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
3008 | return -EINVAL; | |
a97f4424 JB |
3009 | break; |
3010 | case NL80211_IFTYPE_MESH_POINT: | |
3011 | /* disallow things mesh doesn't support */ | |
3012 | if (params.vlan) | |
bdd90d5e | 3013 | return -EINVAL; |
a97f4424 | 3014 | if (params.ht_capa) |
bdd90d5e | 3015 | return -EINVAL; |
a97f4424 | 3016 | if (params.listen_interval >= 0) |
bdd90d5e JB |
3017 | return -EINVAL; |
3018 | /* | |
3019 | * No special handling for TDLS here -- the userspace | |
3020 | * mesh code doesn't have this bug. | |
3021 | */ | |
b39c48fa JC |
3022 | if (params.sta_flags_mask & |
3023 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
8429828e | 3024 | BIT(NL80211_STA_FLAG_MFP) | |
b39c48fa | 3025 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
bdd90d5e | 3026 | return -EINVAL; |
a97f4424 JB |
3027 | break; |
3028 | default: | |
bdd90d5e | 3029 | return -EOPNOTSUPP; |
034d655e JB |
3030 | } |
3031 | ||
bdd90d5e | 3032 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 3033 | |
79c97e97 | 3034 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b | 3035 | |
5727ef1b JB |
3036 | if (params.vlan) |
3037 | dev_put(params.vlan); | |
3b85875a | 3038 | |
5727ef1b JB |
3039 | return err; |
3040 | } | |
3041 | ||
c75786c9 EP |
3042 | static struct nla_policy |
3043 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
3044 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
3045 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
3046 | }; | |
3047 | ||
5727ef1b JB |
3048 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
3049 | { | |
4c476991 | 3050 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 3051 | int err; |
4c476991 | 3052 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
3053 | struct station_parameters params; |
3054 | u8 *mac_addr = NULL; | |
3055 | ||
3056 | memset(¶ms, 0, sizeof(params)); | |
3057 | ||
3058 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3059 | return -EINVAL; | |
3060 | ||
5727ef1b JB |
3061 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
3062 | return -EINVAL; | |
3063 | ||
3064 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
3065 | return -EINVAL; | |
3066 | ||
0e956c13 TLSC |
3067 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
3068 | return -EINVAL; | |
3069 | ||
5727ef1b JB |
3070 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3071 | params.supported_rates = | |
3072 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3073 | params.supported_rates_len = | |
3074 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
3075 | params.listen_interval = | |
3076 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 3077 | |
0e956c13 TLSC |
3078 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
3079 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
3080 | return -EINVAL; | |
51b50fbe | 3081 | |
36aedc90 JM |
3082 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
3083 | params.ht_capa = | |
3084 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 3085 | |
96b78dff JC |
3086 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
3087 | params.plink_action = | |
3088 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
3089 | ||
bdd90d5e JB |
3090 | if (!rdev->ops->add_station) |
3091 | return -EOPNOTSUPP; | |
3092 | ||
bdd3ae3d | 3093 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
3094 | return -EINVAL; |
3095 | ||
bdd90d5e JB |
3096 | switch (dev->ieee80211_ptr->iftype) { |
3097 | case NL80211_IFTYPE_AP: | |
3098 | case NL80211_IFTYPE_AP_VLAN: | |
3099 | case NL80211_IFTYPE_P2P_GO: | |
3100 | /* parse WME attributes if sta is WME capable */ | |
3101 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
3102 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && | |
3103 | info->attrs[NL80211_ATTR_STA_WME]) { | |
3104 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; | |
3105 | struct nlattr *nla; | |
3106 | ||
3107 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
3108 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
3109 | nl80211_sta_wme_policy); | |
3110 | if (err) | |
3111 | return err; | |
3112 | ||
3113 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
3114 | params.uapsd_queues = | |
3115 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
3116 | if (params.uapsd_queues & | |
3117 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
3118 | return -EINVAL; | |
c75786c9 | 3119 | |
bdd90d5e JB |
3120 | if (tb[NL80211_STA_WME_MAX_SP]) |
3121 | params.max_sp = | |
3122 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
c75786c9 | 3123 | |
bdd90d5e JB |
3124 | if (params.max_sp & |
3125 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
3126 | return -EINVAL; | |
4319e193 | 3127 | |
bdd90d5e JB |
3128 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
3129 | } | |
3130 | /* TDLS peers cannot be added */ | |
3131 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 3132 | return -EINVAL; |
bdd90d5e JB |
3133 | /* but don't bother the driver with it */ |
3134 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 3135 | |
bdd90d5e JB |
3136 | /* must be last in here for error handling */ |
3137 | params.vlan = get_vlan(info, rdev); | |
3138 | if (IS_ERR(params.vlan)) | |
3139 | return PTR_ERR(params.vlan); | |
3140 | break; | |
3141 | case NL80211_IFTYPE_MESH_POINT: | |
3142 | /* TDLS peers cannot be added */ | |
3143 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3144 | return -EINVAL; | |
3145 | break; | |
3146 | case NL80211_IFTYPE_STATION: | |
3147 | /* Only TDLS peers can be added */ | |
3148 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3149 | return -EINVAL; | |
3150 | /* Can only add if TDLS ... */ | |
3151 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
3152 | return -EOPNOTSUPP; | |
3153 | /* ... with external setup is supported */ | |
3154 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
3155 | return -EOPNOTSUPP; | |
3156 | break; | |
3157 | default: | |
3158 | return -EOPNOTSUPP; | |
c75786c9 EP |
3159 | } |
3160 | ||
bdd90d5e | 3161 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 3162 | |
79c97e97 | 3163 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b | 3164 | |
5727ef1b JB |
3165 | if (params.vlan) |
3166 | dev_put(params.vlan); | |
5727ef1b JB |
3167 | return err; |
3168 | } | |
3169 | ||
3170 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
3171 | { | |
4c476991 JB |
3172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3173 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
3174 | u8 *mac_addr = NULL; |
3175 | ||
3176 | if (info->attrs[NL80211_ATTR_MAC]) | |
3177 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3178 | ||
e80cf853 | 3179 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 3180 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 3181 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
3182 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
3183 | return -EINVAL; | |
5727ef1b | 3184 | |
4c476991 JB |
3185 | if (!rdev->ops->del_station) |
3186 | return -EOPNOTSUPP; | |
3b85875a | 3187 | |
4c476991 | 3188 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
5727ef1b JB |
3189 | } |
3190 | ||
2ec600d6 LCC |
3191 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
3192 | int flags, struct net_device *dev, | |
3193 | u8 *dst, u8 *next_hop, | |
3194 | struct mpath_info *pinfo) | |
3195 | { | |
3196 | void *hdr; | |
3197 | struct nlattr *pinfoattr; | |
3198 | ||
3199 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
3200 | if (!hdr) | |
3201 | return -1; | |
3202 | ||
9360ffd1 DM |
3203 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3204 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
3205 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
3206 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
3207 | goto nla_put_failure; | |
f5ea9120 | 3208 | |
2ec600d6 LCC |
3209 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
3210 | if (!pinfoattr) | |
3211 | goto nla_put_failure; | |
9360ffd1 DM |
3212 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
3213 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
3214 | pinfo->frame_qlen)) | |
3215 | goto nla_put_failure; | |
3216 | if (((pinfo->filled & MPATH_INFO_SN) && | |
3217 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
3218 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
3219 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
3220 | pinfo->metric)) || | |
3221 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
3222 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
3223 | pinfo->exptime)) || | |
3224 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
3225 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
3226 | pinfo->flags)) || | |
3227 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
3228 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
3229 | pinfo->discovery_timeout)) || | |
3230 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
3231 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
3232 | pinfo->discovery_retries))) | |
3233 | goto nla_put_failure; | |
2ec600d6 LCC |
3234 | |
3235 | nla_nest_end(msg, pinfoattr); | |
3236 | ||
3237 | return genlmsg_end(msg, hdr); | |
3238 | ||
3239 | nla_put_failure: | |
bc3ed28c TG |
3240 | genlmsg_cancel(msg, hdr); |
3241 | return -EMSGSIZE; | |
2ec600d6 LCC |
3242 | } |
3243 | ||
3244 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 3245 | struct netlink_callback *cb) |
2ec600d6 | 3246 | { |
2ec600d6 LCC |
3247 | struct mpath_info pinfo; |
3248 | struct cfg80211_registered_device *dev; | |
bba95fef | 3249 | struct net_device *netdev; |
2ec600d6 LCC |
3250 | u8 dst[ETH_ALEN]; |
3251 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 3252 | int path_idx = cb->args[1]; |
2ec600d6 | 3253 | int err; |
2ec600d6 | 3254 | |
67748893 JB |
3255 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3256 | if (err) | |
3257 | return err; | |
bba95fef JB |
3258 | |
3259 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 3260 | err = -EOPNOTSUPP; |
bba95fef JB |
3261 | goto out_err; |
3262 | } | |
3263 | ||
eec60b03 JM |
3264 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
3265 | err = -EOPNOTSUPP; | |
0448b5fc | 3266 | goto out_err; |
eec60b03 JM |
3267 | } |
3268 | ||
bba95fef JB |
3269 | while (1) { |
3270 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
3271 | dst, next_hop, &pinfo); | |
3272 | if (err == -ENOENT) | |
2ec600d6 | 3273 | break; |
bba95fef | 3274 | if (err) |
3b85875a | 3275 | goto out_err; |
2ec600d6 | 3276 | |
bba95fef JB |
3277 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
3278 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
3279 | netdev, dst, next_hop, | |
3280 | &pinfo) < 0) | |
3281 | goto out; | |
2ec600d6 | 3282 | |
bba95fef | 3283 | path_idx++; |
2ec600d6 | 3284 | } |
2ec600d6 | 3285 | |
2ec600d6 | 3286 | |
bba95fef JB |
3287 | out: |
3288 | cb->args[1] = path_idx; | |
3289 | err = skb->len; | |
bba95fef | 3290 | out_err: |
67748893 | 3291 | nl80211_finish_netdev_dump(dev); |
bba95fef | 3292 | return err; |
2ec600d6 LCC |
3293 | } |
3294 | ||
3295 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
3296 | { | |
4c476991 | 3297 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 3298 | int err; |
4c476991 | 3299 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
3300 | struct mpath_info pinfo; |
3301 | struct sk_buff *msg; | |
3302 | u8 *dst = NULL; | |
3303 | u8 next_hop[ETH_ALEN]; | |
3304 | ||
3305 | memset(&pinfo, 0, sizeof(pinfo)); | |
3306 | ||
3307 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3308 | return -EINVAL; | |
3309 | ||
3310 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3311 | ||
4c476991 JB |
3312 | if (!rdev->ops->get_mpath) |
3313 | return -EOPNOTSUPP; | |
2ec600d6 | 3314 | |
4c476991 JB |
3315 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3316 | return -EOPNOTSUPP; | |
eec60b03 | 3317 | |
79c97e97 | 3318 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 | 3319 | if (err) |
4c476991 | 3320 | return err; |
2ec600d6 | 3321 | |
fd2120ca | 3322 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 3323 | if (!msg) |
4c476991 | 3324 | return -ENOMEM; |
2ec600d6 LCC |
3325 | |
3326 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
4c476991 JB |
3327 | dev, dst, next_hop, &pinfo) < 0) { |
3328 | nlmsg_free(msg); | |
3329 | return -ENOBUFS; | |
3330 | } | |
3b85875a | 3331 | |
4c476991 | 3332 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
3333 | } |
3334 | ||
3335 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
3336 | { | |
4c476991 JB |
3337 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3338 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3339 | u8 *dst = NULL; |
3340 | u8 *next_hop = NULL; | |
3341 | ||
3342 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3343 | return -EINVAL; | |
3344 | ||
3345 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
3346 | return -EINVAL; | |
3347 | ||
3348 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3349 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
3350 | ||
4c476991 JB |
3351 | if (!rdev->ops->change_mpath) |
3352 | return -EOPNOTSUPP; | |
35a8efe1 | 3353 | |
4c476991 JB |
3354 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3355 | return -EOPNOTSUPP; | |
2ec600d6 | 3356 | |
4c476991 | 3357 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 | 3358 | } |
4c476991 | 3359 | |
2ec600d6 LCC |
3360 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
3361 | { | |
4c476991 JB |
3362 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3363 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3364 | u8 *dst = NULL; |
3365 | u8 *next_hop = NULL; | |
3366 | ||
3367 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3368 | return -EINVAL; | |
3369 | ||
3370 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
3371 | return -EINVAL; | |
3372 | ||
3373 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3374 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
3375 | ||
4c476991 JB |
3376 | if (!rdev->ops->add_mpath) |
3377 | return -EOPNOTSUPP; | |
35a8efe1 | 3378 | |
4c476991 JB |
3379 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3380 | return -EOPNOTSUPP; | |
2ec600d6 | 3381 | |
4c476991 | 3382 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
3383 | } |
3384 | ||
3385 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
3386 | { | |
4c476991 JB |
3387 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3388 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3389 | u8 *dst = NULL; |
3390 | ||
3391 | if (info->attrs[NL80211_ATTR_MAC]) | |
3392 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3393 | ||
4c476991 JB |
3394 | if (!rdev->ops->del_mpath) |
3395 | return -EOPNOTSUPP; | |
3b85875a | 3396 | |
4c476991 | 3397 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2ec600d6 LCC |
3398 | } |
3399 | ||
9f1ba906 JM |
3400 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
3401 | { | |
4c476991 JB |
3402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3403 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
3404 | struct bss_parameters params; |
3405 | ||
3406 | memset(¶ms, 0, sizeof(params)); | |
3407 | /* default to not changing parameters */ | |
3408 | params.use_cts_prot = -1; | |
3409 | params.use_short_preamble = -1; | |
3410 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 3411 | params.ap_isolate = -1; |
50b12f59 | 3412 | params.ht_opmode = -1; |
9f1ba906 JM |
3413 | |
3414 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
3415 | params.use_cts_prot = | |
3416 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
3417 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
3418 | params.use_short_preamble = | |
3419 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
3420 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
3421 | params.use_short_slot_time = | |
3422 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
3423 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
3424 | params.basic_rates = | |
3425 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3426 | params.basic_rates_len = | |
3427 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3428 | } | |
fd8aaaf3 FF |
3429 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
3430 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
3431 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
3432 | params.ht_opmode = | |
3433 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 3434 | |
4c476991 JB |
3435 | if (!rdev->ops->change_bss) |
3436 | return -EOPNOTSUPP; | |
9f1ba906 | 3437 | |
074ac8df | 3438 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
3439 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
3440 | return -EOPNOTSUPP; | |
3b85875a | 3441 | |
4c476991 | 3442 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
9f1ba906 JM |
3443 | } |
3444 | ||
b54452b0 | 3445 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
3446 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
3447 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
3448 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
3449 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
3450 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
3451 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
3452 | }; | |
3453 | ||
3454 | static int parse_reg_rule(struct nlattr *tb[], | |
3455 | struct ieee80211_reg_rule *reg_rule) | |
3456 | { | |
3457 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
3458 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
3459 | ||
3460 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
3461 | return -EINVAL; | |
3462 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
3463 | return -EINVAL; | |
3464 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
3465 | return -EINVAL; | |
3466 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
3467 | return -EINVAL; | |
3468 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
3469 | return -EINVAL; | |
3470 | ||
3471 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
3472 | ||
3473 | freq_range->start_freq_khz = | |
3474 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
3475 | freq_range->end_freq_khz = | |
3476 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
3477 | freq_range->max_bandwidth_khz = | |
3478 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
3479 | ||
3480 | power_rule->max_eirp = | |
3481 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
3482 | ||
3483 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
3484 | power_rule->max_antenna_gain = | |
3485 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
3486 | ||
3487 | return 0; | |
3488 | } | |
3489 | ||
3490 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
3491 | { | |
3492 | int r; | |
3493 | char *data = NULL; | |
3494 | ||
80778f18 LR |
3495 | /* |
3496 | * You should only get this when cfg80211 hasn't yet initialized | |
3497 | * completely when built-in to the kernel right between the time | |
3498 | * window between nl80211_init() and regulatory_init(), if that is | |
3499 | * even possible. | |
3500 | */ | |
3501 | mutex_lock(&cfg80211_mutex); | |
3502 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
3503 | mutex_unlock(&cfg80211_mutex); |
3504 | return -EINPROGRESS; | |
80778f18 | 3505 | } |
fe33eb39 | 3506 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 3507 | |
fe33eb39 LR |
3508 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
3509 | return -EINVAL; | |
b2e1b302 LR |
3510 | |
3511 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3512 | ||
fe33eb39 LR |
3513 | r = regulatory_hint_user(data); |
3514 | ||
b2e1b302 LR |
3515 | return r; |
3516 | } | |
3517 | ||
24bdd9f4 | 3518 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 3519 | struct genl_info *info) |
93da9cc1 | 3520 | { |
4c476991 | 3521 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3522 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
3523 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
3524 | struct mesh_config cur_params; | |
3525 | int err = 0; | |
93da9cc1 | 3526 | void *hdr; |
3527 | struct nlattr *pinfoattr; | |
3528 | struct sk_buff *msg; | |
3529 | ||
29cbe68c JB |
3530 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3531 | return -EOPNOTSUPP; | |
3532 | ||
24bdd9f4 | 3533 | if (!rdev->ops->get_mesh_config) |
4c476991 | 3534 | return -EOPNOTSUPP; |
f3f92586 | 3535 | |
29cbe68c JB |
3536 | wdev_lock(wdev); |
3537 | /* If not connected, get default parameters */ | |
3538 | if (!wdev->mesh_id_len) | |
3539 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
3540 | else | |
24bdd9f4 | 3541 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3542 | &cur_params); |
3543 | wdev_unlock(wdev); | |
3544 | ||
93da9cc1 | 3545 | if (err) |
4c476991 | 3546 | return err; |
93da9cc1 | 3547 | |
3548 | /* Draw up a netlink message to send back */ | |
fd2120ca | 3549 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3550 | if (!msg) |
3551 | return -ENOMEM; | |
93da9cc1 | 3552 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
24bdd9f4 | 3553 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 3554 | if (!hdr) |
efe1cf0c | 3555 | goto out; |
24bdd9f4 | 3556 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 3557 | if (!pinfoattr) |
3558 | goto nla_put_failure; | |
9360ffd1 DM |
3559 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3560 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
3561 | cur_params.dot11MeshRetryTimeout) || | |
3562 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
3563 | cur_params.dot11MeshConfirmTimeout) || | |
3564 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
3565 | cur_params.dot11MeshHoldingTimeout) || | |
3566 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
3567 | cur_params.dot11MeshMaxPeerLinks) || | |
3568 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
3569 | cur_params.dot11MeshMaxRetries) || | |
3570 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
3571 | cur_params.dot11MeshTTL) || | |
3572 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
3573 | cur_params.element_ttl) || | |
3574 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
3575 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
3576 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
3577 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
3578 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
3579 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
3580 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
3581 | cur_params.path_refresh_time) || | |
3582 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
3583 | cur_params.min_discovery_timeout) || | |
3584 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3585 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
3586 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
3587 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
3588 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
3589 | cur_params.dot11MeshHWMPperrMinInterval) || | |
3590 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3591 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
3592 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
3593 | cur_params.dot11MeshHWMPRootMode) || | |
3594 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
3595 | cur_params.dot11MeshHWMPRannInterval) || | |
3596 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
3597 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
3598 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
3599 | cur_params.dot11MeshForwarding) || | |
3600 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
3601 | cur_params.rssi_threshold) || |
3602 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
3603 | cur_params.ht_opmode) || |
3604 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
3605 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
3606 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
3607 | cur_params.dot11MeshHWMProotInterval) || |
3608 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3609 | cur_params.dot11MeshHWMPconfirmationInterval)) | |
9360ffd1 | 3610 | goto nla_put_failure; |
93da9cc1 | 3611 | nla_nest_end(msg, pinfoattr); |
3612 | genlmsg_end(msg, hdr); | |
4c476991 | 3613 | return genlmsg_reply(msg, info); |
93da9cc1 | 3614 | |
3b85875a | 3615 | nla_put_failure: |
93da9cc1 | 3616 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 3617 | out: |
d080e275 | 3618 | nlmsg_free(msg); |
4c476991 | 3619 | return -ENOBUFS; |
93da9cc1 | 3620 | } |
3621 | ||
b54452b0 | 3622 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 3623 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
3624 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
3625 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
3626 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
3627 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
3628 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 3629 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 3630 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 3631 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 3632 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
3633 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
3634 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
3635 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
3636 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 3637 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 3638 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 3639 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 3640 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 3641 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 3642 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
3643 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
3644 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
3645 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
3646 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 3647 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 3648 | }; |
3649 | ||
c80d545d JC |
3650 | static const struct nla_policy |
3651 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 3652 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
3653 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
3654 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 3655 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
581a8b0f | 3656 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 3657 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 3658 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
3659 | }; |
3660 | ||
24bdd9f4 | 3661 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
3662 | struct mesh_config *cfg, |
3663 | u32 *mask_out) | |
93da9cc1 | 3664 | { |
93da9cc1 | 3665 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 3666 | u32 mask = 0; |
93da9cc1 | 3667 | |
bd90fdcc JB |
3668 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
3669 | do {\ | |
3670 | if (table[attr_num]) {\ | |
3671 | cfg->param = nla_fn(table[attr_num]); \ | |
3672 | mask |= (1 << (attr_num - 1)); \ | |
3673 | } \ | |
3674 | } while (0);\ | |
3675 | ||
3676 | ||
24bdd9f4 | 3677 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 3678 | return -EINVAL; |
3679 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 3680 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 3681 | nl80211_meshconf_params_policy)) |
93da9cc1 | 3682 | return -EINVAL; |
3683 | ||
93da9cc1 | 3684 | /* This makes sure that there aren't more than 32 mesh config |
3685 | * parameters (otherwise our bitfield scheme would not work.) */ | |
3686 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
3687 | ||
3688 | /* Fill in the params struct */ | |
93da9cc1 | 3689 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
a4f606ea CYY |
3690 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
3691 | nla_get_u16); | |
93da9cc1 | 3692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
a4f606ea CYY |
3693 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
3694 | nla_get_u16); | |
93da9cc1 | 3695 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
a4f606ea CYY |
3696 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
3697 | nla_get_u16); | |
93da9cc1 | 3698 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
a4f606ea CYY |
3699 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
3700 | nla_get_u16); | |
93da9cc1 | 3701 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
a4f606ea CYY |
3702 | mask, NL80211_MESHCONF_MAX_RETRIES, |
3703 | nla_get_u8); | |
93da9cc1 | 3704 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
a4f606ea | 3705 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
45904f21 | 3706 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
a4f606ea CYY |
3707 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
3708 | nla_get_u8); | |
93da9cc1 | 3709 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
a4f606ea CYY |
3710 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
3711 | nla_get_u8); | |
3712 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, mask, | |
3713 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, | |
3714 | nla_get_u32); | |
93da9cc1 | 3715 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
a4f606ea CYY |
3716 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
3717 | nla_get_u8); | |
93da9cc1 | 3718 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
a4f606ea CYY |
3719 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
3720 | nla_get_u32); | |
93da9cc1 | 3721 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
a4f606ea CYY |
3722 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
3723 | nla_get_u16); | |
3724 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, mask, | |
3725 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3726 | nla_get_u32); | |
93da9cc1 | 3727 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
a4f606ea CYY |
3728 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
3729 | nla_get_u16); | |
dca7e943 | 3730 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
a4f606ea CYY |
3731 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, |
3732 | nla_get_u16); | |
0507e159 | 3733 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
a4f606ea CYY |
3734 | dot11MeshHWMPnetDiameterTraversalTime, mask, |
3735 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3736 | nla_get_u16); | |
3737 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, mask, | |
3738 | NL80211_MESHCONF_HWMP_ROOTMODE, nla_get_u8); | |
3739 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, mask, | |
3740 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
3741 | nla_get_u16); | |
16dd7267 | 3742 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
a4f606ea CYY |
3743 | dot11MeshGateAnnouncementProtocol, mask, |
3744 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
3745 | nla_get_u8); | |
94f90656 | 3746 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
a4f606ea CYY |
3747 | mask, NL80211_MESHCONF_FORWARDING, |
3748 | nla_get_u8); | |
55335137 | 3749 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
a4f606ea CYY |
3750 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
3751 | nla_get_u32); | |
70c33eaa | 3752 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
a4f606ea | 3753 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
3754 | nla_get_u16); |
3755 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
3756 | mask, | |
3757 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
3758 | nla_get_u32); | |
3759 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, | |
3760 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
3761 | nla_get_u16); |
3762 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
3763 | dot11MeshHWMPconfirmationInterval, mask, | |
3764 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
a4f606ea | 3765 | nla_get_u16); |
bd90fdcc JB |
3766 | if (mask_out) |
3767 | *mask_out = mask; | |
c80d545d | 3768 | |
bd90fdcc JB |
3769 | return 0; |
3770 | ||
3771 | #undef FILL_IN_MESH_PARAM_IF_SET | |
3772 | } | |
3773 | ||
c80d545d JC |
3774 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
3775 | struct mesh_setup *setup) | |
3776 | { | |
3777 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | |
3778 | ||
3779 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
3780 | return -EINVAL; | |
3781 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
3782 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
3783 | nl80211_mesh_setup_params_policy)) | |
3784 | return -EINVAL; | |
3785 | ||
d299a1f2 JC |
3786 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
3787 | setup->sync_method = | |
3788 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
3789 | IEEE80211_SYNC_METHOD_VENDOR : | |
3790 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
3791 | ||
c80d545d JC |
3792 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
3793 | setup->path_sel_proto = | |
3794 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
3795 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
3796 | IEEE80211_PATH_PROTOCOL_HWMP; | |
3797 | ||
3798 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
3799 | setup->path_metric = | |
3800 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
3801 | IEEE80211_PATH_METRIC_VENDOR : | |
3802 | IEEE80211_PATH_METRIC_AIRTIME; | |
3803 | ||
581a8b0f JC |
3804 | |
3805 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 3806 | struct nlattr *ieattr = |
581a8b0f | 3807 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
3808 | if (!is_valid_ie_attr(ieattr)) |
3809 | return -EINVAL; | |
581a8b0f JC |
3810 | setup->ie = nla_data(ieattr); |
3811 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 3812 | } |
b130e5ce JC |
3813 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
3814 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
c80d545d JC |
3815 | |
3816 | return 0; | |
3817 | } | |
3818 | ||
24bdd9f4 | 3819 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 3820 | struct genl_info *info) |
bd90fdcc JB |
3821 | { |
3822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3823 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 3824 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
3825 | struct mesh_config cfg; |
3826 | u32 mask; | |
3827 | int err; | |
3828 | ||
29cbe68c JB |
3829 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3830 | return -EOPNOTSUPP; | |
3831 | ||
24bdd9f4 | 3832 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
3833 | return -EOPNOTSUPP; |
3834 | ||
24bdd9f4 | 3835 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
3836 | if (err) |
3837 | return err; | |
3838 | ||
29cbe68c JB |
3839 | wdev_lock(wdev); |
3840 | if (!wdev->mesh_id_len) | |
3841 | err = -ENOLINK; | |
3842 | ||
3843 | if (!err) | |
24bdd9f4 | 3844 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3845 | mask, &cfg); |
3846 | ||
3847 | wdev_unlock(wdev); | |
3848 | ||
3849 | return err; | |
93da9cc1 | 3850 | } |
3851 | ||
f130347c LR |
3852 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
3853 | { | |
3854 | struct sk_buff *msg; | |
3855 | void *hdr = NULL; | |
3856 | struct nlattr *nl_reg_rules; | |
3857 | unsigned int i; | |
3858 | int err = -EINVAL; | |
3859 | ||
a1794390 | 3860 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
3861 | |
3862 | if (!cfg80211_regdomain) | |
3863 | goto out; | |
3864 | ||
fd2120ca | 3865 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
3866 | if (!msg) { |
3867 | err = -ENOBUFS; | |
3868 | goto out; | |
3869 | } | |
3870 | ||
3871 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
3872 | NL80211_CMD_GET_REG); | |
3873 | if (!hdr) | |
efe1cf0c | 3874 | goto put_failure; |
f130347c | 3875 | |
9360ffd1 DM |
3876 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
3877 | cfg80211_regdomain->alpha2) || | |
3878 | (cfg80211_regdomain->dfs_region && | |
3879 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, | |
3880 | cfg80211_regdomain->dfs_region))) | |
3881 | goto nla_put_failure; | |
f130347c LR |
3882 | |
3883 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
3884 | if (!nl_reg_rules) | |
3885 | goto nla_put_failure; | |
3886 | ||
3887 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
3888 | struct nlattr *nl_reg_rule; | |
3889 | const struct ieee80211_reg_rule *reg_rule; | |
3890 | const struct ieee80211_freq_range *freq_range; | |
3891 | const struct ieee80211_power_rule *power_rule; | |
3892 | ||
3893 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
3894 | freq_range = ®_rule->freq_range; | |
3895 | power_rule = ®_rule->power_rule; | |
3896 | ||
3897 | nl_reg_rule = nla_nest_start(msg, i); | |
3898 | if (!nl_reg_rule) | |
3899 | goto nla_put_failure; | |
3900 | ||
9360ffd1 DM |
3901 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
3902 | reg_rule->flags) || | |
3903 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
3904 | freq_range->start_freq_khz) || | |
3905 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
3906 | freq_range->end_freq_khz) || | |
3907 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
3908 | freq_range->max_bandwidth_khz) || | |
3909 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
3910 | power_rule->max_antenna_gain) || | |
3911 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
3912 | power_rule->max_eirp)) | |
3913 | goto nla_put_failure; | |
f130347c LR |
3914 | |
3915 | nla_nest_end(msg, nl_reg_rule); | |
3916 | } | |
3917 | ||
3918 | nla_nest_end(msg, nl_reg_rules); | |
3919 | ||
3920 | genlmsg_end(msg, hdr); | |
134e6375 | 3921 | err = genlmsg_reply(msg, info); |
f130347c LR |
3922 | goto out; |
3923 | ||
3924 | nla_put_failure: | |
3925 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 3926 | put_failure: |
d080e275 | 3927 | nlmsg_free(msg); |
f130347c LR |
3928 | err = -EMSGSIZE; |
3929 | out: | |
a1794390 | 3930 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
3931 | return err; |
3932 | } | |
3933 | ||
b2e1b302 LR |
3934 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
3935 | { | |
3936 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
3937 | struct nlattr *nl_reg_rule; | |
3938 | char *alpha2 = NULL; | |
3939 | int rem_reg_rules = 0, r = 0; | |
3940 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 3941 | u8 dfs_region = 0; |
b2e1b302 LR |
3942 | struct ieee80211_regdomain *rd = NULL; |
3943 | ||
3944 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
3945 | return -EINVAL; | |
3946 | ||
3947 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
3948 | return -EINVAL; | |
3949 | ||
3950 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3951 | ||
8b60b078 LR |
3952 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
3953 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
3954 | ||
b2e1b302 LR |
3955 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
3956 | rem_reg_rules) { | |
3957 | num_rules++; | |
3958 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 3959 | return -EINVAL; |
b2e1b302 LR |
3960 | } |
3961 | ||
61405e97 LR |
3962 | mutex_lock(&cfg80211_mutex); |
3963 | ||
d0e18f83 LR |
3964 | if (!reg_is_valid_request(alpha2)) { |
3965 | r = -EINVAL; | |
3966 | goto bad_reg; | |
3967 | } | |
b2e1b302 LR |
3968 | |
3969 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
3970 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
3971 | ||
3972 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
d0e18f83 LR |
3973 | if (!rd) { |
3974 | r = -ENOMEM; | |
3975 | goto bad_reg; | |
3976 | } | |
b2e1b302 LR |
3977 | |
3978 | rd->n_reg_rules = num_rules; | |
3979 | rd->alpha2[0] = alpha2[0]; | |
3980 | rd->alpha2[1] = alpha2[1]; | |
3981 | ||
8b60b078 LR |
3982 | /* |
3983 | * Disable DFS master mode if the DFS region was | |
3984 | * not supported or known on this kernel. | |
3985 | */ | |
3986 | if (reg_supported_dfs_region(dfs_region)) | |
3987 | rd->dfs_region = dfs_region; | |
3988 | ||
b2e1b302 LR |
3989 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
3990 | rem_reg_rules) { | |
3991 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
3992 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
3993 | reg_rule_policy); | |
3994 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
3995 | if (r) | |
3996 | goto bad_reg; | |
3997 | ||
3998 | rule_idx++; | |
3999 | ||
d0e18f83 LR |
4000 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
4001 | r = -EINVAL; | |
b2e1b302 | 4002 | goto bad_reg; |
d0e18f83 | 4003 | } |
b2e1b302 LR |
4004 | } |
4005 | ||
4006 | BUG_ON(rule_idx != num_rules); | |
4007 | ||
b2e1b302 | 4008 | r = set_regdom(rd); |
61405e97 | 4009 | |
a1794390 | 4010 | mutex_unlock(&cfg80211_mutex); |
d0e18f83 | 4011 | |
b2e1b302 LR |
4012 | return r; |
4013 | ||
d2372b31 | 4014 | bad_reg: |
61405e97 | 4015 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 4016 | kfree(rd); |
d0e18f83 | 4017 | return r; |
b2e1b302 LR |
4018 | } |
4019 | ||
83f5e2cf JB |
4020 | static int validate_scan_freqs(struct nlattr *freqs) |
4021 | { | |
4022 | struct nlattr *attr1, *attr2; | |
4023 | int n_channels = 0, tmp1, tmp2; | |
4024 | ||
4025 | nla_for_each_nested(attr1, freqs, tmp1) { | |
4026 | n_channels++; | |
4027 | /* | |
4028 | * Some hardware has a limited channel list for | |
4029 | * scanning, and it is pretty much nonsensical | |
4030 | * to scan for a channel twice, so disallow that | |
4031 | * and don't require drivers to check that the | |
4032 | * channel list they get isn't longer than what | |
4033 | * they can scan, as long as they can scan all | |
4034 | * the channels they registered at once. | |
4035 | */ | |
4036 | nla_for_each_nested(attr2, freqs, tmp2) | |
4037 | if (attr1 != attr2 && | |
4038 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
4039 | return 0; | |
4040 | } | |
4041 | ||
4042 | return n_channels; | |
4043 | } | |
4044 | ||
2a519311 JB |
4045 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
4046 | { | |
4c476991 JB |
4047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4048 | struct net_device *dev = info->user_ptr[1]; | |
2a519311 | 4049 | struct cfg80211_scan_request *request; |
2a519311 JB |
4050 | struct nlattr *attr; |
4051 | struct wiphy *wiphy; | |
83f5e2cf | 4052 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 4053 | size_t ie_len; |
2a519311 | 4054 | |
f4a11bb0 JB |
4055 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4056 | return -EINVAL; | |
4057 | ||
79c97e97 | 4058 | wiphy = &rdev->wiphy; |
2a519311 | 4059 | |
4c476991 JB |
4060 | if (!rdev->ops->scan) |
4061 | return -EOPNOTSUPP; | |
2a519311 | 4062 | |
4c476991 JB |
4063 | if (rdev->scan_req) |
4064 | return -EBUSY; | |
2a519311 JB |
4065 | |
4066 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
4067 | n_channels = validate_scan_freqs( |
4068 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
4069 | if (!n_channels) |
4070 | return -EINVAL; | |
2a519311 | 4071 | } else { |
34850ab2 | 4072 | enum ieee80211_band band; |
83f5e2cf JB |
4073 | n_channels = 0; |
4074 | ||
2a519311 JB |
4075 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
4076 | if (wiphy->bands[band]) | |
4077 | n_channels += wiphy->bands[band]->n_channels; | |
4078 | } | |
4079 | ||
4080 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
4081 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
4082 | n_ssids++; | |
4083 | ||
4c476991 JB |
4084 | if (n_ssids > wiphy->max_scan_ssids) |
4085 | return -EINVAL; | |
2a519311 | 4086 | |
70692ad2 JM |
4087 | if (info->attrs[NL80211_ATTR_IE]) |
4088 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4089 | else | |
4090 | ie_len = 0; | |
4091 | ||
4c476991 JB |
4092 | if (ie_len > wiphy->max_scan_ie_len) |
4093 | return -EINVAL; | |
18a83659 | 4094 | |
2a519311 | 4095 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
4096 | + sizeof(*request->ssids) * n_ssids |
4097 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 4098 | + ie_len, GFP_KERNEL); |
4c476991 JB |
4099 | if (!request) |
4100 | return -ENOMEM; | |
2a519311 | 4101 | |
2a519311 | 4102 | if (n_ssids) |
5ba63533 | 4103 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 4104 | request->n_ssids = n_ssids; |
70692ad2 JM |
4105 | if (ie_len) { |
4106 | if (request->ssids) | |
4107 | request->ie = (void *)(request->ssids + n_ssids); | |
4108 | else | |
4109 | request->ie = (void *)(request->channels + n_channels); | |
4110 | } | |
2a519311 | 4111 | |
584991dc | 4112 | i = 0; |
2a519311 JB |
4113 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
4114 | /* user specified, bail out if channel not found */ | |
2a519311 | 4115 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
4116 | struct ieee80211_channel *chan; |
4117 | ||
4118 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
4119 | ||
4120 | if (!chan) { | |
2a519311 JB |
4121 | err = -EINVAL; |
4122 | goto out_free; | |
4123 | } | |
584991dc JB |
4124 | |
4125 | /* ignore disabled channels */ | |
4126 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4127 | continue; | |
4128 | ||
4129 | request->channels[i] = chan; | |
2a519311 JB |
4130 | i++; |
4131 | } | |
4132 | } else { | |
34850ab2 JB |
4133 | enum ieee80211_band band; |
4134 | ||
2a519311 | 4135 | /* all channels */ |
2a519311 JB |
4136 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
4137 | int j; | |
4138 | if (!wiphy->bands[band]) | |
4139 | continue; | |
4140 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
4141 | struct ieee80211_channel *chan; |
4142 | ||
4143 | chan = &wiphy->bands[band]->channels[j]; | |
4144 | ||
4145 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4146 | continue; | |
4147 | ||
4148 | request->channels[i] = chan; | |
2a519311 JB |
4149 | i++; |
4150 | } | |
4151 | } | |
4152 | } | |
4153 | ||
584991dc JB |
4154 | if (!i) { |
4155 | err = -EINVAL; | |
4156 | goto out_free; | |
4157 | } | |
4158 | ||
4159 | request->n_channels = i; | |
4160 | ||
2a519311 JB |
4161 | i = 0; |
4162 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
4163 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 4164 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
4165 | err = -EINVAL; |
4166 | goto out_free; | |
4167 | } | |
57a27e1d | 4168 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 4169 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
4170 | i++; |
4171 | } | |
4172 | } | |
4173 | ||
70692ad2 JM |
4174 | if (info->attrs[NL80211_ATTR_IE]) { |
4175 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
4176 | memcpy((void *)request->ie, |
4177 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
4178 | request->ie_len); |
4179 | } | |
4180 | ||
34850ab2 | 4181 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
4182 | if (wiphy->bands[i]) |
4183 | request->rates[i] = | |
4184 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
4185 | |
4186 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
4187 | nla_for_each_nested(attr, | |
4188 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
4189 | tmp) { | |
4190 | enum ieee80211_band band = nla_type(attr); | |
4191 | ||
84404623 | 4192 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
4193 | err = -EINVAL; |
4194 | goto out_free; | |
4195 | } | |
4196 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
4197 | nla_data(attr), | |
4198 | nla_len(attr), | |
4199 | &request->rates[band]); | |
4200 | if (err) | |
4201 | goto out_free; | |
4202 | } | |
4203 | } | |
4204 | ||
e9f935e3 RM |
4205 | request->no_cck = |
4206 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
4207 | ||
463d0183 | 4208 | request->dev = dev; |
79c97e97 | 4209 | request->wiphy = &rdev->wiphy; |
2a519311 | 4210 | |
79c97e97 JB |
4211 | rdev->scan_req = request; |
4212 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | |
2a519311 | 4213 | |
463d0183 | 4214 | if (!err) { |
79c97e97 | 4215 | nl80211_send_scan_start(rdev, dev); |
463d0183 | 4216 | dev_hold(dev); |
4c476991 | 4217 | } else { |
2a519311 | 4218 | out_free: |
79c97e97 | 4219 | rdev->scan_req = NULL; |
2a519311 JB |
4220 | kfree(request); |
4221 | } | |
3b85875a | 4222 | |
2a519311 JB |
4223 | return err; |
4224 | } | |
4225 | ||
807f8a8c LC |
4226 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
4227 | struct genl_info *info) | |
4228 | { | |
4229 | struct cfg80211_sched_scan_request *request; | |
4230 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4231 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
4232 | struct nlattr *attr; |
4233 | struct wiphy *wiphy; | |
a1f1c21c | 4234 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 4235 | u32 interval; |
807f8a8c LC |
4236 | enum ieee80211_band band; |
4237 | size_t ie_len; | |
a1f1c21c | 4238 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
4239 | |
4240 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
4241 | !rdev->ops->sched_scan_start) | |
4242 | return -EOPNOTSUPP; | |
4243 | ||
4244 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4245 | return -EINVAL; | |
4246 | ||
bbe6ad6d LC |
4247 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
4248 | return -EINVAL; | |
4249 | ||
4250 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
4251 | if (interval == 0) | |
4252 | return -EINVAL; | |
4253 | ||
807f8a8c LC |
4254 | wiphy = &rdev->wiphy; |
4255 | ||
4256 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
4257 | n_channels = validate_scan_freqs( | |
4258 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4259 | if (!n_channels) | |
4260 | return -EINVAL; | |
4261 | } else { | |
4262 | n_channels = 0; | |
4263 | ||
4264 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
4265 | if (wiphy->bands[band]) | |
4266 | n_channels += wiphy->bands[band]->n_channels; | |
4267 | } | |
4268 | ||
4269 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
4270 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
4271 | tmp) | |
4272 | n_ssids++; | |
4273 | ||
93b6aa69 | 4274 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
4275 | return -EINVAL; |
4276 | ||
a1f1c21c LC |
4277 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
4278 | nla_for_each_nested(attr, | |
4279 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
4280 | tmp) | |
4281 | n_match_sets++; | |
4282 | ||
4283 | if (n_match_sets > wiphy->max_match_sets) | |
4284 | return -EINVAL; | |
4285 | ||
807f8a8c LC |
4286 | if (info->attrs[NL80211_ATTR_IE]) |
4287 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4288 | else | |
4289 | ie_len = 0; | |
4290 | ||
5a865bad | 4291 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
4292 | return -EINVAL; |
4293 | ||
c10841ca LC |
4294 | mutex_lock(&rdev->sched_scan_mtx); |
4295 | ||
4296 | if (rdev->sched_scan_req) { | |
4297 | err = -EINPROGRESS; | |
4298 | goto out; | |
4299 | } | |
4300 | ||
807f8a8c | 4301 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 4302 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 4303 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 4304 | + sizeof(*request->channels) * n_channels |
807f8a8c | 4305 | + ie_len, GFP_KERNEL); |
c10841ca LC |
4306 | if (!request) { |
4307 | err = -ENOMEM; | |
4308 | goto out; | |
4309 | } | |
807f8a8c LC |
4310 | |
4311 | if (n_ssids) | |
4312 | request->ssids = (void *)&request->channels[n_channels]; | |
4313 | request->n_ssids = n_ssids; | |
4314 | if (ie_len) { | |
4315 | if (request->ssids) | |
4316 | request->ie = (void *)(request->ssids + n_ssids); | |
4317 | else | |
4318 | request->ie = (void *)(request->channels + n_channels); | |
4319 | } | |
4320 | ||
a1f1c21c LC |
4321 | if (n_match_sets) { |
4322 | if (request->ie) | |
4323 | request->match_sets = (void *)(request->ie + ie_len); | |
4324 | else if (request->ssids) | |
4325 | request->match_sets = | |
4326 | (void *)(request->ssids + n_ssids); | |
4327 | else | |
4328 | request->match_sets = | |
4329 | (void *)(request->channels + n_channels); | |
4330 | } | |
4331 | request->n_match_sets = n_match_sets; | |
4332 | ||
807f8a8c LC |
4333 | i = 0; |
4334 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
4335 | /* user specified, bail out if channel not found */ | |
4336 | nla_for_each_nested(attr, | |
4337 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
4338 | tmp) { | |
4339 | struct ieee80211_channel *chan; | |
4340 | ||
4341 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
4342 | ||
4343 | if (!chan) { | |
4344 | err = -EINVAL; | |
4345 | goto out_free; | |
4346 | } | |
4347 | ||
4348 | /* ignore disabled channels */ | |
4349 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4350 | continue; | |
4351 | ||
4352 | request->channels[i] = chan; | |
4353 | i++; | |
4354 | } | |
4355 | } else { | |
4356 | /* all channels */ | |
4357 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
4358 | int j; | |
4359 | if (!wiphy->bands[band]) | |
4360 | continue; | |
4361 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
4362 | struct ieee80211_channel *chan; | |
4363 | ||
4364 | chan = &wiphy->bands[band]->channels[j]; | |
4365 | ||
4366 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4367 | continue; | |
4368 | ||
4369 | request->channels[i] = chan; | |
4370 | i++; | |
4371 | } | |
4372 | } | |
4373 | } | |
4374 | ||
4375 | if (!i) { | |
4376 | err = -EINVAL; | |
4377 | goto out_free; | |
4378 | } | |
4379 | ||
4380 | request->n_channels = i; | |
4381 | ||
4382 | i = 0; | |
4383 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
4384 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
4385 | tmp) { | |
57a27e1d | 4386 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
4387 | err = -EINVAL; |
4388 | goto out_free; | |
4389 | } | |
57a27e1d | 4390 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
4391 | memcpy(request->ssids[i].ssid, nla_data(attr), |
4392 | nla_len(attr)); | |
807f8a8c LC |
4393 | i++; |
4394 | } | |
4395 | } | |
4396 | ||
a1f1c21c LC |
4397 | i = 0; |
4398 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
4399 | nla_for_each_nested(attr, | |
4400 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
4401 | tmp) { | |
88e920b4 | 4402 | struct nlattr *ssid, *rssi; |
a1f1c21c LC |
4403 | |
4404 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
4405 | nla_data(attr), nla_len(attr), | |
4406 | nl80211_match_policy); | |
4a4ab0d7 | 4407 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c LC |
4408 | if (ssid) { |
4409 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
4410 | err = -EINVAL; | |
4411 | goto out_free; | |
4412 | } | |
4413 | memcpy(request->match_sets[i].ssid.ssid, | |
4414 | nla_data(ssid), nla_len(ssid)); | |
4415 | request->match_sets[i].ssid.ssid_len = | |
4416 | nla_len(ssid); | |
4417 | } | |
88e920b4 TP |
4418 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; |
4419 | if (rssi) | |
4420 | request->rssi_thold = nla_get_u32(rssi); | |
4421 | else | |
4422 | request->rssi_thold = | |
4423 | NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
4424 | i++; |
4425 | } | |
4426 | } | |
4427 | ||
807f8a8c LC |
4428 | if (info->attrs[NL80211_ATTR_IE]) { |
4429 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4430 | memcpy((void *)request->ie, | |
4431 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
4432 | request->ie_len); | |
4433 | } | |
4434 | ||
4435 | request->dev = dev; | |
4436 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 4437 | request->interval = interval; |
807f8a8c LC |
4438 | |
4439 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); | |
4440 | if (!err) { | |
4441 | rdev->sched_scan_req = request; | |
4442 | nl80211_send_sched_scan(rdev, dev, | |
4443 | NL80211_CMD_START_SCHED_SCAN); | |
4444 | goto out; | |
4445 | } | |
4446 | ||
4447 | out_free: | |
4448 | kfree(request); | |
4449 | out: | |
c10841ca | 4450 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
4451 | return err; |
4452 | } | |
4453 | ||
4454 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
4455 | struct genl_info *info) | |
4456 | { | |
4457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 4458 | int err; |
807f8a8c LC |
4459 | |
4460 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
4461 | !rdev->ops->sched_scan_stop) | |
4462 | return -EOPNOTSUPP; | |
4463 | ||
c10841ca LC |
4464 | mutex_lock(&rdev->sched_scan_mtx); |
4465 | err = __cfg80211_stop_sched_scan(rdev, false); | |
4466 | mutex_unlock(&rdev->sched_scan_mtx); | |
4467 | ||
4468 | return err; | |
807f8a8c LC |
4469 | } |
4470 | ||
9720bb3a JB |
4471 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
4472 | u32 seq, int flags, | |
2a519311 | 4473 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
4474 | struct wireless_dev *wdev, |
4475 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 4476 | { |
48ab905d | 4477 | struct cfg80211_bss *res = &intbss->pub; |
2a519311 JB |
4478 | void *hdr; |
4479 | struct nlattr *bss; | |
48ab905d JB |
4480 | |
4481 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 4482 | |
9720bb3a | 4483 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
2a519311 JB |
4484 | NL80211_CMD_NEW_SCAN_RESULTS); |
4485 | if (!hdr) | |
4486 | return -1; | |
4487 | ||
9720bb3a JB |
4488 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
4489 | ||
9360ffd1 DM |
4490 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
4491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | |
4492 | goto nla_put_failure; | |
2a519311 JB |
4493 | |
4494 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
4495 | if (!bss) | |
4496 | goto nla_put_failure; | |
9360ffd1 DM |
4497 | if ((!is_zero_ether_addr(res->bssid) && |
4498 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || | |
4499 | (res->information_elements && res->len_information_elements && | |
4500 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
4501 | res->len_information_elements, | |
4502 | res->information_elements)) || | |
4503 | (res->beacon_ies && res->len_beacon_ies && | |
4504 | res->beacon_ies != res->information_elements && | |
4505 | nla_put(msg, NL80211_BSS_BEACON_IES, | |
4506 | res->len_beacon_ies, res->beacon_ies))) | |
4507 | goto nla_put_failure; | |
4508 | if (res->tsf && | |
4509 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) | |
4510 | goto nla_put_failure; | |
4511 | if (res->beacon_interval && | |
4512 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
4513 | goto nla_put_failure; | |
4514 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
4515 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
4516 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
4517 | jiffies_to_msecs(jiffies - intbss->ts))) | |
4518 | goto nla_put_failure; | |
2a519311 | 4519 | |
77965c97 | 4520 | switch (rdev->wiphy.signal_type) { |
2a519311 | 4521 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
4522 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
4523 | goto nla_put_failure; | |
2a519311 JB |
4524 | break; |
4525 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
4526 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
4527 | goto nla_put_failure; | |
2a519311 JB |
4528 | break; |
4529 | default: | |
4530 | break; | |
4531 | } | |
4532 | ||
48ab905d | 4533 | switch (wdev->iftype) { |
074ac8df | 4534 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 4535 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
4536 | if (intbss == wdev->current_bss && |
4537 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
4538 | NL80211_BSS_STATUS_ASSOCIATED)) | |
4539 | goto nla_put_failure; | |
48ab905d JB |
4540 | break; |
4541 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
4542 | if (intbss == wdev->current_bss && |
4543 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
4544 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
4545 | goto nla_put_failure; | |
48ab905d JB |
4546 | break; |
4547 | default: | |
4548 | break; | |
4549 | } | |
4550 | ||
2a519311 JB |
4551 | nla_nest_end(msg, bss); |
4552 | ||
4553 | return genlmsg_end(msg, hdr); | |
4554 | ||
4555 | nla_put_failure: | |
4556 | genlmsg_cancel(msg, hdr); | |
4557 | return -EMSGSIZE; | |
4558 | } | |
4559 | ||
4560 | static int nl80211_dump_scan(struct sk_buff *skb, | |
4561 | struct netlink_callback *cb) | |
4562 | { | |
48ab905d JB |
4563 | struct cfg80211_registered_device *rdev; |
4564 | struct net_device *dev; | |
2a519311 | 4565 | struct cfg80211_internal_bss *scan; |
48ab905d | 4566 | struct wireless_dev *wdev; |
2a519311 JB |
4567 | int start = cb->args[1], idx = 0; |
4568 | int err; | |
4569 | ||
67748893 JB |
4570 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
4571 | if (err) | |
4572 | return err; | |
2a519311 | 4573 | |
48ab905d | 4574 | wdev = dev->ieee80211_ptr; |
2a519311 | 4575 | |
48ab905d JB |
4576 | wdev_lock(wdev); |
4577 | spin_lock_bh(&rdev->bss_lock); | |
4578 | cfg80211_bss_expire(rdev); | |
4579 | ||
9720bb3a JB |
4580 | cb->seq = rdev->bss_generation; |
4581 | ||
48ab905d | 4582 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
4583 | if (++idx <= start) |
4584 | continue; | |
9720bb3a | 4585 | if (nl80211_send_bss(skb, cb, |
2a519311 | 4586 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 4587 | rdev, wdev, scan) < 0) { |
2a519311 | 4588 | idx--; |
67748893 | 4589 | break; |
2a519311 JB |
4590 | } |
4591 | } | |
4592 | ||
48ab905d JB |
4593 | spin_unlock_bh(&rdev->bss_lock); |
4594 | wdev_unlock(wdev); | |
2a519311 JB |
4595 | |
4596 | cb->args[1] = idx; | |
67748893 | 4597 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 4598 | |
67748893 | 4599 | return skb->len; |
2a519311 JB |
4600 | } |
4601 | ||
61fa713c HS |
4602 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
4603 | int flags, struct net_device *dev, | |
4604 | struct survey_info *survey) | |
4605 | { | |
4606 | void *hdr; | |
4607 | struct nlattr *infoattr; | |
4608 | ||
61fa713c HS |
4609 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
4610 | NL80211_CMD_NEW_SURVEY_RESULTS); | |
4611 | if (!hdr) | |
4612 | return -ENOMEM; | |
4613 | ||
9360ffd1 DM |
4614 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
4615 | goto nla_put_failure; | |
61fa713c HS |
4616 | |
4617 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
4618 | if (!infoattr) | |
4619 | goto nla_put_failure; | |
4620 | ||
9360ffd1 DM |
4621 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
4622 | survey->channel->center_freq)) | |
4623 | goto nla_put_failure; | |
4624 | ||
4625 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
4626 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
4627 | goto nla_put_failure; | |
4628 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
4629 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
4630 | goto nla_put_failure; | |
4631 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
4632 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
4633 | survey->channel_time)) | |
4634 | goto nla_put_failure; | |
4635 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
4636 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
4637 | survey->channel_time_busy)) | |
4638 | goto nla_put_failure; | |
4639 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
4640 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
4641 | survey->channel_time_ext_busy)) | |
4642 | goto nla_put_failure; | |
4643 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
4644 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
4645 | survey->channel_time_rx)) | |
4646 | goto nla_put_failure; | |
4647 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
4648 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
4649 | survey->channel_time_tx)) | |
4650 | goto nla_put_failure; | |
61fa713c HS |
4651 | |
4652 | nla_nest_end(msg, infoattr); | |
4653 | ||
4654 | return genlmsg_end(msg, hdr); | |
4655 | ||
4656 | nla_put_failure: | |
4657 | genlmsg_cancel(msg, hdr); | |
4658 | return -EMSGSIZE; | |
4659 | } | |
4660 | ||
4661 | static int nl80211_dump_survey(struct sk_buff *skb, | |
4662 | struct netlink_callback *cb) | |
4663 | { | |
4664 | struct survey_info survey; | |
4665 | struct cfg80211_registered_device *dev; | |
4666 | struct net_device *netdev; | |
61fa713c HS |
4667 | int survey_idx = cb->args[1]; |
4668 | int res; | |
4669 | ||
67748893 JB |
4670 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
4671 | if (res) | |
4672 | return res; | |
61fa713c HS |
4673 | |
4674 | if (!dev->ops->dump_survey) { | |
4675 | res = -EOPNOTSUPP; | |
4676 | goto out_err; | |
4677 | } | |
4678 | ||
4679 | while (1) { | |
180cdc79 LR |
4680 | struct ieee80211_channel *chan; |
4681 | ||
61fa713c HS |
4682 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
4683 | &survey); | |
4684 | if (res == -ENOENT) | |
4685 | break; | |
4686 | if (res) | |
4687 | goto out_err; | |
4688 | ||
180cdc79 LR |
4689 | /* Survey without a channel doesn't make sense */ |
4690 | if (!survey.channel) { | |
4691 | res = -EINVAL; | |
4692 | goto out; | |
4693 | } | |
4694 | ||
4695 | chan = ieee80211_get_channel(&dev->wiphy, | |
4696 | survey.channel->center_freq); | |
4697 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
4698 | survey_idx++; | |
4699 | continue; | |
4700 | } | |
4701 | ||
61fa713c HS |
4702 | if (nl80211_send_survey(skb, |
4703 | NETLINK_CB(cb->skb).pid, | |
4704 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4705 | netdev, | |
4706 | &survey) < 0) | |
4707 | goto out; | |
4708 | survey_idx++; | |
4709 | } | |
4710 | ||
4711 | out: | |
4712 | cb->args[1] = survey_idx; | |
4713 | res = skb->len; | |
4714 | out_err: | |
67748893 | 4715 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
4716 | return res; |
4717 | } | |
4718 | ||
255e737e JM |
4719 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
4720 | { | |
b23aa676 SO |
4721 | return auth_type <= NL80211_AUTHTYPE_MAX; |
4722 | } | |
4723 | ||
4724 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | |
4725 | { | |
4726 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
4727 | NL80211_WPA_VERSION_2)); | |
4728 | } | |
4729 | ||
636a5d36 JM |
4730 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
4731 | { | |
4c476991 JB |
4732 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4733 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 JB |
4734 | struct ieee80211_channel *chan; |
4735 | const u8 *bssid, *ssid, *ie = NULL; | |
4736 | int err, ssid_len, ie_len = 0; | |
4737 | enum nl80211_auth_type auth_type; | |
fffd0934 | 4738 | struct key_parse key; |
d5cdfacb | 4739 | bool local_state_change; |
636a5d36 | 4740 | |
f4a11bb0 JB |
4741 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4742 | return -EINVAL; | |
4743 | ||
4744 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4745 | return -EINVAL; | |
4746 | ||
1778092e JM |
4747 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
4748 | return -EINVAL; | |
4749 | ||
19957bb3 JB |
4750 | if (!info->attrs[NL80211_ATTR_SSID]) |
4751 | return -EINVAL; | |
4752 | ||
4753 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
4754 | return -EINVAL; | |
4755 | ||
fffd0934 JB |
4756 | err = nl80211_parse_key(info, &key); |
4757 | if (err) | |
4758 | return err; | |
4759 | ||
4760 | if (key.idx >= 0) { | |
e31b8213 JB |
4761 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
4762 | return -EINVAL; | |
fffd0934 JB |
4763 | if (!key.p.key || !key.p.key_len) |
4764 | return -EINVAL; | |
4765 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
4766 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
4767 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
4768 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
4769 | return -EINVAL; | |
4770 | if (key.idx > 4) | |
4771 | return -EINVAL; | |
4772 | } else { | |
4773 | key.p.key_len = 0; | |
4774 | key.p.key = NULL; | |
4775 | } | |
4776 | ||
afea0b7a JB |
4777 | if (key.idx >= 0) { |
4778 | int i; | |
4779 | bool ok = false; | |
4780 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
4781 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
4782 | ok = true; | |
4783 | break; | |
4784 | } | |
4785 | } | |
4c476991 JB |
4786 | if (!ok) |
4787 | return -EINVAL; | |
afea0b7a JB |
4788 | } |
4789 | ||
4c476991 JB |
4790 | if (!rdev->ops->auth) |
4791 | return -EOPNOTSUPP; | |
636a5d36 | 4792 | |
074ac8df | 4793 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4794 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4795 | return -EOPNOTSUPP; | |
eec60b03 | 4796 | |
19957bb3 | 4797 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 4798 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 4799 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
4800 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4801 | return -EINVAL; | |
636a5d36 | 4802 | |
19957bb3 JB |
4803 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4804 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4805 | |
4806 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4807 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4808 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4809 | } |
4810 | ||
19957bb3 | 4811 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
4c476991 JB |
4812 | if (!nl80211_valid_auth_type(auth_type)) |
4813 | return -EINVAL; | |
636a5d36 | 4814 | |
d5cdfacb JM |
4815 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4816 | ||
95de817b JB |
4817 | /* |
4818 | * Since we no longer track auth state, ignore | |
4819 | * requests to only change local state. | |
4820 | */ | |
4821 | if (local_state_change) | |
4822 | return 0; | |
4823 | ||
4c476991 JB |
4824 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
4825 | ssid, ssid_len, ie, ie_len, | |
95de817b | 4826 | key.p.key, key.p.key_len, key.idx); |
636a5d36 JM |
4827 | } |
4828 | ||
c0692b8f JB |
4829 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
4830 | struct genl_info *info, | |
3dc27d25 JB |
4831 | struct cfg80211_crypto_settings *settings, |
4832 | int cipher_limit) | |
b23aa676 | 4833 | { |
c0b2bbd8 JB |
4834 | memset(settings, 0, sizeof(*settings)); |
4835 | ||
b23aa676 SO |
4836 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
4837 | ||
c0692b8f JB |
4838 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
4839 | u16 proto; | |
4840 | proto = nla_get_u16( | |
4841 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
4842 | settings->control_port_ethertype = cpu_to_be16(proto); | |
4843 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
4844 | proto != ETH_P_PAE) | |
4845 | return -EINVAL; | |
4846 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
4847 | settings->control_port_no_encrypt = true; | |
4848 | } else | |
4849 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
4850 | ||
b23aa676 SO |
4851 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
4852 | void *data; | |
4853 | int len, i; | |
4854 | ||
4855 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4856 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4857 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
4858 | ||
4859 | if (len % sizeof(u32)) | |
4860 | return -EINVAL; | |
4861 | ||
3dc27d25 | 4862 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
4863 | return -EINVAL; |
4864 | ||
4865 | memcpy(settings->ciphers_pairwise, data, len); | |
4866 | ||
4867 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
4868 | if (!cfg80211_supported_cipher_suite( |
4869 | &rdev->wiphy, | |
b23aa676 SO |
4870 | settings->ciphers_pairwise[i])) |
4871 | return -EINVAL; | |
4872 | } | |
4873 | ||
4874 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
4875 | settings->cipher_group = | |
4876 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
4877 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
4878 | settings->cipher_group)) | |
b23aa676 SO |
4879 | return -EINVAL; |
4880 | } | |
4881 | ||
4882 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
4883 | settings->wpa_versions = | |
4884 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
4885 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
4886 | return -EINVAL; | |
4887 | } | |
4888 | ||
4889 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
4890 | void *data; | |
6d30240e | 4891 | int len; |
b23aa676 SO |
4892 | |
4893 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4894 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4895 | settings->n_akm_suites = len / sizeof(u32); | |
4896 | ||
4897 | if (len % sizeof(u32)) | |
4898 | return -EINVAL; | |
4899 | ||
1b9ca027 JM |
4900 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
4901 | return -EINVAL; | |
4902 | ||
b23aa676 | 4903 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
4904 | } |
4905 | ||
4906 | return 0; | |
4907 | } | |
4908 | ||
636a5d36 JM |
4909 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
4910 | { | |
4c476991 JB |
4911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4912 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4913 | struct cfg80211_crypto_settings crypto; |
f444de05 | 4914 | struct ieee80211_channel *chan; |
3e5d7649 | 4915 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
4916 | int err, ssid_len, ie_len = 0; |
4917 | bool use_mfp = false; | |
7e7c8926 BG |
4918 | u32 flags = 0; |
4919 | struct ieee80211_ht_cap *ht_capa = NULL; | |
4920 | struct ieee80211_ht_cap *ht_capa_mask = NULL; | |
636a5d36 | 4921 | |
f4a11bb0 JB |
4922 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4923 | return -EINVAL; | |
4924 | ||
4925 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
4926 | !info->attrs[NL80211_ATTR_SSID] || |
4927 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
4928 | return -EINVAL; |
4929 | ||
4c476991 JB |
4930 | if (!rdev->ops->assoc) |
4931 | return -EOPNOTSUPP; | |
636a5d36 | 4932 | |
074ac8df | 4933 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4934 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4935 | return -EOPNOTSUPP; | |
eec60b03 | 4936 | |
19957bb3 | 4937 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4938 | |
19957bb3 JB |
4939 | chan = ieee80211_get_channel(&rdev->wiphy, |
4940 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
4941 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4942 | return -EINVAL; | |
636a5d36 | 4943 | |
19957bb3 JB |
4944 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4945 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4946 | |
4947 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4948 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4949 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4950 | } |
4951 | ||
dc6382ce | 4952 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 4953 | enum nl80211_mfp mfp = |
dc6382ce | 4954 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 4955 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 4956 | use_mfp = true; |
4c476991 JB |
4957 | else if (mfp != NL80211_MFP_NO) |
4958 | return -EINVAL; | |
dc6382ce JM |
4959 | } |
4960 | ||
3e5d7649 JB |
4961 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
4962 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
4963 | ||
7e7c8926 BG |
4964 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
4965 | flags |= ASSOC_REQ_DISABLE_HT; | |
4966 | ||
4967 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
4968 | ht_capa_mask = | |
4969 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); | |
4970 | ||
4971 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
4972 | if (!ht_capa_mask) | |
4973 | return -EINVAL; | |
4974 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4975 | } | |
4976 | ||
c0692b8f | 4977 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 4978 | if (!err) |
3e5d7649 JB |
4979 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
4980 | ssid, ssid_len, ie, ie_len, use_mfp, | |
7e7c8926 BG |
4981 | &crypto, flags, ht_capa, |
4982 | ht_capa_mask); | |
636a5d36 | 4983 | |
636a5d36 JM |
4984 | return err; |
4985 | } | |
4986 | ||
4987 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
4988 | { | |
4c476991 JB |
4989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4990 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4991 | const u8 *ie = NULL, *bssid; |
4c476991 | 4992 | int ie_len = 0; |
19957bb3 | 4993 | u16 reason_code; |
d5cdfacb | 4994 | bool local_state_change; |
636a5d36 | 4995 | |
f4a11bb0 JB |
4996 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4997 | return -EINVAL; | |
4998 | ||
4999 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5000 | return -EINVAL; | |
5001 | ||
5002 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
5003 | return -EINVAL; | |
5004 | ||
4c476991 JB |
5005 | if (!rdev->ops->deauth) |
5006 | return -EOPNOTSUPP; | |
636a5d36 | 5007 | |
074ac8df | 5008 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5009 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5010 | return -EOPNOTSUPP; | |
eec60b03 | 5011 | |
19957bb3 | 5012 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 5013 | |
19957bb3 JB |
5014 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
5015 | if (reason_code == 0) { | |
f4a11bb0 | 5016 | /* Reason Code 0 is reserved */ |
4c476991 | 5017 | return -EINVAL; |
255e737e | 5018 | } |
636a5d36 JM |
5019 | |
5020 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5021 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5022 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5023 | } |
5024 | ||
d5cdfacb JM |
5025 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5026 | ||
4c476991 JB |
5027 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
5028 | local_state_change); | |
636a5d36 JM |
5029 | } |
5030 | ||
5031 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
5032 | { | |
4c476991 JB |
5033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5034 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 5035 | const u8 *ie = NULL, *bssid; |
4c476991 | 5036 | int ie_len = 0; |
19957bb3 | 5037 | u16 reason_code; |
d5cdfacb | 5038 | bool local_state_change; |
636a5d36 | 5039 | |
f4a11bb0 JB |
5040 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5041 | return -EINVAL; | |
5042 | ||
5043 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5044 | return -EINVAL; | |
5045 | ||
5046 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
5047 | return -EINVAL; | |
5048 | ||
4c476991 JB |
5049 | if (!rdev->ops->disassoc) |
5050 | return -EOPNOTSUPP; | |
636a5d36 | 5051 | |
074ac8df | 5052 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5053 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5054 | return -EOPNOTSUPP; | |
eec60b03 | 5055 | |
19957bb3 | 5056 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 5057 | |
19957bb3 JB |
5058 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
5059 | if (reason_code == 0) { | |
f4a11bb0 | 5060 | /* Reason Code 0 is reserved */ |
4c476991 | 5061 | return -EINVAL; |
255e737e | 5062 | } |
636a5d36 JM |
5063 | |
5064 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
5065 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
5066 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
5067 | } |
5068 | ||
d5cdfacb JM |
5069 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
5070 | ||
4c476991 JB |
5071 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
5072 | local_state_change); | |
636a5d36 JM |
5073 | } |
5074 | ||
dd5b4cc7 FF |
5075 | static bool |
5076 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
5077 | int mcast_rate[IEEE80211_NUM_BANDS], | |
5078 | int rateval) | |
5079 | { | |
5080 | struct wiphy *wiphy = &rdev->wiphy; | |
5081 | bool found = false; | |
5082 | int band, i; | |
5083 | ||
5084 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
5085 | struct ieee80211_supported_band *sband; | |
5086 | ||
5087 | sband = wiphy->bands[band]; | |
5088 | if (!sband) | |
5089 | continue; | |
5090 | ||
5091 | for (i = 0; i < sband->n_bitrates; i++) { | |
5092 | if (sband->bitrates[i].bitrate == rateval) { | |
5093 | mcast_rate[band] = i + 1; | |
5094 | found = true; | |
5095 | break; | |
5096 | } | |
5097 | } | |
5098 | } | |
5099 | ||
5100 | return found; | |
5101 | } | |
5102 | ||
04a773ad JB |
5103 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
5104 | { | |
4c476991 JB |
5105 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5106 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
5107 | struct cfg80211_ibss_params ibss; |
5108 | struct wiphy *wiphy; | |
fffd0934 | 5109 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
5110 | int err; |
5111 | ||
8e30bc55 JB |
5112 | memset(&ibss, 0, sizeof(ibss)); |
5113 | ||
04a773ad JB |
5114 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5115 | return -EINVAL; | |
5116 | ||
5117 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5118 | !info->attrs[NL80211_ATTR_SSID] || | |
5119 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
5120 | return -EINVAL; | |
5121 | ||
8e30bc55 JB |
5122 | ibss.beacon_interval = 100; |
5123 | ||
5124 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
5125 | ibss.beacon_interval = | |
5126 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
5127 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
5128 | return -EINVAL; | |
5129 | } | |
5130 | ||
4c476991 JB |
5131 | if (!rdev->ops->join_ibss) |
5132 | return -EOPNOTSUPP; | |
04a773ad | 5133 | |
4c476991 JB |
5134 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
5135 | return -EOPNOTSUPP; | |
04a773ad | 5136 | |
79c97e97 | 5137 | wiphy = &rdev->wiphy; |
04a773ad | 5138 | |
39193498 | 5139 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 5140 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
5141 | |
5142 | if (!is_valid_ether_addr(ibss.bssid)) | |
5143 | return -EINVAL; | |
5144 | } | |
04a773ad JB |
5145 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
5146 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
5147 | ||
5148 | if (info->attrs[NL80211_ATTR_IE]) { | |
5149 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
5150 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5151 | } | |
5152 | ||
54858ee5 AS |
5153 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
5154 | enum nl80211_channel_type channel_type; | |
5155 | ||
cd6c6598 | 5156 | if (!nl80211_valid_channel_type(info, &channel_type)) |
54858ee5 AS |
5157 | return -EINVAL; |
5158 | ||
5159 | if (channel_type != NL80211_CHAN_NO_HT && | |
5160 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) | |
5161 | return -EINVAL; | |
5162 | ||
5163 | ibss.channel_type = channel_type; | |
5164 | } else { | |
5165 | ibss.channel_type = NL80211_CHAN_NO_HT; | |
5166 | } | |
5167 | ||
5168 | ibss.channel = rdev_freq_to_chan(rdev, | |
5169 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), | |
5170 | ibss.channel_type); | |
04a773ad JB |
5171 | if (!ibss.channel || |
5172 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | |
4c476991 JB |
5173 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
5174 | return -EINVAL; | |
04a773ad | 5175 | |
54858ee5 AS |
5176 | /* Both channels should be able to initiate communication */ |
5177 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || | |
5178 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && | |
5179 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, | |
5180 | ibss.channel_type)) | |
5181 | return -EINVAL; | |
5182 | ||
04a773ad | 5183 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
5184 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
5185 | ||
fbd2c8dc TP |
5186 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5187 | u8 *rates = | |
5188 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5189 | int n_rates = | |
5190 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5191 | struct ieee80211_supported_band *sband = | |
5192 | wiphy->bands[ibss.channel->band]; | |
fbd2c8dc | 5193 | |
34850ab2 JB |
5194 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
5195 | &ibss.basic_rates); | |
5196 | if (err) | |
5197 | return err; | |
fbd2c8dc | 5198 | } |
dd5b4cc7 FF |
5199 | |
5200 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
5201 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
5202 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
5203 | return -EINVAL; | |
fbd2c8dc | 5204 | |
4c476991 JB |
5205 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
5206 | connkeys = nl80211_parse_connkeys(rdev, | |
5207 | info->attrs[NL80211_ATTR_KEYS]); | |
5208 | if (IS_ERR(connkeys)) | |
5209 | return PTR_ERR(connkeys); | |
5210 | } | |
04a773ad | 5211 | |
267335d6 AQ |
5212 | ibss.control_port = |
5213 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
5214 | ||
4c476991 | 5215 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
5216 | if (err) |
5217 | kfree(connkeys); | |
04a773ad JB |
5218 | return err; |
5219 | } | |
5220 | ||
5221 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
5222 | { | |
4c476991 JB |
5223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5224 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 5225 | |
4c476991 JB |
5226 | if (!rdev->ops->leave_ibss) |
5227 | return -EOPNOTSUPP; | |
04a773ad | 5228 | |
4c476991 JB |
5229 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
5230 | return -EOPNOTSUPP; | |
04a773ad | 5231 | |
4c476991 | 5232 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
5233 | } |
5234 | ||
aff89a9b JB |
5235 | #ifdef CONFIG_NL80211_TESTMODE |
5236 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
5237 | .name = "testmode", | |
5238 | }; | |
5239 | ||
5240 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
5241 | { | |
4c476991 | 5242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
5243 | int err; |
5244 | ||
5245 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
5246 | return -EINVAL; | |
5247 | ||
aff89a9b JB |
5248 | err = -EOPNOTSUPP; |
5249 | if (rdev->ops->testmode_cmd) { | |
5250 | rdev->testmode_info = info; | |
5251 | err = rdev->ops->testmode_cmd(&rdev->wiphy, | |
5252 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | |
5253 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
5254 | rdev->testmode_info = NULL; | |
5255 | } | |
5256 | ||
aff89a9b JB |
5257 | return err; |
5258 | } | |
5259 | ||
71063f0e WYG |
5260 | static int nl80211_testmode_dump(struct sk_buff *skb, |
5261 | struct netlink_callback *cb) | |
5262 | { | |
00918d33 | 5263 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
5264 | int err; |
5265 | long phy_idx; | |
5266 | void *data = NULL; | |
5267 | int data_len = 0; | |
5268 | ||
5269 | if (cb->args[0]) { | |
5270 | /* | |
5271 | * 0 is a valid index, but not valid for args[0], | |
5272 | * so we need to offset by 1. | |
5273 | */ | |
5274 | phy_idx = cb->args[0] - 1; | |
5275 | } else { | |
5276 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
5277 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
5278 | nl80211_policy); | |
5279 | if (err) | |
5280 | return err; | |
00918d33 | 5281 | |
2bd7e35d JB |
5282 | mutex_lock(&cfg80211_mutex); |
5283 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), | |
5284 | nl80211_fam.attrbuf); | |
5285 | if (IS_ERR(rdev)) { | |
5286 | mutex_unlock(&cfg80211_mutex); | |
5287 | return PTR_ERR(rdev); | |
00918d33 | 5288 | } |
2bd7e35d JB |
5289 | phy_idx = rdev->wiphy_idx; |
5290 | rdev = NULL; | |
5291 | mutex_unlock(&cfg80211_mutex); | |
5292 | ||
71063f0e WYG |
5293 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
5294 | cb->args[1] = | |
5295 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
5296 | } | |
5297 | ||
5298 | if (cb->args[1]) { | |
5299 | data = nla_data((void *)cb->args[1]); | |
5300 | data_len = nla_len((void *)cb->args[1]); | |
5301 | } | |
5302 | ||
5303 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
5304 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
5305 | if (!rdev) { | |
71063f0e WYG |
5306 | mutex_unlock(&cfg80211_mutex); |
5307 | return -ENOENT; | |
5308 | } | |
00918d33 | 5309 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
5310 | mutex_unlock(&cfg80211_mutex); |
5311 | ||
00918d33 | 5312 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
5313 | err = -EOPNOTSUPP; |
5314 | goto out_err; | |
5315 | } | |
5316 | ||
5317 | while (1) { | |
5318 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, | |
5319 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
5320 | NL80211_CMD_TESTMODE); | |
5321 | struct nlattr *tmdata; | |
5322 | ||
9360ffd1 | 5323 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
5324 | genlmsg_cancel(skb, hdr); |
5325 | break; | |
5326 | } | |
5327 | ||
5328 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
5329 | if (!tmdata) { | |
5330 | genlmsg_cancel(skb, hdr); | |
5331 | break; | |
5332 | } | |
00918d33 JB |
5333 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
5334 | data, data_len); | |
71063f0e WYG |
5335 | nla_nest_end(skb, tmdata); |
5336 | ||
5337 | if (err == -ENOBUFS || err == -ENOENT) { | |
5338 | genlmsg_cancel(skb, hdr); | |
5339 | break; | |
5340 | } else if (err) { | |
5341 | genlmsg_cancel(skb, hdr); | |
5342 | goto out_err; | |
5343 | } | |
5344 | ||
5345 | genlmsg_end(skb, hdr); | |
5346 | } | |
5347 | ||
5348 | err = skb->len; | |
5349 | /* see above */ | |
5350 | cb->args[0] = phy_idx + 1; | |
5351 | out_err: | |
00918d33 | 5352 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
5353 | return err; |
5354 | } | |
5355 | ||
aff89a9b JB |
5356 | static struct sk_buff * |
5357 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
5358 | int approxlen, u32 pid, u32 seq, gfp_t gfp) | |
5359 | { | |
5360 | struct sk_buff *skb; | |
5361 | void *hdr; | |
5362 | struct nlattr *data; | |
5363 | ||
5364 | skb = nlmsg_new(approxlen + 100, gfp); | |
5365 | if (!skb) | |
5366 | return NULL; | |
5367 | ||
5368 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); | |
5369 | if (!hdr) { | |
5370 | kfree_skb(skb); | |
5371 | return NULL; | |
5372 | } | |
5373 | ||
9360ffd1 DM |
5374 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
5375 | goto nla_put_failure; | |
aff89a9b JB |
5376 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
5377 | ||
5378 | ((void **)skb->cb)[0] = rdev; | |
5379 | ((void **)skb->cb)[1] = hdr; | |
5380 | ((void **)skb->cb)[2] = data; | |
5381 | ||
5382 | return skb; | |
5383 | ||
5384 | nla_put_failure: | |
5385 | kfree_skb(skb); | |
5386 | return NULL; | |
5387 | } | |
5388 | ||
5389 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
5390 | int approxlen) | |
5391 | { | |
5392 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
5393 | ||
5394 | if (WARN_ON(!rdev->testmode_info)) | |
5395 | return NULL; | |
5396 | ||
5397 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
5398 | rdev->testmode_info->snd_pid, | |
5399 | rdev->testmode_info->snd_seq, | |
5400 | GFP_KERNEL); | |
5401 | } | |
5402 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
5403 | ||
5404 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
5405 | { | |
5406 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
5407 | void *hdr = ((void **)skb->cb)[1]; | |
5408 | struct nlattr *data = ((void **)skb->cb)[2]; | |
5409 | ||
5410 | if (WARN_ON(!rdev->testmode_info)) { | |
5411 | kfree_skb(skb); | |
5412 | return -EINVAL; | |
5413 | } | |
5414 | ||
5415 | nla_nest_end(skb, data); | |
5416 | genlmsg_end(skb, hdr); | |
5417 | return genlmsg_reply(skb, rdev->testmode_info); | |
5418 | } | |
5419 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
5420 | ||
5421 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
5422 | int approxlen, gfp_t gfp) | |
5423 | { | |
5424 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
5425 | ||
5426 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
5427 | } | |
5428 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
5429 | ||
5430 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
5431 | { | |
5432 | void *hdr = ((void **)skb->cb)[1]; | |
5433 | struct nlattr *data = ((void **)skb->cb)[2]; | |
5434 | ||
5435 | nla_nest_end(skb, data); | |
5436 | genlmsg_end(skb, hdr); | |
5437 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
5438 | } | |
5439 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
5440 | #endif | |
5441 | ||
b23aa676 SO |
5442 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
5443 | { | |
4c476991 JB |
5444 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5445 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
5446 | struct cfg80211_connect_params connect; |
5447 | struct wiphy *wiphy; | |
fffd0934 | 5448 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
5449 | int err; |
5450 | ||
5451 | memset(&connect, 0, sizeof(connect)); | |
5452 | ||
5453 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5454 | return -EINVAL; | |
5455 | ||
5456 | if (!info->attrs[NL80211_ATTR_SSID] || | |
5457 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
5458 | return -EINVAL; | |
5459 | ||
5460 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
5461 | connect.auth_type = | |
5462 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
5463 | if (!nl80211_valid_auth_type(connect.auth_type)) | |
5464 | return -EINVAL; | |
5465 | } else | |
5466 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
5467 | ||
5468 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
5469 | ||
c0692b8f | 5470 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 5471 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
5472 | if (err) |
5473 | return err; | |
b23aa676 | 5474 | |
074ac8df | 5475 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5476 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5477 | return -EOPNOTSUPP; | |
b23aa676 | 5478 | |
79c97e97 | 5479 | wiphy = &rdev->wiphy; |
b23aa676 | 5480 | |
4486ea98 BS |
5481 | connect.bg_scan_period = -1; |
5482 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
5483 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
5484 | connect.bg_scan_period = | |
5485 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
5486 | } | |
5487 | ||
b23aa676 SO |
5488 | if (info->attrs[NL80211_ATTR_MAC]) |
5489 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5490 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
5491 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
5492 | ||
5493 | if (info->attrs[NL80211_ATTR_IE]) { | |
5494 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
5495 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5496 | } | |
5497 | ||
5498 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
5499 | connect.channel = | |
5500 | ieee80211_get_channel(wiphy, | |
5501 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
5502 | if (!connect.channel || | |
4c476991 JB |
5503 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
5504 | return -EINVAL; | |
b23aa676 SO |
5505 | } |
5506 | ||
fffd0934 JB |
5507 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
5508 | connkeys = nl80211_parse_connkeys(rdev, | |
5509 | info->attrs[NL80211_ATTR_KEYS]); | |
4c476991 JB |
5510 | if (IS_ERR(connkeys)) |
5511 | return PTR_ERR(connkeys); | |
fffd0934 JB |
5512 | } |
5513 | ||
7e7c8926 BG |
5514 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
5515 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
5516 | ||
5517 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
5518 | memcpy(&connect.ht_capa_mask, | |
5519 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
5520 | sizeof(connect.ht_capa_mask)); | |
5521 | ||
5522 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
5523 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
5524 | return -EINVAL; | |
5525 | memcpy(&connect.ht_capa, | |
5526 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
5527 | sizeof(connect.ht_capa)); | |
5528 | } | |
5529 | ||
fffd0934 | 5530 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
5531 | if (err) |
5532 | kfree(connkeys); | |
b23aa676 SO |
5533 | return err; |
5534 | } | |
5535 | ||
5536 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
5537 | { | |
4c476991 JB |
5538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5539 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
5540 | u16 reason; |
5541 | ||
5542 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
5543 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
5544 | else | |
5545 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5546 | ||
5547 | if (reason == 0) | |
5548 | return -EINVAL; | |
5549 | ||
074ac8df | 5550 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5551 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5552 | return -EOPNOTSUPP; | |
b23aa676 | 5553 | |
4c476991 | 5554 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
5555 | } |
5556 | ||
463d0183 JB |
5557 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
5558 | { | |
4c476991 | 5559 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
5560 | struct net *net; |
5561 | int err; | |
5562 | u32 pid; | |
5563 | ||
5564 | if (!info->attrs[NL80211_ATTR_PID]) | |
5565 | return -EINVAL; | |
5566 | ||
5567 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
5568 | ||
463d0183 | 5569 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
5570 | if (IS_ERR(net)) |
5571 | return PTR_ERR(net); | |
463d0183 JB |
5572 | |
5573 | err = 0; | |
5574 | ||
5575 | /* check if anything to do */ | |
4c476991 JB |
5576 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
5577 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 5578 | |
463d0183 | 5579 | put_net(net); |
463d0183 JB |
5580 | return err; |
5581 | } | |
5582 | ||
67fbb16b SO |
5583 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
5584 | { | |
4c476991 | 5585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
5586 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
5587 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 5588 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
5589 | struct cfg80211_pmksa pmksa; |
5590 | ||
5591 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
5592 | ||
5593 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5594 | return -EINVAL; | |
5595 | ||
5596 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
5597 | return -EINVAL; | |
5598 | ||
67fbb16b SO |
5599 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
5600 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5601 | ||
074ac8df | 5602 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5603 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5604 | return -EOPNOTSUPP; | |
67fbb16b SO |
5605 | |
5606 | switch (info->genlhdr->cmd) { | |
5607 | case NL80211_CMD_SET_PMKSA: | |
5608 | rdev_ops = rdev->ops->set_pmksa; | |
5609 | break; | |
5610 | case NL80211_CMD_DEL_PMKSA: | |
5611 | rdev_ops = rdev->ops->del_pmksa; | |
5612 | break; | |
5613 | default: | |
5614 | WARN_ON(1); | |
5615 | break; | |
5616 | } | |
5617 | ||
4c476991 JB |
5618 | if (!rdev_ops) |
5619 | return -EOPNOTSUPP; | |
67fbb16b | 5620 | |
4c476991 | 5621 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
5622 | } |
5623 | ||
5624 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
5625 | { | |
4c476991 JB |
5626 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5627 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 5628 | |
074ac8df | 5629 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5630 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5631 | return -EOPNOTSUPP; | |
67fbb16b | 5632 | |
4c476991 JB |
5633 | if (!rdev->ops->flush_pmksa) |
5634 | return -EOPNOTSUPP; | |
67fbb16b | 5635 | |
4c476991 | 5636 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
67fbb16b SO |
5637 | } |
5638 | ||
109086ce AN |
5639 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
5640 | { | |
5641 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5642 | struct net_device *dev = info->user_ptr[1]; | |
5643 | u8 action_code, dialog_token; | |
5644 | u16 status_code; | |
5645 | u8 *peer; | |
5646 | ||
5647 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
5648 | !rdev->ops->tdls_mgmt) | |
5649 | return -EOPNOTSUPP; | |
5650 | ||
5651 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
5652 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
5653 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
5654 | !info->attrs[NL80211_ATTR_IE] || | |
5655 | !info->attrs[NL80211_ATTR_MAC]) | |
5656 | return -EINVAL; | |
5657 | ||
5658 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5659 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
5660 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
5661 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
5662 | ||
5663 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, | |
5664 | dialog_token, status_code, | |
5665 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5666 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
5667 | } | |
5668 | ||
5669 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
5670 | { | |
5671 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5672 | struct net_device *dev = info->user_ptr[1]; | |
5673 | enum nl80211_tdls_operation operation; | |
5674 | u8 *peer; | |
5675 | ||
5676 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
5677 | !rdev->ops->tdls_oper) | |
5678 | return -EOPNOTSUPP; | |
5679 | ||
5680 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
5681 | !info->attrs[NL80211_ATTR_MAC]) | |
5682 | return -EINVAL; | |
5683 | ||
5684 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
5685 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5686 | ||
5687 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); | |
5688 | } | |
5689 | ||
9588bbd5 JM |
5690 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
5691 | struct genl_info *info) | |
5692 | { | |
4c476991 JB |
5693 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5694 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 JM |
5695 | struct ieee80211_channel *chan; |
5696 | struct sk_buff *msg; | |
5697 | void *hdr; | |
5698 | u64 cookie; | |
5699 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
5700 | u32 freq, duration; | |
5701 | int err; | |
5702 | ||
5703 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5704 | !info->attrs[NL80211_ATTR_DURATION]) | |
5705 | return -EINVAL; | |
5706 | ||
5707 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
5708 | ||
ebf348fc JB |
5709 | if (!rdev->ops->remain_on_channel || |
5710 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
5711 | return -EOPNOTSUPP; | |
5712 | ||
9588bbd5 | 5713 | /* |
ebf348fc JB |
5714 | * We should be on that channel for at least a minimum amount of |
5715 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 5716 | */ |
ebf348fc | 5717 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 5718 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
5719 | return -EINVAL; |
5720 | ||
cd6c6598 JB |
5721 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
5722 | !nl80211_valid_channel_type(info, &channel_type)) | |
5723 | return -EINVAL; | |
9588bbd5 JM |
5724 | |
5725 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
5726 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
5727 | if (chan == NULL) |
5728 | return -EINVAL; | |
9588bbd5 JM |
5729 | |
5730 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5731 | if (!msg) |
5732 | return -ENOMEM; | |
9588bbd5 JM |
5733 | |
5734 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5735 | NL80211_CMD_REMAIN_ON_CHANNEL); | |
5736 | ||
5737 | if (IS_ERR(hdr)) { | |
5738 | err = PTR_ERR(hdr); | |
5739 | goto free_msg; | |
5740 | } | |
5741 | ||
5742 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, | |
5743 | channel_type, duration, &cookie); | |
5744 | ||
5745 | if (err) | |
5746 | goto free_msg; | |
5747 | ||
9360ffd1 DM |
5748 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
5749 | goto nla_put_failure; | |
9588bbd5 JM |
5750 | |
5751 | genlmsg_end(msg, hdr); | |
4c476991 JB |
5752 | |
5753 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
5754 | |
5755 | nla_put_failure: | |
5756 | err = -ENOBUFS; | |
5757 | free_msg: | |
5758 | nlmsg_free(msg); | |
9588bbd5 JM |
5759 | return err; |
5760 | } | |
5761 | ||
5762 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
5763 | struct genl_info *info) | |
5764 | { | |
4c476991 JB |
5765 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5766 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 | 5767 | u64 cookie; |
9588bbd5 JM |
5768 | |
5769 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
5770 | return -EINVAL; | |
5771 | ||
4c476991 JB |
5772 | if (!rdev->ops->cancel_remain_on_channel) |
5773 | return -EOPNOTSUPP; | |
9588bbd5 | 5774 | |
9588bbd5 JM |
5775 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
5776 | ||
4c476991 | 5777 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
9588bbd5 JM |
5778 | } |
5779 | ||
13ae75b1 JM |
5780 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
5781 | u8 *rates, u8 rates_len) | |
5782 | { | |
5783 | u8 i; | |
5784 | u32 mask = 0; | |
5785 | ||
5786 | for (i = 0; i < rates_len; i++) { | |
5787 | int rate = (rates[i] & 0x7f) * 5; | |
5788 | int ridx; | |
5789 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
5790 | struct ieee80211_rate *srate = | |
5791 | &sband->bitrates[ridx]; | |
5792 | if (rate == srate->bitrate) { | |
5793 | mask |= 1 << ridx; | |
5794 | break; | |
5795 | } | |
5796 | } | |
5797 | if (ridx == sband->n_bitrates) | |
5798 | return 0; /* rate not found */ | |
5799 | } | |
5800 | ||
5801 | return mask; | |
5802 | } | |
5803 | ||
24db78c0 SW |
5804 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
5805 | u8 *rates, u8 rates_len, | |
5806 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
5807 | { | |
5808 | u8 i; | |
5809 | ||
5810 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
5811 | ||
5812 | for (i = 0; i < rates_len; i++) { | |
5813 | int ridx, rbit; | |
5814 | ||
5815 | ridx = rates[i] / 8; | |
5816 | rbit = BIT(rates[i] % 8); | |
5817 | ||
5818 | /* check validity */ | |
910570b5 | 5819 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
5820 | return false; |
5821 | ||
5822 | /* check availability */ | |
5823 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
5824 | mcs[ridx] |= rbit; | |
5825 | else | |
5826 | return false; | |
5827 | } | |
5828 | ||
5829 | return true; | |
5830 | } | |
5831 | ||
b54452b0 | 5832 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
5833 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
5834 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
5835 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
5836 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
5837 | }; |
5838 | ||
5839 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
5840 | struct genl_info *info) | |
5841 | { | |
5842 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 5843 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 5844 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
5845 | int rem, i; |
5846 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
5847 | struct nlattr *tx_rates; |
5848 | struct ieee80211_supported_band *sband; | |
5849 | ||
5850 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
5851 | return -EINVAL; | |
5852 | ||
4c476991 JB |
5853 | if (!rdev->ops->set_bitrate_mask) |
5854 | return -EOPNOTSUPP; | |
13ae75b1 JM |
5855 | |
5856 | memset(&mask, 0, sizeof(mask)); | |
5857 | /* Default to all rates enabled */ | |
5858 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
5859 | sband = rdev->wiphy.bands[i]; | |
5860 | mask.control[i].legacy = | |
5861 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
5862 | if (sband) |
5863 | memcpy(mask.control[i].mcs, | |
5864 | sband->ht_cap.mcs.rx_mask, | |
5865 | sizeof(mask.control[i].mcs)); | |
5866 | else | |
5867 | memset(mask.control[i].mcs, 0, | |
5868 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
5869 | } |
5870 | ||
5871 | /* | |
5872 | * The nested attribute uses enum nl80211_band as the index. This maps | |
5873 | * directly to the enum ieee80211_band values used in cfg80211. | |
5874 | */ | |
24db78c0 | 5875 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
5876 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
5877 | { | |
5878 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
5879 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
5880 | return -EINVAL; | |
13ae75b1 | 5881 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
5882 | if (sband == NULL) |
5883 | return -EINVAL; | |
13ae75b1 JM |
5884 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
5885 | nla_len(tx_rates), nl80211_txattr_policy); | |
5886 | if (tb[NL80211_TXRATE_LEGACY]) { | |
5887 | mask.control[band].legacy = rateset_to_mask( | |
5888 | sband, | |
5889 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
5890 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
5891 | if ((mask.control[band].legacy == 0) && |
5892 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
5893 | return -EINVAL; | |
24db78c0 SW |
5894 | } |
5895 | if (tb[NL80211_TXRATE_MCS]) { | |
5896 | if (!ht_rateset_to_mask( | |
5897 | sband, | |
5898 | nla_data(tb[NL80211_TXRATE_MCS]), | |
5899 | nla_len(tb[NL80211_TXRATE_MCS]), | |
5900 | mask.control[band].mcs)) | |
5901 | return -EINVAL; | |
5902 | } | |
5903 | ||
5904 | if (mask.control[band].legacy == 0) { | |
5905 | /* don't allow empty legacy rates if HT | |
5906 | * is not even supported. */ | |
5907 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
5908 | return -EINVAL; | |
5909 | ||
5910 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
5911 | if (mask.control[band].mcs[i]) | |
5912 | break; | |
5913 | ||
5914 | /* legacy and mcs rates may not be both empty */ | |
5915 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 5916 | return -EINVAL; |
13ae75b1 JM |
5917 | } |
5918 | } | |
5919 | ||
4c476991 | 5920 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
13ae75b1 JM |
5921 | } |
5922 | ||
2e161f78 | 5923 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 5924 | { |
4c476991 JB |
5925 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5926 | struct net_device *dev = info->user_ptr[1]; | |
2e161f78 | 5927 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
5928 | |
5929 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
5930 | return -EINVAL; | |
5931 | ||
2e161f78 JB |
5932 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
5933 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 5934 | |
9d38d85d | 5935 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 5936 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
5937 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
5938 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5939 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 5940 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5941 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5942 | return -EOPNOTSUPP; | |
026331c4 JM |
5943 | |
5944 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
5945 | if (!rdev->ops->mgmt_tx) |
5946 | return -EOPNOTSUPP; | |
026331c4 | 5947 | |
4c476991 | 5948 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
2e161f78 | 5949 | frame_type, |
026331c4 JM |
5950 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
5951 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
5952 | } |
5953 | ||
2e161f78 | 5954 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 5955 | { |
4c476991 JB |
5956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5957 | struct net_device *dev = info->user_ptr[1]; | |
026331c4 JM |
5958 | struct ieee80211_channel *chan; |
5959 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
252aa631 | 5960 | bool channel_type_valid = false; |
026331c4 JM |
5961 | u32 freq; |
5962 | int err; | |
d64d373f | 5963 | void *hdr = NULL; |
026331c4 | 5964 | u64 cookie; |
e247bd90 | 5965 | struct sk_buff *msg = NULL; |
f7ca38df | 5966 | unsigned int wait = 0; |
e247bd90 JB |
5967 | bool offchan, no_cck, dont_wait_for_ack; |
5968 | ||
5969 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 JM |
5970 | |
5971 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
5972 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5973 | return -EINVAL; | |
5974 | ||
4c476991 JB |
5975 | if (!rdev->ops->mgmt_tx) |
5976 | return -EOPNOTSUPP; | |
026331c4 | 5977 | |
9d38d85d | 5978 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 5979 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
5980 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
5981 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5982 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 5983 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5984 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5985 | return -EOPNOTSUPP; | |
026331c4 | 5986 | |
f7ca38df | 5987 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 5988 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
5989 | return -EINVAL; |
5990 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
ebf348fc JB |
5991 | |
5992 | /* | |
5993 | * We should wait on the channel for at least a minimum amount | |
5994 | * of time (10ms) but no longer than the driver supports. | |
5995 | */ | |
5996 | if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || | |
5997 | wait > rdev->wiphy.max_remain_on_channel_duration) | |
5998 | return -EINVAL; | |
5999 | ||
f7ca38df JB |
6000 | } |
6001 | ||
026331c4 | 6002 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
cd6c6598 | 6003 | if (!nl80211_valid_channel_type(info, &channel_type)) |
4c476991 | 6004 | return -EINVAL; |
252aa631 | 6005 | channel_type_valid = true; |
026331c4 JM |
6006 | } |
6007 | ||
f7ca38df JB |
6008 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
6009 | ||
7c4ef712 JB |
6010 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
6011 | return -EINVAL; | |
6012 | ||
e9f935e3 RM |
6013 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
6014 | ||
026331c4 JM |
6015 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
6016 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
6017 | if (chan == NULL) |
6018 | return -EINVAL; | |
026331c4 | 6019 | |
e247bd90 JB |
6020 | if (!dont_wait_for_ack) { |
6021 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6022 | if (!msg) | |
6023 | return -ENOMEM; | |
026331c4 | 6024 | |
e247bd90 JB |
6025 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
6026 | NL80211_CMD_FRAME); | |
026331c4 | 6027 | |
e247bd90 JB |
6028 | if (IS_ERR(hdr)) { |
6029 | err = PTR_ERR(hdr); | |
6030 | goto free_msg; | |
6031 | } | |
026331c4 | 6032 | } |
e247bd90 | 6033 | |
f7ca38df JB |
6034 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
6035 | channel_type_valid, wait, | |
2e161f78 JB |
6036 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
6037 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 6038 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
6039 | if (err) |
6040 | goto free_msg; | |
6041 | ||
e247bd90 | 6042 | if (msg) { |
9360ffd1 DM |
6043 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6044 | goto nla_put_failure; | |
026331c4 | 6045 | |
e247bd90 JB |
6046 | genlmsg_end(msg, hdr); |
6047 | return genlmsg_reply(msg, info); | |
6048 | } | |
6049 | ||
6050 | return 0; | |
026331c4 JM |
6051 | |
6052 | nla_put_failure: | |
6053 | err = -ENOBUFS; | |
6054 | free_msg: | |
6055 | nlmsg_free(msg); | |
026331c4 JM |
6056 | return err; |
6057 | } | |
6058 | ||
f7ca38df JB |
6059 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
6060 | { | |
6061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6062 | struct net_device *dev = info->user_ptr[1]; | |
6063 | u64 cookie; | |
6064 | ||
6065 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
6066 | return -EINVAL; | |
6067 | ||
6068 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
6069 | return -EOPNOTSUPP; | |
6070 | ||
6071 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | |
6072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
6073 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && | |
6074 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
6075 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
6076 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
6077 | return -EOPNOTSUPP; | |
6078 | ||
6079 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
6080 | ||
6081 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); | |
6082 | } | |
6083 | ||
ffb9eb3d KV |
6084 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
6085 | { | |
4c476991 | 6086 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 6087 | struct wireless_dev *wdev; |
4c476991 | 6088 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
6089 | u8 ps_state; |
6090 | bool state; | |
6091 | int err; | |
6092 | ||
4c476991 JB |
6093 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
6094 | return -EINVAL; | |
ffb9eb3d KV |
6095 | |
6096 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
6097 | ||
4c476991 JB |
6098 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
6099 | return -EINVAL; | |
ffb9eb3d KV |
6100 | |
6101 | wdev = dev->ieee80211_ptr; | |
6102 | ||
4c476991 JB |
6103 | if (!rdev->ops->set_power_mgmt) |
6104 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
6105 | |
6106 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
6107 | ||
6108 | if (state == wdev->ps) | |
4c476991 | 6109 | return 0; |
ffb9eb3d | 6110 | |
4c476991 JB |
6111 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
6112 | wdev->ps_timeout); | |
6113 | if (!err) | |
6114 | wdev->ps = state; | |
ffb9eb3d KV |
6115 | return err; |
6116 | } | |
6117 | ||
6118 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
6119 | { | |
4c476991 | 6120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
6121 | enum nl80211_ps_state ps_state; |
6122 | struct wireless_dev *wdev; | |
4c476991 | 6123 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
6124 | struct sk_buff *msg; |
6125 | void *hdr; | |
6126 | int err; | |
6127 | ||
ffb9eb3d KV |
6128 | wdev = dev->ieee80211_ptr; |
6129 | ||
4c476991 JB |
6130 | if (!rdev->ops->set_power_mgmt) |
6131 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
6132 | |
6133 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
6134 | if (!msg) |
6135 | return -ENOMEM; | |
ffb9eb3d KV |
6136 | |
6137 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
6138 | NL80211_CMD_GET_POWER_SAVE); | |
6139 | if (!hdr) { | |
4c476991 | 6140 | err = -ENOBUFS; |
ffb9eb3d KV |
6141 | goto free_msg; |
6142 | } | |
6143 | ||
6144 | if (wdev->ps) | |
6145 | ps_state = NL80211_PS_ENABLED; | |
6146 | else | |
6147 | ps_state = NL80211_PS_DISABLED; | |
6148 | ||
9360ffd1 DM |
6149 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
6150 | goto nla_put_failure; | |
ffb9eb3d KV |
6151 | |
6152 | genlmsg_end(msg, hdr); | |
4c476991 | 6153 | return genlmsg_reply(msg, info); |
ffb9eb3d | 6154 | |
4c476991 | 6155 | nla_put_failure: |
ffb9eb3d | 6156 | err = -ENOBUFS; |
4c476991 | 6157 | free_msg: |
ffb9eb3d | 6158 | nlmsg_free(msg); |
ffb9eb3d KV |
6159 | return err; |
6160 | } | |
6161 | ||
d6dc1a38 JO |
6162 | static struct nla_policy |
6163 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
6164 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
6165 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
6166 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
6167 | }; | |
6168 | ||
6169 | static int nl80211_set_cqm_rssi(struct genl_info *info, | |
6170 | s32 threshold, u32 hysteresis) | |
6171 | { | |
4c476991 | 6172 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 6173 | struct wireless_dev *wdev; |
4c476991 | 6174 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
6175 | |
6176 | if (threshold > 0) | |
6177 | return -EINVAL; | |
6178 | ||
d6dc1a38 JO |
6179 | wdev = dev->ieee80211_ptr; |
6180 | ||
4c476991 JB |
6181 | if (!rdev->ops->set_cqm_rssi_config) |
6182 | return -EOPNOTSUPP; | |
d6dc1a38 | 6183 | |
074ac8df | 6184 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6185 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6186 | return -EOPNOTSUPP; | |
d6dc1a38 | 6187 | |
4c476991 JB |
6188 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
6189 | threshold, hysteresis); | |
d6dc1a38 JO |
6190 | } |
6191 | ||
6192 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
6193 | { | |
6194 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
6195 | struct nlattr *cqm; | |
6196 | int err; | |
6197 | ||
6198 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
6199 | if (!cqm) { | |
6200 | err = -EINVAL; | |
6201 | goto out; | |
6202 | } | |
6203 | ||
6204 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
6205 | nl80211_attr_cqm_policy); | |
6206 | if (err) | |
6207 | goto out; | |
6208 | ||
6209 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
6210 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
6211 | s32 threshold; | |
6212 | u32 hysteresis; | |
6213 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
6214 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
6215 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
6216 | } else | |
6217 | err = -EINVAL; | |
6218 | ||
6219 | out: | |
6220 | return err; | |
6221 | } | |
6222 | ||
29cbe68c JB |
6223 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
6224 | { | |
6225 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6226 | struct net_device *dev = info->user_ptr[1]; | |
6227 | struct mesh_config cfg; | |
c80d545d | 6228 | struct mesh_setup setup; |
29cbe68c JB |
6229 | int err; |
6230 | ||
6231 | /* start with default */ | |
6232 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 6233 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 6234 | |
24bdd9f4 | 6235 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 6236 | /* and parse parameters if given */ |
24bdd9f4 | 6237 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
6238 | if (err) |
6239 | return err; | |
6240 | } | |
6241 | ||
6242 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
6243 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
6244 | return -EINVAL; | |
6245 | ||
c80d545d JC |
6246 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
6247 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
6248 | ||
4bb62344 CYY |
6249 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6250 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
6251 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6252 | return -EINVAL; | |
6253 | ||
c80d545d JC |
6254 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
6255 | /* parse additional setup parameters if given */ | |
6256 | err = nl80211_parse_mesh_setup(info, &setup); | |
6257 | if (err) | |
6258 | return err; | |
6259 | } | |
6260 | ||
cc1d2806 JB |
6261 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
6262 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
6263 | ||
6264 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && | |
6265 | !nl80211_valid_channel_type(info, &channel_type)) | |
6266 | return -EINVAL; | |
6267 | ||
6268 | setup.channel = rdev_freq_to_chan(rdev, | |
6269 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), | |
6270 | channel_type); | |
6271 | if (!setup.channel) | |
6272 | return -EINVAL; | |
6273 | setup.channel_type = channel_type; | |
6274 | } else { | |
6275 | /* cfg80211_join_mesh() will sort it out */ | |
6276 | setup.channel = NULL; | |
6277 | } | |
6278 | ||
c80d545d | 6279 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
6280 | } |
6281 | ||
6282 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
6283 | { | |
6284 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6285 | struct net_device *dev = info->user_ptr[1]; | |
6286 | ||
6287 | return cfg80211_leave_mesh(rdev, dev); | |
6288 | } | |
6289 | ||
dfb89c56 | 6290 | #ifdef CONFIG_PM |
ff1b6e69 JB |
6291 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
6292 | { | |
6293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6294 | struct sk_buff *msg; | |
6295 | void *hdr; | |
6296 | ||
6297 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
6298 | return -EOPNOTSUPP; | |
6299 | ||
6300 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6301 | if (!msg) | |
6302 | return -ENOMEM; | |
6303 | ||
6304 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
6305 | NL80211_CMD_GET_WOWLAN); | |
6306 | if (!hdr) | |
6307 | goto nla_put_failure; | |
6308 | ||
6309 | if (rdev->wowlan) { | |
6310 | struct nlattr *nl_wowlan; | |
6311 | ||
6312 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
6313 | if (!nl_wowlan) | |
6314 | goto nla_put_failure; | |
6315 | ||
9360ffd1 DM |
6316 | if ((rdev->wowlan->any && |
6317 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
6318 | (rdev->wowlan->disconnect && | |
6319 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
6320 | (rdev->wowlan->magic_pkt && | |
6321 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
6322 | (rdev->wowlan->gtk_rekey_failure && | |
6323 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
6324 | (rdev->wowlan->eap_identity_req && | |
6325 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
6326 | (rdev->wowlan->four_way_handshake && | |
6327 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
6328 | (rdev->wowlan->rfkill_release && | |
6329 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
6330 | goto nla_put_failure; | |
ff1b6e69 JB |
6331 | if (rdev->wowlan->n_patterns) { |
6332 | struct nlattr *nl_pats, *nl_pat; | |
6333 | int i, pat_len; | |
6334 | ||
6335 | nl_pats = nla_nest_start(msg, | |
6336 | NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
6337 | if (!nl_pats) | |
6338 | goto nla_put_failure; | |
6339 | ||
6340 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
6341 | nl_pat = nla_nest_start(msg, i + 1); | |
6342 | if (!nl_pat) | |
6343 | goto nla_put_failure; | |
6344 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
9360ffd1 DM |
6345 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
6346 | DIV_ROUND_UP(pat_len, 8), | |
6347 | rdev->wowlan->patterns[i].mask) || | |
6348 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
6349 | pat_len, | |
6350 | rdev->wowlan->patterns[i].pattern)) | |
6351 | goto nla_put_failure; | |
ff1b6e69 JB |
6352 | nla_nest_end(msg, nl_pat); |
6353 | } | |
6354 | nla_nest_end(msg, nl_pats); | |
6355 | } | |
6356 | ||
6357 | nla_nest_end(msg, nl_wowlan); | |
6358 | } | |
6359 | ||
6360 | genlmsg_end(msg, hdr); | |
6361 | return genlmsg_reply(msg, info); | |
6362 | ||
6363 | nla_put_failure: | |
6364 | nlmsg_free(msg); | |
6365 | return -ENOBUFS; | |
6366 | } | |
6367 | ||
6368 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | |
6369 | { | |
6370 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6371 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
6372 | struct cfg80211_wowlan no_triggers = {}; | |
6373 | struct cfg80211_wowlan new_triggers = {}; | |
6374 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; | |
6375 | int err, i; | |
6d52563f | 6376 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 JB |
6377 | |
6378 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
6379 | return -EOPNOTSUPP; | |
6380 | ||
6381 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) | |
6382 | goto no_triggers; | |
6383 | ||
6384 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
6385 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
6386 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
6387 | nl80211_wowlan_policy); | |
6388 | if (err) | |
6389 | return err; | |
6390 | ||
6391 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
6392 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
6393 | return -EINVAL; | |
6394 | new_triggers.any = true; | |
6395 | } | |
6396 | ||
6397 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
6398 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
6399 | return -EINVAL; | |
6400 | new_triggers.disconnect = true; | |
6401 | } | |
6402 | ||
6403 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
6404 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
6405 | return -EINVAL; | |
6406 | new_triggers.magic_pkt = true; | |
6407 | } | |
6408 | ||
77dbbb13 JB |
6409 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
6410 | return -EINVAL; | |
6411 | ||
6412 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
6413 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
6414 | return -EINVAL; | |
6415 | new_triggers.gtk_rekey_failure = true; | |
6416 | } | |
6417 | ||
6418 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
6419 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
6420 | return -EINVAL; | |
6421 | new_triggers.eap_identity_req = true; | |
6422 | } | |
6423 | ||
6424 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
6425 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
6426 | return -EINVAL; | |
6427 | new_triggers.four_way_handshake = true; | |
6428 | } | |
6429 | ||
6430 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
6431 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
6432 | return -EINVAL; | |
6433 | new_triggers.rfkill_release = true; | |
6434 | } | |
6435 | ||
ff1b6e69 JB |
6436 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
6437 | struct nlattr *pat; | |
6438 | int n_patterns = 0; | |
6439 | int rem, pat_len, mask_len; | |
6440 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; | |
6441 | ||
6442 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
6443 | rem) | |
6444 | n_patterns++; | |
6445 | if (n_patterns > wowlan->n_patterns) | |
6446 | return -EINVAL; | |
6447 | ||
6448 | new_triggers.patterns = kcalloc(n_patterns, | |
6449 | sizeof(new_triggers.patterns[0]), | |
6450 | GFP_KERNEL); | |
6451 | if (!new_triggers.patterns) | |
6452 | return -ENOMEM; | |
6453 | ||
6454 | new_triggers.n_patterns = n_patterns; | |
6455 | i = 0; | |
6456 | ||
6457 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
6458 | rem) { | |
6459 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
6460 | nla_data(pat), nla_len(pat), NULL); | |
6461 | err = -EINVAL; | |
6462 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
6463 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
6464 | goto error; | |
6465 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
6466 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
6467 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
6468 | mask_len) | |
6469 | goto error; | |
6470 | if (pat_len > wowlan->pattern_max_len || | |
6471 | pat_len < wowlan->pattern_min_len) | |
6472 | goto error; | |
6473 | ||
6474 | new_triggers.patterns[i].mask = | |
6475 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
6476 | if (!new_triggers.patterns[i].mask) { | |
6477 | err = -ENOMEM; | |
6478 | goto error; | |
6479 | } | |
6480 | new_triggers.patterns[i].pattern = | |
6481 | new_triggers.patterns[i].mask + mask_len; | |
6482 | memcpy(new_triggers.patterns[i].mask, | |
6483 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
6484 | mask_len); | |
6485 | new_triggers.patterns[i].pattern_len = pat_len; | |
6486 | memcpy(new_triggers.patterns[i].pattern, | |
6487 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
6488 | pat_len); | |
6489 | i++; | |
6490 | } | |
6491 | } | |
6492 | ||
6493 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { | |
6494 | struct cfg80211_wowlan *ntrig; | |
6495 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), | |
6496 | GFP_KERNEL); | |
6497 | if (!ntrig) { | |
6498 | err = -ENOMEM; | |
6499 | goto error; | |
6500 | } | |
6501 | cfg80211_rdev_free_wowlan(rdev); | |
6502 | rdev->wowlan = ntrig; | |
6503 | } else { | |
6504 | no_triggers: | |
6505 | cfg80211_rdev_free_wowlan(rdev); | |
6506 | rdev->wowlan = NULL; | |
6507 | } | |
6508 | ||
6d52563f JB |
6509 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
6510 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); | |
6511 | ||
ff1b6e69 JB |
6512 | return 0; |
6513 | error: | |
6514 | for (i = 0; i < new_triggers.n_patterns; i++) | |
6515 | kfree(new_triggers.patterns[i].mask); | |
6516 | kfree(new_triggers.patterns); | |
6517 | return err; | |
6518 | } | |
dfb89c56 | 6519 | #endif |
ff1b6e69 | 6520 | |
e5497d76 JB |
6521 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
6522 | { | |
6523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6524 | struct net_device *dev = info->user_ptr[1]; | |
6525 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6526 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
6527 | struct cfg80211_gtk_rekey_data rekey_data; | |
6528 | int err; | |
6529 | ||
6530 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
6531 | return -EINVAL; | |
6532 | ||
6533 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
6534 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
6535 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
6536 | nl80211_rekey_policy); | |
6537 | if (err) | |
6538 | return err; | |
6539 | ||
6540 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
6541 | return -ERANGE; | |
6542 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
6543 | return -ERANGE; | |
6544 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
6545 | return -ERANGE; | |
6546 | ||
6547 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
6548 | NL80211_KEK_LEN); | |
6549 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
6550 | NL80211_KCK_LEN); | |
6551 | memcpy(rekey_data.replay_ctr, | |
6552 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
6553 | NL80211_REPLAY_CTR_LEN); | |
6554 | ||
6555 | wdev_lock(wdev); | |
6556 | if (!wdev->current_bss) { | |
6557 | err = -ENOTCONN; | |
6558 | goto out; | |
6559 | } | |
6560 | ||
6561 | if (!rdev->ops->set_rekey_data) { | |
6562 | err = -EOPNOTSUPP; | |
6563 | goto out; | |
6564 | } | |
6565 | ||
6566 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); | |
6567 | out: | |
6568 | wdev_unlock(wdev); | |
6569 | return err; | |
6570 | } | |
6571 | ||
28946da7 JB |
6572 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
6573 | struct genl_info *info) | |
6574 | { | |
6575 | struct net_device *dev = info->user_ptr[1]; | |
6576 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6577 | ||
6578 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
6579 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
6580 | return -EINVAL; | |
6581 | ||
6582 | if (wdev->ap_unexpected_nlpid) | |
6583 | return -EBUSY; | |
6584 | ||
6585 | wdev->ap_unexpected_nlpid = info->snd_pid; | |
6586 | return 0; | |
6587 | } | |
6588 | ||
7f6cf311 JB |
6589 | static int nl80211_probe_client(struct sk_buff *skb, |
6590 | struct genl_info *info) | |
6591 | { | |
6592 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6593 | struct net_device *dev = info->user_ptr[1]; | |
6594 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6595 | struct sk_buff *msg; | |
6596 | void *hdr; | |
6597 | const u8 *addr; | |
6598 | u64 cookie; | |
6599 | int err; | |
6600 | ||
6601 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
6602 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
6603 | return -EOPNOTSUPP; | |
6604 | ||
6605 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6606 | return -EINVAL; | |
6607 | ||
6608 | if (!rdev->ops->probe_client) | |
6609 | return -EOPNOTSUPP; | |
6610 | ||
6611 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6612 | if (!msg) | |
6613 | return -ENOMEM; | |
6614 | ||
6615 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
6616 | NL80211_CMD_PROBE_CLIENT); | |
6617 | ||
6618 | if (IS_ERR(hdr)) { | |
6619 | err = PTR_ERR(hdr); | |
6620 | goto free_msg; | |
6621 | } | |
6622 | ||
6623 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6624 | ||
6625 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); | |
6626 | if (err) | |
6627 | goto free_msg; | |
6628 | ||
9360ffd1 DM |
6629 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6630 | goto nla_put_failure; | |
7f6cf311 JB |
6631 | |
6632 | genlmsg_end(msg, hdr); | |
6633 | ||
6634 | return genlmsg_reply(msg, info); | |
6635 | ||
6636 | nla_put_failure: | |
6637 | err = -ENOBUFS; | |
6638 | free_msg: | |
6639 | nlmsg_free(msg); | |
6640 | return err; | |
6641 | } | |
6642 | ||
5e760230 JB |
6643 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
6644 | { | |
6645 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6646 | ||
6647 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
6648 | return -EOPNOTSUPP; | |
6649 | ||
6650 | if (rdev->ap_beacons_nlpid) | |
6651 | return -EBUSY; | |
6652 | ||
6653 | rdev->ap_beacons_nlpid = info->snd_pid; | |
6654 | ||
6655 | return 0; | |
6656 | } | |
6657 | ||
4c476991 JB |
6658 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
6659 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
6660 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
6661 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
6662 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
6663 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
6664 | |
6665 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
6666 | struct genl_info *info) | |
6667 | { | |
6668 | struct cfg80211_registered_device *rdev; | |
6669 | struct net_device *dev; | |
6670 | int err; | |
6671 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | |
6672 | ||
6673 | if (rtnl) | |
6674 | rtnl_lock(); | |
6675 | ||
6676 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 6677 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
6678 | if (IS_ERR(rdev)) { |
6679 | if (rtnl) | |
6680 | rtnl_unlock(); | |
6681 | return PTR_ERR(rdev); | |
6682 | } | |
6683 | info->user_ptr[0] = rdev; | |
6684 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | |
00918d33 JB |
6685 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
6686 | &rdev, &dev); | |
4c476991 JB |
6687 | if (err) { |
6688 | if (rtnl) | |
6689 | rtnl_unlock(); | |
6690 | return err; | |
6691 | } | |
41265714 JB |
6692 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
6693 | !netif_running(dev)) { | |
d537f5fd JB |
6694 | cfg80211_unlock_rdev(rdev); |
6695 | dev_put(dev); | |
41265714 JB |
6696 | if (rtnl) |
6697 | rtnl_unlock(); | |
6698 | return -ENETDOWN; | |
6699 | } | |
4c476991 JB |
6700 | info->user_ptr[0] = rdev; |
6701 | info->user_ptr[1] = dev; | |
6702 | } | |
6703 | ||
6704 | return 0; | |
6705 | } | |
6706 | ||
6707 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
6708 | struct genl_info *info) | |
6709 | { | |
6710 | if (info->user_ptr[0]) | |
6711 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
6712 | if (info->user_ptr[1]) | |
6713 | dev_put(info->user_ptr[1]); | |
6714 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | |
6715 | rtnl_unlock(); | |
6716 | } | |
6717 | ||
55682965 JB |
6718 | static struct genl_ops nl80211_ops[] = { |
6719 | { | |
6720 | .cmd = NL80211_CMD_GET_WIPHY, | |
6721 | .doit = nl80211_get_wiphy, | |
6722 | .dumpit = nl80211_dump_wiphy, | |
6723 | .policy = nl80211_policy, | |
6724 | /* can be retrieved by unprivileged users */ | |
4c476991 | 6725 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
6726 | }, |
6727 | { | |
6728 | .cmd = NL80211_CMD_SET_WIPHY, | |
6729 | .doit = nl80211_set_wiphy, | |
6730 | .policy = nl80211_policy, | |
6731 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 6732 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
6733 | }, |
6734 | { | |
6735 | .cmd = NL80211_CMD_GET_INTERFACE, | |
6736 | .doit = nl80211_get_interface, | |
6737 | .dumpit = nl80211_dump_interface, | |
6738 | .policy = nl80211_policy, | |
6739 | /* can be retrieved by unprivileged users */ | |
4c476991 | 6740 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
55682965 JB |
6741 | }, |
6742 | { | |
6743 | .cmd = NL80211_CMD_SET_INTERFACE, | |
6744 | .doit = nl80211_set_interface, | |
6745 | .policy = nl80211_policy, | |
6746 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6747 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6748 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
6749 | }, |
6750 | { | |
6751 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
6752 | .doit = nl80211_new_interface, | |
6753 | .policy = nl80211_policy, | |
6754 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6755 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6756 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
6757 | }, |
6758 | { | |
6759 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
6760 | .doit = nl80211_del_interface, | |
6761 | .policy = nl80211_policy, | |
41ade00f | 6762 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
6763 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6764 | NL80211_FLAG_NEED_RTNL, | |
41ade00f JB |
6765 | }, |
6766 | { | |
6767 | .cmd = NL80211_CMD_GET_KEY, | |
6768 | .doit = nl80211_get_key, | |
6769 | .policy = nl80211_policy, | |
6770 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6771 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6772 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6773 | }, |
6774 | { | |
6775 | .cmd = NL80211_CMD_SET_KEY, | |
6776 | .doit = nl80211_set_key, | |
6777 | .policy = nl80211_policy, | |
6778 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6779 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6780 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6781 | }, |
6782 | { | |
6783 | .cmd = NL80211_CMD_NEW_KEY, | |
6784 | .doit = nl80211_new_key, | |
6785 | .policy = nl80211_policy, | |
6786 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6787 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6788 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6789 | }, |
6790 | { | |
6791 | .cmd = NL80211_CMD_DEL_KEY, | |
6792 | .doit = nl80211_del_key, | |
6793 | .policy = nl80211_policy, | |
55682965 | 6794 | .flags = GENL_ADMIN_PERM, |
41265714 | 6795 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6796 | NL80211_FLAG_NEED_RTNL, |
55682965 | 6797 | }, |
ed1b6cc7 JB |
6798 | { |
6799 | .cmd = NL80211_CMD_SET_BEACON, | |
6800 | .policy = nl80211_policy, | |
6801 | .flags = GENL_ADMIN_PERM, | |
8860020e | 6802 | .doit = nl80211_set_beacon, |
2b5f8b0b | 6803 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6804 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
6805 | }, |
6806 | { | |
8860020e | 6807 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
6808 | .policy = nl80211_policy, |
6809 | .flags = GENL_ADMIN_PERM, | |
8860020e | 6810 | .doit = nl80211_start_ap, |
2b5f8b0b | 6811 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6812 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
6813 | }, |
6814 | { | |
8860020e | 6815 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
6816 | .policy = nl80211_policy, |
6817 | .flags = GENL_ADMIN_PERM, | |
8860020e | 6818 | .doit = nl80211_stop_ap, |
2b5f8b0b | 6819 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6820 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 6821 | }, |
5727ef1b JB |
6822 | { |
6823 | .cmd = NL80211_CMD_GET_STATION, | |
6824 | .doit = nl80211_get_station, | |
2ec600d6 | 6825 | .dumpit = nl80211_dump_station, |
5727ef1b | 6826 | .policy = nl80211_policy, |
4c476991 JB |
6827 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6828 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
6829 | }, |
6830 | { | |
6831 | .cmd = NL80211_CMD_SET_STATION, | |
6832 | .doit = nl80211_set_station, | |
6833 | .policy = nl80211_policy, | |
6834 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6835 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6836 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
6837 | }, |
6838 | { | |
6839 | .cmd = NL80211_CMD_NEW_STATION, | |
6840 | .doit = nl80211_new_station, | |
6841 | .policy = nl80211_policy, | |
6842 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6843 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6844 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
6845 | }, |
6846 | { | |
6847 | .cmd = NL80211_CMD_DEL_STATION, | |
6848 | .doit = nl80211_del_station, | |
6849 | .policy = nl80211_policy, | |
2ec600d6 | 6850 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 6851 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6852 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6853 | }, |
6854 | { | |
6855 | .cmd = NL80211_CMD_GET_MPATH, | |
6856 | .doit = nl80211_get_mpath, | |
6857 | .dumpit = nl80211_dump_mpath, | |
6858 | .policy = nl80211_policy, | |
6859 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6860 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6861 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6862 | }, |
6863 | { | |
6864 | .cmd = NL80211_CMD_SET_MPATH, | |
6865 | .doit = nl80211_set_mpath, | |
6866 | .policy = nl80211_policy, | |
6867 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6868 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6869 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6870 | }, |
6871 | { | |
6872 | .cmd = NL80211_CMD_NEW_MPATH, | |
6873 | .doit = nl80211_new_mpath, | |
6874 | .policy = nl80211_policy, | |
6875 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6876 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6877 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6878 | }, |
6879 | { | |
6880 | .cmd = NL80211_CMD_DEL_MPATH, | |
6881 | .doit = nl80211_del_mpath, | |
6882 | .policy = nl80211_policy, | |
9f1ba906 | 6883 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 6884 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6885 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
6886 | }, |
6887 | { | |
6888 | .cmd = NL80211_CMD_SET_BSS, | |
6889 | .doit = nl80211_set_bss, | |
6890 | .policy = nl80211_policy, | |
b2e1b302 | 6891 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 6892 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6893 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 6894 | }, |
f130347c LR |
6895 | { |
6896 | .cmd = NL80211_CMD_GET_REG, | |
6897 | .doit = nl80211_get_reg, | |
6898 | .policy = nl80211_policy, | |
6899 | /* can be retrieved by unprivileged users */ | |
6900 | }, | |
b2e1b302 LR |
6901 | { |
6902 | .cmd = NL80211_CMD_SET_REG, | |
6903 | .doit = nl80211_set_reg, | |
6904 | .policy = nl80211_policy, | |
6905 | .flags = GENL_ADMIN_PERM, | |
6906 | }, | |
6907 | { | |
6908 | .cmd = NL80211_CMD_REQ_SET_REG, | |
6909 | .doit = nl80211_req_set_reg, | |
6910 | .policy = nl80211_policy, | |
93da9cc1 | 6911 | .flags = GENL_ADMIN_PERM, |
6912 | }, | |
6913 | { | |
24bdd9f4 JC |
6914 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
6915 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 6916 | .policy = nl80211_policy, |
6917 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 6918 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6919 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 6920 | }, |
6921 | { | |
24bdd9f4 JC |
6922 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
6923 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 6924 | .policy = nl80211_policy, |
9aed3cc1 | 6925 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 6926 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6927 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 6928 | }, |
2a519311 JB |
6929 | { |
6930 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
6931 | .doit = nl80211_trigger_scan, | |
6932 | .policy = nl80211_policy, | |
6933 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6934 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6935 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
6936 | }, |
6937 | { | |
6938 | .cmd = NL80211_CMD_GET_SCAN, | |
6939 | .policy = nl80211_policy, | |
6940 | .dumpit = nl80211_dump_scan, | |
6941 | }, | |
807f8a8c LC |
6942 | { |
6943 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
6944 | .doit = nl80211_start_sched_scan, | |
6945 | .policy = nl80211_policy, | |
6946 | .flags = GENL_ADMIN_PERM, | |
6947 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6948 | NL80211_FLAG_NEED_RTNL, | |
6949 | }, | |
6950 | { | |
6951 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
6952 | .doit = nl80211_stop_sched_scan, | |
6953 | .policy = nl80211_policy, | |
6954 | .flags = GENL_ADMIN_PERM, | |
6955 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6956 | NL80211_FLAG_NEED_RTNL, | |
6957 | }, | |
636a5d36 JM |
6958 | { |
6959 | .cmd = NL80211_CMD_AUTHENTICATE, | |
6960 | .doit = nl80211_authenticate, | |
6961 | .policy = nl80211_policy, | |
6962 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6963 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6964 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6965 | }, |
6966 | { | |
6967 | .cmd = NL80211_CMD_ASSOCIATE, | |
6968 | .doit = nl80211_associate, | |
6969 | .policy = nl80211_policy, | |
6970 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6971 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6972 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6973 | }, |
6974 | { | |
6975 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
6976 | .doit = nl80211_deauthenticate, | |
6977 | .policy = nl80211_policy, | |
6978 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6979 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6980 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6981 | }, |
6982 | { | |
6983 | .cmd = NL80211_CMD_DISASSOCIATE, | |
6984 | .doit = nl80211_disassociate, | |
6985 | .policy = nl80211_policy, | |
6986 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6988 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 6989 | }, |
04a773ad JB |
6990 | { |
6991 | .cmd = NL80211_CMD_JOIN_IBSS, | |
6992 | .doit = nl80211_join_ibss, | |
6993 | .policy = nl80211_policy, | |
6994 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6995 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6996 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
6997 | }, |
6998 | { | |
6999 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
7000 | .doit = nl80211_leave_ibss, | |
7001 | .policy = nl80211_policy, | |
7002 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7004 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 7005 | }, |
aff89a9b JB |
7006 | #ifdef CONFIG_NL80211_TESTMODE |
7007 | { | |
7008 | .cmd = NL80211_CMD_TESTMODE, | |
7009 | .doit = nl80211_testmode_do, | |
71063f0e | 7010 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
7011 | .policy = nl80211_policy, |
7012 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7013 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
7014 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
7015 | }, |
7016 | #endif | |
b23aa676 SO |
7017 | { |
7018 | .cmd = NL80211_CMD_CONNECT, | |
7019 | .doit = nl80211_connect, | |
7020 | .policy = nl80211_policy, | |
7021 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7023 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
7024 | }, |
7025 | { | |
7026 | .cmd = NL80211_CMD_DISCONNECT, | |
7027 | .doit = nl80211_disconnect, | |
7028 | .policy = nl80211_policy, | |
7029 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7030 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7031 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 7032 | }, |
463d0183 JB |
7033 | { |
7034 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
7035 | .doit = nl80211_wiphy_netns, | |
7036 | .policy = nl80211_policy, | |
7037 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7038 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
7039 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 7040 | }, |
61fa713c HS |
7041 | { |
7042 | .cmd = NL80211_CMD_GET_SURVEY, | |
7043 | .policy = nl80211_policy, | |
7044 | .dumpit = nl80211_dump_survey, | |
7045 | }, | |
67fbb16b SO |
7046 | { |
7047 | .cmd = NL80211_CMD_SET_PMKSA, | |
7048 | .doit = nl80211_setdel_pmksa, | |
7049 | .policy = nl80211_policy, | |
7050 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7051 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7052 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
7053 | }, |
7054 | { | |
7055 | .cmd = NL80211_CMD_DEL_PMKSA, | |
7056 | .doit = nl80211_setdel_pmksa, | |
7057 | .policy = nl80211_policy, | |
7058 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7059 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7060 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
7061 | }, |
7062 | { | |
7063 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
7064 | .doit = nl80211_flush_pmksa, | |
7065 | .policy = nl80211_policy, | |
7066 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7067 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7068 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 7069 | }, |
9588bbd5 JM |
7070 | { |
7071 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
7072 | .doit = nl80211_remain_on_channel, | |
7073 | .policy = nl80211_policy, | |
7074 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7075 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7076 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
7077 | }, |
7078 | { | |
7079 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
7080 | .doit = nl80211_cancel_remain_on_channel, | |
7081 | .policy = nl80211_policy, | |
7082 | .flags = GENL_ADMIN_PERM, | |
41265714 | 7083 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7084 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 7085 | }, |
13ae75b1 JM |
7086 | { |
7087 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
7088 | .doit = nl80211_set_tx_bitrate_mask, | |
7089 | .policy = nl80211_policy, | |
7090 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7091 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7092 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 7093 | }, |
026331c4 | 7094 | { |
2e161f78 JB |
7095 | .cmd = NL80211_CMD_REGISTER_FRAME, |
7096 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
7097 | .policy = nl80211_policy, |
7098 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7099 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7100 | NL80211_FLAG_NEED_RTNL, | |
026331c4 JM |
7101 | }, |
7102 | { | |
2e161f78 JB |
7103 | .cmd = NL80211_CMD_FRAME, |
7104 | .doit = nl80211_tx_mgmt, | |
026331c4 | 7105 | .policy = nl80211_policy, |
f7ca38df JB |
7106 | .flags = GENL_ADMIN_PERM, |
7107 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7108 | NL80211_FLAG_NEED_RTNL, | |
7109 | }, | |
7110 | { | |
7111 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
7112 | .doit = nl80211_tx_mgmt_cancel_wait, | |
7113 | .policy = nl80211_policy, | |
026331c4 | 7114 | .flags = GENL_ADMIN_PERM, |
41265714 | 7115 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 7116 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 7117 | }, |
ffb9eb3d KV |
7118 | { |
7119 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
7120 | .doit = nl80211_set_power_save, | |
7121 | .policy = nl80211_policy, | |
7122 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7123 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7124 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
7125 | }, |
7126 | { | |
7127 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
7128 | .doit = nl80211_get_power_save, | |
7129 | .policy = nl80211_policy, | |
7130 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
7131 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7132 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 7133 | }, |
d6dc1a38 JO |
7134 | { |
7135 | .cmd = NL80211_CMD_SET_CQM, | |
7136 | .doit = nl80211_set_cqm, | |
7137 | .policy = nl80211_policy, | |
7138 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7139 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7140 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 7141 | }, |
f444de05 JB |
7142 | { |
7143 | .cmd = NL80211_CMD_SET_CHANNEL, | |
7144 | .doit = nl80211_set_channel, | |
7145 | .policy = nl80211_policy, | |
7146 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
7147 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7148 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 7149 | }, |
e8347eba BJ |
7150 | { |
7151 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
7152 | .doit = nl80211_set_wds_peer, | |
7153 | .policy = nl80211_policy, | |
7154 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
7155 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
7156 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 7157 | }, |
29cbe68c JB |
7158 | { |
7159 | .cmd = NL80211_CMD_JOIN_MESH, | |
7160 | .doit = nl80211_join_mesh, | |
7161 | .policy = nl80211_policy, | |
7162 | .flags = GENL_ADMIN_PERM, | |
7163 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7164 | NL80211_FLAG_NEED_RTNL, | |
7165 | }, | |
7166 | { | |
7167 | .cmd = NL80211_CMD_LEAVE_MESH, | |
7168 | .doit = nl80211_leave_mesh, | |
7169 | .policy = nl80211_policy, | |
7170 | .flags = GENL_ADMIN_PERM, | |
7171 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7172 | NL80211_FLAG_NEED_RTNL, | |
7173 | }, | |
dfb89c56 | 7174 | #ifdef CONFIG_PM |
ff1b6e69 JB |
7175 | { |
7176 | .cmd = NL80211_CMD_GET_WOWLAN, | |
7177 | .doit = nl80211_get_wowlan, | |
7178 | .policy = nl80211_policy, | |
7179 | /* can be retrieved by unprivileged users */ | |
7180 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
7181 | NL80211_FLAG_NEED_RTNL, | |
7182 | }, | |
7183 | { | |
7184 | .cmd = NL80211_CMD_SET_WOWLAN, | |
7185 | .doit = nl80211_set_wowlan, | |
7186 | .policy = nl80211_policy, | |
7187 | .flags = GENL_ADMIN_PERM, | |
7188 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
7189 | NL80211_FLAG_NEED_RTNL, | |
7190 | }, | |
dfb89c56 | 7191 | #endif |
e5497d76 JB |
7192 | { |
7193 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
7194 | .doit = nl80211_set_rekey_data, | |
7195 | .policy = nl80211_policy, | |
7196 | .flags = GENL_ADMIN_PERM, | |
7197 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7198 | NL80211_FLAG_NEED_RTNL, | |
7199 | }, | |
109086ce AN |
7200 | { |
7201 | .cmd = NL80211_CMD_TDLS_MGMT, | |
7202 | .doit = nl80211_tdls_mgmt, | |
7203 | .policy = nl80211_policy, | |
7204 | .flags = GENL_ADMIN_PERM, | |
7205 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7206 | NL80211_FLAG_NEED_RTNL, | |
7207 | }, | |
7208 | { | |
7209 | .cmd = NL80211_CMD_TDLS_OPER, | |
7210 | .doit = nl80211_tdls_oper, | |
7211 | .policy = nl80211_policy, | |
7212 | .flags = GENL_ADMIN_PERM, | |
7213 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7214 | NL80211_FLAG_NEED_RTNL, | |
7215 | }, | |
28946da7 JB |
7216 | { |
7217 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
7218 | .doit = nl80211_register_unexpected_frame, | |
7219 | .policy = nl80211_policy, | |
7220 | .flags = GENL_ADMIN_PERM, | |
7221 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
7222 | NL80211_FLAG_NEED_RTNL, | |
7223 | }, | |
7f6cf311 JB |
7224 | { |
7225 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
7226 | .doit = nl80211_probe_client, | |
7227 | .policy = nl80211_policy, | |
7228 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7229 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
7230 | NL80211_FLAG_NEED_RTNL, |
7231 | }, | |
5e760230 JB |
7232 | { |
7233 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
7234 | .doit = nl80211_register_beacons, | |
7235 | .policy = nl80211_policy, | |
7236 | .flags = GENL_ADMIN_PERM, | |
7237 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
7238 | NL80211_FLAG_NEED_RTNL, | |
7239 | }, | |
1d9d9213 SW |
7240 | { |
7241 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
7242 | .doit = nl80211_set_noack_map, | |
7243 | .policy = nl80211_policy, | |
7244 | .flags = GENL_ADMIN_PERM, | |
7245 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
7246 | NL80211_FLAG_NEED_RTNL, | |
7247 | }, | |
7248 | ||
55682965 | 7249 | }; |
9588bbd5 | 7250 | |
6039f6d2 JM |
7251 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
7252 | .name = "mlme", | |
7253 | }; | |
55682965 JB |
7254 | |
7255 | /* multicast groups */ | |
7256 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
7257 | .name = "config", | |
7258 | }; | |
2a519311 JB |
7259 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
7260 | .name = "scan", | |
7261 | }; | |
73d54c9e LR |
7262 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
7263 | .name = "regulatory", | |
7264 | }; | |
55682965 JB |
7265 | |
7266 | /* notification functions */ | |
7267 | ||
7268 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
7269 | { | |
7270 | struct sk_buff *msg; | |
7271 | ||
fd2120ca | 7272 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
7273 | if (!msg) |
7274 | return; | |
7275 | ||
7276 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
7277 | nlmsg_free(msg); | |
7278 | return; | |
7279 | } | |
7280 | ||
463d0183 JB |
7281 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7282 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
7283 | } |
7284 | ||
362a415d JB |
7285 | static int nl80211_add_scan_req(struct sk_buff *msg, |
7286 | struct cfg80211_registered_device *rdev) | |
7287 | { | |
7288 | struct cfg80211_scan_request *req = rdev->scan_req; | |
7289 | struct nlattr *nest; | |
7290 | int i; | |
7291 | ||
667503dd JB |
7292 | ASSERT_RDEV_LOCK(rdev); |
7293 | ||
362a415d JB |
7294 | if (WARN_ON(!req)) |
7295 | return 0; | |
7296 | ||
7297 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
7298 | if (!nest) | |
7299 | goto nla_put_failure; | |
9360ffd1 DM |
7300 | for (i = 0; i < req->n_ssids; i++) { |
7301 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
7302 | goto nla_put_failure; | |
7303 | } | |
362a415d JB |
7304 | nla_nest_end(msg, nest); |
7305 | ||
7306 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
7307 | if (!nest) | |
7308 | goto nla_put_failure; | |
9360ffd1 DM |
7309 | for (i = 0; i < req->n_channels; i++) { |
7310 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
7311 | goto nla_put_failure; | |
7312 | } | |
362a415d JB |
7313 | nla_nest_end(msg, nest); |
7314 | ||
9360ffd1 DM |
7315 | if (req->ie && |
7316 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
7317 | goto nla_put_failure; | |
362a415d JB |
7318 | |
7319 | return 0; | |
7320 | nla_put_failure: | |
7321 | return -ENOBUFS; | |
7322 | } | |
7323 | ||
a538e2d5 JB |
7324 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
7325 | struct cfg80211_registered_device *rdev, | |
7326 | struct net_device *netdev, | |
7327 | u32 pid, u32 seq, int flags, | |
7328 | u32 cmd) | |
2a519311 JB |
7329 | { |
7330 | void *hdr; | |
7331 | ||
7332 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
7333 | if (!hdr) | |
7334 | return -1; | |
7335 | ||
9360ffd1 DM |
7336 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7337 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
7338 | goto nla_put_failure; | |
2a519311 | 7339 | |
362a415d JB |
7340 | /* ignore errors and send incomplete event anyway */ |
7341 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
7342 | |
7343 | return genlmsg_end(msg, hdr); | |
7344 | ||
7345 | nla_put_failure: | |
7346 | genlmsg_cancel(msg, hdr); | |
7347 | return -EMSGSIZE; | |
7348 | } | |
7349 | ||
807f8a8c LC |
7350 | static int |
7351 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
7352 | struct cfg80211_registered_device *rdev, | |
7353 | struct net_device *netdev, | |
7354 | u32 pid, u32 seq, int flags, u32 cmd) | |
7355 | { | |
7356 | void *hdr; | |
7357 | ||
7358 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
7359 | if (!hdr) | |
7360 | return -1; | |
7361 | ||
9360ffd1 DM |
7362 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7363 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
7364 | goto nla_put_failure; | |
807f8a8c LC |
7365 | |
7366 | return genlmsg_end(msg, hdr); | |
7367 | ||
7368 | nla_put_failure: | |
7369 | genlmsg_cancel(msg, hdr); | |
7370 | return -EMSGSIZE; | |
7371 | } | |
7372 | ||
a538e2d5 JB |
7373 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
7374 | struct net_device *netdev) | |
7375 | { | |
7376 | struct sk_buff *msg; | |
7377 | ||
7378 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
7379 | if (!msg) | |
7380 | return; | |
7381 | ||
7382 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
7383 | NL80211_CMD_TRIGGER_SCAN) < 0) { | |
7384 | nlmsg_free(msg); | |
7385 | return; | |
7386 | } | |
7387 | ||
463d0183 JB |
7388 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7389 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
7390 | } |
7391 | ||
2a519311 JB |
7392 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
7393 | struct net_device *netdev) | |
7394 | { | |
7395 | struct sk_buff *msg; | |
7396 | ||
fd2120ca | 7397 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
7398 | if (!msg) |
7399 | return; | |
7400 | ||
a538e2d5 JB |
7401 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
7402 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 JB |
7403 | nlmsg_free(msg); |
7404 | return; | |
7405 | } | |
7406 | ||
463d0183 JB |
7407 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7408 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
7409 | } |
7410 | ||
7411 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
7412 | struct net_device *netdev) | |
7413 | { | |
7414 | struct sk_buff *msg; | |
7415 | ||
fd2120ca | 7416 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
7417 | if (!msg) |
7418 | return; | |
7419 | ||
a538e2d5 JB |
7420 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
7421 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
2a519311 JB |
7422 | nlmsg_free(msg); |
7423 | return; | |
7424 | } | |
7425 | ||
463d0183 JB |
7426 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7427 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
7428 | } |
7429 | ||
807f8a8c LC |
7430 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
7431 | struct net_device *netdev) | |
7432 | { | |
7433 | struct sk_buff *msg; | |
7434 | ||
7435 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7436 | if (!msg) | |
7437 | return; | |
7438 | ||
7439 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
7440 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
7441 | nlmsg_free(msg); | |
7442 | return; | |
7443 | } | |
7444 | ||
7445 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7446 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
7447 | } | |
7448 | ||
7449 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
7450 | struct net_device *netdev, u32 cmd) | |
7451 | { | |
7452 | struct sk_buff *msg; | |
7453 | ||
7454 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
7455 | if (!msg) | |
7456 | return; | |
7457 | ||
7458 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
7459 | nlmsg_free(msg); | |
7460 | return; | |
7461 | } | |
7462 | ||
7463 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7464 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
7465 | } | |
7466 | ||
73d54c9e LR |
7467 | /* |
7468 | * This can happen on global regulatory changes or device specific settings | |
7469 | * based on custom world regulatory domains. | |
7470 | */ | |
7471 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
7472 | { | |
7473 | struct sk_buff *msg; | |
7474 | void *hdr; | |
7475 | ||
fd2120ca | 7476 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
7477 | if (!msg) |
7478 | return; | |
7479 | ||
7480 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
7481 | if (!hdr) { | |
7482 | nlmsg_free(msg); | |
7483 | return; | |
7484 | } | |
7485 | ||
7486 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
7487 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
7488 | goto nla_put_failure; | |
7489 | ||
7490 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
7491 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7492 | NL80211_REGDOM_TYPE_WORLD)) | |
7493 | goto nla_put_failure; | |
7494 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
7495 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7496 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
7497 | goto nla_put_failure; | |
7498 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
7499 | request->intersect) { | |
7500 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7501 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
7502 | goto nla_put_failure; | |
7503 | } else { | |
7504 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7505 | NL80211_REGDOM_TYPE_COUNTRY) || | |
7506 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
7507 | request->alpha2)) | |
7508 | goto nla_put_failure; | |
7509 | } | |
7510 | ||
7511 | if (wiphy_idx_valid(request->wiphy_idx) && | |
7512 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
7513 | goto nla_put_failure; | |
73d54c9e | 7514 | |
3b7b72ee | 7515 | genlmsg_end(msg, hdr); |
73d54c9e | 7516 | |
bc43b28c | 7517 | rcu_read_lock(); |
463d0183 | 7518 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
7519 | GFP_ATOMIC); |
7520 | rcu_read_unlock(); | |
73d54c9e LR |
7521 | |
7522 | return; | |
7523 | ||
7524 | nla_put_failure: | |
7525 | genlmsg_cancel(msg, hdr); | |
7526 | nlmsg_free(msg); | |
7527 | } | |
7528 | ||
6039f6d2 JM |
7529 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
7530 | struct net_device *netdev, | |
7531 | const u8 *buf, size_t len, | |
e6d6e342 | 7532 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
7533 | { |
7534 | struct sk_buff *msg; | |
7535 | void *hdr; | |
7536 | ||
e6d6e342 | 7537 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
7538 | if (!msg) |
7539 | return; | |
7540 | ||
7541 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7542 | if (!hdr) { | |
7543 | nlmsg_free(msg); | |
7544 | return; | |
7545 | } | |
7546 | ||
9360ffd1 DM |
7547 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7548 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7549 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
7550 | goto nla_put_failure; | |
6039f6d2 | 7551 | |
3b7b72ee | 7552 | genlmsg_end(msg, hdr); |
6039f6d2 | 7553 | |
463d0183 JB |
7554 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7555 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
7556 | return; |
7557 | ||
7558 | nla_put_failure: | |
7559 | genlmsg_cancel(msg, hdr); | |
7560 | nlmsg_free(msg); | |
7561 | } | |
7562 | ||
7563 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
7564 | struct net_device *netdev, const u8 *buf, |
7565 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
7566 | { |
7567 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 7568 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
7569 | } |
7570 | ||
7571 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
7572 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 7573 | size_t len, gfp_t gfp) |
6039f6d2 | 7574 | { |
e6d6e342 JB |
7575 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
7576 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
7577 | } |
7578 | ||
53b46b84 | 7579 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
7580 | struct net_device *netdev, const u8 *buf, |
7581 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
7582 | { |
7583 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 7584 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
7585 | } |
7586 | ||
53b46b84 JM |
7587 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
7588 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 7589 | size_t len, gfp_t gfp) |
6039f6d2 JM |
7590 | { |
7591 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 7592 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
7593 | } |
7594 | ||
cf4e594e JM |
7595 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
7596 | struct net_device *netdev, const u8 *buf, | |
7597 | size_t len, gfp_t gfp) | |
7598 | { | |
7599 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
7600 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); | |
7601 | } | |
7602 | ||
7603 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, | |
7604 | struct net_device *netdev, const u8 *buf, | |
7605 | size_t len, gfp_t gfp) | |
7606 | { | |
7607 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
7608 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); | |
7609 | } | |
7610 | ||
1b06bb40 LR |
7611 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
7612 | struct net_device *netdev, int cmd, | |
e6d6e342 | 7613 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
7614 | { |
7615 | struct sk_buff *msg; | |
7616 | void *hdr; | |
7617 | ||
e6d6e342 | 7618 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
7619 | if (!msg) |
7620 | return; | |
7621 | ||
7622 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7623 | if (!hdr) { | |
7624 | nlmsg_free(msg); | |
7625 | return; | |
7626 | } | |
7627 | ||
9360ffd1 DM |
7628 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7629 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7630 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
7631 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
7632 | goto nla_put_failure; | |
1965c853 | 7633 | |
3b7b72ee | 7634 | genlmsg_end(msg, hdr); |
1965c853 | 7635 | |
463d0183 JB |
7636 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7637 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
7638 | return; |
7639 | ||
7640 | nla_put_failure: | |
7641 | genlmsg_cancel(msg, hdr); | |
7642 | nlmsg_free(msg); | |
7643 | } | |
7644 | ||
7645 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
7646 | struct net_device *netdev, const u8 *addr, |
7647 | gfp_t gfp) | |
1965c853 JM |
7648 | { |
7649 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 7650 | addr, gfp); |
1965c853 JM |
7651 | } |
7652 | ||
7653 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
7654 | struct net_device *netdev, const u8 *addr, |
7655 | gfp_t gfp) | |
1965c853 | 7656 | { |
e6d6e342 JB |
7657 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
7658 | addr, gfp); | |
1965c853 JM |
7659 | } |
7660 | ||
b23aa676 SO |
7661 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
7662 | struct net_device *netdev, const u8 *bssid, | |
7663 | const u8 *req_ie, size_t req_ie_len, | |
7664 | const u8 *resp_ie, size_t resp_ie_len, | |
7665 | u16 status, gfp_t gfp) | |
7666 | { | |
7667 | struct sk_buff *msg; | |
7668 | void *hdr; | |
7669 | ||
7670 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7671 | if (!msg) | |
7672 | return; | |
7673 | ||
7674 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
7675 | if (!hdr) { | |
7676 | nlmsg_free(msg); | |
7677 | return; | |
7678 | } | |
7679 | ||
9360ffd1 DM |
7680 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7681 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7682 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
7683 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
7684 | (req_ie && | |
7685 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
7686 | (resp_ie && | |
7687 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
7688 | goto nla_put_failure; | |
b23aa676 | 7689 | |
3b7b72ee | 7690 | genlmsg_end(msg, hdr); |
b23aa676 | 7691 | |
463d0183 JB |
7692 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7693 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
7694 | return; |
7695 | ||
7696 | nla_put_failure: | |
7697 | genlmsg_cancel(msg, hdr); | |
7698 | nlmsg_free(msg); | |
7699 | ||
7700 | } | |
7701 | ||
7702 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
7703 | struct net_device *netdev, const u8 *bssid, | |
7704 | const u8 *req_ie, size_t req_ie_len, | |
7705 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
7706 | { | |
7707 | struct sk_buff *msg; | |
7708 | void *hdr; | |
7709 | ||
7710 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7711 | if (!msg) | |
7712 | return; | |
7713 | ||
7714 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
7715 | if (!hdr) { | |
7716 | nlmsg_free(msg); | |
7717 | return; | |
7718 | } | |
7719 | ||
9360ffd1 DM |
7720 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7721 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7722 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
7723 | (req_ie && | |
7724 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
7725 | (resp_ie && | |
7726 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
7727 | goto nla_put_failure; | |
b23aa676 | 7728 | |
3b7b72ee | 7729 | genlmsg_end(msg, hdr); |
b23aa676 | 7730 | |
463d0183 JB |
7731 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7732 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
7733 | return; |
7734 | ||
7735 | nla_put_failure: | |
7736 | genlmsg_cancel(msg, hdr); | |
7737 | nlmsg_free(msg); | |
7738 | ||
7739 | } | |
7740 | ||
7741 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
7742 | struct net_device *netdev, u16 reason, | |
667503dd | 7743 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
7744 | { |
7745 | struct sk_buff *msg; | |
7746 | void *hdr; | |
7747 | ||
667503dd | 7748 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
b23aa676 SO |
7749 | if (!msg) |
7750 | return; | |
7751 | ||
7752 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
7753 | if (!hdr) { | |
7754 | nlmsg_free(msg); | |
7755 | return; | |
7756 | } | |
7757 | ||
9360ffd1 DM |
7758 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7759 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7760 | (from_ap && reason && | |
7761 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
7762 | (from_ap && | |
7763 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
7764 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
7765 | goto nla_put_failure; | |
b23aa676 | 7766 | |
3b7b72ee | 7767 | genlmsg_end(msg, hdr); |
b23aa676 | 7768 | |
463d0183 JB |
7769 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7770 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
7771 | return; |
7772 | ||
7773 | nla_put_failure: | |
7774 | genlmsg_cancel(msg, hdr); | |
7775 | nlmsg_free(msg); | |
7776 | ||
7777 | } | |
7778 | ||
04a773ad JB |
7779 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
7780 | struct net_device *netdev, const u8 *bssid, | |
7781 | gfp_t gfp) | |
7782 | { | |
7783 | struct sk_buff *msg; | |
7784 | void *hdr; | |
7785 | ||
fd2120ca | 7786 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
7787 | if (!msg) |
7788 | return; | |
7789 | ||
7790 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
7791 | if (!hdr) { | |
7792 | nlmsg_free(msg); | |
7793 | return; | |
7794 | } | |
7795 | ||
9360ffd1 DM |
7796 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7797 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7798 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
7799 | goto nla_put_failure; | |
04a773ad | 7800 | |
3b7b72ee | 7801 | genlmsg_end(msg, hdr); |
04a773ad | 7802 | |
463d0183 JB |
7803 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7804 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
7805 | return; |
7806 | ||
7807 | nla_put_failure: | |
7808 | genlmsg_cancel(msg, hdr); | |
7809 | nlmsg_free(msg); | |
7810 | } | |
7811 | ||
c93b5e71 JC |
7812 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
7813 | struct net_device *netdev, | |
7814 | const u8 *macaddr, const u8* ie, u8 ie_len, | |
7815 | gfp_t gfp) | |
7816 | { | |
7817 | struct sk_buff *msg; | |
7818 | void *hdr; | |
7819 | ||
7820 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7821 | if (!msg) | |
7822 | return; | |
7823 | ||
7824 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
7825 | if (!hdr) { | |
7826 | nlmsg_free(msg); | |
7827 | return; | |
7828 | } | |
7829 | ||
9360ffd1 DM |
7830 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7831 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7832 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || | |
7833 | (ie_len && ie && | |
7834 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
7835 | goto nla_put_failure; | |
c93b5e71 | 7836 | |
3b7b72ee | 7837 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
7838 | |
7839 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7840 | nl80211_mlme_mcgrp.id, gfp); | |
7841 | return; | |
7842 | ||
7843 | nla_put_failure: | |
7844 | genlmsg_cancel(msg, hdr); | |
7845 | nlmsg_free(msg); | |
7846 | } | |
7847 | ||
a3b8b056 JM |
7848 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
7849 | struct net_device *netdev, const u8 *addr, | |
7850 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 7851 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
7852 | { |
7853 | struct sk_buff *msg; | |
7854 | void *hdr; | |
7855 | ||
e6d6e342 | 7856 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
7857 | if (!msg) |
7858 | return; | |
7859 | ||
7860 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
7861 | if (!hdr) { | |
7862 | nlmsg_free(msg); | |
7863 | return; | |
7864 | } | |
7865 | ||
9360ffd1 DM |
7866 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7867 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7868 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
7869 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
7870 | (key_id != -1 && | |
7871 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
7872 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
7873 | goto nla_put_failure; | |
a3b8b056 | 7874 | |
3b7b72ee | 7875 | genlmsg_end(msg, hdr); |
a3b8b056 | 7876 | |
463d0183 JB |
7877 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7878 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
7879 | return; |
7880 | ||
7881 | nla_put_failure: | |
7882 | genlmsg_cancel(msg, hdr); | |
7883 | nlmsg_free(msg); | |
7884 | } | |
7885 | ||
6bad8766 LR |
7886 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
7887 | struct ieee80211_channel *channel_before, | |
7888 | struct ieee80211_channel *channel_after) | |
7889 | { | |
7890 | struct sk_buff *msg; | |
7891 | void *hdr; | |
7892 | struct nlattr *nl_freq; | |
7893 | ||
fd2120ca | 7894 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
7895 | if (!msg) |
7896 | return; | |
7897 | ||
7898 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
7899 | if (!hdr) { | |
7900 | nlmsg_free(msg); | |
7901 | return; | |
7902 | } | |
7903 | ||
7904 | /* | |
7905 | * Since we are applying the beacon hint to a wiphy we know its | |
7906 | * wiphy_idx is valid | |
7907 | */ | |
9360ffd1 DM |
7908 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
7909 | goto nla_put_failure; | |
6bad8766 LR |
7910 | |
7911 | /* Before */ | |
7912 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
7913 | if (!nl_freq) | |
7914 | goto nla_put_failure; | |
7915 | if (nl80211_msg_put_channel(msg, channel_before)) | |
7916 | goto nla_put_failure; | |
7917 | nla_nest_end(msg, nl_freq); | |
7918 | ||
7919 | /* After */ | |
7920 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
7921 | if (!nl_freq) | |
7922 | goto nla_put_failure; | |
7923 | if (nl80211_msg_put_channel(msg, channel_after)) | |
7924 | goto nla_put_failure; | |
7925 | nla_nest_end(msg, nl_freq); | |
7926 | ||
3b7b72ee | 7927 | genlmsg_end(msg, hdr); |
6bad8766 | 7928 | |
463d0183 JB |
7929 | rcu_read_lock(); |
7930 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
7931 | GFP_ATOMIC); | |
7932 | rcu_read_unlock(); | |
6bad8766 LR |
7933 | |
7934 | return; | |
7935 | ||
7936 | nla_put_failure: | |
7937 | genlmsg_cancel(msg, hdr); | |
7938 | nlmsg_free(msg); | |
7939 | } | |
7940 | ||
9588bbd5 JM |
7941 | static void nl80211_send_remain_on_chan_event( |
7942 | int cmd, struct cfg80211_registered_device *rdev, | |
7943 | struct net_device *netdev, u64 cookie, | |
7944 | struct ieee80211_channel *chan, | |
7945 | enum nl80211_channel_type channel_type, | |
7946 | unsigned int duration, gfp_t gfp) | |
7947 | { | |
7948 | struct sk_buff *msg; | |
7949 | void *hdr; | |
7950 | ||
7951 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7952 | if (!msg) | |
7953 | return; | |
7954 | ||
7955 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7956 | if (!hdr) { | |
7957 | nlmsg_free(msg); | |
7958 | return; | |
7959 | } | |
7960 | ||
9360ffd1 DM |
7961 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7962 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7963 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || | |
7964 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || | |
7965 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) | |
7966 | goto nla_put_failure; | |
9588bbd5 | 7967 | |
9360ffd1 DM |
7968 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
7969 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
7970 | goto nla_put_failure; | |
9588bbd5 | 7971 | |
3b7b72ee | 7972 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
7973 | |
7974 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7975 | nl80211_mlme_mcgrp.id, gfp); | |
7976 | return; | |
7977 | ||
7978 | nla_put_failure: | |
7979 | genlmsg_cancel(msg, hdr); | |
7980 | nlmsg_free(msg); | |
7981 | } | |
7982 | ||
7983 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
7984 | struct net_device *netdev, u64 cookie, | |
7985 | struct ieee80211_channel *chan, | |
7986 | enum nl80211_channel_type channel_type, | |
7987 | unsigned int duration, gfp_t gfp) | |
7988 | { | |
7989 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
7990 | rdev, netdev, cookie, chan, | |
7991 | channel_type, duration, gfp); | |
7992 | } | |
7993 | ||
7994 | void nl80211_send_remain_on_channel_cancel( | |
7995 | struct cfg80211_registered_device *rdev, struct net_device *netdev, | |
7996 | u64 cookie, struct ieee80211_channel *chan, | |
7997 | enum nl80211_channel_type channel_type, gfp_t gfp) | |
7998 | { | |
7999 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
8000 | rdev, netdev, cookie, chan, | |
8001 | channel_type, 0, gfp); | |
8002 | } | |
8003 | ||
98b62183 JB |
8004 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
8005 | struct net_device *dev, const u8 *mac_addr, | |
8006 | struct station_info *sinfo, gfp_t gfp) | |
8007 | { | |
8008 | struct sk_buff *msg; | |
8009 | ||
8010 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8011 | if (!msg) | |
8012 | return; | |
8013 | ||
66266b3a JL |
8014 | if (nl80211_send_station(msg, 0, 0, 0, |
8015 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
8016 | nlmsg_free(msg); |
8017 | return; | |
8018 | } | |
8019 | ||
8020 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8021 | nl80211_mlme_mcgrp.id, gfp); | |
8022 | } | |
8023 | ||
ec15e68b JM |
8024 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
8025 | struct net_device *dev, const u8 *mac_addr, | |
8026 | gfp_t gfp) | |
8027 | { | |
8028 | struct sk_buff *msg; | |
8029 | void *hdr; | |
8030 | ||
8031 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8032 | if (!msg) | |
8033 | return; | |
8034 | ||
8035 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
8036 | if (!hdr) { | |
8037 | nlmsg_free(msg); | |
8038 | return; | |
8039 | } | |
8040 | ||
9360ffd1 DM |
8041 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
8042 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
8043 | goto nla_put_failure; | |
ec15e68b | 8044 | |
3b7b72ee | 8045 | genlmsg_end(msg, hdr); |
ec15e68b JM |
8046 | |
8047 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8048 | nl80211_mlme_mcgrp.id, gfp); | |
8049 | return; | |
8050 | ||
8051 | nla_put_failure: | |
8052 | genlmsg_cancel(msg, hdr); | |
8053 | nlmsg_free(msg); | |
8054 | } | |
8055 | ||
b92ab5d8 JB |
8056 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
8057 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
8058 | { |
8059 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8060 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
8061 | struct sk_buff *msg; | |
8062 | void *hdr; | |
8063 | int err; | |
8064 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); | |
8065 | ||
8066 | if (!nlpid) | |
8067 | return false; | |
8068 | ||
8069 | msg = nlmsg_new(100, gfp); | |
8070 | if (!msg) | |
8071 | return true; | |
8072 | ||
b92ab5d8 | 8073 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
8074 | if (!hdr) { |
8075 | nlmsg_free(msg); | |
8076 | return true; | |
8077 | } | |
8078 | ||
9360ffd1 DM |
8079 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8080 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
8081 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
8082 | goto nla_put_failure; | |
28946da7 JB |
8083 | |
8084 | err = genlmsg_end(msg, hdr); | |
8085 | if (err < 0) { | |
8086 | nlmsg_free(msg); | |
8087 | return true; | |
8088 | } | |
8089 | ||
8090 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
8091 | return true; | |
8092 | ||
8093 | nla_put_failure: | |
8094 | genlmsg_cancel(msg, hdr); | |
8095 | nlmsg_free(msg); | |
8096 | return true; | |
8097 | } | |
8098 | ||
b92ab5d8 JB |
8099 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
8100 | { | |
8101 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
8102 | addr, gfp); | |
8103 | } | |
8104 | ||
8105 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, | |
8106 | const u8 *addr, gfp_t gfp) | |
8107 | { | |
8108 | return __nl80211_unexpected_frame(dev, | |
8109 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
8110 | addr, gfp); | |
8111 | } | |
8112 | ||
2e161f78 JB |
8113 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
8114 | struct net_device *netdev, u32 nlpid, | |
804483e9 JB |
8115 | int freq, int sig_dbm, |
8116 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 JM |
8117 | { |
8118 | struct sk_buff *msg; | |
8119 | void *hdr; | |
026331c4 JM |
8120 | |
8121 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
8122 | if (!msg) | |
8123 | return -ENOMEM; | |
8124 | ||
2e161f78 | 8125 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
8126 | if (!hdr) { |
8127 | nlmsg_free(msg); | |
8128 | return -ENOMEM; | |
8129 | } | |
8130 | ||
9360ffd1 DM |
8131 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8132 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8133 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | |
8134 | (sig_dbm && | |
8135 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
8136 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
8137 | goto nla_put_failure; | |
026331c4 | 8138 | |
3b7b72ee | 8139 | genlmsg_end(msg, hdr); |
026331c4 | 8140 | |
3b7b72ee | 8141 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
026331c4 JM |
8142 | |
8143 | nla_put_failure: | |
8144 | genlmsg_cancel(msg, hdr); | |
8145 | nlmsg_free(msg); | |
8146 | return -ENOBUFS; | |
8147 | } | |
8148 | ||
2e161f78 JB |
8149 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
8150 | struct net_device *netdev, u64 cookie, | |
8151 | const u8 *buf, size_t len, bool ack, | |
8152 | gfp_t gfp) | |
026331c4 JM |
8153 | { |
8154 | struct sk_buff *msg; | |
8155 | void *hdr; | |
8156 | ||
8157 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
8158 | if (!msg) | |
8159 | return; | |
8160 | ||
2e161f78 | 8161 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
8162 | if (!hdr) { |
8163 | nlmsg_free(msg); | |
8164 | return; | |
8165 | } | |
8166 | ||
9360ffd1 DM |
8167 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8168 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8169 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | |
8170 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
8171 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
8172 | goto nla_put_failure; | |
026331c4 | 8173 | |
3b7b72ee | 8174 | genlmsg_end(msg, hdr); |
026331c4 JM |
8175 | |
8176 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
8177 | return; | |
8178 | ||
8179 | nla_put_failure: | |
8180 | genlmsg_cancel(msg, hdr); | |
8181 | nlmsg_free(msg); | |
8182 | } | |
8183 | ||
d6dc1a38 JO |
8184 | void |
8185 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |
8186 | struct net_device *netdev, | |
8187 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
8188 | gfp_t gfp) | |
8189 | { | |
8190 | struct sk_buff *msg; | |
8191 | struct nlattr *pinfoattr; | |
8192 | void *hdr; | |
8193 | ||
8194 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8195 | if (!msg) | |
8196 | return; | |
8197 | ||
8198 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
8199 | if (!hdr) { | |
8200 | nlmsg_free(msg); | |
8201 | return; | |
8202 | } | |
8203 | ||
9360ffd1 DM |
8204 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8205 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
8206 | goto nla_put_failure; | |
d6dc1a38 JO |
8207 | |
8208 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
8209 | if (!pinfoattr) | |
8210 | goto nla_put_failure; | |
8211 | ||
9360ffd1 DM |
8212 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
8213 | rssi_event)) | |
8214 | goto nla_put_failure; | |
d6dc1a38 JO |
8215 | |
8216 | nla_nest_end(msg, pinfoattr); | |
8217 | ||
3b7b72ee | 8218 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
8219 | |
8220 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8221 | nl80211_mlme_mcgrp.id, gfp); | |
8222 | return; | |
8223 | ||
8224 | nla_put_failure: | |
8225 | genlmsg_cancel(msg, hdr); | |
8226 | nlmsg_free(msg); | |
8227 | } | |
8228 | ||
e5497d76 JB |
8229 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
8230 | struct net_device *netdev, const u8 *bssid, | |
8231 | const u8 *replay_ctr, gfp_t gfp) | |
8232 | { | |
8233 | struct sk_buff *msg; | |
8234 | struct nlattr *rekey_attr; | |
8235 | void *hdr; | |
8236 | ||
8237 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8238 | if (!msg) | |
8239 | return; | |
8240 | ||
8241 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
8242 | if (!hdr) { | |
8243 | nlmsg_free(msg); | |
8244 | return; | |
8245 | } | |
8246 | ||
9360ffd1 DM |
8247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8248 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8249 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
8250 | goto nla_put_failure; | |
e5497d76 JB |
8251 | |
8252 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
8253 | if (!rekey_attr) | |
8254 | goto nla_put_failure; | |
8255 | ||
9360ffd1 DM |
8256 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
8257 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
8258 | goto nla_put_failure; | |
e5497d76 JB |
8259 | |
8260 | nla_nest_end(msg, rekey_attr); | |
8261 | ||
3b7b72ee | 8262 | genlmsg_end(msg, hdr); |
e5497d76 JB |
8263 | |
8264 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8265 | nl80211_mlme_mcgrp.id, gfp); | |
8266 | return; | |
8267 | ||
8268 | nla_put_failure: | |
8269 | genlmsg_cancel(msg, hdr); | |
8270 | nlmsg_free(msg); | |
8271 | } | |
8272 | ||
c9df56b4 JM |
8273 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
8274 | struct net_device *netdev, int index, | |
8275 | const u8 *bssid, bool preauth, gfp_t gfp) | |
8276 | { | |
8277 | struct sk_buff *msg; | |
8278 | struct nlattr *attr; | |
8279 | void *hdr; | |
8280 | ||
8281 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8282 | if (!msg) | |
8283 | return; | |
8284 | ||
8285 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
8286 | if (!hdr) { | |
8287 | nlmsg_free(msg); | |
8288 | return; | |
8289 | } | |
8290 | ||
9360ffd1 DM |
8291 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8292 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
8293 | goto nla_put_failure; | |
c9df56b4 JM |
8294 | |
8295 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
8296 | if (!attr) | |
8297 | goto nla_put_failure; | |
8298 | ||
9360ffd1 DM |
8299 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
8300 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
8301 | (preauth && | |
8302 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
8303 | goto nla_put_failure; | |
c9df56b4 JM |
8304 | |
8305 | nla_nest_end(msg, attr); | |
8306 | ||
3b7b72ee | 8307 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
8308 | |
8309 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8310 | nl80211_mlme_mcgrp.id, gfp); | |
8311 | return; | |
8312 | ||
8313 | nla_put_failure: | |
8314 | genlmsg_cancel(msg, hdr); | |
8315 | nlmsg_free(msg); | |
8316 | } | |
8317 | ||
5314526b TP |
8318 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
8319 | struct net_device *netdev, int freq, | |
8320 | enum nl80211_channel_type type, gfp_t gfp) | |
8321 | { | |
8322 | struct sk_buff *msg; | |
8323 | void *hdr; | |
8324 | ||
8325 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8326 | if (!msg) | |
8327 | return; | |
8328 | ||
8329 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
8330 | if (!hdr) { | |
8331 | nlmsg_free(msg); | |
8332 | return; | |
8333 | } | |
8334 | ||
7eab0f64 JL |
8335 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
8336 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | |
8337 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) | |
8338 | goto nla_put_failure; | |
5314526b TP |
8339 | |
8340 | genlmsg_end(msg, hdr); | |
8341 | ||
8342 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8343 | nl80211_mlme_mcgrp.id, gfp); | |
8344 | return; | |
8345 | ||
8346 | nla_put_failure: | |
8347 | genlmsg_cancel(msg, hdr); | |
8348 | nlmsg_free(msg); | |
8349 | } | |
8350 | ||
c063dbf5 JB |
8351 | void |
8352 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, | |
8353 | struct net_device *netdev, const u8 *peer, | |
8354 | u32 num_packets, gfp_t gfp) | |
8355 | { | |
8356 | struct sk_buff *msg; | |
8357 | struct nlattr *pinfoattr; | |
8358 | void *hdr; | |
8359 | ||
8360 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8361 | if (!msg) | |
8362 | return; | |
8363 | ||
8364 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
8365 | if (!hdr) { | |
8366 | nlmsg_free(msg); | |
8367 | return; | |
8368 | } | |
8369 | ||
9360ffd1 DM |
8370 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8371 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8372 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) | |
8373 | goto nla_put_failure; | |
c063dbf5 JB |
8374 | |
8375 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
8376 | if (!pinfoattr) | |
8377 | goto nla_put_failure; | |
8378 | ||
9360ffd1 DM |
8379 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
8380 | goto nla_put_failure; | |
c063dbf5 JB |
8381 | |
8382 | nla_nest_end(msg, pinfoattr); | |
8383 | ||
3b7b72ee | 8384 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
8385 | |
8386 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8387 | nl80211_mlme_mcgrp.id, gfp); | |
8388 | return; | |
8389 | ||
8390 | nla_put_failure: | |
8391 | genlmsg_cancel(msg, hdr); | |
8392 | nlmsg_free(msg); | |
8393 | } | |
8394 | ||
7f6cf311 JB |
8395 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
8396 | u64 cookie, bool acked, gfp_t gfp) | |
8397 | { | |
8398 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8399 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
8400 | struct sk_buff *msg; | |
8401 | void *hdr; | |
8402 | int err; | |
8403 | ||
8404 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8405 | if (!msg) | |
8406 | return; | |
8407 | ||
8408 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
8409 | if (!hdr) { | |
8410 | nlmsg_free(msg); | |
8411 | return; | |
8412 | } | |
8413 | ||
9360ffd1 DM |
8414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8415 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
8416 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8417 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
8418 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
8419 | goto nla_put_failure; | |
7f6cf311 JB |
8420 | |
8421 | err = genlmsg_end(msg, hdr); | |
8422 | if (err < 0) { | |
8423 | nlmsg_free(msg); | |
8424 | return; | |
8425 | } | |
8426 | ||
8427 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8428 | nl80211_mlme_mcgrp.id, gfp); | |
8429 | return; | |
8430 | ||
8431 | nla_put_failure: | |
8432 | genlmsg_cancel(msg, hdr); | |
8433 | nlmsg_free(msg); | |
8434 | } | |
8435 | EXPORT_SYMBOL(cfg80211_probe_status); | |
8436 | ||
5e760230 JB |
8437 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
8438 | const u8 *frame, size_t len, | |
804483e9 | 8439 | int freq, int sig_dbm, gfp_t gfp) |
5e760230 JB |
8440 | { |
8441 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
8442 | struct sk_buff *msg; | |
8443 | void *hdr; | |
8444 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); | |
8445 | ||
8446 | if (!nlpid) | |
8447 | return; | |
8448 | ||
8449 | msg = nlmsg_new(len + 100, gfp); | |
8450 | if (!msg) | |
8451 | return; | |
8452 | ||
8453 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | |
8454 | if (!hdr) { | |
8455 | nlmsg_free(msg); | |
8456 | return; | |
8457 | } | |
8458 | ||
9360ffd1 DM |
8459 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8460 | (freq && | |
8461 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
8462 | (sig_dbm && | |
8463 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
8464 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
8465 | goto nla_put_failure; | |
5e760230 JB |
8466 | |
8467 | genlmsg_end(msg, hdr); | |
8468 | ||
8469 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
8470 | return; | |
8471 | ||
8472 | nla_put_failure: | |
8473 | genlmsg_cancel(msg, hdr); | |
8474 | nlmsg_free(msg); | |
8475 | } | |
8476 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
8477 | ||
026331c4 JM |
8478 | static int nl80211_netlink_notify(struct notifier_block * nb, |
8479 | unsigned long state, | |
8480 | void *_notify) | |
8481 | { | |
8482 | struct netlink_notify *notify = _notify; | |
8483 | struct cfg80211_registered_device *rdev; | |
8484 | struct wireless_dev *wdev; | |
8485 | ||
8486 | if (state != NETLINK_URELEASE) | |
8487 | return NOTIFY_DONE; | |
8488 | ||
8489 | rcu_read_lock(); | |
8490 | ||
5e760230 | 8491 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
026331c4 | 8492 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
2e161f78 | 8493 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
5e760230 JB |
8494 | if (rdev->ap_beacons_nlpid == notify->pid) |
8495 | rdev->ap_beacons_nlpid = 0; | |
8496 | } | |
026331c4 JM |
8497 | |
8498 | rcu_read_unlock(); | |
8499 | ||
8500 | return NOTIFY_DONE; | |
8501 | } | |
8502 | ||
8503 | static struct notifier_block nl80211_netlink_notifier = { | |
8504 | .notifier_call = nl80211_netlink_notify, | |
8505 | }; | |
8506 | ||
55682965 JB |
8507 | /* initialisation/exit functions */ |
8508 | ||
8509 | int nl80211_init(void) | |
8510 | { | |
0d63cbb5 | 8511 | int err; |
55682965 | 8512 | |
0d63cbb5 MM |
8513 | err = genl_register_family_with_ops(&nl80211_fam, |
8514 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
8515 | if (err) |
8516 | return err; | |
8517 | ||
55682965 JB |
8518 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
8519 | if (err) | |
8520 | goto err_out; | |
8521 | ||
2a519311 JB |
8522 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
8523 | if (err) | |
8524 | goto err_out; | |
8525 | ||
73d54c9e LR |
8526 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
8527 | if (err) | |
8528 | goto err_out; | |
8529 | ||
6039f6d2 JM |
8530 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
8531 | if (err) | |
8532 | goto err_out; | |
8533 | ||
aff89a9b JB |
8534 | #ifdef CONFIG_NL80211_TESTMODE |
8535 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
8536 | if (err) | |
8537 | goto err_out; | |
8538 | #endif | |
8539 | ||
026331c4 JM |
8540 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
8541 | if (err) | |
8542 | goto err_out; | |
8543 | ||
55682965 JB |
8544 | return 0; |
8545 | err_out: | |
8546 | genl_unregister_family(&nl80211_fam); | |
8547 | return err; | |
8548 | } | |
8549 | ||
8550 | void nl80211_exit(void) | |
8551 | { | |
026331c4 | 8552 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
8553 | genl_unregister_family(&nl80211_fam); |
8554 | } |