2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
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>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
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
,
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
);
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
,
45 .pre_doit
= nl80211_pre_doit
,
46 .post_doit
= nl80211_post_doit
,
49 /* internal helper: get rdev and dev */
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
)
56 if (!attrs
[NL80211_ATTR_IFINDEX
])
59 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
60 *dev
= dev_get_by_index(netns
, ifindex
);
64 *rdev
= cfg80211_get_dev_from_ifindex(netns
, ifindex
);
67 return PTR_ERR(*rdev
);
73 /* policy for the attributes */
74 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
75 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
78 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
79 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
80 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
81 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
82 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
83 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
84 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
87 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
88 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
89 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
91 [NL80211_ATTR_MAC
] = { .len
= ETH_ALEN
},
92 [NL80211_ATTR_PREV_BSSID
] = { .len
= ETH_ALEN
},
94 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
95 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
96 .len
= WLAN_MAX_KEY_LEN
},
97 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
98 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
99 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
100 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
101 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
103 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
104 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
105 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
106 .len
= IEEE80211_MAX_DATA_LEN
},
107 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
108 .len
= IEEE80211_MAX_DATA_LEN
},
109 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
110 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
111 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
112 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
113 .len
= NL80211_MAX_SUPP_RATES
},
114 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
115 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
116 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
117 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
118 .len
= IEEE80211_MAX_MESH_ID_LEN
},
119 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
121 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
122 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
124 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
125 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
126 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
127 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
128 .len
= NL80211_MAX_SUPP_RATES
},
129 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
131 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
132 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
134 [NL80211_ATTR_HT_CAPABILITY
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
136 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
137 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
138 .len
= IEEE80211_MAX_DATA_LEN
},
139 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
140 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
142 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
143 .len
= IEEE80211_MAX_SSID_LEN
},
144 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
145 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
146 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
147 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
148 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
149 [NL80211_ATTR_STA_FLAGS2
] = {
150 .len
= sizeof(struct nl80211_sta_flag_update
),
152 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
153 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
154 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
155 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
156 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
157 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
158 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
160 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
161 .len
= WLAN_PMKID_LEN
},
162 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
163 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
164 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
165 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
166 .len
= IEEE80211_MAX_DATA_LEN
},
167 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
168 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
170 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
171 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
172 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
174 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
175 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
176 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
177 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
178 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
179 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
180 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
181 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
182 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
183 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
184 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
185 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
186 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
187 .len
= IEEE80211_MAX_DATA_LEN
},
188 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
189 .len
= IEEE80211_MAX_DATA_LEN
},
190 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
191 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
192 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
193 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
194 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
195 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
196 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
197 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
198 [NL80211_ATTR_DONT_WAIT_FOR_ACK
] = { .type
= NLA_FLAG
},
199 [NL80211_ATTR_PROBE_RESP
] = { .type
= NLA_BINARY
,
200 .len
= IEEE80211_MAX_DATA_LEN
},
201 [NL80211_ATTR_DFS_REGION
] = { .type
= NLA_U8
},
202 [NL80211_ATTR_DISABLE_HT
] = { .type
= NLA_FLAG
},
203 [NL80211_ATTR_HT_CAPABILITY_MASK
] = {
204 .len
= NL80211_HT_CAPABILITY_LEN
206 [NL80211_ATTR_NOACK_MAP
] = { .type
= NLA_U16
},
209 /* policy for the key attributes */
210 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
211 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
212 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
213 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
214 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 16 },
215 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
216 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
217 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
218 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
221 /* policy for the key default flags */
222 static const struct nla_policy
223 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
224 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
225 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
228 /* policy for WoWLAN attributes */
229 static const struct nla_policy
230 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
231 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
232 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
233 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
234 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
235 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
236 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
237 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
238 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
241 /* policy for GTK rekey offload attributes */
242 static const struct nla_policy
243 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
244 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
245 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
246 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
249 static const struct nla_policy
250 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
251 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID
] = { .type
= NLA_BINARY
,
252 .len
= IEEE80211_MAX_SSID_LEN
},
255 /* ifidx get helper */
256 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
260 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
261 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
266 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
269 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
275 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
276 struct netlink_callback
*cb
,
277 struct cfg80211_registered_device
**rdev
,
278 struct net_device
**dev
)
280 int ifidx
= cb
->args
[0];
284 ifidx
= nl80211_get_ifidx(cb
);
292 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
298 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
300 err
= PTR_ERR(*rdev
);
310 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
312 cfg80211_unlock_rdev(rdev
);
317 static bool is_valid_ie_attr(const struct nlattr
*attr
)
325 pos
= nla_data(attr
);
346 /* message building helper */
347 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
350 /* since there is no private header just add the generic one */
351 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
354 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
355 struct ieee80211_channel
*chan
)
357 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
360 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
361 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
362 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
363 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
364 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
365 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
366 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
367 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
369 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
370 DBM_TO_MBM(chan
->max_power
));
378 /* netlink command implementations */
385 bool def_uni
, def_multi
;
388 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
390 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
391 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
396 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
397 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
406 if (tb
[NL80211_KEY_IDX
])
407 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
409 if (tb
[NL80211_KEY_DATA
]) {
410 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
411 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
414 if (tb
[NL80211_KEY_SEQ
]) {
415 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
416 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
419 if (tb
[NL80211_KEY_CIPHER
])
420 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
422 if (tb
[NL80211_KEY_TYPE
]) {
423 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
424 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
428 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
429 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
430 int err
= nla_parse_nested(kdt
,
431 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
432 tb
[NL80211_KEY_DEFAULT_TYPES
],
433 nl80211_key_default_policy
);
437 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
438 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
444 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
446 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
447 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
448 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
451 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
452 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
453 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
456 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
457 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
459 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
460 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
462 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
463 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
472 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
473 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
474 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
478 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
479 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
480 int err
= nla_parse_nested(
481 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
482 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
483 nl80211_key_default_policy
);
487 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
488 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
494 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
498 memset(k
, 0, sizeof(*k
));
502 if (info
->attrs
[NL80211_ATTR_KEY
])
503 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
505 err
= nl80211_parse_key_old(info
, k
);
510 if (k
->def
&& k
->defmgmt
)
514 if (k
->def_uni
|| !k
->def_multi
)
520 if (k
->idx
< 4 || k
->idx
> 5)
523 if (k
->idx
< 0 || k
->idx
> 3)
526 if (k
->idx
< 0 || k
->idx
> 5)
534 static struct cfg80211_cached_keys
*
535 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
538 struct key_parse parse
;
540 struct cfg80211_cached_keys
*result
;
541 int rem
, err
, def
= 0;
543 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
545 return ERR_PTR(-ENOMEM
);
548 result
->defmgmt
= -1;
550 nla_for_each_nested(key
, keys
, rem
) {
551 memset(&parse
, 0, sizeof(parse
));
554 err
= nl80211_parse_key_new(key
, &parse
);
560 if (parse
.idx
< 0 || parse
.idx
> 4)
566 result
->def
= parse
.idx
;
567 if (!parse
.def_uni
|| !parse
.def_multi
)
569 } else if (parse
.defmgmt
)
571 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
572 parse
.idx
, false, NULL
);
575 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
576 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
577 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
578 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
587 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
589 ASSERT_WDEV_LOCK(wdev
);
591 switch (wdev
->iftype
) {
592 case NL80211_IFTYPE_AP
:
593 case NL80211_IFTYPE_AP_VLAN
:
594 case NL80211_IFTYPE_P2P_GO
:
595 case NL80211_IFTYPE_MESH_POINT
:
597 case NL80211_IFTYPE_ADHOC
:
598 if (!wdev
->current_bss
)
601 case NL80211_IFTYPE_STATION
:
602 case NL80211_IFTYPE_P2P_CLIENT
:
603 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
613 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
615 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
619 goto nla_put_failure
;
624 NLA_PUT_FLAG(msg
, i
);
629 nla_nest_end(msg
, nl_modes
);
636 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
639 struct nlattr
*nl_combis
;
642 nl_combis
= nla_nest_start(msg
,
643 NL80211_ATTR_INTERFACE_COMBINATIONS
);
645 goto nla_put_failure
;
647 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
648 const struct ieee80211_iface_combination
*c
;
649 struct nlattr
*nl_combi
, *nl_limits
;
651 c
= &wiphy
->iface_combinations
[i
];
653 nl_combi
= nla_nest_start(msg
, i
+ 1);
655 goto nla_put_failure
;
657 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
659 goto nla_put_failure
;
661 for (j
= 0; j
< c
->n_limits
; j
++) {
662 struct nlattr
*nl_limit
;
664 nl_limit
= nla_nest_start(msg
, j
+ 1);
666 goto nla_put_failure
;
667 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
669 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
671 goto nla_put_failure
;
672 nla_nest_end(msg
, nl_limit
);
675 nla_nest_end(msg
, nl_limits
);
677 if (c
->beacon_int_infra_match
)
679 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
680 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
681 c
->num_different_channels
);
682 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
685 nla_nest_end(msg
, nl_combi
);
688 nla_nest_end(msg
, nl_combis
);
695 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
696 struct cfg80211_registered_device
*dev
)
699 struct nlattr
*nl_bands
, *nl_band
;
700 struct nlattr
*nl_freqs
, *nl_freq
;
701 struct nlattr
*nl_rates
, *nl_rate
;
702 struct nlattr
*nl_cmds
;
703 enum ieee80211_band band
;
704 struct ieee80211_channel
*chan
;
705 struct ieee80211_rate
*rate
;
707 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
708 dev
->wiphy
.mgmt_stypes
;
710 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
714 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
715 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
717 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
718 cfg80211_rdev_list_generation
);
720 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
721 dev
->wiphy
.retry_short
);
722 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
723 dev
->wiphy
.retry_long
);
724 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
725 dev
->wiphy
.frag_threshold
);
726 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
727 dev
->wiphy
.rts_threshold
);
728 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
729 dev
->wiphy
.coverage_class
);
730 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
731 dev
->wiphy
.max_scan_ssids
);
732 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
733 dev
->wiphy
.max_sched_scan_ssids
);
734 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
735 dev
->wiphy
.max_scan_ie_len
);
736 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
737 dev
->wiphy
.max_sched_scan_ie_len
);
738 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
739 dev
->wiphy
.max_match_sets
);
741 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
742 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
743 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
744 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
745 if (dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
)
746 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
);
747 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)
748 NLA_PUT_FLAG(msg
, NL80211_ATTR_ROAM_SUPPORT
);
749 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
)
750 NLA_PUT_FLAG(msg
, NL80211_ATTR_TDLS_SUPPORT
);
751 if (dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
)
752 NLA_PUT_FLAG(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
);
754 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
755 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
756 dev
->wiphy
.cipher_suites
);
758 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
759 dev
->wiphy
.max_num_pmkids
);
761 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
762 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
764 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
765 dev
->wiphy
.available_antennas_tx
);
766 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
767 dev
->wiphy
.available_antennas_rx
);
769 if (dev
->wiphy
.flags
& WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
)
770 NLA_PUT_U32(msg
, NL80211_ATTR_PROBE_RESP_OFFLOAD
,
771 dev
->wiphy
.probe_resp_offload
);
773 if ((dev
->wiphy
.available_antennas_tx
||
774 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
775 u32 tx_ant
= 0, rx_ant
= 0;
777 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
779 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
780 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
784 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
785 dev
->wiphy
.interface_modes
))
786 goto nla_put_failure
;
788 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
790 goto nla_put_failure
;
792 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
793 if (!dev
->wiphy
.bands
[band
])
796 nl_band
= nla_nest_start(msg
, band
);
798 goto nla_put_failure
;
801 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
802 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
803 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
804 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
805 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
806 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
807 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
808 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
809 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
810 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
813 /* add frequencies */
814 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
816 goto nla_put_failure
;
818 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
819 nl_freq
= nla_nest_start(msg
, i
);
821 goto nla_put_failure
;
823 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
825 if (nl80211_msg_put_channel(msg
, chan
))
826 goto nla_put_failure
;
828 nla_nest_end(msg
, nl_freq
);
831 nla_nest_end(msg
, nl_freqs
);
834 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
836 goto nla_put_failure
;
838 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
839 nl_rate
= nla_nest_start(msg
, i
);
841 goto nla_put_failure
;
843 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
844 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
846 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
848 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
850 nla_nest_end(msg
, nl_rate
);
853 nla_nest_end(msg
, nl_rates
);
855 nla_nest_end(msg
, nl_band
);
857 nla_nest_end(msg
, nl_bands
);
859 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
861 goto nla_put_failure
;
866 if (dev->ops->op) { \
868 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
872 CMD(add_virtual_intf
, NEW_INTERFACE
);
873 CMD(change_virtual_intf
, SET_INTERFACE
);
874 CMD(add_key
, NEW_KEY
);
875 CMD(add_beacon
, NEW_BEACON
);
876 CMD(add_station
, NEW_STATION
);
877 CMD(add_mpath
, NEW_MPATH
);
878 CMD(update_mesh_config
, SET_MESH_CONFIG
);
879 CMD(change_bss
, SET_BSS
);
880 CMD(auth
, AUTHENTICATE
);
881 CMD(assoc
, ASSOCIATE
);
882 CMD(deauth
, DEAUTHENTICATE
);
883 CMD(disassoc
, DISASSOCIATE
);
884 CMD(join_ibss
, JOIN_IBSS
);
885 CMD(join_mesh
, JOIN_MESH
);
886 CMD(set_pmksa
, SET_PMKSA
);
887 CMD(del_pmksa
, DEL_PMKSA
);
888 CMD(flush_pmksa
, FLUSH_PMKSA
);
889 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
890 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
891 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
893 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
894 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
896 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
898 CMD(set_channel
, SET_CHANNEL
);
899 CMD(set_wds_peer
, SET_WDS_PEER
);
900 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
901 CMD(tdls_mgmt
, TDLS_MGMT
);
902 CMD(tdls_oper
, TDLS_OPER
);
904 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
905 CMD(sched_scan_start
, START_SCHED_SCAN
);
906 CMD(probe_client
, PROBE_CLIENT
);
907 CMD(set_noack_map
, SET_NOACK_MAP
);
908 if (dev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
) {
910 NLA_PUT_U32(msg
, i
, NL80211_CMD_REGISTER_BEACONS
);
913 #ifdef CONFIG_NL80211_TESTMODE
914 CMD(testmode_cmd
, TESTMODE
);
919 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
921 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
924 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
926 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
929 nla_nest_end(msg
, nl_cmds
);
931 if (dev
->ops
->remain_on_channel
&&
932 dev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
)
933 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
934 dev
->wiphy
.max_remain_on_channel_duration
);
936 if (dev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
)
937 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
941 struct nlattr
*nl_ftypes
, *nl_ifs
;
942 enum nl80211_iftype ift
;
944 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
946 goto nla_put_failure
;
948 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
949 nl_ftypes
= nla_nest_start(msg
, ift
);
951 goto nla_put_failure
;
953 stypes
= mgmt_stypes
[ift
].tx
;
956 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
957 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
961 nla_nest_end(msg
, nl_ftypes
);
964 nla_nest_end(msg
, nl_ifs
);
966 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
968 goto nla_put_failure
;
970 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
971 nl_ftypes
= nla_nest_start(msg
, ift
);
973 goto nla_put_failure
;
975 stypes
= mgmt_stypes
[ift
].rx
;
978 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
979 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
983 nla_nest_end(msg
, nl_ftypes
);
985 nla_nest_end(msg
, nl_ifs
);
988 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
989 struct nlattr
*nl_wowlan
;
991 nl_wowlan
= nla_nest_start(msg
,
992 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
994 goto nla_put_failure
;
996 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
997 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
998 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
999 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
1000 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
1001 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
1002 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
)
1003 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
);
1004 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
)
1005 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
1006 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
)
1007 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
1008 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
)
1009 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
1010 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
)
1011 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
1012 if (dev
->wiphy
.wowlan
.n_patterns
) {
1013 struct nl80211_wowlan_pattern_support pat
= {
1014 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
1016 dev
->wiphy
.wowlan
.pattern_min_len
,
1018 dev
->wiphy
.wowlan
.pattern_max_len
,
1020 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1024 nla_nest_end(msg
, nl_wowlan
);
1027 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1028 dev
->wiphy
.software_iftypes
))
1029 goto nla_put_failure
;
1031 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1032 goto nla_put_failure
;
1034 if (dev
->wiphy
.flags
& WIPHY_FLAG_HAVE_AP_SME
)
1035 NLA_PUT_U32(msg
, NL80211_ATTR_DEVICE_AP_SME
,
1036 dev
->wiphy
.ap_sme_capa
);
1038 NLA_PUT_U32(msg
, NL80211_ATTR_FEATURE_FLAGS
, dev
->wiphy
.features
);
1040 if (dev
->wiphy
.ht_capa_mod_mask
)
1041 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
,
1042 sizeof(*dev
->wiphy
.ht_capa_mod_mask
),
1043 dev
->wiphy
.ht_capa_mod_mask
);
1045 return genlmsg_end(msg
, hdr
);
1048 genlmsg_cancel(msg
, hdr
);
1052 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1055 int start
= cb
->args
[0];
1056 struct cfg80211_registered_device
*dev
;
1058 mutex_lock(&cfg80211_mutex
);
1059 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1060 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1064 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1065 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1071 mutex_unlock(&cfg80211_mutex
);
1078 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1080 struct sk_buff
*msg
;
1081 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1083 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1087 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1092 return genlmsg_reply(msg
, info
);
1095 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1096 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1097 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1098 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1099 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1100 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1103 static int parse_txq_params(struct nlattr
*tb
[],
1104 struct ieee80211_txq_params
*txq_params
)
1106 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1107 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1108 !tb
[NL80211_TXQ_ATTR_AIFS
])
1111 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1112 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1113 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1114 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1115 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1120 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1123 * You can only set the channel explicitly for AP, mesh
1124 * and WDS type interfaces; all others have their channel
1125 * managed via their respective "establish a connection"
1126 * command (connect, join, ...)
1128 * Monitors are special as they are normally slaved to
1129 * whatever else is going on, so they behave as though
1130 * you tried setting the wiphy channel itself.
1133 wdev
->iftype
== NL80211_IFTYPE_AP
||
1134 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1135 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1136 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1137 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1140 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1141 struct wireless_dev
*wdev
,
1142 struct genl_info
*info
)
1144 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1148 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1151 if (!nl80211_can_set_dev_channel(wdev
))
1154 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1155 channel_type
= nla_get_u32(info
->attrs
[
1156 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1157 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1158 channel_type
!= NL80211_CHAN_HT20
&&
1159 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1160 channel_type
!= NL80211_CHAN_HT40MINUS
)
1164 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1166 mutex_lock(&rdev
->devlist_mtx
);
1169 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1172 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1174 mutex_unlock(&rdev
->devlist_mtx
);
1179 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1181 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1182 struct net_device
*netdev
= info
->user_ptr
[1];
1184 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1187 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1189 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1190 struct net_device
*dev
= info
->user_ptr
[1];
1191 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1194 if (!info
->attrs
[NL80211_ATTR_MAC
])
1197 if (netif_running(dev
))
1200 if (!rdev
->ops
->set_wds_peer
)
1203 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1206 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1207 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1211 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1213 struct cfg80211_registered_device
*rdev
;
1214 struct net_device
*netdev
= NULL
;
1215 struct wireless_dev
*wdev
;
1216 int result
= 0, rem_txq_params
= 0;
1217 struct nlattr
*nl_txq_params
;
1219 u8 retry_short
= 0, retry_long
= 0;
1220 u32 frag_threshold
= 0, rts_threshold
= 0;
1221 u8 coverage_class
= 0;
1224 * Try to find the wiphy and netdev. Normally this
1225 * function shouldn't need the netdev, but this is
1226 * done for backward compatibility -- previously
1227 * setting the channel was done per wiphy, but now
1228 * it is per netdev. Previous userland like hostapd
1229 * also passed a netdev to set_wiphy, so that it is
1230 * possible to let that go to the right netdev!
1232 mutex_lock(&cfg80211_mutex
);
1234 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1235 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1237 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1238 if (netdev
&& netdev
->ieee80211_ptr
) {
1239 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1240 mutex_lock(&rdev
->mtx
);
1246 rdev
= __cfg80211_rdev_from_info(info
);
1248 mutex_unlock(&cfg80211_mutex
);
1249 return PTR_ERR(rdev
);
1255 mutex_lock(&rdev
->mtx
);
1256 } else if (netif_running(netdev
) &&
1257 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1258 wdev
= netdev
->ieee80211_ptr
;
1263 * end workaround code, by now the rdev is available
1264 * and locked, and wdev may or may not be NULL.
1267 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1268 result
= cfg80211_dev_rename(
1269 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1271 mutex_unlock(&cfg80211_mutex
);
1276 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1277 struct ieee80211_txq_params txq_params
;
1278 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1280 if (!rdev
->ops
->set_txq_params
) {
1281 result
= -EOPNOTSUPP
;
1290 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1291 netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
) {
1296 if (!netif_running(netdev
)) {
1301 nla_for_each_nested(nl_txq_params
,
1302 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1304 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1305 nla_data(nl_txq_params
),
1306 nla_len(nl_txq_params
),
1308 result
= parse_txq_params(tb
, &txq_params
);
1312 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1320 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1321 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1326 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1327 enum nl80211_tx_power_setting type
;
1330 if (!rdev
->ops
->set_tx_power
) {
1331 result
= -EOPNOTSUPP
;
1335 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1336 type
= nla_get_u32(info
->attrs
[idx
]);
1338 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1339 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1344 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1345 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1346 mbm
= nla_get_u32(info
->attrs
[idx
]);
1349 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1354 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1355 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1357 if ((!rdev
->wiphy
.available_antennas_tx
&&
1358 !rdev
->wiphy
.available_antennas_rx
) ||
1359 !rdev
->ops
->set_antenna
) {
1360 result
= -EOPNOTSUPP
;
1364 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1365 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1367 /* reject antenna configurations which don't match the
1368 * available antenna masks, except for the "all" mask */
1369 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1370 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1375 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1376 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1378 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1385 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1386 retry_short
= nla_get_u8(
1387 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1388 if (retry_short
== 0) {
1392 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1395 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1396 retry_long
= nla_get_u8(
1397 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1398 if (retry_long
== 0) {
1402 changed
|= WIPHY_PARAM_RETRY_LONG
;
1405 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1406 frag_threshold
= nla_get_u32(
1407 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1408 if (frag_threshold
< 256) {
1412 if (frag_threshold
!= (u32
) -1) {
1414 * Fragments (apart from the last one) are required to
1415 * have even length. Make the fragmentation code
1416 * simpler by stripping LSB should someone try to use
1417 * odd threshold value.
1419 frag_threshold
&= ~0x1;
1421 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1424 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1425 rts_threshold
= nla_get_u32(
1426 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1427 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1430 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1431 coverage_class
= nla_get_u8(
1432 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1433 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1437 u8 old_retry_short
, old_retry_long
;
1438 u32 old_frag_threshold
, old_rts_threshold
;
1439 u8 old_coverage_class
;
1441 if (!rdev
->ops
->set_wiphy_params
) {
1442 result
= -EOPNOTSUPP
;
1446 old_retry_short
= rdev
->wiphy
.retry_short
;
1447 old_retry_long
= rdev
->wiphy
.retry_long
;
1448 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1449 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1450 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1452 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1453 rdev
->wiphy
.retry_short
= retry_short
;
1454 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1455 rdev
->wiphy
.retry_long
= retry_long
;
1456 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1457 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1458 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1459 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1460 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1461 rdev
->wiphy
.coverage_class
= coverage_class
;
1463 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1465 rdev
->wiphy
.retry_short
= old_retry_short
;
1466 rdev
->wiphy
.retry_long
= old_retry_long
;
1467 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1468 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1469 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1474 mutex_unlock(&rdev
->mtx
);
1481 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1482 struct cfg80211_registered_device
*rdev
,
1483 struct net_device
*dev
)
1487 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1491 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1492 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1493 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1494 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1496 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1497 rdev
->devlist_generation
^
1498 (cfg80211_rdev_list_generation
<< 2));
1500 return genlmsg_end(msg
, hdr
);
1503 genlmsg_cancel(msg
, hdr
);
1507 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1511 int wp_start
= cb
->args
[0];
1512 int if_start
= cb
->args
[1];
1513 struct cfg80211_registered_device
*rdev
;
1514 struct wireless_dev
*wdev
;
1516 mutex_lock(&cfg80211_mutex
);
1517 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1518 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1520 if (wp_idx
< wp_start
) {
1526 mutex_lock(&rdev
->devlist_mtx
);
1527 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1528 if (if_idx
< if_start
) {
1532 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1533 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1534 rdev
, wdev
->netdev
) < 0) {
1535 mutex_unlock(&rdev
->devlist_mtx
);
1540 mutex_unlock(&rdev
->devlist_mtx
);
1545 mutex_unlock(&cfg80211_mutex
);
1547 cb
->args
[0] = wp_idx
;
1548 cb
->args
[1] = if_idx
;
1553 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1555 struct sk_buff
*msg
;
1556 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1557 struct net_device
*netdev
= info
->user_ptr
[1];
1559 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1563 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1569 return genlmsg_reply(msg
, info
);
1572 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1573 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1574 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1575 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1576 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1577 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1580 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1582 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1590 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1591 nla
, mntr_flags_policy
))
1594 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1596 *mntrflags
|= (1<<flag
);
1601 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1602 struct net_device
*netdev
, u8 use_4addr
,
1603 enum nl80211_iftype iftype
)
1606 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1612 case NL80211_IFTYPE_AP_VLAN
:
1613 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1616 case NL80211_IFTYPE_STATION
:
1617 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1627 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1629 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1630 struct vif_params params
;
1632 enum nl80211_iftype otype
, ntype
;
1633 struct net_device
*dev
= info
->user_ptr
[1];
1634 u32 _flags
, *flags
= NULL
;
1635 bool change
= false;
1637 memset(¶ms
, 0, sizeof(params
));
1639 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1641 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1642 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1645 if (ntype
> NL80211_IFTYPE_MAX
)
1649 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1650 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1652 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1654 if (netif_running(dev
))
1658 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1659 IEEE80211_MAX_MESH_ID_LEN
);
1660 wdev
->mesh_id_up_len
=
1661 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1662 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1663 wdev
->mesh_id_up_len
);
1667 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1668 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1670 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1674 params
.use_4addr
= -1;
1677 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1678 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1680 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1690 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1694 if (!err
&& params
.use_4addr
!= -1)
1695 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1700 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1702 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1703 struct vif_params params
;
1704 struct net_device
*dev
;
1706 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1709 memset(¶ms
, 0, sizeof(params
));
1711 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1714 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1715 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1716 if (type
> NL80211_IFTYPE_MAX
)
1720 if (!rdev
->ops
->add_virtual_intf
||
1721 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1724 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1725 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1726 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1731 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1732 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1734 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1735 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1736 type
, err
? NULL
: &flags
, ¶ms
);
1738 return PTR_ERR(dev
);
1740 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1741 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1742 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1745 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1746 IEEE80211_MAX_MESH_ID_LEN
);
1747 wdev
->mesh_id_up_len
=
1748 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1749 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1750 wdev
->mesh_id_up_len
);
1757 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1759 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1760 struct net_device
*dev
= info
->user_ptr
[1];
1762 if (!rdev
->ops
->del_virtual_intf
)
1765 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1768 static int nl80211_set_noack_map(struct sk_buff
*skb
, struct genl_info
*info
)
1770 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1771 struct net_device
*dev
= info
->user_ptr
[1];
1774 if (!info
->attrs
[NL80211_ATTR_NOACK_MAP
])
1777 if (!rdev
->ops
->set_noack_map
)
1780 noack_map
= nla_get_u16(info
->attrs
[NL80211_ATTR_NOACK_MAP
]);
1782 return rdev
->ops
->set_noack_map(&rdev
->wiphy
, dev
, noack_map
);
1785 struct get_key_cookie
{
1786 struct sk_buff
*msg
;
1791 static void get_key_callback(void *c
, struct key_params
*params
)
1794 struct get_key_cookie
*cookie
= c
;
1797 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1798 params
->key_len
, params
->key
);
1801 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1802 params
->seq_len
, params
->seq
);
1805 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1808 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1810 goto nla_put_failure
;
1813 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1814 params
->key_len
, params
->key
);
1817 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1818 params
->seq_len
, params
->seq
);
1821 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1824 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1826 nla_nest_end(cookie
->msg
, key
);
1833 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1835 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1837 struct net_device
*dev
= info
->user_ptr
[1];
1839 const u8
*mac_addr
= NULL
;
1841 struct get_key_cookie cookie
= {
1845 struct sk_buff
*msg
;
1847 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1848 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1853 if (info
->attrs
[NL80211_ATTR_MAC
])
1854 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1856 pairwise
= !!mac_addr
;
1857 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1858 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1859 if (kt
>= NUM_NL80211_KEYTYPES
)
1861 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1862 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1864 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1867 if (!rdev
->ops
->get_key
)
1870 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1874 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1875 NL80211_CMD_NEW_KEY
);
1877 return PTR_ERR(hdr
);
1880 cookie
.idx
= key_idx
;
1882 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1883 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1885 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1887 if (pairwise
&& mac_addr
&&
1888 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1891 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1892 mac_addr
, &cookie
, get_key_callback
);
1898 goto nla_put_failure
;
1900 genlmsg_end(msg
, hdr
);
1901 return genlmsg_reply(msg
, info
);
1910 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1912 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1913 struct key_parse key
;
1915 struct net_device
*dev
= info
->user_ptr
[1];
1917 err
= nl80211_parse_key(info
, &key
);
1924 /* only support setting default key */
1925 if (!key
.def
&& !key
.defmgmt
)
1928 wdev_lock(dev
->ieee80211_ptr
);
1931 if (!rdev
->ops
->set_default_key
) {
1936 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1940 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1941 key
.def_uni
, key
.def_multi
);
1946 #ifdef CONFIG_CFG80211_WEXT
1947 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1950 if (key
.def_uni
|| !key
.def_multi
) {
1955 if (!rdev
->ops
->set_default_mgmt_key
) {
1960 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1964 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1969 #ifdef CONFIG_CFG80211_WEXT
1970 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1975 wdev_unlock(dev
->ieee80211_ptr
);
1980 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1982 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1984 struct net_device
*dev
= info
->user_ptr
[1];
1985 struct key_parse key
;
1986 const u8
*mac_addr
= NULL
;
1988 err
= nl80211_parse_key(info
, &key
);
1995 if (info
->attrs
[NL80211_ATTR_MAC
])
1996 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1998 if (key
.type
== -1) {
2000 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2002 key
.type
= NL80211_KEYTYPE_GROUP
;
2006 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2007 key
.type
!= NL80211_KEYTYPE_GROUP
)
2010 if (!rdev
->ops
->add_key
)
2013 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
2014 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2018 wdev_lock(dev
->ieee80211_ptr
);
2019 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2021 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
2022 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2024 wdev_unlock(dev
->ieee80211_ptr
);
2029 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
2031 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2033 struct net_device
*dev
= info
->user_ptr
[1];
2034 u8
*mac_addr
= NULL
;
2035 struct key_parse key
;
2037 err
= nl80211_parse_key(info
, &key
);
2041 if (info
->attrs
[NL80211_ATTR_MAC
])
2042 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2044 if (key
.type
== -1) {
2046 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
2048 key
.type
= NL80211_KEYTYPE_GROUP
;
2052 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
2053 key
.type
!= NL80211_KEYTYPE_GROUP
)
2056 if (!rdev
->ops
->del_key
)
2059 wdev_lock(dev
->ieee80211_ptr
);
2060 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2062 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2063 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2067 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2068 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2071 #ifdef CONFIG_CFG80211_WEXT
2073 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2074 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2075 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2076 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2079 wdev_unlock(dev
->ieee80211_ptr
);
2084 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2086 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
2087 struct beacon_parameters
*info
);
2088 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2089 struct net_device
*dev
= info
->user_ptr
[1];
2090 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2091 struct beacon_parameters params
;
2092 int haveinfo
= 0, err
;
2094 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2095 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2096 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2097 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2100 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2101 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2104 memset(¶ms
, 0, sizeof(params
));
2106 switch (info
->genlhdr
->cmd
) {
2107 case NL80211_CMD_NEW_BEACON
:
2108 /* these are required for NEW_BEACON */
2109 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2110 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2111 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2115 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2116 params
.dtim_period
=
2117 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2119 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
2124 * In theory, some of these attributes could be required for
2125 * NEW_BEACON, but since they were not used when the command was
2126 * originally added, keep them optional for old user space
2127 * programs to work with drivers that do not need the additional
2130 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2131 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2133 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2134 if (params
.ssid_len
== 0 ||
2135 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2139 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2140 params
.hidden_ssid
= nla_get_u32(
2141 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2142 if (params
.hidden_ssid
!=
2143 NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2144 params
.hidden_ssid
!=
2145 NL80211_HIDDEN_SSID_ZERO_LEN
&&
2146 params
.hidden_ssid
!=
2147 NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2151 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2153 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2154 params
.auth_type
= nla_get_u32(
2155 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2156 if (!nl80211_valid_auth_type(params
.auth_type
))
2159 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2161 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2162 NL80211_MAX_NR_CIPHER_SUITES
);
2166 call
= rdev
->ops
->add_beacon
;
2168 case NL80211_CMD_SET_BEACON
:
2169 call
= rdev
->ops
->set_beacon
;
2179 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2180 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2182 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2186 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2187 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2189 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2196 if (info
->attrs
[NL80211_ATTR_IE
]) {
2197 params
.beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2198 params
.beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2201 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2202 params
.proberesp_ies
=
2203 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2204 params
.proberesp_ies_len
=
2205 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2208 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2209 params
.assocresp_ies
=
2210 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2211 params
.assocresp_ies_len
=
2212 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2215 if (info
->attrs
[NL80211_ATTR_PROBE_RESP
]) {
2217 nla_data(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2218 params
.probe_resp_len
=
2219 nla_len(info
->attrs
[NL80211_ATTR_PROBE_RESP
]);
2222 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2223 if (!err
&& params
.interval
)
2224 wdev
->beacon_interval
= params
.interval
;
2228 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2230 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2231 struct net_device
*dev
= info
->user_ptr
[1];
2232 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2235 if (!rdev
->ops
->del_beacon
)
2238 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2239 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2242 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2244 wdev
->beacon_interval
= 0;
2248 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2249 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2250 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2251 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2252 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2253 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2254 [NL80211_STA_FLAG_TDLS_PEER
] = { .type
= NLA_FLAG
},
2257 static int parse_station_flags(struct genl_info
*info
,
2258 enum nl80211_iftype iftype
,
2259 struct station_parameters
*params
)
2261 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2266 * Try parsing the new attribute first so userspace
2267 * can specify both for older kernels.
2269 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2271 struct nl80211_sta_flag_update
*sta_flags
;
2273 sta_flags
= nla_data(nla
);
2274 params
->sta_flags_mask
= sta_flags
->mask
;
2275 params
->sta_flags_set
= sta_flags
->set
;
2276 if ((params
->sta_flags_mask
|
2277 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2282 /* if present, parse the old attribute */
2284 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2288 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2289 nla
, sta_flags_policy
))
2293 * Only allow certain flags for interface types so that
2294 * other attributes are silently ignored. Remember that
2295 * this is backward compatibility code with old userspace
2296 * and shouldn't be hit in other cases anyway.
2299 case NL80211_IFTYPE_AP
:
2300 case NL80211_IFTYPE_AP_VLAN
:
2301 case NL80211_IFTYPE_P2P_GO
:
2302 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2303 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2304 BIT(NL80211_STA_FLAG_WME
) |
2305 BIT(NL80211_STA_FLAG_MFP
);
2307 case NL80211_IFTYPE_P2P_CLIENT
:
2308 case NL80211_IFTYPE_STATION
:
2309 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2310 BIT(NL80211_STA_FLAG_TDLS_PEER
);
2312 case NL80211_IFTYPE_MESH_POINT
:
2313 params
->sta_flags_mask
= BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2314 BIT(NL80211_STA_FLAG_MFP
) |
2315 BIT(NL80211_STA_FLAG_AUTHORIZED
);
2320 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2322 params
->sta_flags_set
|= (1<<flag
);
2327 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2330 struct nlattr
*rate
;
2333 rate
= nla_nest_start(msg
, attr
);
2335 goto nla_put_failure
;
2337 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2338 bitrate
= cfg80211_calculate_bitrate(info
);
2340 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2342 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2343 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2344 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2345 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2346 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2347 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2349 nla_nest_end(msg
, rate
);
2356 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2357 int flags
, struct net_device
*dev
,
2358 const u8
*mac_addr
, struct station_info
*sinfo
)
2361 struct nlattr
*sinfoattr
, *bss_param
;
2363 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2367 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2368 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2370 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2372 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2374 goto nla_put_failure
;
2375 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2376 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2377 sinfo
->connected_time
);
2378 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2379 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2380 sinfo
->inactive_time
);
2381 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2382 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2384 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2385 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2387 if (sinfo
->filled
& STATION_INFO_LLID
)
2388 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2390 if (sinfo
->filled
& STATION_INFO_PLID
)
2391 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2393 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2394 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2395 sinfo
->plink_state
);
2396 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2397 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2399 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2400 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2402 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2403 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2404 NL80211_STA_INFO_TX_BITRATE
))
2405 goto nla_put_failure
;
2407 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2408 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2409 NL80211_STA_INFO_RX_BITRATE
))
2410 goto nla_put_failure
;
2412 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2413 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2415 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2416 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2418 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2419 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2421 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2422 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2424 if (sinfo
->filled
& STATION_INFO_BEACON_LOSS_COUNT
)
2425 NLA_PUT_U32(msg
, NL80211_STA_INFO_BEACON_LOSS
,
2426 sinfo
->beacon_loss_count
);
2427 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2428 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2430 goto nla_put_failure
;
2432 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2433 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2434 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2435 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2436 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2438 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2439 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2440 sinfo
->bss_param
.dtim_period
);
2441 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2442 sinfo
->bss_param
.beacon_interval
);
2444 nla_nest_end(msg
, bss_param
);
2446 if (sinfo
->filled
& STATION_INFO_STA_FLAGS
)
2447 NLA_PUT(msg
, NL80211_STA_INFO_STA_FLAGS
,
2448 sizeof(struct nl80211_sta_flag_update
),
2450 nla_nest_end(msg
, sinfoattr
);
2452 if (sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
)
2453 NLA_PUT(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2454 sinfo
->assoc_req_ies
);
2456 return genlmsg_end(msg
, hdr
);
2459 genlmsg_cancel(msg
, hdr
);
2463 static int nl80211_dump_station(struct sk_buff
*skb
,
2464 struct netlink_callback
*cb
)
2466 struct station_info sinfo
;
2467 struct cfg80211_registered_device
*dev
;
2468 struct net_device
*netdev
;
2469 u8 mac_addr
[ETH_ALEN
];
2470 int sta_idx
= cb
->args
[1];
2473 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2477 if (!dev
->ops
->dump_station
) {
2483 memset(&sinfo
, 0, sizeof(sinfo
));
2484 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2491 if (nl80211_send_station(skb
,
2492 NETLINK_CB(cb
->skb
).pid
,
2493 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2503 cb
->args
[1] = sta_idx
;
2506 nl80211_finish_netdev_dump(dev
);
2511 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2513 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2514 struct net_device
*dev
= info
->user_ptr
[1];
2515 struct station_info sinfo
;
2516 struct sk_buff
*msg
;
2517 u8
*mac_addr
= NULL
;
2520 memset(&sinfo
, 0, sizeof(sinfo
));
2522 if (!info
->attrs
[NL80211_ATTR_MAC
])
2525 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2527 if (!rdev
->ops
->get_station
)
2530 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2534 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2538 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2539 dev
, mac_addr
, &sinfo
) < 0) {
2544 return genlmsg_reply(msg
, info
);
2548 * Get vlan interface making sure it is running and on the right wiphy.
2550 static struct net_device
*get_vlan(struct genl_info
*info
,
2551 struct cfg80211_registered_device
*rdev
)
2553 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2554 struct net_device
*v
;
2560 v
= dev_get_by_index(genl_info_net(info
), nla_get_u32(vlanattr
));
2562 return ERR_PTR(-ENODEV
);
2564 if (!v
->ieee80211_ptr
|| v
->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
) {
2569 if (!netif_running(v
)) {
2577 return ERR_PTR(ret
);
2580 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2582 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2584 struct net_device
*dev
= info
->user_ptr
[1];
2585 struct station_parameters params
;
2586 u8
*mac_addr
= NULL
;
2588 memset(¶ms
, 0, sizeof(params
));
2590 params
.listen_interval
= -1;
2591 params
.plink_state
= -1;
2593 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2596 if (!info
->attrs
[NL80211_ATTR_MAC
])
2599 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2601 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2602 params
.supported_rates
=
2603 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2604 params
.supported_rates_len
=
2605 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2608 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2609 params
.listen_interval
=
2610 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2612 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2614 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2616 if (!rdev
->ops
->change_station
)
2619 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
2622 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2623 params
.plink_action
=
2624 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2626 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2627 params
.plink_state
=
2628 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2630 switch (dev
->ieee80211_ptr
->iftype
) {
2631 case NL80211_IFTYPE_AP
:
2632 case NL80211_IFTYPE_AP_VLAN
:
2633 case NL80211_IFTYPE_P2P_GO
:
2634 /* disallow mesh-specific things */
2635 if (params
.plink_action
)
2638 /* TDLS can't be set, ... */
2639 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
2642 * ... but don't bother the driver with it. This works around
2643 * a hostapd/wpa_supplicant issue -- it always includes the
2644 * TLDS_PEER flag in the mask even for AP mode.
2646 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2648 /* accept only the listed bits */
2649 if (params
.sta_flags_mask
&
2650 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2651 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
) |
2652 BIT(NL80211_STA_FLAG_WME
) |
2653 BIT(NL80211_STA_FLAG_MFP
)))
2656 /* must be last in here for error handling */
2657 params
.vlan
= get_vlan(info
, rdev
);
2658 if (IS_ERR(params
.vlan
))
2659 return PTR_ERR(params
.vlan
);
2661 case NL80211_IFTYPE_P2P_CLIENT
:
2662 case NL80211_IFTYPE_STATION
:
2663 /* disallow things sta doesn't support */
2664 if (params
.plink_action
)
2668 if (params
.listen_interval
>= 0)
2671 * Don't allow userspace to change the TDLS_PEER flag,
2672 * but silently ignore attempts to change it since we
2673 * don't have state here to verify that it doesn't try
2674 * to change the flag.
2676 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2678 /* reject any changes other than AUTHORIZED */
2679 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2682 case NL80211_IFTYPE_MESH_POINT
:
2683 /* disallow things mesh doesn't support */
2688 if (params
.listen_interval
>= 0)
2691 * No special handling for TDLS here -- the userspace
2692 * mesh code doesn't have this bug.
2694 if (params
.sta_flags_mask
&
2695 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2696 BIT(NL80211_STA_FLAG_MFP
) |
2697 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2704 /* be aware of params.vlan when changing code here */
2706 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2709 dev_put(params
.vlan
);
2714 static struct nla_policy
2715 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
2716 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
2717 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
2720 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2722 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2724 struct net_device
*dev
= info
->user_ptr
[1];
2725 struct station_parameters params
;
2726 u8
*mac_addr
= NULL
;
2728 memset(¶ms
, 0, sizeof(params
));
2730 if (!info
->attrs
[NL80211_ATTR_MAC
])
2733 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2736 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2739 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2742 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2743 params
.supported_rates
=
2744 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2745 params
.supported_rates_len
=
2746 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2747 params
.listen_interval
=
2748 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2750 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2751 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2754 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2756 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2758 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2759 params
.plink_action
=
2760 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2762 if (!rdev
->ops
->add_station
)
2765 if (parse_station_flags(info
, dev
->ieee80211_ptr
->iftype
, ¶ms
))
2768 switch (dev
->ieee80211_ptr
->iftype
) {
2769 case NL80211_IFTYPE_AP
:
2770 case NL80211_IFTYPE_AP_VLAN
:
2771 case NL80211_IFTYPE_P2P_GO
:
2772 /* parse WME attributes if sta is WME capable */
2773 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
2774 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
2775 info
->attrs
[NL80211_ATTR_STA_WME
]) {
2776 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
2779 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
2780 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
2781 nl80211_sta_wme_policy
);
2785 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
2786 params
.uapsd_queues
=
2787 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
2788 if (params
.uapsd_queues
&
2789 ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
2792 if (tb
[NL80211_STA_WME_MAX_SP
])
2794 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
2797 ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
2800 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
2802 /* TDLS peers cannot be added */
2803 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
2805 /* but don't bother the driver with it */
2806 params
.sta_flags_mask
&= ~BIT(NL80211_STA_FLAG_TDLS_PEER
);
2808 /* must be last in here for error handling */
2809 params
.vlan
= get_vlan(info
, rdev
);
2810 if (IS_ERR(params
.vlan
))
2811 return PTR_ERR(params
.vlan
);
2813 case NL80211_IFTYPE_MESH_POINT
:
2814 /* TDLS peers cannot be added */
2815 if (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
2818 case NL80211_IFTYPE_STATION
:
2819 /* Only TDLS peers can be added */
2820 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2822 /* Can only add if TDLS ... */
2823 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
))
2825 /* ... with external setup is supported */
2826 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
))
2833 /* be aware of params.vlan when changing code here */
2835 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2838 dev_put(params
.vlan
);
2842 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2844 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2845 struct net_device
*dev
= info
->user_ptr
[1];
2846 u8
*mac_addr
= NULL
;
2848 if (info
->attrs
[NL80211_ATTR_MAC
])
2849 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2851 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2852 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2853 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2854 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2857 if (!rdev
->ops
->del_station
)
2860 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2863 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2864 int flags
, struct net_device
*dev
,
2865 u8
*dst
, u8
*next_hop
,
2866 struct mpath_info
*pinfo
)
2869 struct nlattr
*pinfoattr
;
2871 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2875 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2876 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2877 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2879 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2881 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2883 goto nla_put_failure
;
2884 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2885 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2887 if (pinfo
->filled
& MPATH_INFO_SN
)
2888 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2890 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2891 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2893 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2894 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2896 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2897 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2899 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2900 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2901 pinfo
->discovery_timeout
);
2902 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2903 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2904 pinfo
->discovery_retries
);
2906 nla_nest_end(msg
, pinfoattr
);
2908 return genlmsg_end(msg
, hdr
);
2911 genlmsg_cancel(msg
, hdr
);
2915 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2916 struct netlink_callback
*cb
)
2918 struct mpath_info pinfo
;
2919 struct cfg80211_registered_device
*dev
;
2920 struct net_device
*netdev
;
2922 u8 next_hop
[ETH_ALEN
];
2923 int path_idx
= cb
->args
[1];
2926 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2930 if (!dev
->ops
->dump_mpath
) {
2935 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2941 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2942 dst
, next_hop
, &pinfo
);
2948 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2949 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2950 netdev
, dst
, next_hop
,
2959 cb
->args
[1] = path_idx
;
2962 nl80211_finish_netdev_dump(dev
);
2966 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2968 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2970 struct net_device
*dev
= info
->user_ptr
[1];
2971 struct mpath_info pinfo
;
2972 struct sk_buff
*msg
;
2974 u8 next_hop
[ETH_ALEN
];
2976 memset(&pinfo
, 0, sizeof(pinfo
));
2978 if (!info
->attrs
[NL80211_ATTR_MAC
])
2981 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2983 if (!rdev
->ops
->get_mpath
)
2986 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2989 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2993 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2997 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2998 dev
, dst
, next_hop
, &pinfo
) < 0) {
3003 return genlmsg_reply(msg
, info
);
3006 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3008 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3009 struct net_device
*dev
= info
->user_ptr
[1];
3011 u8
*next_hop
= NULL
;
3013 if (!info
->attrs
[NL80211_ATTR_MAC
])
3016 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3019 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3020 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3022 if (!rdev
->ops
->change_mpath
)
3025 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3028 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3031 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3033 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3034 struct net_device
*dev
= info
->user_ptr
[1];
3036 u8
*next_hop
= NULL
;
3038 if (!info
->attrs
[NL80211_ATTR_MAC
])
3041 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
3044 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3045 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
3047 if (!rdev
->ops
->add_mpath
)
3050 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3053 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
3056 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
3058 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3059 struct net_device
*dev
= info
->user_ptr
[1];
3062 if (info
->attrs
[NL80211_ATTR_MAC
])
3063 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3065 if (!rdev
->ops
->del_mpath
)
3068 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
3071 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
3073 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3074 struct net_device
*dev
= info
->user_ptr
[1];
3075 struct bss_parameters params
;
3077 memset(¶ms
, 0, sizeof(params
));
3078 /* default to not changing parameters */
3079 params
.use_cts_prot
= -1;
3080 params
.use_short_preamble
= -1;
3081 params
.use_short_slot_time
= -1;
3082 params
.ap_isolate
= -1;
3083 params
.ht_opmode
= -1;
3085 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
3086 params
.use_cts_prot
=
3087 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
3088 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
3089 params
.use_short_preamble
=
3090 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
3091 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
3092 params
.use_short_slot_time
=
3093 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
3094 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3095 params
.basic_rates
=
3096 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3097 params
.basic_rates_len
=
3098 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3100 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
3101 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
3102 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
3104 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
3106 if (!rdev
->ops
->change_bss
)
3109 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
3110 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
3113 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
3116 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
3117 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
3118 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
3119 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
3120 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
3121 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
3122 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
3125 static int parse_reg_rule(struct nlattr
*tb
[],
3126 struct ieee80211_reg_rule
*reg_rule
)
3128 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
3129 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
3131 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3133 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3135 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3137 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3139 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3142 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3144 freq_range
->start_freq_khz
=
3145 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3146 freq_range
->end_freq_khz
=
3147 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3148 freq_range
->max_bandwidth_khz
=
3149 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3151 power_rule
->max_eirp
=
3152 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3154 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3155 power_rule
->max_antenna_gain
=
3156 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3161 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3167 * You should only get this when cfg80211 hasn't yet initialized
3168 * completely when built-in to the kernel right between the time
3169 * window between nl80211_init() and regulatory_init(), if that is
3172 mutex_lock(&cfg80211_mutex
);
3173 if (unlikely(!cfg80211_regdomain
)) {
3174 mutex_unlock(&cfg80211_mutex
);
3175 return -EINPROGRESS
;
3177 mutex_unlock(&cfg80211_mutex
);
3179 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3182 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3184 r
= regulatory_hint_user(data
);
3189 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3190 struct genl_info
*info
)
3192 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3193 struct net_device
*dev
= info
->user_ptr
[1];
3194 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3195 struct mesh_config cur_params
;
3198 struct nlattr
*pinfoattr
;
3199 struct sk_buff
*msg
;
3201 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3204 if (!rdev
->ops
->get_mesh_config
)
3208 /* If not connected, get default parameters */
3209 if (!wdev
->mesh_id_len
)
3210 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3212 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3219 /* Draw up a netlink message to send back */
3220 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3223 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3224 NL80211_CMD_GET_MESH_CONFIG
);
3227 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3229 goto nla_put_failure
;
3230 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3231 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3232 cur_params
.dot11MeshRetryTimeout
);
3233 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3234 cur_params
.dot11MeshConfirmTimeout
);
3235 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3236 cur_params
.dot11MeshHoldingTimeout
);
3237 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3238 cur_params
.dot11MeshMaxPeerLinks
);
3239 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3240 cur_params
.dot11MeshMaxRetries
);
3241 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
3242 cur_params
.dot11MeshTTL
);
3243 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3244 cur_params
.element_ttl
);
3245 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3246 cur_params
.auto_open_plinks
);
3247 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3248 cur_params
.dot11MeshHWMPmaxPREQretries
);
3249 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3250 cur_params
.path_refresh_time
);
3251 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3252 cur_params
.min_discovery_timeout
);
3253 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3254 cur_params
.dot11MeshHWMPactivePathTimeout
);
3255 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3256 cur_params
.dot11MeshHWMPpreqMinInterval
);
3257 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3258 cur_params
.dot11MeshHWMPperrMinInterval
);
3259 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3260 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
3261 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3262 cur_params
.dot11MeshHWMPRootMode
);
3263 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3264 cur_params
.dot11MeshHWMPRannInterval
);
3265 NLA_PUT_U8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3266 cur_params
.dot11MeshGateAnnouncementProtocol
);
3267 nla_nest_end(msg
, pinfoattr
);
3268 genlmsg_end(msg
, hdr
);
3269 return genlmsg_reply(msg
, info
);
3272 genlmsg_cancel(msg
, hdr
);
3278 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3279 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3280 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3281 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3282 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3283 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3284 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3285 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3286 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3288 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3289 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3290 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3291 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3292 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3293 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
] = { .type
= NLA_U16
},
3294 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3295 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3296 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3297 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3300 static const struct nla_policy
3301 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3302 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3303 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3304 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3305 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3306 .len
= IEEE80211_MAX_DATA_LEN
},
3307 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3310 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3311 struct mesh_config
*cfg
,
3314 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3317 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3319 if (table[attr_num]) {\
3320 cfg->param = nla_fn(table[attr_num]); \
3321 mask |= (1 << (attr_num - 1)); \
3326 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3328 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3329 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3330 nl80211_meshconf_params_policy
))
3333 /* This makes sure that there aren't more than 32 mesh config
3334 * parameters (otherwise our bitfield scheme would not work.) */
3335 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3337 /* Fill in the params struct */
3338 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3339 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
3340 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3341 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3342 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3343 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3344 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3345 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3346 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3347 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3348 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3349 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3350 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3351 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3352 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3353 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3354 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3355 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3357 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3358 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3359 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3360 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3362 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3363 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3365 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3366 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3368 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPperrMinInterval
,
3369 mask
, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL
,
3371 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3372 dot11MeshHWMPnetDiameterTraversalTime
,
3373 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3375 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3376 dot11MeshHWMPRootMode
, mask
,
3377 NL80211_MESHCONF_HWMP_ROOTMODE
,
3379 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3380 dot11MeshHWMPRannInterval
, mask
,
3381 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3383 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3384 dot11MeshGateAnnouncementProtocol
, mask
,
3385 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3392 #undef FILL_IN_MESH_PARAM_IF_SET
3395 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3396 struct mesh_setup
*setup
)
3398 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3400 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3402 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3403 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3404 nl80211_mesh_setup_params_policy
))
3407 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3408 setup
->path_sel_proto
=
3409 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3410 IEEE80211_PATH_PROTOCOL_VENDOR
:
3411 IEEE80211_PATH_PROTOCOL_HWMP
;
3413 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3414 setup
->path_metric
=
3415 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3416 IEEE80211_PATH_METRIC_VENDOR
:
3417 IEEE80211_PATH_METRIC_AIRTIME
;
3420 if (tb
[NL80211_MESH_SETUP_IE
]) {
3421 struct nlattr
*ieattr
=
3422 tb
[NL80211_MESH_SETUP_IE
];
3423 if (!is_valid_ie_attr(ieattr
))
3425 setup
->ie
= nla_data(ieattr
);
3426 setup
->ie_len
= nla_len(ieattr
);
3428 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3429 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3434 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3435 struct genl_info
*info
)
3437 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3438 struct net_device
*dev
= info
->user_ptr
[1];
3439 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3440 struct mesh_config cfg
;
3444 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3447 if (!rdev
->ops
->update_mesh_config
)
3450 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3455 if (!wdev
->mesh_id_len
)
3459 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3467 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3469 struct sk_buff
*msg
;
3471 struct nlattr
*nl_reg_rules
;
3475 mutex_lock(&cfg80211_mutex
);
3477 if (!cfg80211_regdomain
)
3480 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3486 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3487 NL80211_CMD_GET_REG
);
3491 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3492 cfg80211_regdomain
->alpha2
);
3493 if (cfg80211_regdomain
->dfs_region
)
3494 NLA_PUT_U8(msg
, NL80211_ATTR_DFS_REGION
,
3495 cfg80211_regdomain
->dfs_region
);
3497 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3499 goto nla_put_failure
;
3501 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3502 struct nlattr
*nl_reg_rule
;
3503 const struct ieee80211_reg_rule
*reg_rule
;
3504 const struct ieee80211_freq_range
*freq_range
;
3505 const struct ieee80211_power_rule
*power_rule
;
3507 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3508 freq_range
= ®_rule
->freq_range
;
3509 power_rule
= ®_rule
->power_rule
;
3511 nl_reg_rule
= nla_nest_start(msg
, i
);
3513 goto nla_put_failure
;
3515 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3517 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3518 freq_range
->start_freq_khz
);
3519 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3520 freq_range
->end_freq_khz
);
3521 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3522 freq_range
->max_bandwidth_khz
);
3523 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3524 power_rule
->max_antenna_gain
);
3525 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3526 power_rule
->max_eirp
);
3528 nla_nest_end(msg
, nl_reg_rule
);
3531 nla_nest_end(msg
, nl_reg_rules
);
3533 genlmsg_end(msg
, hdr
);
3534 err
= genlmsg_reply(msg
, info
);
3538 genlmsg_cancel(msg
, hdr
);
3543 mutex_unlock(&cfg80211_mutex
);
3547 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3549 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3550 struct nlattr
*nl_reg_rule
;
3551 char *alpha2
= NULL
;
3552 int rem_reg_rules
= 0, r
= 0;
3553 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3555 struct ieee80211_regdomain
*rd
= NULL
;
3557 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3560 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3563 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3565 if (info
->attrs
[NL80211_ATTR_DFS_REGION
])
3566 dfs_region
= nla_get_u8(info
->attrs
[NL80211_ATTR_DFS_REGION
]);
3568 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3571 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3575 mutex_lock(&cfg80211_mutex
);
3577 if (!reg_is_valid_request(alpha2
)) {
3582 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3583 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3585 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3591 rd
->n_reg_rules
= num_rules
;
3592 rd
->alpha2
[0] = alpha2
[0];
3593 rd
->alpha2
[1] = alpha2
[1];
3596 * Disable DFS master mode if the DFS region was
3597 * not supported or known on this kernel.
3599 if (reg_supported_dfs_region(dfs_region
))
3600 rd
->dfs_region
= dfs_region
;
3602 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3604 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3605 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3607 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3613 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3619 BUG_ON(rule_idx
!= num_rules
);
3623 mutex_unlock(&cfg80211_mutex
);
3628 mutex_unlock(&cfg80211_mutex
);
3633 static int validate_scan_freqs(struct nlattr
*freqs
)
3635 struct nlattr
*attr1
, *attr2
;
3636 int n_channels
= 0, tmp1
, tmp2
;
3638 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3641 * Some hardware has a limited channel list for
3642 * scanning, and it is pretty much nonsensical
3643 * to scan for a channel twice, so disallow that
3644 * and don't require drivers to check that the
3645 * channel list they get isn't longer than what
3646 * they can scan, as long as they can scan all
3647 * the channels they registered at once.
3649 nla_for_each_nested(attr2
, freqs
, tmp2
)
3650 if (attr1
!= attr2
&&
3651 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3658 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3660 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3661 struct net_device
*dev
= info
->user_ptr
[1];
3662 struct cfg80211_scan_request
*request
;
3663 struct nlattr
*attr
;
3664 struct wiphy
*wiphy
;
3665 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3668 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3671 wiphy
= &rdev
->wiphy
;
3673 if (!rdev
->ops
->scan
)
3679 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3680 n_channels
= validate_scan_freqs(
3681 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3685 enum ieee80211_band band
;
3688 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3689 if (wiphy
->bands
[band
])
3690 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3693 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3694 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3697 if (n_ssids
> wiphy
->max_scan_ssids
)
3700 if (info
->attrs
[NL80211_ATTR_IE
])
3701 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3705 if (ie_len
> wiphy
->max_scan_ie_len
)
3708 request
= kzalloc(sizeof(*request
)
3709 + sizeof(*request
->ssids
) * n_ssids
3710 + sizeof(*request
->channels
) * n_channels
3711 + ie_len
, GFP_KERNEL
);
3716 request
->ssids
= (void *)&request
->channels
[n_channels
];
3717 request
->n_ssids
= n_ssids
;
3720 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3722 request
->ie
= (void *)(request
->channels
+ n_channels
);
3726 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3727 /* user specified, bail out if channel not found */
3728 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3729 struct ieee80211_channel
*chan
;
3731 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3738 /* ignore disabled channels */
3739 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3742 request
->channels
[i
] = chan
;
3746 enum ieee80211_band band
;
3749 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3751 if (!wiphy
->bands
[band
])
3753 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3754 struct ieee80211_channel
*chan
;
3756 chan
= &wiphy
->bands
[band
]->channels
[j
];
3758 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3761 request
->channels
[i
] = chan
;
3772 request
->n_channels
= i
;
3775 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3776 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3777 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3781 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3782 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3787 if (info
->attrs
[NL80211_ATTR_IE
]) {
3788 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3789 memcpy((void *)request
->ie
,
3790 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3794 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
3795 if (wiphy
->bands
[i
])
3797 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
3799 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
3800 nla_for_each_nested(attr
,
3801 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
3803 enum ieee80211_band band
= nla_type(attr
);
3805 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
3809 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
3812 &request
->rates
[band
]);
3819 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
3822 request
->wiphy
= &rdev
->wiphy
;
3824 rdev
->scan_req
= request
;
3825 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3828 nl80211_send_scan_start(rdev
, dev
);
3832 rdev
->scan_req
= NULL
;
3839 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3840 struct genl_info
*info
)
3842 struct cfg80211_sched_scan_request
*request
;
3843 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3844 struct net_device
*dev
= info
->user_ptr
[1];
3845 struct nlattr
*attr
;
3846 struct wiphy
*wiphy
;
3847 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
3849 enum ieee80211_band band
;
3851 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
3853 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3854 !rdev
->ops
->sched_scan_start
)
3857 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3860 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3863 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3867 wiphy
= &rdev
->wiphy
;
3869 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3870 n_channels
= validate_scan_freqs(
3871 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3877 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3878 if (wiphy
->bands
[band
])
3879 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3882 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3883 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3887 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
3890 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
3891 nla_for_each_nested(attr
,
3892 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
3896 if (n_match_sets
> wiphy
->max_match_sets
)
3899 if (info
->attrs
[NL80211_ATTR_IE
])
3900 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3904 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
3907 mutex_lock(&rdev
->sched_scan_mtx
);
3909 if (rdev
->sched_scan_req
) {
3914 request
= kzalloc(sizeof(*request
)
3915 + sizeof(*request
->ssids
) * n_ssids
3916 + sizeof(*request
->match_sets
) * n_match_sets
3917 + sizeof(*request
->channels
) * n_channels
3918 + ie_len
, GFP_KERNEL
);
3925 request
->ssids
= (void *)&request
->channels
[n_channels
];
3926 request
->n_ssids
= n_ssids
;
3929 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3931 request
->ie
= (void *)(request
->channels
+ n_channels
);
3936 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
3937 else if (request
->ssids
)
3938 request
->match_sets
=
3939 (void *)(request
->ssids
+ n_ssids
);
3941 request
->match_sets
=
3942 (void *)(request
->channels
+ n_channels
);
3944 request
->n_match_sets
= n_match_sets
;
3947 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3948 /* user specified, bail out if channel not found */
3949 nla_for_each_nested(attr
,
3950 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3952 struct ieee80211_channel
*chan
;
3954 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3961 /* ignore disabled channels */
3962 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3965 request
->channels
[i
] = chan
;
3970 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3972 if (!wiphy
->bands
[band
])
3974 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3975 struct ieee80211_channel
*chan
;
3977 chan
= &wiphy
->bands
[band
]->channels
[j
];
3979 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3982 request
->channels
[i
] = chan
;
3993 request
->n_channels
= i
;
3996 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3997 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3999 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
4003 request
->ssids
[i
].ssid_len
= nla_len(attr
);
4004 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
4011 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
4012 nla_for_each_nested(attr
,
4013 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
4015 struct nlattr
*ssid
;
4017 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
4018 nla_data(attr
), nla_len(attr
),
4019 nl80211_match_policy
);
4020 ssid
= tb
[NL80211_ATTR_SCHED_SCAN_MATCH_SSID
];
4022 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
4026 memcpy(request
->match_sets
[i
].ssid
.ssid
,
4027 nla_data(ssid
), nla_len(ssid
));
4028 request
->match_sets
[i
].ssid
.ssid_len
=
4035 if (info
->attrs
[NL80211_ATTR_IE
]) {
4036 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4037 memcpy((void *)request
->ie
,
4038 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
4043 request
->wiphy
= &rdev
->wiphy
;
4044 request
->interval
= interval
;
4046 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
4048 rdev
->sched_scan_req
= request
;
4049 nl80211_send_sched_scan(rdev
, dev
,
4050 NL80211_CMD_START_SCHED_SCAN
);
4057 mutex_unlock(&rdev
->sched_scan_mtx
);
4061 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
4062 struct genl_info
*info
)
4064 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4067 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
4068 !rdev
->ops
->sched_scan_stop
)
4071 mutex_lock(&rdev
->sched_scan_mtx
);
4072 err
= __cfg80211_stop_sched_scan(rdev
, false);
4073 mutex_unlock(&rdev
->sched_scan_mtx
);
4078 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
4080 struct cfg80211_registered_device
*rdev
,
4081 struct wireless_dev
*wdev
,
4082 struct cfg80211_internal_bss
*intbss
)
4084 struct cfg80211_bss
*res
= &intbss
->pub
;
4089 ASSERT_WDEV_LOCK(wdev
);
4091 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
4092 NL80211_CMD_NEW_SCAN_RESULTS
);
4096 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
4098 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
4099 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
4101 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
4103 goto nla_put_failure
;
4104 if (!is_zero_ether_addr(res
->bssid
))
4105 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
4106 if (res
->information_elements
&& res
->len_information_elements
)
4107 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
4108 res
->len_information_elements
,
4109 res
->information_elements
);
4110 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
4111 res
->beacon_ies
!= res
->information_elements
)
4112 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
4113 res
->len_beacon_ies
, res
->beacon_ies
);
4115 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
4116 if (res
->beacon_interval
)
4117 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
4118 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
4119 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
4120 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
4121 jiffies_to_msecs(jiffies
- intbss
->ts
));
4123 switch (rdev
->wiphy
.signal_type
) {
4124 case CFG80211_SIGNAL_TYPE_MBM
:
4125 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
4127 case CFG80211_SIGNAL_TYPE_UNSPEC
:
4128 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
4134 switch (wdev
->iftype
) {
4135 case NL80211_IFTYPE_P2P_CLIENT
:
4136 case NL80211_IFTYPE_STATION
:
4137 if (intbss
== wdev
->current_bss
)
4138 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
4139 NL80211_BSS_STATUS_ASSOCIATED
);
4140 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
4141 if (intbss
!= wdev
->auth_bsses
[i
])
4143 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
4144 NL80211_BSS_STATUS_AUTHENTICATED
);
4148 case NL80211_IFTYPE_ADHOC
:
4149 if (intbss
== wdev
->current_bss
)
4150 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
4151 NL80211_BSS_STATUS_IBSS_JOINED
);
4157 nla_nest_end(msg
, bss
);
4159 return genlmsg_end(msg
, hdr
);
4162 genlmsg_cancel(msg
, hdr
);
4166 static int nl80211_dump_scan(struct sk_buff
*skb
,
4167 struct netlink_callback
*cb
)
4169 struct cfg80211_registered_device
*rdev
;
4170 struct net_device
*dev
;
4171 struct cfg80211_internal_bss
*scan
;
4172 struct wireless_dev
*wdev
;
4173 int start
= cb
->args
[1], idx
= 0;
4176 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4180 wdev
= dev
->ieee80211_ptr
;
4183 spin_lock_bh(&rdev
->bss_lock
);
4184 cfg80211_bss_expire(rdev
);
4186 cb
->seq
= rdev
->bss_generation
;
4188 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4191 if (nl80211_send_bss(skb
, cb
,
4192 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4193 rdev
, wdev
, scan
) < 0) {
4199 spin_unlock_bh(&rdev
->bss_lock
);
4203 nl80211_finish_netdev_dump(rdev
);
4208 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4209 int flags
, struct net_device
*dev
,
4210 struct survey_info
*survey
)
4213 struct nlattr
*infoattr
;
4215 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4216 NL80211_CMD_NEW_SURVEY_RESULTS
);
4220 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
4222 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4224 goto nla_put_failure
;
4226 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4227 survey
->channel
->center_freq
);
4228 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
4229 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
4231 if (survey
->filled
& SURVEY_INFO_IN_USE
)
4232 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
4233 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
4234 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4235 survey
->channel_time
);
4236 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
4237 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4238 survey
->channel_time_busy
);
4239 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
4240 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4241 survey
->channel_time_ext_busy
);
4242 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
4243 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4244 survey
->channel_time_rx
);
4245 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
4246 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4247 survey
->channel_time_tx
);
4249 nla_nest_end(msg
, infoattr
);
4251 return genlmsg_end(msg
, hdr
);
4254 genlmsg_cancel(msg
, hdr
);
4258 static int nl80211_dump_survey(struct sk_buff
*skb
,
4259 struct netlink_callback
*cb
)
4261 struct survey_info survey
;
4262 struct cfg80211_registered_device
*dev
;
4263 struct net_device
*netdev
;
4264 int survey_idx
= cb
->args
[1];
4267 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4271 if (!dev
->ops
->dump_survey
) {
4277 struct ieee80211_channel
*chan
;
4279 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4286 /* Survey without a channel doesn't make sense */
4287 if (!survey
.channel
) {
4292 chan
= ieee80211_get_channel(&dev
->wiphy
,
4293 survey
.channel
->center_freq
);
4294 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4299 if (nl80211_send_survey(skb
,
4300 NETLINK_CB(cb
->skb
).pid
,
4301 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4309 cb
->args
[1] = survey_idx
;
4312 nl80211_finish_netdev_dump(dev
);
4316 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4318 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4321 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4323 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4324 NL80211_WPA_VERSION_2
));
4327 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4330 struct net_device
*dev
= info
->user_ptr
[1];
4331 struct ieee80211_channel
*chan
;
4332 const u8
*bssid
, *ssid
, *ie
= NULL
;
4333 int err
, ssid_len
, ie_len
= 0;
4334 enum nl80211_auth_type auth_type
;
4335 struct key_parse key
;
4336 bool local_state_change
;
4338 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4341 if (!info
->attrs
[NL80211_ATTR_MAC
])
4344 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4347 if (!info
->attrs
[NL80211_ATTR_SSID
])
4350 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4353 err
= nl80211_parse_key(info
, &key
);
4358 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4360 if (!key
.p
.key
|| !key
.p
.key_len
)
4362 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4363 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4364 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4365 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4377 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4378 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4387 if (!rdev
->ops
->auth
)
4390 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4391 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4394 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4395 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4396 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4397 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4400 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4401 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4403 if (info
->attrs
[NL80211_ATTR_IE
]) {
4404 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4405 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4408 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4409 if (!nl80211_valid_auth_type(auth_type
))
4412 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4414 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4415 ssid
, ssid_len
, ie
, ie_len
,
4416 key
.p
.key
, key
.p
.key_len
, key
.idx
,
4417 local_state_change
);
4420 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4421 struct genl_info
*info
,
4422 struct cfg80211_crypto_settings
*settings
,
4425 memset(settings
, 0, sizeof(*settings
));
4427 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4429 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4431 proto
= nla_get_u16(
4432 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4433 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4434 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4437 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4438 settings
->control_port_no_encrypt
= true;
4440 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4442 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4446 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4447 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4448 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4450 if (len
% sizeof(u32
))
4453 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4456 memcpy(settings
->ciphers_pairwise
, data
, len
);
4458 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4459 if (!cfg80211_supported_cipher_suite(
4461 settings
->ciphers_pairwise
[i
]))
4465 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4466 settings
->cipher_group
=
4467 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4468 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4469 settings
->cipher_group
))
4473 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4474 settings
->wpa_versions
=
4475 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4476 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4480 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4484 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4485 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4486 settings
->n_akm_suites
= len
/ sizeof(u32
);
4488 if (len
% sizeof(u32
))
4491 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4494 memcpy(settings
->akm_suites
, data
, len
);
4500 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4503 struct net_device
*dev
= info
->user_ptr
[1];
4504 struct cfg80211_crypto_settings crypto
;
4505 struct ieee80211_channel
*chan
;
4506 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4507 int err
, ssid_len
, ie_len
= 0;
4508 bool use_mfp
= false;
4510 struct ieee80211_ht_cap
*ht_capa
= NULL
;
4511 struct ieee80211_ht_cap
*ht_capa_mask
= NULL
;
4513 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4516 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4517 !info
->attrs
[NL80211_ATTR_SSID
] ||
4518 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4521 if (!rdev
->ops
->assoc
)
4524 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4525 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4528 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4530 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4531 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4532 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4535 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4536 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4538 if (info
->attrs
[NL80211_ATTR_IE
]) {
4539 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4540 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4543 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4544 enum nl80211_mfp mfp
=
4545 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4546 if (mfp
== NL80211_MFP_REQUIRED
)
4548 else if (mfp
!= NL80211_MFP_NO
)
4552 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4553 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4555 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
4556 flags
|= ASSOC_REQ_DISABLE_HT
;
4558 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
4560 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]);
4562 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
4565 ht_capa
= nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
4568 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4570 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4571 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4572 &crypto
, flags
, ht_capa
,
4578 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4580 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4581 struct net_device
*dev
= info
->user_ptr
[1];
4582 const u8
*ie
= NULL
, *bssid
;
4585 bool local_state_change
;
4587 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4590 if (!info
->attrs
[NL80211_ATTR_MAC
])
4593 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4596 if (!rdev
->ops
->deauth
)
4599 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4600 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4603 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4605 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4606 if (reason_code
== 0) {
4607 /* Reason Code 0 is reserved */
4611 if (info
->attrs
[NL80211_ATTR_IE
]) {
4612 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4613 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4616 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4618 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4619 local_state_change
);
4622 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4624 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4625 struct net_device
*dev
= info
->user_ptr
[1];
4626 const u8
*ie
= NULL
, *bssid
;
4629 bool local_state_change
;
4631 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4634 if (!info
->attrs
[NL80211_ATTR_MAC
])
4637 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4640 if (!rdev
->ops
->disassoc
)
4643 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4644 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4647 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4649 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4650 if (reason_code
== 0) {
4651 /* Reason Code 0 is reserved */
4655 if (info
->attrs
[NL80211_ATTR_IE
]) {
4656 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4657 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4660 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4662 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4663 local_state_change
);
4667 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4668 int mcast_rate
[IEEE80211_NUM_BANDS
],
4671 struct wiphy
*wiphy
= &rdev
->wiphy
;
4675 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4676 struct ieee80211_supported_band
*sband
;
4678 sband
= wiphy
->bands
[band
];
4682 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4683 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4684 mcast_rate
[band
] = i
+ 1;
4694 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4696 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4697 struct net_device
*dev
= info
->user_ptr
[1];
4698 struct cfg80211_ibss_params ibss
;
4699 struct wiphy
*wiphy
;
4700 struct cfg80211_cached_keys
*connkeys
= NULL
;
4703 memset(&ibss
, 0, sizeof(ibss
));
4705 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4708 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4709 !info
->attrs
[NL80211_ATTR_SSID
] ||
4710 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4713 ibss
.beacon_interval
= 100;
4715 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4716 ibss
.beacon_interval
=
4717 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4718 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4722 if (!rdev
->ops
->join_ibss
)
4725 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4728 wiphy
= &rdev
->wiphy
;
4730 if (info
->attrs
[NL80211_ATTR_MAC
]) {
4731 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4733 if (!is_valid_ether_addr(ibss
.bssid
))
4736 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4737 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4739 if (info
->attrs
[NL80211_ATTR_IE
]) {
4740 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4741 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4744 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4745 enum nl80211_channel_type channel_type
;
4747 channel_type
= nla_get_u32(
4748 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4749 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4750 channel_type
!= NL80211_CHAN_HT20
&&
4751 channel_type
!= NL80211_CHAN_HT40MINUS
&&
4752 channel_type
!= NL80211_CHAN_HT40PLUS
)
4755 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4756 !(wiphy
->features
& NL80211_FEATURE_HT_IBSS
))
4759 ibss
.channel_type
= channel_type
;
4761 ibss
.channel_type
= NL80211_CHAN_NO_HT
;
4764 ibss
.channel
= rdev_freq_to_chan(rdev
,
4765 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]),
4767 if (!ibss
.channel
||
4768 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4769 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4772 /* Both channels should be able to initiate communication */
4773 if ((ibss
.channel_type
== NL80211_CHAN_HT40PLUS
||
4774 ibss
.channel_type
== NL80211_CHAN_HT40MINUS
) &&
4775 !cfg80211_can_beacon_sec_chan(&rdev
->wiphy
, ibss
.channel
,
4779 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4780 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4782 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4784 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4786 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4787 struct ieee80211_supported_band
*sband
=
4788 wiphy
->bands
[ibss
.channel
->band
];
4791 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
4797 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4798 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4799 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4802 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4803 connkeys
= nl80211_parse_connkeys(rdev
,
4804 info
->attrs
[NL80211_ATTR_KEYS
]);
4805 if (IS_ERR(connkeys
))
4806 return PTR_ERR(connkeys
);
4809 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4815 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4817 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4818 struct net_device
*dev
= info
->user_ptr
[1];
4820 if (!rdev
->ops
->leave_ibss
)
4823 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4826 return cfg80211_leave_ibss(rdev
, dev
, false);
4829 #ifdef CONFIG_NL80211_TESTMODE
4830 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4834 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4839 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4843 if (rdev
->ops
->testmode_cmd
) {
4844 rdev
->testmode_info
= info
;
4845 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4846 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4847 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4848 rdev
->testmode_info
= NULL
;
4854 static int nl80211_testmode_dump(struct sk_buff
*skb
,
4855 struct netlink_callback
*cb
)
4857 struct cfg80211_registered_device
*rdev
;
4865 * 0 is a valid index, but not valid for args[0],
4866 * so we need to offset by 1.
4868 phy_idx
= cb
->args
[0] - 1;
4870 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
4871 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
4875 if (nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
]) {
4876 phy_idx
= nla_get_u32(
4877 nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
]);
4879 struct net_device
*netdev
;
4881 err
= get_rdev_dev_by_ifindex(sock_net(skb
->sk
),
4882 nl80211_fam
.attrbuf
,
4887 phy_idx
= rdev
->wiphy_idx
;
4888 cfg80211_unlock_rdev(rdev
);
4890 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
4892 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
4896 data
= nla_data((void *)cb
->args
[1]);
4897 data_len
= nla_len((void *)cb
->args
[1]);
4900 mutex_lock(&cfg80211_mutex
);
4901 rdev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
4903 mutex_unlock(&cfg80211_mutex
);
4906 cfg80211_lock_rdev(rdev
);
4907 mutex_unlock(&cfg80211_mutex
);
4909 if (!rdev
->ops
->testmode_dump
) {
4915 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
4916 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4917 NL80211_CMD_TESTMODE
);
4918 struct nlattr
*tmdata
;
4920 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, phy_idx
) < 0) {
4921 genlmsg_cancel(skb
, hdr
);
4925 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4927 genlmsg_cancel(skb
, hdr
);
4930 err
= rdev
->ops
->testmode_dump(&rdev
->wiphy
, skb
, cb
,
4932 nla_nest_end(skb
, tmdata
);
4934 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
4935 genlmsg_cancel(skb
, hdr
);
4938 genlmsg_cancel(skb
, hdr
);
4942 genlmsg_end(skb
, hdr
);
4947 cb
->args
[0] = phy_idx
+ 1;
4949 cfg80211_unlock_rdev(rdev
);
4953 static struct sk_buff
*
4954 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4955 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4957 struct sk_buff
*skb
;
4959 struct nlattr
*data
;
4961 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4965 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4971 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4972 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4974 ((void **)skb
->cb
)[0] = rdev
;
4975 ((void **)skb
->cb
)[1] = hdr
;
4976 ((void **)skb
->cb
)[2] = data
;
4985 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4988 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4990 if (WARN_ON(!rdev
->testmode_info
))
4993 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4994 rdev
->testmode_info
->snd_pid
,
4995 rdev
->testmode_info
->snd_seq
,
4998 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
5000 int cfg80211_testmode_reply(struct sk_buff
*skb
)
5002 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
5003 void *hdr
= ((void **)skb
->cb
)[1];
5004 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5006 if (WARN_ON(!rdev
->testmode_info
)) {
5011 nla_nest_end(skb
, data
);
5012 genlmsg_end(skb
, hdr
);
5013 return genlmsg_reply(skb
, rdev
->testmode_info
);
5015 EXPORT_SYMBOL(cfg80211_testmode_reply
);
5017 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
5018 int approxlen
, gfp_t gfp
)
5020 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
5022 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
5024 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
5026 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
5028 void *hdr
= ((void **)skb
->cb
)[1];
5029 struct nlattr
*data
= ((void **)skb
->cb
)[2];
5031 nla_nest_end(skb
, data
);
5032 genlmsg_end(skb
, hdr
);
5033 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
5035 EXPORT_SYMBOL(cfg80211_testmode_event
);
5038 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
5040 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5041 struct net_device
*dev
= info
->user_ptr
[1];
5042 struct cfg80211_connect_params connect
;
5043 struct wiphy
*wiphy
;
5044 struct cfg80211_cached_keys
*connkeys
= NULL
;
5047 memset(&connect
, 0, sizeof(connect
));
5049 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
5052 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
5053 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
5056 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
5058 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
5059 if (!nl80211_valid_auth_type(connect
.auth_type
))
5062 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
5064 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
5066 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
5067 NL80211_MAX_NR_CIPHER_SUITES
);
5071 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5072 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5075 wiphy
= &rdev
->wiphy
;
5077 if (info
->attrs
[NL80211_ATTR_MAC
])
5078 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5079 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
5080 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
5082 if (info
->attrs
[NL80211_ATTR_IE
]) {
5083 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
5084 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
5087 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
5089 ieee80211_get_channel(wiphy
,
5090 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
5091 if (!connect
.channel
||
5092 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
5096 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
5097 connkeys
= nl80211_parse_connkeys(rdev
,
5098 info
->attrs
[NL80211_ATTR_KEYS
]);
5099 if (IS_ERR(connkeys
))
5100 return PTR_ERR(connkeys
);
5103 if (nla_get_flag(info
->attrs
[NL80211_ATTR_DISABLE_HT
]))
5104 connect
.flags
|= ASSOC_REQ_DISABLE_HT
;
5106 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5107 memcpy(&connect
.ht_capa_mask
,
5108 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
]),
5109 sizeof(connect
.ht_capa_mask
));
5111 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]) {
5112 if (!info
->attrs
[NL80211_ATTR_HT_CAPABILITY_MASK
])
5114 memcpy(&connect
.ht_capa
,
5115 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]),
5116 sizeof(connect
.ht_capa
));
5119 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
5125 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
5127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5128 struct net_device
*dev
= info
->user_ptr
[1];
5131 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
5132 reason
= WLAN_REASON_DEAUTH_LEAVING
;
5134 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
5139 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5140 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5143 return cfg80211_disconnect(rdev
, dev
, reason
, true);
5146 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
5148 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5153 if (!info
->attrs
[NL80211_ATTR_PID
])
5156 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
5158 net
= get_net_ns_by_pid(pid
);
5160 return PTR_ERR(net
);
5164 /* check if anything to do */
5165 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
5166 err
= cfg80211_switch_netns(rdev
, net
);
5172 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5174 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5175 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
5176 struct cfg80211_pmksa
*pmksa
) = NULL
;
5177 struct net_device
*dev
= info
->user_ptr
[1];
5178 struct cfg80211_pmksa pmksa
;
5180 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
5182 if (!info
->attrs
[NL80211_ATTR_MAC
])
5185 if (!info
->attrs
[NL80211_ATTR_PMKID
])
5188 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
5189 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5191 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5192 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5195 switch (info
->genlhdr
->cmd
) {
5196 case NL80211_CMD_SET_PMKSA
:
5197 rdev_ops
= rdev
->ops
->set_pmksa
;
5199 case NL80211_CMD_DEL_PMKSA
:
5200 rdev_ops
= rdev
->ops
->del_pmksa
;
5210 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
5213 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
5215 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5216 struct net_device
*dev
= info
->user_ptr
[1];
5218 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5219 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5222 if (!rdev
->ops
->flush_pmksa
)
5225 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5228 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5230 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5231 struct net_device
*dev
= info
->user_ptr
[1];
5232 u8 action_code
, dialog_token
;
5236 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5237 !rdev
->ops
->tdls_mgmt
)
5240 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5241 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5242 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5243 !info
->attrs
[NL80211_ATTR_IE
] ||
5244 !info
->attrs
[NL80211_ATTR_MAC
])
5247 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5248 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5249 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5250 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5252 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5253 dialog_token
, status_code
,
5254 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5255 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5258 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5260 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5261 struct net_device
*dev
= info
->user_ptr
[1];
5262 enum nl80211_tdls_operation operation
;
5265 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5266 !rdev
->ops
->tdls_oper
)
5269 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5270 !info
->attrs
[NL80211_ATTR_MAC
])
5273 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5274 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5276 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5279 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5280 struct genl_info
*info
)
5282 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5283 struct net_device
*dev
= info
->user_ptr
[1];
5284 struct ieee80211_channel
*chan
;
5285 struct sk_buff
*msg
;
5288 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5292 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5293 !info
->attrs
[NL80211_ATTR_DURATION
])
5296 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5299 * We should be on that channel for at least one jiffie,
5300 * and more than 5 seconds seems excessive.
5302 if (!duration
|| !msecs_to_jiffies(duration
) ||
5303 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5306 if (!rdev
->ops
->remain_on_channel
||
5307 !(rdev
->wiphy
.flags
& WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
))
5310 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5311 channel_type
= nla_get_u32(
5312 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5313 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5314 channel_type
!= NL80211_CHAN_HT20
&&
5315 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5316 channel_type
!= NL80211_CHAN_HT40MINUS
)
5320 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5321 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5325 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5329 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5330 NL80211_CMD_REMAIN_ON_CHANNEL
);
5337 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
5338 channel_type
, duration
, &cookie
);
5343 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5345 genlmsg_end(msg
, hdr
);
5347 return genlmsg_reply(msg
, info
);
5356 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5357 struct genl_info
*info
)
5359 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5360 struct net_device
*dev
= info
->user_ptr
[1];
5363 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5366 if (!rdev
->ops
->cancel_remain_on_channel
)
5369 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5371 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
5374 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5375 u8
*rates
, u8 rates_len
)
5380 for (i
= 0; i
< rates_len
; i
++) {
5381 int rate
= (rates
[i
] & 0x7f) * 5;
5383 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5384 struct ieee80211_rate
*srate
=
5385 &sband
->bitrates
[ridx
];
5386 if (rate
== srate
->bitrate
) {
5391 if (ridx
== sband
->n_bitrates
)
5392 return 0; /* rate not found */
5398 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5399 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5400 .len
= NL80211_MAX_SUPP_RATES
},
5403 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5404 struct genl_info
*info
)
5406 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5407 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5408 struct cfg80211_bitrate_mask mask
;
5410 struct net_device
*dev
= info
->user_ptr
[1];
5411 struct nlattr
*tx_rates
;
5412 struct ieee80211_supported_band
*sband
;
5414 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5417 if (!rdev
->ops
->set_bitrate_mask
)
5420 memset(&mask
, 0, sizeof(mask
));
5421 /* Default to all rates enabled */
5422 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5423 sband
= rdev
->wiphy
.bands
[i
];
5424 mask
.control
[i
].legacy
=
5425 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5429 * The nested attribute uses enum nl80211_band as the index. This maps
5430 * directly to the enum ieee80211_band values used in cfg80211.
5432 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5434 enum ieee80211_band band
= nla_type(tx_rates
);
5435 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5437 sband
= rdev
->wiphy
.bands
[band
];
5440 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5441 nla_len(tx_rates
), nl80211_txattr_policy
);
5442 if (tb
[NL80211_TXRATE_LEGACY
]) {
5443 mask
.control
[band
].legacy
= rateset_to_mask(
5445 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5446 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5447 if (mask
.control
[band
].legacy
== 0)
5452 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5455 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5457 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5458 struct net_device
*dev
= info
->user_ptr
[1];
5459 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
5461 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
5464 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
5465 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
5467 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5468 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5469 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5470 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5471 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5472 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5473 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5476 /* not much point in registering if we can't reply */
5477 if (!rdev
->ops
->mgmt_tx
)
5480 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
5482 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
5483 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
5486 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5488 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5489 struct net_device
*dev
= info
->user_ptr
[1];
5490 struct ieee80211_channel
*chan
;
5491 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5492 bool channel_type_valid
= false;
5497 struct sk_buff
*msg
= NULL
;
5498 unsigned int wait
= 0;
5499 bool offchan
, no_cck
, dont_wait_for_ack
;
5501 dont_wait_for_ack
= info
->attrs
[NL80211_ATTR_DONT_WAIT_FOR_ACK
];
5503 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5504 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5507 if (!rdev
->ops
->mgmt_tx
)
5510 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5511 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5512 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5513 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5514 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5515 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5516 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5519 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5520 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
5522 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5525 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5526 channel_type
= nla_get_u32(
5527 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5528 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5529 channel_type
!= NL80211_CHAN_HT20
&&
5530 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5531 channel_type
!= NL80211_CHAN_HT40MINUS
)
5533 channel_type_valid
= true;
5536 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5538 if (offchan
&& !(rdev
->wiphy
.flags
& WIPHY_FLAG_OFFCHAN_TX
))
5541 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5543 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5544 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5548 if (!dont_wait_for_ack
) {
5549 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5553 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5562 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
5563 channel_type_valid
, wait
,
5564 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
5565 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
5566 no_cck
, dont_wait_for_ack
, &cookie
);
5571 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5573 genlmsg_end(msg
, hdr
);
5574 return genlmsg_reply(msg
, info
);
5586 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
5588 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5589 struct net_device
*dev
= info
->user_ptr
[1];
5592 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5595 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5598 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5599 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5600 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5601 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5602 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5603 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5606 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5608 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
5611 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5613 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5614 struct wireless_dev
*wdev
;
5615 struct net_device
*dev
= info
->user_ptr
[1];
5620 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
5623 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
5625 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
5628 wdev
= dev
->ieee80211_ptr
;
5630 if (!rdev
->ops
->set_power_mgmt
)
5633 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
5635 if (state
== wdev
->ps
)
5638 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
5645 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5647 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5648 enum nl80211_ps_state ps_state
;
5649 struct wireless_dev
*wdev
;
5650 struct net_device
*dev
= info
->user_ptr
[1];
5651 struct sk_buff
*msg
;
5655 wdev
= dev
->ieee80211_ptr
;
5657 if (!rdev
->ops
->set_power_mgmt
)
5660 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5664 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5665 NL80211_CMD_GET_POWER_SAVE
);
5672 ps_state
= NL80211_PS_ENABLED
;
5674 ps_state
= NL80211_PS_DISABLED
;
5676 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5678 genlmsg_end(msg
, hdr
);
5679 return genlmsg_reply(msg
, info
);
5688 static struct nla_policy
5689 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5690 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5691 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5692 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5695 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5696 s32 threshold
, u32 hysteresis
)
5698 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5699 struct wireless_dev
*wdev
;
5700 struct net_device
*dev
= info
->user_ptr
[1];
5705 wdev
= dev
->ieee80211_ptr
;
5707 if (!rdev
->ops
->set_cqm_rssi_config
)
5710 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5711 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5714 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5715 threshold
, hysteresis
);
5718 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5720 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5724 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5730 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5731 nl80211_attr_cqm_policy
);
5735 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5736 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5739 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5740 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5741 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5749 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5751 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5752 struct net_device
*dev
= info
->user_ptr
[1];
5753 struct mesh_config cfg
;
5754 struct mesh_setup setup
;
5757 /* start with default */
5758 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5759 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5761 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5762 /* and parse parameters if given */
5763 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5768 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5769 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5772 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5773 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5775 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
5776 !nl80211_parse_mcast_rate(rdev
, setup
.mcast_rate
,
5777 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
5780 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5781 /* parse additional setup parameters if given */
5782 err
= nl80211_parse_mesh_setup(info
, &setup
);
5787 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5790 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5792 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5793 struct net_device
*dev
= info
->user_ptr
[1];
5795 return cfg80211_leave_mesh(rdev
, dev
);
5798 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5800 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5801 struct sk_buff
*msg
;
5804 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5807 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5811 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5812 NL80211_CMD_GET_WOWLAN
);
5814 goto nla_put_failure
;
5817 struct nlattr
*nl_wowlan
;
5819 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5821 goto nla_put_failure
;
5823 if (rdev
->wowlan
->any
)
5824 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5825 if (rdev
->wowlan
->disconnect
)
5826 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5827 if (rdev
->wowlan
->magic_pkt
)
5828 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5829 if (rdev
->wowlan
->gtk_rekey_failure
)
5830 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
5831 if (rdev
->wowlan
->eap_identity_req
)
5832 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
5833 if (rdev
->wowlan
->four_way_handshake
)
5834 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
5835 if (rdev
->wowlan
->rfkill_release
)
5836 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
5837 if (rdev
->wowlan
->n_patterns
) {
5838 struct nlattr
*nl_pats
, *nl_pat
;
5841 nl_pats
= nla_nest_start(msg
,
5842 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5844 goto nla_put_failure
;
5846 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5847 nl_pat
= nla_nest_start(msg
, i
+ 1);
5849 goto nla_put_failure
;
5850 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5851 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5852 DIV_ROUND_UP(pat_len
, 8),
5853 rdev
->wowlan
->patterns
[i
].mask
);
5854 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5856 rdev
->wowlan
->patterns
[i
].pattern
);
5857 nla_nest_end(msg
, nl_pat
);
5859 nla_nest_end(msg
, nl_pats
);
5862 nla_nest_end(msg
, nl_wowlan
);
5865 genlmsg_end(msg
, hdr
);
5866 return genlmsg_reply(msg
, info
);
5873 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5875 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5876 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5877 struct cfg80211_wowlan no_triggers
= {};
5878 struct cfg80211_wowlan new_triggers
= {};
5879 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5882 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5885 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5888 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5889 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5890 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5891 nl80211_wowlan_policy
);
5895 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5896 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5898 new_triggers
.any
= true;
5901 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5902 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5904 new_triggers
.disconnect
= true;
5907 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5908 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5910 new_triggers
.magic_pkt
= true;
5913 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
5916 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
5917 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
5919 new_triggers
.gtk_rekey_failure
= true;
5922 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
5923 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
5925 new_triggers
.eap_identity_req
= true;
5928 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
5929 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
5931 new_triggers
.four_way_handshake
= true;
5934 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
5935 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
5937 new_triggers
.rfkill_release
= true;
5940 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5943 int rem
, pat_len
, mask_len
;
5944 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5946 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5949 if (n_patterns
> wowlan
->n_patterns
)
5952 new_triggers
.patterns
= kcalloc(n_patterns
,
5953 sizeof(new_triggers
.patterns
[0]),
5955 if (!new_triggers
.patterns
)
5958 new_triggers
.n_patterns
= n_patterns
;
5961 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5963 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5964 nla_data(pat
), nla_len(pat
), NULL
);
5966 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5967 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5969 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5970 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5971 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5974 if (pat_len
> wowlan
->pattern_max_len
||
5975 pat_len
< wowlan
->pattern_min_len
)
5978 new_triggers
.patterns
[i
].mask
=
5979 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5980 if (!new_triggers
.patterns
[i
].mask
) {
5984 new_triggers
.patterns
[i
].pattern
=
5985 new_triggers
.patterns
[i
].mask
+ mask_len
;
5986 memcpy(new_triggers
.patterns
[i
].mask
,
5987 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5989 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5990 memcpy(new_triggers
.patterns
[i
].pattern
,
5991 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5997 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5998 struct cfg80211_wowlan
*ntrig
;
5999 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
6005 cfg80211_rdev_free_wowlan(rdev
);
6006 rdev
->wowlan
= ntrig
;
6009 cfg80211_rdev_free_wowlan(rdev
);
6010 rdev
->wowlan
= NULL
;
6015 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
6016 kfree(new_triggers
.patterns
[i
].mask
);
6017 kfree(new_triggers
.patterns
);
6021 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
6023 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6024 struct net_device
*dev
= info
->user_ptr
[1];
6025 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6026 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
6027 struct cfg80211_gtk_rekey_data rekey_data
;
6030 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
6033 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
6034 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6035 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
6036 nl80211_rekey_policy
);
6040 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
6042 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
6044 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
6047 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
6049 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
6051 memcpy(rekey_data
.replay_ctr
,
6052 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
6053 NL80211_REPLAY_CTR_LEN
);
6056 if (!wdev
->current_bss
) {
6061 if (!rdev
->ops
->set_rekey_data
) {
6066 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
6072 static int nl80211_register_unexpected_frame(struct sk_buff
*skb
,
6073 struct genl_info
*info
)
6075 struct net_device
*dev
= info
->user_ptr
[1];
6076 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6078 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6079 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6082 if (wdev
->ap_unexpected_nlpid
)
6085 wdev
->ap_unexpected_nlpid
= info
->snd_pid
;
6089 static int nl80211_probe_client(struct sk_buff
*skb
,
6090 struct genl_info
*info
)
6092 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6093 struct net_device
*dev
= info
->user_ptr
[1];
6094 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
6095 struct sk_buff
*msg
;
6101 if (wdev
->iftype
!= NL80211_IFTYPE_AP
&&
6102 wdev
->iftype
!= NL80211_IFTYPE_P2P_GO
)
6105 if (!info
->attrs
[NL80211_ATTR_MAC
])
6108 if (!rdev
->ops
->probe_client
)
6111 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6115 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
6116 NL80211_CMD_PROBE_CLIENT
);
6123 addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
6125 err
= rdev
->ops
->probe_client(&rdev
->wiphy
, dev
, addr
, &cookie
);
6129 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6131 genlmsg_end(msg
, hdr
);
6133 return genlmsg_reply(msg
, info
);
6142 static int nl80211_register_beacons(struct sk_buff
*skb
, struct genl_info
*info
)
6144 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
6146 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_REPORTS_OBSS
))
6149 if (rdev
->ap_beacons_nlpid
)
6152 rdev
->ap_beacons_nlpid
= info
->snd_pid
;
6157 #define NL80211_FLAG_NEED_WIPHY 0x01
6158 #define NL80211_FLAG_NEED_NETDEV 0x02
6159 #define NL80211_FLAG_NEED_RTNL 0x04
6160 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
6161 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
6162 NL80211_FLAG_CHECK_NETDEV_UP)
6164 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6165 struct genl_info
*info
)
6167 struct cfg80211_registered_device
*rdev
;
6168 struct net_device
*dev
;
6170 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
6175 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
6176 rdev
= cfg80211_get_dev_from_info(info
);
6180 return PTR_ERR(rdev
);
6182 info
->user_ptr
[0] = rdev
;
6183 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
6184 err
= get_rdev_dev_by_ifindex(genl_info_net(info
), info
->attrs
,
6191 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
6192 !netif_running(dev
)) {
6193 cfg80211_unlock_rdev(rdev
);
6199 info
->user_ptr
[0] = rdev
;
6200 info
->user_ptr
[1] = dev
;
6206 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
6207 struct genl_info
*info
)
6209 if (info
->user_ptr
[0])
6210 cfg80211_unlock_rdev(info
->user_ptr
[0]);
6211 if (info
->user_ptr
[1])
6212 dev_put(info
->user_ptr
[1]);
6213 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
6217 static struct genl_ops nl80211_ops
[] = {
6219 .cmd
= NL80211_CMD_GET_WIPHY
,
6220 .doit
= nl80211_get_wiphy
,
6221 .dumpit
= nl80211_dump_wiphy
,
6222 .policy
= nl80211_policy
,
6223 /* can be retrieved by unprivileged users */
6224 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
6227 .cmd
= NL80211_CMD_SET_WIPHY
,
6228 .doit
= nl80211_set_wiphy
,
6229 .policy
= nl80211_policy
,
6230 .flags
= GENL_ADMIN_PERM
,
6231 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
6234 .cmd
= NL80211_CMD_GET_INTERFACE
,
6235 .doit
= nl80211_get_interface
,
6236 .dumpit
= nl80211_dump_interface
,
6237 .policy
= nl80211_policy
,
6238 /* can be retrieved by unprivileged users */
6239 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
6242 .cmd
= NL80211_CMD_SET_INTERFACE
,
6243 .doit
= nl80211_set_interface
,
6244 .policy
= nl80211_policy
,
6245 .flags
= GENL_ADMIN_PERM
,
6246 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6247 NL80211_FLAG_NEED_RTNL
,
6250 .cmd
= NL80211_CMD_NEW_INTERFACE
,
6251 .doit
= nl80211_new_interface
,
6252 .policy
= nl80211_policy
,
6253 .flags
= GENL_ADMIN_PERM
,
6254 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6255 NL80211_FLAG_NEED_RTNL
,
6258 .cmd
= NL80211_CMD_DEL_INTERFACE
,
6259 .doit
= nl80211_del_interface
,
6260 .policy
= nl80211_policy
,
6261 .flags
= GENL_ADMIN_PERM
,
6262 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6263 NL80211_FLAG_NEED_RTNL
,
6266 .cmd
= NL80211_CMD_GET_KEY
,
6267 .doit
= nl80211_get_key
,
6268 .policy
= nl80211_policy
,
6269 .flags
= GENL_ADMIN_PERM
,
6270 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6271 NL80211_FLAG_NEED_RTNL
,
6274 .cmd
= NL80211_CMD_SET_KEY
,
6275 .doit
= nl80211_set_key
,
6276 .policy
= nl80211_policy
,
6277 .flags
= GENL_ADMIN_PERM
,
6278 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6279 NL80211_FLAG_NEED_RTNL
,
6282 .cmd
= NL80211_CMD_NEW_KEY
,
6283 .doit
= nl80211_new_key
,
6284 .policy
= nl80211_policy
,
6285 .flags
= GENL_ADMIN_PERM
,
6286 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6287 NL80211_FLAG_NEED_RTNL
,
6290 .cmd
= NL80211_CMD_DEL_KEY
,
6291 .doit
= nl80211_del_key
,
6292 .policy
= nl80211_policy
,
6293 .flags
= GENL_ADMIN_PERM
,
6294 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6295 NL80211_FLAG_NEED_RTNL
,
6298 .cmd
= NL80211_CMD_SET_BEACON
,
6299 .policy
= nl80211_policy
,
6300 .flags
= GENL_ADMIN_PERM
,
6301 .doit
= nl80211_addset_beacon
,
6302 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6303 NL80211_FLAG_NEED_RTNL
,
6306 .cmd
= NL80211_CMD_NEW_BEACON
,
6307 .policy
= nl80211_policy
,
6308 .flags
= GENL_ADMIN_PERM
,
6309 .doit
= nl80211_addset_beacon
,
6310 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6311 NL80211_FLAG_NEED_RTNL
,
6314 .cmd
= NL80211_CMD_DEL_BEACON
,
6315 .policy
= nl80211_policy
,
6316 .flags
= GENL_ADMIN_PERM
,
6317 .doit
= nl80211_del_beacon
,
6318 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6319 NL80211_FLAG_NEED_RTNL
,
6322 .cmd
= NL80211_CMD_GET_STATION
,
6323 .doit
= nl80211_get_station
,
6324 .dumpit
= nl80211_dump_station
,
6325 .policy
= nl80211_policy
,
6326 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6327 NL80211_FLAG_NEED_RTNL
,
6330 .cmd
= NL80211_CMD_SET_STATION
,
6331 .doit
= nl80211_set_station
,
6332 .policy
= nl80211_policy
,
6333 .flags
= GENL_ADMIN_PERM
,
6334 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6335 NL80211_FLAG_NEED_RTNL
,
6338 .cmd
= NL80211_CMD_NEW_STATION
,
6339 .doit
= nl80211_new_station
,
6340 .policy
= nl80211_policy
,
6341 .flags
= GENL_ADMIN_PERM
,
6342 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6343 NL80211_FLAG_NEED_RTNL
,
6346 .cmd
= NL80211_CMD_DEL_STATION
,
6347 .doit
= nl80211_del_station
,
6348 .policy
= nl80211_policy
,
6349 .flags
= GENL_ADMIN_PERM
,
6350 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6351 NL80211_FLAG_NEED_RTNL
,
6354 .cmd
= NL80211_CMD_GET_MPATH
,
6355 .doit
= nl80211_get_mpath
,
6356 .dumpit
= nl80211_dump_mpath
,
6357 .policy
= nl80211_policy
,
6358 .flags
= GENL_ADMIN_PERM
,
6359 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6360 NL80211_FLAG_NEED_RTNL
,
6363 .cmd
= NL80211_CMD_SET_MPATH
,
6364 .doit
= nl80211_set_mpath
,
6365 .policy
= nl80211_policy
,
6366 .flags
= GENL_ADMIN_PERM
,
6367 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6368 NL80211_FLAG_NEED_RTNL
,
6371 .cmd
= NL80211_CMD_NEW_MPATH
,
6372 .doit
= nl80211_new_mpath
,
6373 .policy
= nl80211_policy
,
6374 .flags
= GENL_ADMIN_PERM
,
6375 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6376 NL80211_FLAG_NEED_RTNL
,
6379 .cmd
= NL80211_CMD_DEL_MPATH
,
6380 .doit
= nl80211_del_mpath
,
6381 .policy
= nl80211_policy
,
6382 .flags
= GENL_ADMIN_PERM
,
6383 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6384 NL80211_FLAG_NEED_RTNL
,
6387 .cmd
= NL80211_CMD_SET_BSS
,
6388 .doit
= nl80211_set_bss
,
6389 .policy
= nl80211_policy
,
6390 .flags
= GENL_ADMIN_PERM
,
6391 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6392 NL80211_FLAG_NEED_RTNL
,
6395 .cmd
= NL80211_CMD_GET_REG
,
6396 .doit
= nl80211_get_reg
,
6397 .policy
= nl80211_policy
,
6398 /* can be retrieved by unprivileged users */
6401 .cmd
= NL80211_CMD_SET_REG
,
6402 .doit
= nl80211_set_reg
,
6403 .policy
= nl80211_policy
,
6404 .flags
= GENL_ADMIN_PERM
,
6407 .cmd
= NL80211_CMD_REQ_SET_REG
,
6408 .doit
= nl80211_req_set_reg
,
6409 .policy
= nl80211_policy
,
6410 .flags
= GENL_ADMIN_PERM
,
6413 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
6414 .doit
= nl80211_get_mesh_config
,
6415 .policy
= nl80211_policy
,
6416 /* can be retrieved by unprivileged users */
6417 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6418 NL80211_FLAG_NEED_RTNL
,
6421 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
6422 .doit
= nl80211_update_mesh_config
,
6423 .policy
= nl80211_policy
,
6424 .flags
= GENL_ADMIN_PERM
,
6425 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6426 NL80211_FLAG_NEED_RTNL
,
6429 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
6430 .doit
= nl80211_trigger_scan
,
6431 .policy
= nl80211_policy
,
6432 .flags
= GENL_ADMIN_PERM
,
6433 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6434 NL80211_FLAG_NEED_RTNL
,
6437 .cmd
= NL80211_CMD_GET_SCAN
,
6438 .policy
= nl80211_policy
,
6439 .dumpit
= nl80211_dump_scan
,
6442 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
6443 .doit
= nl80211_start_sched_scan
,
6444 .policy
= nl80211_policy
,
6445 .flags
= GENL_ADMIN_PERM
,
6446 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6447 NL80211_FLAG_NEED_RTNL
,
6450 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
6451 .doit
= nl80211_stop_sched_scan
,
6452 .policy
= nl80211_policy
,
6453 .flags
= GENL_ADMIN_PERM
,
6454 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6455 NL80211_FLAG_NEED_RTNL
,
6458 .cmd
= NL80211_CMD_AUTHENTICATE
,
6459 .doit
= nl80211_authenticate
,
6460 .policy
= nl80211_policy
,
6461 .flags
= GENL_ADMIN_PERM
,
6462 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6463 NL80211_FLAG_NEED_RTNL
,
6466 .cmd
= NL80211_CMD_ASSOCIATE
,
6467 .doit
= nl80211_associate
,
6468 .policy
= nl80211_policy
,
6469 .flags
= GENL_ADMIN_PERM
,
6470 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6471 NL80211_FLAG_NEED_RTNL
,
6474 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
6475 .doit
= nl80211_deauthenticate
,
6476 .policy
= nl80211_policy
,
6477 .flags
= GENL_ADMIN_PERM
,
6478 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6479 NL80211_FLAG_NEED_RTNL
,
6482 .cmd
= NL80211_CMD_DISASSOCIATE
,
6483 .doit
= nl80211_disassociate
,
6484 .policy
= nl80211_policy
,
6485 .flags
= GENL_ADMIN_PERM
,
6486 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6487 NL80211_FLAG_NEED_RTNL
,
6490 .cmd
= NL80211_CMD_JOIN_IBSS
,
6491 .doit
= nl80211_join_ibss
,
6492 .policy
= nl80211_policy
,
6493 .flags
= GENL_ADMIN_PERM
,
6494 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6495 NL80211_FLAG_NEED_RTNL
,
6498 .cmd
= NL80211_CMD_LEAVE_IBSS
,
6499 .doit
= nl80211_leave_ibss
,
6500 .policy
= nl80211_policy
,
6501 .flags
= GENL_ADMIN_PERM
,
6502 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6503 NL80211_FLAG_NEED_RTNL
,
6505 #ifdef CONFIG_NL80211_TESTMODE
6507 .cmd
= NL80211_CMD_TESTMODE
,
6508 .doit
= nl80211_testmode_do
,
6509 .dumpit
= nl80211_testmode_dump
,
6510 .policy
= nl80211_policy
,
6511 .flags
= GENL_ADMIN_PERM
,
6512 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6513 NL80211_FLAG_NEED_RTNL
,
6517 .cmd
= NL80211_CMD_CONNECT
,
6518 .doit
= nl80211_connect
,
6519 .policy
= nl80211_policy
,
6520 .flags
= GENL_ADMIN_PERM
,
6521 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6522 NL80211_FLAG_NEED_RTNL
,
6525 .cmd
= NL80211_CMD_DISCONNECT
,
6526 .doit
= nl80211_disconnect
,
6527 .policy
= nl80211_policy
,
6528 .flags
= GENL_ADMIN_PERM
,
6529 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6530 NL80211_FLAG_NEED_RTNL
,
6533 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
6534 .doit
= nl80211_wiphy_netns
,
6535 .policy
= nl80211_policy
,
6536 .flags
= GENL_ADMIN_PERM
,
6537 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6538 NL80211_FLAG_NEED_RTNL
,
6541 .cmd
= NL80211_CMD_GET_SURVEY
,
6542 .policy
= nl80211_policy
,
6543 .dumpit
= nl80211_dump_survey
,
6546 .cmd
= NL80211_CMD_SET_PMKSA
,
6547 .doit
= nl80211_setdel_pmksa
,
6548 .policy
= nl80211_policy
,
6549 .flags
= GENL_ADMIN_PERM
,
6550 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6551 NL80211_FLAG_NEED_RTNL
,
6554 .cmd
= NL80211_CMD_DEL_PMKSA
,
6555 .doit
= nl80211_setdel_pmksa
,
6556 .policy
= nl80211_policy
,
6557 .flags
= GENL_ADMIN_PERM
,
6558 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6559 NL80211_FLAG_NEED_RTNL
,
6562 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
6563 .doit
= nl80211_flush_pmksa
,
6564 .policy
= nl80211_policy
,
6565 .flags
= GENL_ADMIN_PERM
,
6566 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6567 NL80211_FLAG_NEED_RTNL
,
6570 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
6571 .doit
= nl80211_remain_on_channel
,
6572 .policy
= nl80211_policy
,
6573 .flags
= GENL_ADMIN_PERM
,
6574 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6575 NL80211_FLAG_NEED_RTNL
,
6578 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6579 .doit
= nl80211_cancel_remain_on_channel
,
6580 .policy
= nl80211_policy
,
6581 .flags
= GENL_ADMIN_PERM
,
6582 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6583 NL80211_FLAG_NEED_RTNL
,
6586 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
6587 .doit
= nl80211_set_tx_bitrate_mask
,
6588 .policy
= nl80211_policy
,
6589 .flags
= GENL_ADMIN_PERM
,
6590 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6591 NL80211_FLAG_NEED_RTNL
,
6594 .cmd
= NL80211_CMD_REGISTER_FRAME
,
6595 .doit
= nl80211_register_mgmt
,
6596 .policy
= nl80211_policy
,
6597 .flags
= GENL_ADMIN_PERM
,
6598 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6599 NL80211_FLAG_NEED_RTNL
,
6602 .cmd
= NL80211_CMD_FRAME
,
6603 .doit
= nl80211_tx_mgmt
,
6604 .policy
= nl80211_policy
,
6605 .flags
= GENL_ADMIN_PERM
,
6606 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6607 NL80211_FLAG_NEED_RTNL
,
6610 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
6611 .doit
= nl80211_tx_mgmt_cancel_wait
,
6612 .policy
= nl80211_policy
,
6613 .flags
= GENL_ADMIN_PERM
,
6614 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6615 NL80211_FLAG_NEED_RTNL
,
6618 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
6619 .doit
= nl80211_set_power_save
,
6620 .policy
= nl80211_policy
,
6621 .flags
= GENL_ADMIN_PERM
,
6622 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6623 NL80211_FLAG_NEED_RTNL
,
6626 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
6627 .doit
= nl80211_get_power_save
,
6628 .policy
= nl80211_policy
,
6629 /* can be retrieved by unprivileged users */
6630 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6631 NL80211_FLAG_NEED_RTNL
,
6634 .cmd
= NL80211_CMD_SET_CQM
,
6635 .doit
= nl80211_set_cqm
,
6636 .policy
= nl80211_policy
,
6637 .flags
= GENL_ADMIN_PERM
,
6638 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6639 NL80211_FLAG_NEED_RTNL
,
6642 .cmd
= NL80211_CMD_SET_CHANNEL
,
6643 .doit
= nl80211_set_channel
,
6644 .policy
= nl80211_policy
,
6645 .flags
= GENL_ADMIN_PERM
,
6646 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6647 NL80211_FLAG_NEED_RTNL
,
6650 .cmd
= NL80211_CMD_SET_WDS_PEER
,
6651 .doit
= nl80211_set_wds_peer
,
6652 .policy
= nl80211_policy
,
6653 .flags
= GENL_ADMIN_PERM
,
6654 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6655 NL80211_FLAG_NEED_RTNL
,
6658 .cmd
= NL80211_CMD_JOIN_MESH
,
6659 .doit
= nl80211_join_mesh
,
6660 .policy
= nl80211_policy
,
6661 .flags
= GENL_ADMIN_PERM
,
6662 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6663 NL80211_FLAG_NEED_RTNL
,
6666 .cmd
= NL80211_CMD_LEAVE_MESH
,
6667 .doit
= nl80211_leave_mesh
,
6668 .policy
= nl80211_policy
,
6669 .flags
= GENL_ADMIN_PERM
,
6670 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6671 NL80211_FLAG_NEED_RTNL
,
6674 .cmd
= NL80211_CMD_GET_WOWLAN
,
6675 .doit
= nl80211_get_wowlan
,
6676 .policy
= nl80211_policy
,
6677 /* can be retrieved by unprivileged users */
6678 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6679 NL80211_FLAG_NEED_RTNL
,
6682 .cmd
= NL80211_CMD_SET_WOWLAN
,
6683 .doit
= nl80211_set_wowlan
,
6684 .policy
= nl80211_policy
,
6685 .flags
= GENL_ADMIN_PERM
,
6686 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6687 NL80211_FLAG_NEED_RTNL
,
6690 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
6691 .doit
= nl80211_set_rekey_data
,
6692 .policy
= nl80211_policy
,
6693 .flags
= GENL_ADMIN_PERM
,
6694 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6695 NL80211_FLAG_NEED_RTNL
,
6698 .cmd
= NL80211_CMD_TDLS_MGMT
,
6699 .doit
= nl80211_tdls_mgmt
,
6700 .policy
= nl80211_policy
,
6701 .flags
= GENL_ADMIN_PERM
,
6702 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6703 NL80211_FLAG_NEED_RTNL
,
6706 .cmd
= NL80211_CMD_TDLS_OPER
,
6707 .doit
= nl80211_tdls_oper
,
6708 .policy
= nl80211_policy
,
6709 .flags
= GENL_ADMIN_PERM
,
6710 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6711 NL80211_FLAG_NEED_RTNL
,
6714 .cmd
= NL80211_CMD_UNEXPECTED_FRAME
,
6715 .doit
= nl80211_register_unexpected_frame
,
6716 .policy
= nl80211_policy
,
6717 .flags
= GENL_ADMIN_PERM
,
6718 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6719 NL80211_FLAG_NEED_RTNL
,
6722 .cmd
= NL80211_CMD_PROBE_CLIENT
,
6723 .doit
= nl80211_probe_client
,
6724 .policy
= nl80211_policy
,
6725 .flags
= GENL_ADMIN_PERM
,
6726 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6727 NL80211_FLAG_NEED_RTNL
,
6730 .cmd
= NL80211_CMD_REGISTER_BEACONS
,
6731 .doit
= nl80211_register_beacons
,
6732 .policy
= nl80211_policy
,
6733 .flags
= GENL_ADMIN_PERM
,
6734 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6735 NL80211_FLAG_NEED_RTNL
,
6738 .cmd
= NL80211_CMD_SET_NOACK_MAP
,
6739 .doit
= nl80211_set_noack_map
,
6740 .policy
= nl80211_policy
,
6741 .flags
= GENL_ADMIN_PERM
,
6742 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6743 NL80211_FLAG_NEED_RTNL
,
6748 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
6752 /* multicast groups */
6753 static struct genl_multicast_group nl80211_config_mcgrp
= {
6756 static struct genl_multicast_group nl80211_scan_mcgrp
= {
6759 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
6760 .name
= "regulatory",
6763 /* notification functions */
6765 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
6767 struct sk_buff
*msg
;
6769 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6773 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
6778 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6779 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
6782 static int nl80211_add_scan_req(struct sk_buff
*msg
,
6783 struct cfg80211_registered_device
*rdev
)
6785 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
6786 struct nlattr
*nest
;
6789 ASSERT_RDEV_LOCK(rdev
);
6794 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
6796 goto nla_put_failure
;
6797 for (i
= 0; i
< req
->n_ssids
; i
++)
6798 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
6799 nla_nest_end(msg
, nest
);
6801 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
6803 goto nla_put_failure
;
6804 for (i
= 0; i
< req
->n_channels
; i
++)
6805 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
6806 nla_nest_end(msg
, nest
);
6809 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
6816 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
6817 struct cfg80211_registered_device
*rdev
,
6818 struct net_device
*netdev
,
6819 u32 pid
, u32 seq
, int flags
,
6824 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6828 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6829 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6831 /* ignore errors and send incomplete event anyway */
6832 nl80211_add_scan_req(msg
, rdev
);
6834 return genlmsg_end(msg
, hdr
);
6837 genlmsg_cancel(msg
, hdr
);
6842 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
6843 struct cfg80211_registered_device
*rdev
,
6844 struct net_device
*netdev
,
6845 u32 pid
, u32 seq
, int flags
, u32 cmd
)
6849 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6853 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6854 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6856 return genlmsg_end(msg
, hdr
);
6859 genlmsg_cancel(msg
, hdr
);
6863 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
6864 struct net_device
*netdev
)
6866 struct sk_buff
*msg
;
6868 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6872 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6873 NL80211_CMD_TRIGGER_SCAN
) < 0) {
6878 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6879 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6882 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
6883 struct net_device
*netdev
)
6885 struct sk_buff
*msg
;
6887 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6891 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6892 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6897 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6898 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6901 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6902 struct net_device
*netdev
)
6904 struct sk_buff
*msg
;
6906 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6910 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6911 NL80211_CMD_SCAN_ABORTED
) < 0) {
6916 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6917 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6920 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6921 struct net_device
*netdev
)
6923 struct sk_buff
*msg
;
6925 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6929 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6930 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6935 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6936 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6939 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6940 struct net_device
*netdev
, u32 cmd
)
6942 struct sk_buff
*msg
;
6944 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6948 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6953 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6954 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6958 * This can happen on global regulatory changes or device specific settings
6959 * based on custom world regulatory domains.
6961 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6963 struct sk_buff
*msg
;
6966 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6970 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6976 /* Userspace can always count this one always being set */
6977 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6979 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6980 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6981 NL80211_REGDOM_TYPE_WORLD
);
6982 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6983 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6984 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6985 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6987 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6988 NL80211_REGDOM_TYPE_INTERSECTION
);
6990 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6991 NL80211_REGDOM_TYPE_COUNTRY
);
6992 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6995 if (wiphy_idx_valid(request
->wiphy_idx
))
6996 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6998 genlmsg_end(msg
, hdr
);
7001 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7008 genlmsg_cancel(msg
, hdr
);
7012 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
7013 struct net_device
*netdev
,
7014 const u8
*buf
, size_t len
,
7015 enum nl80211_commands cmd
, gfp_t gfp
)
7017 struct sk_buff
*msg
;
7020 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7024 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7030 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7031 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7032 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7034 genlmsg_end(msg
, hdr
);
7036 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7037 nl80211_mlme_mcgrp
.id
, gfp
);
7041 genlmsg_cancel(msg
, hdr
);
7045 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
7046 struct net_device
*netdev
, const u8
*buf
,
7047 size_t len
, gfp_t gfp
)
7049 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7050 NL80211_CMD_AUTHENTICATE
, gfp
);
7053 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
7054 struct net_device
*netdev
, const u8
*buf
,
7055 size_t len
, gfp_t gfp
)
7057 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7058 NL80211_CMD_ASSOCIATE
, gfp
);
7061 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
7062 struct net_device
*netdev
, const u8
*buf
,
7063 size_t len
, gfp_t gfp
)
7065 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7066 NL80211_CMD_DEAUTHENTICATE
, gfp
);
7069 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
7070 struct net_device
*netdev
, const u8
*buf
,
7071 size_t len
, gfp_t gfp
)
7073 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7074 NL80211_CMD_DISASSOCIATE
, gfp
);
7077 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
7078 struct net_device
*netdev
, const u8
*buf
,
7079 size_t len
, gfp_t gfp
)
7081 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7082 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
7085 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
7086 struct net_device
*netdev
, const u8
*buf
,
7087 size_t len
, gfp_t gfp
)
7089 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
7090 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
7093 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
7094 struct net_device
*netdev
, int cmd
,
7095 const u8
*addr
, gfp_t gfp
)
7097 struct sk_buff
*msg
;
7100 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7104 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7110 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7111 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7112 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
7113 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7115 genlmsg_end(msg
, hdr
);
7117 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7118 nl80211_mlme_mcgrp
.id
, gfp
);
7122 genlmsg_cancel(msg
, hdr
);
7126 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
7127 struct net_device
*netdev
, const u8
*addr
,
7130 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
7134 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
7135 struct net_device
*netdev
, const u8
*addr
,
7138 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
7142 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
7143 struct net_device
*netdev
, const u8
*bssid
,
7144 const u8
*req_ie
, size_t req_ie_len
,
7145 const u8
*resp_ie
, size_t resp_ie_len
,
7146 u16 status
, gfp_t gfp
)
7148 struct sk_buff
*msg
;
7151 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7155 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
7161 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7162 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7164 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7165 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
7167 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
7169 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
7171 genlmsg_end(msg
, hdr
);
7173 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7174 nl80211_mlme_mcgrp
.id
, gfp
);
7178 genlmsg_cancel(msg
, hdr
);
7183 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
7184 struct net_device
*netdev
, const u8
*bssid
,
7185 const u8
*req_ie
, size_t req_ie_len
,
7186 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
7188 struct sk_buff
*msg
;
7191 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7195 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
7201 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7202 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7203 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7205 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
7207 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
7209 genlmsg_end(msg
, hdr
);
7211 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7212 nl80211_mlme_mcgrp
.id
, gfp
);
7216 genlmsg_cancel(msg
, hdr
);
7221 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
7222 struct net_device
*netdev
, u16 reason
,
7223 const u8
*ie
, size_t ie_len
, bool from_ap
)
7225 struct sk_buff
*msg
;
7228 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
7232 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
7238 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7239 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7240 if (from_ap
&& reason
)
7241 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
7243 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
7245 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
7247 genlmsg_end(msg
, hdr
);
7249 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7250 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
7254 genlmsg_cancel(msg
, hdr
);
7259 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
7260 struct net_device
*netdev
, const u8
*bssid
,
7263 struct sk_buff
*msg
;
7266 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7270 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
7276 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7277 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7278 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7280 genlmsg_end(msg
, hdr
);
7282 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7283 nl80211_mlme_mcgrp
.id
, gfp
);
7287 genlmsg_cancel(msg
, hdr
);
7291 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
7292 struct net_device
*netdev
,
7293 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
7296 struct sk_buff
*msg
;
7299 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7303 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
7309 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7310 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7311 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
7313 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
7315 genlmsg_end(msg
, hdr
);
7317 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7318 nl80211_mlme_mcgrp
.id
, gfp
);
7322 genlmsg_cancel(msg
, hdr
);
7326 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
7327 struct net_device
*netdev
, const u8
*addr
,
7328 enum nl80211_key_type key_type
, int key_id
,
7329 const u8
*tsc
, gfp_t gfp
)
7331 struct sk_buff
*msg
;
7334 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7338 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
7344 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7345 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7347 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7348 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
7350 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
7352 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
7354 genlmsg_end(msg
, hdr
);
7356 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7357 nl80211_mlme_mcgrp
.id
, gfp
);
7361 genlmsg_cancel(msg
, hdr
);
7365 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
7366 struct ieee80211_channel
*channel_before
,
7367 struct ieee80211_channel
*channel_after
)
7369 struct sk_buff
*msg
;
7371 struct nlattr
*nl_freq
;
7373 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
7377 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
7384 * Since we are applying the beacon hint to a wiphy we know its
7385 * wiphy_idx is valid
7387 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
7390 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
7392 goto nla_put_failure
;
7393 if (nl80211_msg_put_channel(msg
, channel_before
))
7394 goto nla_put_failure
;
7395 nla_nest_end(msg
, nl_freq
);
7398 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
7400 goto nla_put_failure
;
7401 if (nl80211_msg_put_channel(msg
, channel_after
))
7402 goto nla_put_failure
;
7403 nla_nest_end(msg
, nl_freq
);
7405 genlmsg_end(msg
, hdr
);
7408 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7415 genlmsg_cancel(msg
, hdr
);
7419 static void nl80211_send_remain_on_chan_event(
7420 int cmd
, struct cfg80211_registered_device
*rdev
,
7421 struct net_device
*netdev
, u64 cookie
,
7422 struct ieee80211_channel
*chan
,
7423 enum nl80211_channel_type channel_type
,
7424 unsigned int duration
, gfp_t gfp
)
7426 struct sk_buff
*msg
;
7429 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7433 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7439 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7440 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7441 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
7442 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
7443 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7445 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
7446 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
7448 genlmsg_end(msg
, hdr
);
7450 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7451 nl80211_mlme_mcgrp
.id
, gfp
);
7455 genlmsg_cancel(msg
, hdr
);
7459 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
7460 struct net_device
*netdev
, u64 cookie
,
7461 struct ieee80211_channel
*chan
,
7462 enum nl80211_channel_type channel_type
,
7463 unsigned int duration
, gfp_t gfp
)
7465 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
7466 rdev
, netdev
, cookie
, chan
,
7467 channel_type
, duration
, gfp
);
7470 void nl80211_send_remain_on_channel_cancel(
7471 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
7472 u64 cookie
, struct ieee80211_channel
*chan
,
7473 enum nl80211_channel_type channel_type
, gfp_t gfp
)
7475 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7476 rdev
, netdev
, cookie
, chan
,
7477 channel_type
, 0, gfp
);
7480 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
7481 struct net_device
*dev
, const u8
*mac_addr
,
7482 struct station_info
*sinfo
, gfp_t gfp
)
7484 struct sk_buff
*msg
;
7486 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7490 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
7495 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7496 nl80211_mlme_mcgrp
.id
, gfp
);
7499 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
7500 struct net_device
*dev
, const u8
*mac_addr
,
7503 struct sk_buff
*msg
;
7506 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7510 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
7516 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
7517 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
7519 genlmsg_end(msg
, hdr
);
7521 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7522 nl80211_mlme_mcgrp
.id
, gfp
);
7526 genlmsg_cancel(msg
, hdr
);
7530 static bool __nl80211_unexpected_frame(struct net_device
*dev
, u8 cmd
,
7531 const u8
*addr
, gfp_t gfp
)
7533 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7534 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
7535 struct sk_buff
*msg
;
7538 u32 nlpid
= ACCESS_ONCE(wdev
->ap_unexpected_nlpid
);
7543 msg
= nlmsg_new(100, gfp
);
7547 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7553 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7554 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
7555 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7557 err
= genlmsg_end(msg
, hdr
);
7563 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
7567 genlmsg_cancel(msg
, hdr
);
7572 bool nl80211_unexpected_frame(struct net_device
*dev
, const u8
*addr
, gfp_t gfp
)
7574 return __nl80211_unexpected_frame(dev
, NL80211_CMD_UNEXPECTED_FRAME
,
7578 bool nl80211_unexpected_4addr_frame(struct net_device
*dev
,
7579 const u8
*addr
, gfp_t gfp
)
7581 return __nl80211_unexpected_frame(dev
,
7582 NL80211_CMD_UNEXPECTED_4ADDR_FRAME
,
7586 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
7587 struct net_device
*netdev
, u32 nlpid
,
7588 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
7590 struct sk_buff
*msg
;
7593 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7597 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
7603 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7604 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7605 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7606 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7608 genlmsg_end(msg
, hdr
);
7610 return genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
7613 genlmsg_cancel(msg
, hdr
);
7618 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
7619 struct net_device
*netdev
, u64 cookie
,
7620 const u8
*buf
, size_t len
, bool ack
,
7623 struct sk_buff
*msg
;
7626 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7630 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
7636 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7637 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7638 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7639 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7641 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
7643 genlmsg_end(msg
, hdr
);
7645 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
7649 genlmsg_cancel(msg
, hdr
);
7654 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
7655 struct net_device
*netdev
,
7656 enum nl80211_cqm_rssi_threshold_event rssi_event
,
7659 struct sk_buff
*msg
;
7660 struct nlattr
*pinfoattr
;
7663 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7667 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7673 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7674 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7676 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7678 goto nla_put_failure
;
7680 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
7683 nla_nest_end(msg
, pinfoattr
);
7685 genlmsg_end(msg
, hdr
);
7687 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7688 nl80211_mlme_mcgrp
.id
, gfp
);
7692 genlmsg_cancel(msg
, hdr
);
7696 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
7697 struct net_device
*netdev
, const u8
*bssid
,
7698 const u8
*replay_ctr
, gfp_t gfp
)
7700 struct sk_buff
*msg
;
7701 struct nlattr
*rekey_attr
;
7704 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7708 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7714 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7715 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7716 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7718 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7720 goto nla_put_failure
;
7722 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
7723 NL80211_REPLAY_CTR_LEN
, replay_ctr
);
7725 nla_nest_end(msg
, rekey_attr
);
7727 genlmsg_end(msg
, hdr
);
7729 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7730 nl80211_mlme_mcgrp
.id
, gfp
);
7734 genlmsg_cancel(msg
, hdr
);
7738 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
7739 struct net_device
*netdev
, int index
,
7740 const u8
*bssid
, bool preauth
, gfp_t gfp
)
7742 struct sk_buff
*msg
;
7743 struct nlattr
*attr
;
7746 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7750 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
7756 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7757 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7759 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
7761 goto nla_put_failure
;
7763 NLA_PUT_U32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
);
7764 NLA_PUT(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
);
7766 NLA_PUT_FLAG(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
);
7768 nla_nest_end(msg
, attr
);
7770 genlmsg_end(msg
, hdr
);
7772 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7773 nl80211_mlme_mcgrp
.id
, gfp
);
7777 genlmsg_cancel(msg
, hdr
);
7782 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
7783 struct net_device
*netdev
, const u8
*peer
,
7784 u32 num_packets
, gfp_t gfp
)
7786 struct sk_buff
*msg
;
7787 struct nlattr
*pinfoattr
;
7790 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7794 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7800 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7801 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7802 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
7804 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7806 goto nla_put_failure
;
7808 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
7810 nla_nest_end(msg
, pinfoattr
);
7812 genlmsg_end(msg
, hdr
);
7814 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7815 nl80211_mlme_mcgrp
.id
, gfp
);
7819 genlmsg_cancel(msg
, hdr
);
7823 void cfg80211_probe_status(struct net_device
*dev
, const u8
*addr
,
7824 u64 cookie
, bool acked
, gfp_t gfp
)
7826 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
7827 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wdev
->wiphy
);
7828 struct sk_buff
*msg
;
7832 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7836 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PROBE_CLIENT
);
7842 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7843 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
7844 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7845 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7847 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
7849 err
= genlmsg_end(msg
, hdr
);
7855 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7856 nl80211_mlme_mcgrp
.id
, gfp
);
7860 genlmsg_cancel(msg
, hdr
);
7863 EXPORT_SYMBOL(cfg80211_probe_status
);
7865 void cfg80211_report_obss_beacon(struct wiphy
*wiphy
,
7866 const u8
*frame
, size_t len
,
7867 int freq
, gfp_t gfp
)
7869 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
7870 struct sk_buff
*msg
;
7872 u32 nlpid
= ACCESS_ONCE(rdev
->ap_beacons_nlpid
);
7877 msg
= nlmsg_new(len
+ 100, gfp
);
7881 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
7887 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7889 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7890 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, frame
);
7892 genlmsg_end(msg
, hdr
);
7894 genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
7898 genlmsg_cancel(msg
, hdr
);
7901 EXPORT_SYMBOL(cfg80211_report_obss_beacon
);
7903 static int nl80211_netlink_notify(struct notifier_block
* nb
,
7904 unsigned long state
,
7907 struct netlink_notify
*notify
= _notify
;
7908 struct cfg80211_registered_device
*rdev
;
7909 struct wireless_dev
*wdev
;
7911 if (state
!= NETLINK_URELEASE
)
7916 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
) {
7917 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
7918 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
7919 if (rdev
->ap_beacons_nlpid
== notify
->pid
)
7920 rdev
->ap_beacons_nlpid
= 0;
7928 static struct notifier_block nl80211_netlink_notifier
= {
7929 .notifier_call
= nl80211_netlink_notify
,
7932 /* initialisation/exit functions */
7934 int nl80211_init(void)
7938 err
= genl_register_family_with_ops(&nl80211_fam
,
7939 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
7943 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
7947 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
7951 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
7955 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
7959 #ifdef CONFIG_NL80211_TESTMODE
7960 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
7965 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
7971 genl_unregister_family(&nl80211_fam
);
7975 void nl80211_exit(void)
7977 netlink_unregister_notifier(&nl80211_netlink_notifier
);
7978 genl_unregister_family(&nl80211_fam
);