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