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