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_info_ifindex(struct genl_info
*info
,
51 struct cfg80211_registered_device
**rdev
,
52 struct net_device
**dev
)
54 struct nlattr
**attrs
= info
->attrs
;
57 if (!attrs
[NL80211_ATTR_IFINDEX
])
60 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
61 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
65 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
68 return PTR_ERR(*rdev
);
74 /* policy for the attributes */
75 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
76 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
77 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
79 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
80 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
81 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
82 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
83 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
84 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
86 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
88 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
89 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
92 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
93 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
95 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
96 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
97 .len
= WLAN_MAX_KEY_LEN
},
98 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
99 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
101 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
102 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
104 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
105 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
106 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
107 .len
= IEEE80211_MAX_DATA_LEN
},
108 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
109 .len
= IEEE80211_MAX_DATA_LEN
},
110 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
111 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
112 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
113 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
114 .len
= NL80211_MAX_SUPP_RATES
},
115 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
116 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
117 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
118 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
119 .len
= IEEE80211_MAX_MESH_ID_LEN
},
120 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
122 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
123 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
125 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
126 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
127 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
128 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
129 .len
= NL80211_MAX_SUPP_RATES
},
130 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
132 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
133 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
135 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
136 .len
= NL80211_HT_CAPABILITY_LEN
},
138 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
139 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
140 .len
= IEEE80211_MAX_DATA_LEN
},
141 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
142 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
144 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
145 .len
= IEEE80211_MAX_SSID_LEN
},
146 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
147 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
148 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
149 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
150 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
151 [NL80211_ATTR_STA_FLAGS2
] = {
152 .len
= sizeof(struct nl80211_sta_flag_update
),
154 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
155 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
156 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
157 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
158 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
160 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
161 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
162 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
163 .len
= WLAN_PMKID_LEN
},
164 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
165 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
166 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
167 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
168 .len
= IEEE80211_MAX_DATA_LEN
},
169 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
170 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
171 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
172 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
173 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
174 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
175 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
176 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
177 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
178 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
179 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
180 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
181 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
182 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
183 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
184 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
185 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
186 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
187 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
188 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
189 .len
= IEEE80211_MAX_DATA_LEN
},
190 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
191 .len
= IEEE80211_MAX_DATA_LEN
},
192 [NL80211_ATTR_ROAM_SUPPORT
] = { .type
= NLA_FLAG
},
193 [NL80211_ATTR_SCHED_SCAN_MATCH
] = { .type
= NLA_NESTED
},
194 [NL80211_ATTR_TX_NO_CCK_RATE
] = { .type
= NLA_FLAG
},
195 [NL80211_ATTR_TDLS_ACTION
] = { .type
= NLA_U8
},
196 [NL80211_ATTR_TDLS_DIALOG_TOKEN
] = { .type
= NLA_U8
},
197 [NL80211_ATTR_TDLS_OPERATION
] = { .type
= NLA_U8
},
198 [NL80211_ATTR_TDLS_SUPPORT
] = { .type
= NLA_FLAG
},
199 [NL80211_ATTR_TDLS_EXTERNAL_SETUP
] = { .type
= NLA_FLAG
},
202 /* policy for the key attributes */
203 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
204 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
205 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
206 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
207 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
208 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
209 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
210 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
211 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
214 /* policy for the key default flags */
215 static const struct nla_policy
216 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
217 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
218 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
221 /* policy for WoWLAN attributes */
222 static const struct nla_policy
223 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
224 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
225 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
226 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
227 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
228 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
229 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
230 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
231 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
234 /* policy for GTK rekey offload attributes */
235 static const struct nla_policy
236 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
237 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
238 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
239 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
242 static const struct nla_policy
243 nl80211_match_policy
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1] = {
244 [NL80211_ATTR_SCHED_SCAN_MATCH_SSID
] = { .type
= NLA_BINARY
,
245 .len
= IEEE80211_MAX_SSID_LEN
},
248 /* ifidx get helper */
249 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
253 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
254 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
259 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
262 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
268 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
269 struct netlink_callback
*cb
,
270 struct cfg80211_registered_device
**rdev
,
271 struct net_device
**dev
)
273 int ifidx
= cb
->args
[0];
277 ifidx
= nl80211_get_ifidx(cb
);
285 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
291 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
293 err
= PTR_ERR(*rdev
);
303 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
305 cfg80211_unlock_rdev(rdev
);
310 static bool is_valid_ie_attr(const struct nlattr
*attr
)
318 pos
= nla_data(attr
);
339 /* message building helper */
340 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
343 /* since there is no private header just add the generic one */
344 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
347 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
348 struct ieee80211_channel
*chan
)
350 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
353 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
354 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
355 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
356 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
357 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
358 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
359 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
360 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
362 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
363 DBM_TO_MBM(chan
->max_power
));
371 /* netlink command implementations */
378 bool def_uni
, def_multi
;
381 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
383 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
384 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
389 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
390 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
399 if (tb
[NL80211_KEY_IDX
])
400 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
402 if (tb
[NL80211_KEY_DATA
]) {
403 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
404 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
407 if (tb
[NL80211_KEY_SEQ
]) {
408 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
409 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
412 if (tb
[NL80211_KEY_CIPHER
])
413 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
415 if (tb
[NL80211_KEY_TYPE
]) {
416 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
417 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
421 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
422 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
423 int err
= nla_parse_nested(kdt
,
424 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
425 tb
[NL80211_KEY_DEFAULT_TYPES
],
426 nl80211_key_default_policy
);
430 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
431 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
437 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
439 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
440 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
441 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
444 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
445 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
446 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
449 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
450 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
452 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
453 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
455 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
456 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
465 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
466 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
467 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
471 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
472 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
473 int err
= nla_parse_nested(
474 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
475 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
476 nl80211_key_default_policy
);
480 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
481 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
487 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
491 memset(k
, 0, sizeof(*k
));
495 if (info
->attrs
[NL80211_ATTR_KEY
])
496 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
498 err
= nl80211_parse_key_old(info
, k
);
503 if (k
->def
&& k
->defmgmt
)
507 if (k
->def_uni
|| !k
->def_multi
)
513 if (k
->idx
< 4 || k
->idx
> 5)
516 if (k
->idx
< 0 || k
->idx
> 3)
519 if (k
->idx
< 0 || k
->idx
> 5)
527 static struct cfg80211_cached_keys
*
528 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
531 struct key_parse parse
;
533 struct cfg80211_cached_keys
*result
;
534 int rem
, err
, def
= 0;
536 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
538 return ERR_PTR(-ENOMEM
);
541 result
->defmgmt
= -1;
543 nla_for_each_nested(key
, keys
, rem
) {
544 memset(&parse
, 0, sizeof(parse
));
547 err
= nl80211_parse_key_new(key
, &parse
);
553 if (parse
.idx
< 0 || parse
.idx
> 4)
559 result
->def
= parse
.idx
;
560 if (!parse
.def_uni
|| !parse
.def_multi
)
562 } else if (parse
.defmgmt
)
564 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
565 parse
.idx
, false, NULL
);
568 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
569 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
570 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
571 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
580 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
582 ASSERT_WDEV_LOCK(wdev
);
584 switch (wdev
->iftype
) {
585 case NL80211_IFTYPE_AP
:
586 case NL80211_IFTYPE_AP_VLAN
:
587 case NL80211_IFTYPE_P2P_GO
:
588 case NL80211_IFTYPE_MESH_POINT
:
590 case NL80211_IFTYPE_ADHOC
:
591 if (!wdev
->current_bss
)
594 case NL80211_IFTYPE_STATION
:
595 case NL80211_IFTYPE_P2P_CLIENT
:
596 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
606 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
608 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
612 goto nla_put_failure
;
617 NLA_PUT_FLAG(msg
, i
);
622 nla_nest_end(msg
, nl_modes
);
629 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
632 struct nlattr
*nl_combis
;
635 nl_combis
= nla_nest_start(msg
,
636 NL80211_ATTR_INTERFACE_COMBINATIONS
);
638 goto nla_put_failure
;
640 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
641 const struct ieee80211_iface_combination
*c
;
642 struct nlattr
*nl_combi
, *nl_limits
;
644 c
= &wiphy
->iface_combinations
[i
];
646 nl_combi
= nla_nest_start(msg
, i
+ 1);
648 goto nla_put_failure
;
650 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
652 goto nla_put_failure
;
654 for (j
= 0; j
< c
->n_limits
; j
++) {
655 struct nlattr
*nl_limit
;
657 nl_limit
= nla_nest_start(msg
, j
+ 1);
659 goto nla_put_failure
;
660 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
662 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
664 goto nla_put_failure
;
665 nla_nest_end(msg
, nl_limit
);
668 nla_nest_end(msg
, nl_limits
);
670 if (c
->beacon_int_infra_match
)
672 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
673 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
674 c
->num_different_channels
);
675 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
678 nla_nest_end(msg
, nl_combi
);
681 nla_nest_end(msg
, nl_combis
);
688 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
689 struct cfg80211_registered_device
*dev
)
692 struct nlattr
*nl_bands
, *nl_band
;
693 struct nlattr
*nl_freqs
, *nl_freq
;
694 struct nlattr
*nl_rates
, *nl_rate
;
695 struct nlattr
*nl_cmds
;
696 enum ieee80211_band band
;
697 struct ieee80211_channel
*chan
;
698 struct ieee80211_rate
*rate
;
700 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
701 dev
->wiphy
.mgmt_stypes
;
703 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
707 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
708 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
710 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
711 cfg80211_rdev_list_generation
);
713 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
714 dev
->wiphy
.retry_short
);
715 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
716 dev
->wiphy
.retry_long
);
717 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
718 dev
->wiphy
.frag_threshold
);
719 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
720 dev
->wiphy
.rts_threshold
);
721 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
722 dev
->wiphy
.coverage_class
);
723 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
724 dev
->wiphy
.max_scan_ssids
);
725 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
726 dev
->wiphy
.max_sched_scan_ssids
);
727 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
728 dev
->wiphy
.max_scan_ie_len
);
729 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
730 dev
->wiphy
.max_sched_scan_ie_len
);
731 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_MATCH_SETS
,
732 dev
->wiphy
.max_match_sets
);
734 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
735 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
736 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
737 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
738 if (dev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
)
739 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_AP_UAPSD
);
740 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_FW_ROAM
)
741 NLA_PUT_FLAG(msg
, NL80211_ATTR_ROAM_SUPPORT
);
742 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
)
743 NLA_PUT_FLAG(msg
, NL80211_ATTR_TDLS_SUPPORT
);
744 if (dev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
)
745 NLA_PUT_FLAG(msg
, NL80211_ATTR_TDLS_EXTERNAL_SETUP
);
747 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
748 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
749 dev
->wiphy
.cipher_suites
);
751 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
752 dev
->wiphy
.max_num_pmkids
);
754 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
755 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
757 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
758 dev
->wiphy
.available_antennas_tx
);
759 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
760 dev
->wiphy
.available_antennas_rx
);
762 if ((dev
->wiphy
.available_antennas_tx
||
763 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
764 u32 tx_ant
= 0, rx_ant
= 0;
766 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
768 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
769 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
773 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
774 dev
->wiphy
.interface_modes
))
775 goto nla_put_failure
;
777 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
779 goto nla_put_failure
;
781 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
782 if (!dev
->wiphy
.bands
[band
])
785 nl_band
= nla_nest_start(msg
, band
);
787 goto nla_put_failure
;
790 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
791 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
792 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
793 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
794 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
795 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
796 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
797 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
798 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
799 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
802 /* add frequencies */
803 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
805 goto nla_put_failure
;
807 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
808 nl_freq
= nla_nest_start(msg
, i
);
810 goto nla_put_failure
;
812 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
814 if (nl80211_msg_put_channel(msg
, chan
))
815 goto nla_put_failure
;
817 nla_nest_end(msg
, nl_freq
);
820 nla_nest_end(msg
, nl_freqs
);
823 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
825 goto nla_put_failure
;
827 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
828 nl_rate
= nla_nest_start(msg
, i
);
830 goto nla_put_failure
;
832 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
833 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
835 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
837 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
839 nla_nest_end(msg
, nl_rate
);
842 nla_nest_end(msg
, nl_rates
);
844 nla_nest_end(msg
, nl_band
);
846 nla_nest_end(msg
, nl_bands
);
848 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
850 goto nla_put_failure
;
855 if (dev->ops->op) { \
857 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
861 CMD(add_virtual_intf
, NEW_INTERFACE
);
862 CMD(change_virtual_intf
, SET_INTERFACE
);
863 CMD(add_key
, NEW_KEY
);
864 CMD(add_beacon
, NEW_BEACON
);
865 CMD(add_station
, NEW_STATION
);
866 CMD(add_mpath
, NEW_MPATH
);
867 CMD(update_mesh_config
, SET_MESH_CONFIG
);
868 CMD(change_bss
, SET_BSS
);
869 CMD(auth
, AUTHENTICATE
);
870 CMD(assoc
, ASSOCIATE
);
871 CMD(deauth
, DEAUTHENTICATE
);
872 CMD(disassoc
, DISASSOCIATE
);
873 CMD(join_ibss
, JOIN_IBSS
);
874 CMD(join_mesh
, JOIN_MESH
);
875 CMD(set_pmksa
, SET_PMKSA
);
876 CMD(del_pmksa
, DEL_PMKSA
);
877 CMD(flush_pmksa
, FLUSH_PMKSA
);
878 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
879 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
881 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
882 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
884 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
886 CMD(set_channel
, SET_CHANNEL
);
887 CMD(set_wds_peer
, SET_WDS_PEER
);
888 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) {
889 CMD(tdls_mgmt
, TDLS_MGMT
);
890 CMD(tdls_oper
, TDLS_OPER
);
892 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
893 CMD(sched_scan_start
, START_SCHED_SCAN
);
897 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
899 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
902 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
904 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
907 nla_nest_end(msg
, nl_cmds
);
909 if (dev
->ops
->remain_on_channel
)
910 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
911 dev
->wiphy
.max_remain_on_channel_duration
);
913 if (dev
->ops
->mgmt_tx_cancel_wait
)
914 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
918 struct nlattr
*nl_ftypes
, *nl_ifs
;
919 enum nl80211_iftype ift
;
921 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
923 goto nla_put_failure
;
925 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
926 nl_ftypes
= nla_nest_start(msg
, ift
);
928 goto nla_put_failure
;
930 stypes
= mgmt_stypes
[ift
].tx
;
933 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
934 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
938 nla_nest_end(msg
, nl_ftypes
);
941 nla_nest_end(msg
, nl_ifs
);
943 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
945 goto nla_put_failure
;
947 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
948 nl_ftypes
= nla_nest_start(msg
, ift
);
950 goto nla_put_failure
;
952 stypes
= mgmt_stypes
[ift
].rx
;
955 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
956 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
960 nla_nest_end(msg
, nl_ftypes
);
962 nla_nest_end(msg
, nl_ifs
);
965 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
966 struct nlattr
*nl_wowlan
;
968 nl_wowlan
= nla_nest_start(msg
,
969 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
971 goto nla_put_failure
;
973 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
974 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
975 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
976 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
977 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
978 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
979 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
)
980 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
);
981 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
)
982 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
983 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
)
984 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
985 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
)
986 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
987 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
)
988 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
989 if (dev
->wiphy
.wowlan
.n_patterns
) {
990 struct nl80211_wowlan_pattern_support pat
= {
991 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
993 dev
->wiphy
.wowlan
.pattern_min_len
,
995 dev
->wiphy
.wowlan
.pattern_max_len
,
997 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
1001 nla_nest_end(msg
, nl_wowlan
);
1004 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
1005 dev
->wiphy
.software_iftypes
))
1006 goto nla_put_failure
;
1008 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
1009 goto nla_put_failure
;
1011 return genlmsg_end(msg
, hdr
);
1014 genlmsg_cancel(msg
, hdr
);
1018 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1021 int start
= cb
->args
[0];
1022 struct cfg80211_registered_device
*dev
;
1024 mutex_lock(&cfg80211_mutex
);
1025 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
1026 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1030 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1031 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1037 mutex_unlock(&cfg80211_mutex
);
1044 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1046 struct sk_buff
*msg
;
1047 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1049 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1053 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1058 return genlmsg_reply(msg
, info
);
1061 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1062 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1063 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1064 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1065 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1066 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1069 static int parse_txq_params(struct nlattr
*tb
[],
1070 struct ieee80211_txq_params
*txq_params
)
1072 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1073 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1074 !tb
[NL80211_TXQ_ATTR_AIFS
])
1077 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1078 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1079 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1080 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1081 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1086 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1089 * You can only set the channel explicitly for AP, mesh
1090 * and WDS type interfaces; all others have their channel
1091 * managed via their respective "establish a connection"
1092 * command (connect, join, ...)
1094 * Monitors are special as they are normally slaved to
1095 * whatever else is going on, so they behave as though
1096 * you tried setting the wiphy channel itself.
1099 wdev
->iftype
== NL80211_IFTYPE_AP
||
1100 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1101 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1102 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1103 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1106 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1107 struct wireless_dev
*wdev
,
1108 struct genl_info
*info
)
1110 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1114 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1117 if (!nl80211_can_set_dev_channel(wdev
))
1120 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1121 channel_type
= nla_get_u32(info
->attrs
[
1122 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1123 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1124 channel_type
!= NL80211_CHAN_HT20
&&
1125 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1126 channel_type
!= NL80211_CHAN_HT40MINUS
)
1130 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1132 mutex_lock(&rdev
->devlist_mtx
);
1135 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1138 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1140 mutex_unlock(&rdev
->devlist_mtx
);
1145 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1147 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1148 struct net_device
*netdev
= info
->user_ptr
[1];
1150 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1153 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1155 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1156 struct net_device
*dev
= info
->user_ptr
[1];
1157 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1160 if (!info
->attrs
[NL80211_ATTR_MAC
])
1163 if (netif_running(dev
))
1166 if (!rdev
->ops
->set_wds_peer
)
1169 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1172 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1173 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1177 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1179 struct cfg80211_registered_device
*rdev
;
1180 struct net_device
*netdev
= NULL
;
1181 struct wireless_dev
*wdev
;
1182 int result
= 0, rem_txq_params
= 0;
1183 struct nlattr
*nl_txq_params
;
1185 u8 retry_short
= 0, retry_long
= 0;
1186 u32 frag_threshold
= 0, rts_threshold
= 0;
1187 u8 coverage_class
= 0;
1190 * Try to find the wiphy and netdev. Normally this
1191 * function shouldn't need the netdev, but this is
1192 * done for backward compatibility -- previously
1193 * setting the channel was done per wiphy, but now
1194 * it is per netdev. Previous userland like hostapd
1195 * also passed a netdev to set_wiphy, so that it is
1196 * possible to let that go to the right netdev!
1198 mutex_lock(&cfg80211_mutex
);
1200 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1201 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1203 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1204 if (netdev
&& netdev
->ieee80211_ptr
) {
1205 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1206 mutex_lock(&rdev
->mtx
);
1212 rdev
= __cfg80211_rdev_from_info(info
);
1214 mutex_unlock(&cfg80211_mutex
);
1215 return PTR_ERR(rdev
);
1221 mutex_lock(&rdev
->mtx
);
1222 } else if (netif_running(netdev
) &&
1223 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1224 wdev
= netdev
->ieee80211_ptr
;
1229 * end workaround code, by now the rdev is available
1230 * and locked, and wdev may or may not be NULL.
1233 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1234 result
= cfg80211_dev_rename(
1235 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1237 mutex_unlock(&cfg80211_mutex
);
1242 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1243 struct ieee80211_txq_params txq_params
;
1244 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1246 if (!rdev
->ops
->set_txq_params
) {
1247 result
= -EOPNOTSUPP
;
1256 nla_for_each_nested(nl_txq_params
,
1257 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1259 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1260 nla_data(nl_txq_params
),
1261 nla_len(nl_txq_params
),
1263 result
= parse_txq_params(tb
, &txq_params
);
1267 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1275 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1276 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1281 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1282 enum nl80211_tx_power_setting type
;
1285 if (!rdev
->ops
->set_tx_power
) {
1286 result
= -EOPNOTSUPP
;
1290 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1291 type
= nla_get_u32(info
->attrs
[idx
]);
1293 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1294 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1299 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1300 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1301 mbm
= nla_get_u32(info
->attrs
[idx
]);
1304 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1309 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1310 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1312 if ((!rdev
->wiphy
.available_antennas_tx
&&
1313 !rdev
->wiphy
.available_antennas_rx
) ||
1314 !rdev
->ops
->set_antenna
) {
1315 result
= -EOPNOTSUPP
;
1319 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1320 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1322 /* reject antenna configurations which don't match the
1323 * available antenna masks, except for the "all" mask */
1324 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1325 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1330 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1331 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1333 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1340 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1341 retry_short
= nla_get_u8(
1342 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1343 if (retry_short
== 0) {
1347 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1350 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1351 retry_long
= nla_get_u8(
1352 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1353 if (retry_long
== 0) {
1357 changed
|= WIPHY_PARAM_RETRY_LONG
;
1360 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1361 frag_threshold
= nla_get_u32(
1362 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1363 if (frag_threshold
< 256) {
1367 if (frag_threshold
!= (u32
) -1) {
1369 * Fragments (apart from the last one) are required to
1370 * have even length. Make the fragmentation code
1371 * simpler by stripping LSB should someone try to use
1372 * odd threshold value.
1374 frag_threshold
&= ~0x1;
1376 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1379 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1380 rts_threshold
= nla_get_u32(
1381 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1382 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1385 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1386 coverage_class
= nla_get_u8(
1387 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1388 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1392 u8 old_retry_short
, old_retry_long
;
1393 u32 old_frag_threshold
, old_rts_threshold
;
1394 u8 old_coverage_class
;
1396 if (!rdev
->ops
->set_wiphy_params
) {
1397 result
= -EOPNOTSUPP
;
1401 old_retry_short
= rdev
->wiphy
.retry_short
;
1402 old_retry_long
= rdev
->wiphy
.retry_long
;
1403 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1404 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1405 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1407 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1408 rdev
->wiphy
.retry_short
= retry_short
;
1409 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1410 rdev
->wiphy
.retry_long
= retry_long
;
1411 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1412 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1413 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1414 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1415 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1416 rdev
->wiphy
.coverage_class
= coverage_class
;
1418 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1420 rdev
->wiphy
.retry_short
= old_retry_short
;
1421 rdev
->wiphy
.retry_long
= old_retry_long
;
1422 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1423 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1424 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1429 mutex_unlock(&rdev
->mtx
);
1436 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1437 struct cfg80211_registered_device
*rdev
,
1438 struct net_device
*dev
)
1442 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1446 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1447 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1448 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1449 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1451 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1452 rdev
->devlist_generation
^
1453 (cfg80211_rdev_list_generation
<< 2));
1455 return genlmsg_end(msg
, hdr
);
1458 genlmsg_cancel(msg
, hdr
);
1462 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1466 int wp_start
= cb
->args
[0];
1467 int if_start
= cb
->args
[1];
1468 struct cfg80211_registered_device
*rdev
;
1469 struct wireless_dev
*wdev
;
1471 mutex_lock(&cfg80211_mutex
);
1472 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1473 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1475 if (wp_idx
< wp_start
) {
1481 mutex_lock(&rdev
->devlist_mtx
);
1482 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1483 if (if_idx
< if_start
) {
1487 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1488 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1489 rdev
, wdev
->netdev
) < 0) {
1490 mutex_unlock(&rdev
->devlist_mtx
);
1495 mutex_unlock(&rdev
->devlist_mtx
);
1500 mutex_unlock(&cfg80211_mutex
);
1502 cb
->args
[0] = wp_idx
;
1503 cb
->args
[1] = if_idx
;
1508 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1510 struct sk_buff
*msg
;
1511 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1512 struct net_device
*netdev
= info
->user_ptr
[1];
1514 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1518 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1524 return genlmsg_reply(msg
, info
);
1527 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1528 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1529 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1530 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1531 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1532 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1535 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1537 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1545 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1546 nla
, mntr_flags_policy
))
1549 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1551 *mntrflags
|= (1<<flag
);
1556 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1557 struct net_device
*netdev
, u8 use_4addr
,
1558 enum nl80211_iftype iftype
)
1561 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1567 case NL80211_IFTYPE_AP_VLAN
:
1568 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1571 case NL80211_IFTYPE_STATION
:
1572 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1582 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1584 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1585 struct vif_params params
;
1587 enum nl80211_iftype otype
, ntype
;
1588 struct net_device
*dev
= info
->user_ptr
[1];
1589 u32 _flags
, *flags
= NULL
;
1590 bool change
= false;
1592 memset(¶ms
, 0, sizeof(params
));
1594 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1596 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1597 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1600 if (ntype
> NL80211_IFTYPE_MAX
)
1604 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1605 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1607 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1609 if (netif_running(dev
))
1613 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1614 IEEE80211_MAX_MESH_ID_LEN
);
1615 wdev
->mesh_id_up_len
=
1616 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1617 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1618 wdev
->mesh_id_up_len
);
1622 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1623 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1625 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1629 params
.use_4addr
= -1;
1632 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1633 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1635 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1645 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1649 if (!err
&& params
.use_4addr
!= -1)
1650 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1655 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1657 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1658 struct vif_params params
;
1659 struct net_device
*dev
;
1661 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1664 memset(¶ms
, 0, sizeof(params
));
1666 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1669 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1670 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1671 if (type
> NL80211_IFTYPE_MAX
)
1675 if (!rdev
->ops
->add_virtual_intf
||
1676 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1679 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1680 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1681 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1686 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1687 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1689 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1690 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1691 type
, err
? NULL
: &flags
, ¶ms
);
1693 return PTR_ERR(dev
);
1695 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1696 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1697 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1700 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1701 IEEE80211_MAX_MESH_ID_LEN
);
1702 wdev
->mesh_id_up_len
=
1703 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1704 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1705 wdev
->mesh_id_up_len
);
1712 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1714 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1715 struct net_device
*dev
= info
->user_ptr
[1];
1717 if (!rdev
->ops
->del_virtual_intf
)
1720 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1723 struct get_key_cookie
{
1724 struct sk_buff
*msg
;
1729 static void get_key_callback(void *c
, struct key_params
*params
)
1732 struct get_key_cookie
*cookie
= c
;
1735 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1736 params
->key_len
, params
->key
);
1739 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1740 params
->seq_len
, params
->seq
);
1743 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1746 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1748 goto nla_put_failure
;
1751 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1752 params
->key_len
, params
->key
);
1755 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1756 params
->seq_len
, params
->seq
);
1759 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1762 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1764 nla_nest_end(cookie
->msg
, key
);
1771 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1773 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1775 struct net_device
*dev
= info
->user_ptr
[1];
1777 const u8
*mac_addr
= NULL
;
1779 struct get_key_cookie cookie
= {
1783 struct sk_buff
*msg
;
1785 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1786 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1791 if (info
->attrs
[NL80211_ATTR_MAC
])
1792 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1794 pairwise
= !!mac_addr
;
1795 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1796 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1797 if (kt
>= NUM_NL80211_KEYTYPES
)
1799 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1800 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1802 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1805 if (!rdev
->ops
->get_key
)
1808 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1812 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1813 NL80211_CMD_NEW_KEY
);
1815 return PTR_ERR(hdr
);
1818 cookie
.idx
= key_idx
;
1820 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1821 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1823 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1825 if (pairwise
&& mac_addr
&&
1826 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1829 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1830 mac_addr
, &cookie
, get_key_callback
);
1836 goto nla_put_failure
;
1838 genlmsg_end(msg
, hdr
);
1839 return genlmsg_reply(msg
, info
);
1848 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1850 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1851 struct key_parse key
;
1853 struct net_device
*dev
= info
->user_ptr
[1];
1855 err
= nl80211_parse_key(info
, &key
);
1862 /* only support setting default key */
1863 if (!key
.def
&& !key
.defmgmt
)
1866 wdev_lock(dev
->ieee80211_ptr
);
1869 if (!rdev
->ops
->set_default_key
) {
1874 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1878 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1879 key
.def_uni
, key
.def_multi
);
1884 #ifdef CONFIG_CFG80211_WEXT
1885 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1888 if (key
.def_uni
|| !key
.def_multi
) {
1893 if (!rdev
->ops
->set_default_mgmt_key
) {
1898 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1902 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1907 #ifdef CONFIG_CFG80211_WEXT
1908 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1913 wdev_unlock(dev
->ieee80211_ptr
);
1918 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1920 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1922 struct net_device
*dev
= info
->user_ptr
[1];
1923 struct key_parse key
;
1924 const u8
*mac_addr
= NULL
;
1926 err
= nl80211_parse_key(info
, &key
);
1933 if (info
->attrs
[NL80211_ATTR_MAC
])
1934 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1936 if (key
.type
== -1) {
1938 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1940 key
.type
= NL80211_KEYTYPE_GROUP
;
1944 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1945 key
.type
!= NL80211_KEYTYPE_GROUP
)
1948 if (!rdev
->ops
->add_key
)
1951 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1952 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1956 wdev_lock(dev
->ieee80211_ptr
);
1957 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1959 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1960 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1962 wdev_unlock(dev
->ieee80211_ptr
);
1967 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1969 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1971 struct net_device
*dev
= info
->user_ptr
[1];
1972 u8
*mac_addr
= NULL
;
1973 struct key_parse key
;
1975 err
= nl80211_parse_key(info
, &key
);
1979 if (info
->attrs
[NL80211_ATTR_MAC
])
1980 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1982 if (key
.type
== -1) {
1984 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1986 key
.type
= NL80211_KEYTYPE_GROUP
;
1990 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1991 key
.type
!= NL80211_KEYTYPE_GROUP
)
1994 if (!rdev
->ops
->del_key
)
1997 wdev_lock(dev
->ieee80211_ptr
);
1998 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
2000 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
2001 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
2005 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
2006 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
2009 #ifdef CONFIG_CFG80211_WEXT
2011 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
2012 dev
->ieee80211_ptr
->wext
.default_key
= -1;
2013 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
2014 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
2017 wdev_unlock(dev
->ieee80211_ptr
);
2022 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2024 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
2025 struct beacon_parameters
*info
);
2026 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2027 struct net_device
*dev
= info
->user_ptr
[1];
2028 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2029 struct beacon_parameters params
;
2030 int haveinfo
= 0, err
;
2032 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
2033 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2034 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2035 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2038 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2039 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2042 memset(¶ms
, 0, sizeof(params
));
2044 switch (info
->genlhdr
->cmd
) {
2045 case NL80211_CMD_NEW_BEACON
:
2046 /* these are required for NEW_BEACON */
2047 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2048 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2049 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2053 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2054 params
.dtim_period
=
2055 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2057 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
2062 * In theory, some of these attributes could be required for
2063 * NEW_BEACON, but since they were not used when the command was
2064 * originally added, keep them optional for old user space
2065 * programs to work with drivers that do not need the additional
2068 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2069 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2071 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2072 if (params
.ssid_len
== 0 ||
2073 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2077 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2078 params
.hidden_ssid
= nla_get_u32(
2079 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2080 if (params
.hidden_ssid
!=
2081 NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2082 params
.hidden_ssid
!=
2083 NL80211_HIDDEN_SSID_ZERO_LEN
&&
2084 params
.hidden_ssid
!=
2085 NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2089 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2091 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2092 params
.auth_type
= nla_get_u32(
2093 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2094 if (!nl80211_valid_auth_type(params
.auth_type
))
2097 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2099 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2100 NL80211_MAX_NR_CIPHER_SUITES
);
2104 call
= rdev
->ops
->add_beacon
;
2106 case NL80211_CMD_SET_BEACON
:
2107 call
= rdev
->ops
->set_beacon
;
2117 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2118 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2120 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2124 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2125 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2127 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2134 if (info
->attrs
[NL80211_ATTR_IE
]) {
2135 params
.beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2136 params
.beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2139 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2140 params
.proberesp_ies
=
2141 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2142 params
.proberesp_ies_len
=
2143 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2146 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2147 params
.assocresp_ies
=
2148 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2149 params
.assocresp_ies_len
=
2150 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2153 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2154 if (!err
&& params
.interval
)
2155 wdev
->beacon_interval
= params
.interval
;
2159 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2161 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2162 struct net_device
*dev
= info
->user_ptr
[1];
2163 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2166 if (!rdev
->ops
->del_beacon
)
2169 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2170 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2173 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2175 wdev
->beacon_interval
= 0;
2179 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2180 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2181 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2182 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2183 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2184 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2187 static int parse_station_flags(struct genl_info
*info
,
2188 struct station_parameters
*params
)
2190 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2195 * Try parsing the new attribute first so userspace
2196 * can specify both for older kernels.
2198 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2200 struct nl80211_sta_flag_update
*sta_flags
;
2202 sta_flags
= nla_data(nla
);
2203 params
->sta_flags_mask
= sta_flags
->mask
;
2204 params
->sta_flags_set
= sta_flags
->set
;
2205 if ((params
->sta_flags_mask
|
2206 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2211 /* if present, parse the old attribute */
2213 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2217 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2218 nla
, sta_flags_policy
))
2221 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2222 params
->sta_flags_mask
&= ~1;
2224 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2226 params
->sta_flags_set
|= (1<<flag
);
2231 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2234 struct nlattr
*rate
;
2237 rate
= nla_nest_start(msg
, attr
);
2239 goto nla_put_failure
;
2241 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2242 bitrate
= cfg80211_calculate_bitrate(info
);
2244 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2246 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2247 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2248 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2249 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2250 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2251 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2253 nla_nest_end(msg
, rate
);
2260 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2261 int flags
, struct net_device
*dev
,
2262 const u8
*mac_addr
, struct station_info
*sinfo
)
2265 struct nlattr
*sinfoattr
, *bss_param
;
2267 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2271 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2272 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2274 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2276 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2278 goto nla_put_failure
;
2279 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2280 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2281 sinfo
->connected_time
);
2282 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2283 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2284 sinfo
->inactive_time
);
2285 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2286 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2288 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2289 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2291 if (sinfo
->filled
& STATION_INFO_LLID
)
2292 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2294 if (sinfo
->filled
& STATION_INFO_PLID
)
2295 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2297 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2298 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2299 sinfo
->plink_state
);
2300 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2301 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2303 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2304 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2306 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2307 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2308 NL80211_STA_INFO_TX_BITRATE
))
2309 goto nla_put_failure
;
2311 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2312 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2313 NL80211_STA_INFO_RX_BITRATE
))
2314 goto nla_put_failure
;
2316 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2317 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2319 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2320 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2322 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2323 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2325 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2326 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2328 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2329 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2331 goto nla_put_failure
;
2333 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2334 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2335 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2336 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2337 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2339 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2340 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2341 sinfo
->bss_param
.dtim_period
);
2342 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2343 sinfo
->bss_param
.beacon_interval
);
2345 nla_nest_end(msg
, bss_param
);
2347 if (sinfo
->filled
& STATION_INFO_STA_FLAGS
)
2348 NLA_PUT(msg
, NL80211_STA_INFO_STA_FLAGS
,
2349 sizeof(struct nl80211_sta_flag_update
),
2351 nla_nest_end(msg
, sinfoattr
);
2353 if (sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
)
2354 NLA_PUT(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2355 sinfo
->assoc_req_ies
);
2357 return genlmsg_end(msg
, hdr
);
2360 genlmsg_cancel(msg
, hdr
);
2364 static int nl80211_dump_station(struct sk_buff
*skb
,
2365 struct netlink_callback
*cb
)
2367 struct station_info sinfo
;
2368 struct cfg80211_registered_device
*dev
;
2369 struct net_device
*netdev
;
2370 u8 mac_addr
[ETH_ALEN
];
2371 int sta_idx
= cb
->args
[1];
2374 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2378 if (!dev
->ops
->dump_station
) {
2384 memset(&sinfo
, 0, sizeof(sinfo
));
2385 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2392 if (nl80211_send_station(skb
,
2393 NETLINK_CB(cb
->skb
).pid
,
2394 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2404 cb
->args
[1] = sta_idx
;
2407 nl80211_finish_netdev_dump(dev
);
2412 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2414 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2415 struct net_device
*dev
= info
->user_ptr
[1];
2416 struct station_info sinfo
;
2417 struct sk_buff
*msg
;
2418 u8
*mac_addr
= NULL
;
2421 memset(&sinfo
, 0, sizeof(sinfo
));
2423 if (!info
->attrs
[NL80211_ATTR_MAC
])
2426 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2428 if (!rdev
->ops
->get_station
)
2431 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2435 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2439 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2440 dev
, mac_addr
, &sinfo
) < 0) {
2445 return genlmsg_reply(msg
, info
);
2449 * Get vlan interface making sure it is running and on the right wiphy.
2451 static int get_vlan(struct genl_info
*info
,
2452 struct cfg80211_registered_device
*rdev
,
2453 struct net_device
**vlan
)
2455 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2459 *vlan
= dev_get_by_index(genl_info_net(info
),
2460 nla_get_u32(vlanattr
));
2463 if (!(*vlan
)->ieee80211_ptr
)
2465 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2467 if (!netif_running(*vlan
))
2473 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2475 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2477 struct net_device
*dev
= info
->user_ptr
[1];
2478 struct station_parameters params
;
2479 u8
*mac_addr
= NULL
;
2481 memset(¶ms
, 0, sizeof(params
));
2483 params
.listen_interval
= -1;
2484 params
.plink_state
= -1;
2486 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2489 if (!info
->attrs
[NL80211_ATTR_MAC
])
2492 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2494 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2495 params
.supported_rates
=
2496 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2497 params
.supported_rates_len
=
2498 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2501 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2502 params
.listen_interval
=
2503 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2505 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2507 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2509 if (parse_station_flags(info
, ¶ms
))
2512 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2513 params
.plink_action
=
2514 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2516 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2517 params
.plink_state
=
2518 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2520 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2524 /* validate settings */
2527 switch (dev
->ieee80211_ptr
->iftype
) {
2528 case NL80211_IFTYPE_AP
:
2529 case NL80211_IFTYPE_AP_VLAN
:
2530 case NL80211_IFTYPE_P2P_GO
:
2531 /* disallow mesh-specific things */
2532 if (params
.plink_action
)
2535 case NL80211_IFTYPE_P2P_CLIENT
:
2536 case NL80211_IFTYPE_STATION
:
2537 /* disallow things sta doesn't support */
2538 if (params
.plink_action
)
2542 if (params
.supported_rates
&&
2543 !(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2547 if (params
.listen_interval
>= 0)
2549 if (params
.sta_flags_mask
&
2550 ~(BIT(NL80211_STA_FLAG_AUTHORIZED
) |
2551 BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2553 /* can't change the TDLS bit */
2554 if (!(params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
2555 (params
.sta_flags_mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)))
2558 case NL80211_IFTYPE_MESH_POINT
:
2559 /* disallow things mesh doesn't support */
2564 if (params
.listen_interval
>= 0)
2566 if (params
.sta_flags_mask
&
2567 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2568 BIT(NL80211_STA_FLAG_MFP
) |
2569 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2579 if (!rdev
->ops
->change_station
) {
2584 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2588 dev_put(params
.vlan
);
2593 static struct nla_policy
2594 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
2595 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
2596 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
2599 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2601 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2603 struct net_device
*dev
= info
->user_ptr
[1];
2604 struct station_parameters params
;
2605 u8
*mac_addr
= NULL
;
2607 memset(¶ms
, 0, sizeof(params
));
2609 if (!info
->attrs
[NL80211_ATTR_MAC
])
2612 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2615 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2618 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2621 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2622 params
.supported_rates
=
2623 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2624 params
.supported_rates_len
=
2625 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2626 params
.listen_interval
=
2627 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2629 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2630 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2633 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2635 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2637 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2638 params
.plink_action
=
2639 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2641 if (parse_station_flags(info
, ¶ms
))
2644 /* parse WME attributes if sta is WME capable */
2645 if ((rdev
->wiphy
.flags
& WIPHY_FLAG_AP_UAPSD
) &&
2646 (params
.sta_flags_set
& BIT(NL80211_STA_FLAG_WME
)) &&
2647 info
->attrs
[NL80211_ATTR_STA_WME
]) {
2648 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
2651 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
2652 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
2653 nl80211_sta_wme_policy
);
2657 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
2658 params
.uapsd_queues
=
2659 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
2660 if (params
.uapsd_queues
& ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK
)
2663 if (tb
[NL80211_STA_WME_MAX_SP
])
2665 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
2667 if (params
.max_sp
& ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK
)
2670 params
.sta_modify_mask
|= STATION_PARAM_APPLY_UAPSD
;
2673 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2674 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2675 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2676 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
&&
2677 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
)
2681 * Only managed stations can add TDLS peers, and only when the
2682 * wiphy supports external TDLS setup.
2684 if (dev
->ieee80211_ptr
->iftype
== NL80211_IFTYPE_STATION
&&
2685 !((params
.sta_flags_set
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) &&
2686 (rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) &&
2687 (rdev
->wiphy
.flags
& WIPHY_FLAG_TDLS_EXTERNAL_SETUP
)))
2690 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2694 /* validate settings */
2697 if (!rdev
->ops
->add_station
) {
2702 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2706 dev_put(params
.vlan
);
2710 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2712 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2713 struct net_device
*dev
= info
->user_ptr
[1];
2714 u8
*mac_addr
= NULL
;
2716 if (info
->attrs
[NL80211_ATTR_MAC
])
2717 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2719 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2720 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2721 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2722 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2725 if (!rdev
->ops
->del_station
)
2728 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2731 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2732 int flags
, struct net_device
*dev
,
2733 u8
*dst
, u8
*next_hop
,
2734 struct mpath_info
*pinfo
)
2737 struct nlattr
*pinfoattr
;
2739 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2743 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2744 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2745 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2747 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2749 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2751 goto nla_put_failure
;
2752 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2753 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2755 if (pinfo
->filled
& MPATH_INFO_SN
)
2756 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2758 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2759 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2761 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2762 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2764 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2765 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2767 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2768 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2769 pinfo
->discovery_timeout
);
2770 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2771 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2772 pinfo
->discovery_retries
);
2774 nla_nest_end(msg
, pinfoattr
);
2776 return genlmsg_end(msg
, hdr
);
2779 genlmsg_cancel(msg
, hdr
);
2783 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2784 struct netlink_callback
*cb
)
2786 struct mpath_info pinfo
;
2787 struct cfg80211_registered_device
*dev
;
2788 struct net_device
*netdev
;
2790 u8 next_hop
[ETH_ALEN
];
2791 int path_idx
= cb
->args
[1];
2794 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2798 if (!dev
->ops
->dump_mpath
) {
2803 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2809 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2810 dst
, next_hop
, &pinfo
);
2816 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2817 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2818 netdev
, dst
, next_hop
,
2827 cb
->args
[1] = path_idx
;
2830 nl80211_finish_netdev_dump(dev
);
2834 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2836 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2838 struct net_device
*dev
= info
->user_ptr
[1];
2839 struct mpath_info pinfo
;
2840 struct sk_buff
*msg
;
2842 u8 next_hop
[ETH_ALEN
];
2844 memset(&pinfo
, 0, sizeof(pinfo
));
2846 if (!info
->attrs
[NL80211_ATTR_MAC
])
2849 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2851 if (!rdev
->ops
->get_mpath
)
2854 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2857 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2861 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2865 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2866 dev
, dst
, next_hop
, &pinfo
) < 0) {
2871 return genlmsg_reply(msg
, info
);
2874 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2876 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2877 struct net_device
*dev
= info
->user_ptr
[1];
2879 u8
*next_hop
= NULL
;
2881 if (!info
->attrs
[NL80211_ATTR_MAC
])
2884 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2887 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2888 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2890 if (!rdev
->ops
->change_mpath
)
2893 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2896 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2899 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2901 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2902 struct net_device
*dev
= info
->user_ptr
[1];
2904 u8
*next_hop
= NULL
;
2906 if (!info
->attrs
[NL80211_ATTR_MAC
])
2909 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2912 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2913 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2915 if (!rdev
->ops
->add_mpath
)
2918 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2921 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2924 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2926 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2927 struct net_device
*dev
= info
->user_ptr
[1];
2930 if (info
->attrs
[NL80211_ATTR_MAC
])
2931 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2933 if (!rdev
->ops
->del_mpath
)
2936 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2939 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2941 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2942 struct net_device
*dev
= info
->user_ptr
[1];
2943 struct bss_parameters params
;
2945 memset(¶ms
, 0, sizeof(params
));
2946 /* default to not changing parameters */
2947 params
.use_cts_prot
= -1;
2948 params
.use_short_preamble
= -1;
2949 params
.use_short_slot_time
= -1;
2950 params
.ap_isolate
= -1;
2951 params
.ht_opmode
= -1;
2953 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2954 params
.use_cts_prot
=
2955 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2956 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2957 params
.use_short_preamble
=
2958 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2959 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2960 params
.use_short_slot_time
=
2961 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2962 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2963 params
.basic_rates
=
2964 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2965 params
.basic_rates_len
=
2966 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2968 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2969 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2970 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2972 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2974 if (!rdev
->ops
->change_bss
)
2977 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2978 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2981 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2984 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2985 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2986 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2987 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2988 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2989 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2990 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2993 static int parse_reg_rule(struct nlattr
*tb
[],
2994 struct ieee80211_reg_rule
*reg_rule
)
2996 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2997 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2999 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
3001 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
3003 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
3005 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
3007 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
3010 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
3012 freq_range
->start_freq_khz
=
3013 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
3014 freq_range
->end_freq_khz
=
3015 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
3016 freq_range
->max_bandwidth_khz
=
3017 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
3019 power_rule
->max_eirp
=
3020 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
3022 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
3023 power_rule
->max_antenna_gain
=
3024 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
3029 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3035 * You should only get this when cfg80211 hasn't yet initialized
3036 * completely when built-in to the kernel right between the time
3037 * window between nl80211_init() and regulatory_init(), if that is
3040 mutex_lock(&cfg80211_mutex
);
3041 if (unlikely(!cfg80211_regdomain
)) {
3042 mutex_unlock(&cfg80211_mutex
);
3043 return -EINPROGRESS
;
3045 mutex_unlock(&cfg80211_mutex
);
3047 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3050 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3052 r
= regulatory_hint_user(data
);
3057 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
3058 struct genl_info
*info
)
3060 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3061 struct net_device
*dev
= info
->user_ptr
[1];
3062 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3063 struct mesh_config cur_params
;
3066 struct nlattr
*pinfoattr
;
3067 struct sk_buff
*msg
;
3069 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3072 if (!rdev
->ops
->get_mesh_config
)
3076 /* If not connected, get default parameters */
3077 if (!wdev
->mesh_id_len
)
3078 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3080 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3087 /* Draw up a netlink message to send back */
3088 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3091 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3092 NL80211_CMD_GET_MESH_CONFIG
);
3095 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3097 goto nla_put_failure
;
3098 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3099 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3100 cur_params
.dot11MeshRetryTimeout
);
3101 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3102 cur_params
.dot11MeshConfirmTimeout
);
3103 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3104 cur_params
.dot11MeshHoldingTimeout
);
3105 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3106 cur_params
.dot11MeshMaxPeerLinks
);
3107 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3108 cur_params
.dot11MeshMaxRetries
);
3109 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
3110 cur_params
.dot11MeshTTL
);
3111 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3112 cur_params
.element_ttl
);
3113 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3114 cur_params
.auto_open_plinks
);
3115 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3116 cur_params
.dot11MeshHWMPmaxPREQretries
);
3117 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3118 cur_params
.path_refresh_time
);
3119 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3120 cur_params
.min_discovery_timeout
);
3121 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3122 cur_params
.dot11MeshHWMPactivePathTimeout
);
3123 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3124 cur_params
.dot11MeshHWMPpreqMinInterval
);
3125 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3126 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
3127 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3128 cur_params
.dot11MeshHWMPRootMode
);
3129 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3130 cur_params
.dot11MeshHWMPRannInterval
);
3131 NLA_PUT_U8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3132 cur_params
.dot11MeshGateAnnouncementProtocol
);
3133 nla_nest_end(msg
, pinfoattr
);
3134 genlmsg_end(msg
, hdr
);
3135 return genlmsg_reply(msg
, info
);
3138 genlmsg_cancel(msg
, hdr
);
3144 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3145 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3146 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3147 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3148 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3149 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3150 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3151 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3152 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3154 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3155 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3156 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3157 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3158 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3159 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3160 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3161 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3162 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3165 static const struct nla_policy
3166 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3167 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3168 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3169 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3170 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3171 .len
= IEEE80211_MAX_DATA_LEN
},
3172 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3175 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3176 struct mesh_config
*cfg
,
3179 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3182 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3184 if (table[attr_num]) {\
3185 cfg->param = nla_fn(table[attr_num]); \
3186 mask |= (1 << (attr_num - 1)); \
3191 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3193 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3194 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3195 nl80211_meshconf_params_policy
))
3198 /* This makes sure that there aren't more than 32 mesh config
3199 * parameters (otherwise our bitfield scheme would not work.) */
3200 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3202 /* Fill in the params struct */
3203 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3204 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
3205 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3206 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3207 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3208 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3209 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3210 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3211 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3212 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3213 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3214 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3215 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3216 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3217 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3218 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3219 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3220 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3222 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3223 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3224 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3225 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3227 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3228 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3230 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3231 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3233 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3234 dot11MeshHWMPnetDiameterTraversalTime
,
3235 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3237 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3238 dot11MeshHWMPRootMode
, mask
,
3239 NL80211_MESHCONF_HWMP_ROOTMODE
,
3241 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3242 dot11MeshHWMPRannInterval
, mask
,
3243 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3245 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3246 dot11MeshGateAnnouncementProtocol
, mask
,
3247 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3254 #undef FILL_IN_MESH_PARAM_IF_SET
3257 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3258 struct mesh_setup
*setup
)
3260 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3262 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3264 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3265 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3266 nl80211_mesh_setup_params_policy
))
3269 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3270 setup
->path_sel_proto
=
3271 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3272 IEEE80211_PATH_PROTOCOL_VENDOR
:
3273 IEEE80211_PATH_PROTOCOL_HWMP
;
3275 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3276 setup
->path_metric
=
3277 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3278 IEEE80211_PATH_METRIC_VENDOR
:
3279 IEEE80211_PATH_METRIC_AIRTIME
;
3282 if (tb
[NL80211_MESH_SETUP_IE
]) {
3283 struct nlattr
*ieattr
=
3284 tb
[NL80211_MESH_SETUP_IE
];
3285 if (!is_valid_ie_attr(ieattr
))
3287 setup
->ie
= nla_data(ieattr
);
3288 setup
->ie_len
= nla_len(ieattr
);
3290 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3291 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3296 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3297 struct genl_info
*info
)
3299 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3300 struct net_device
*dev
= info
->user_ptr
[1];
3301 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3302 struct mesh_config cfg
;
3306 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3309 if (!rdev
->ops
->update_mesh_config
)
3312 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3317 if (!wdev
->mesh_id_len
)
3321 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3329 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3331 struct sk_buff
*msg
;
3333 struct nlattr
*nl_reg_rules
;
3337 mutex_lock(&cfg80211_mutex
);
3339 if (!cfg80211_regdomain
)
3342 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3348 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3349 NL80211_CMD_GET_REG
);
3353 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3354 cfg80211_regdomain
->alpha2
);
3356 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3358 goto nla_put_failure
;
3360 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3361 struct nlattr
*nl_reg_rule
;
3362 const struct ieee80211_reg_rule
*reg_rule
;
3363 const struct ieee80211_freq_range
*freq_range
;
3364 const struct ieee80211_power_rule
*power_rule
;
3366 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3367 freq_range
= ®_rule
->freq_range
;
3368 power_rule
= ®_rule
->power_rule
;
3370 nl_reg_rule
= nla_nest_start(msg
, i
);
3372 goto nla_put_failure
;
3374 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3376 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3377 freq_range
->start_freq_khz
);
3378 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3379 freq_range
->end_freq_khz
);
3380 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3381 freq_range
->max_bandwidth_khz
);
3382 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3383 power_rule
->max_antenna_gain
);
3384 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3385 power_rule
->max_eirp
);
3387 nla_nest_end(msg
, nl_reg_rule
);
3390 nla_nest_end(msg
, nl_reg_rules
);
3392 genlmsg_end(msg
, hdr
);
3393 err
= genlmsg_reply(msg
, info
);
3397 genlmsg_cancel(msg
, hdr
);
3402 mutex_unlock(&cfg80211_mutex
);
3406 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3408 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3409 struct nlattr
*nl_reg_rule
;
3410 char *alpha2
= NULL
;
3411 int rem_reg_rules
= 0, r
= 0;
3412 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3413 struct ieee80211_regdomain
*rd
= NULL
;
3415 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3418 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3421 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3423 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3426 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3430 mutex_lock(&cfg80211_mutex
);
3432 if (!reg_is_valid_request(alpha2
)) {
3437 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3438 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3440 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3446 rd
->n_reg_rules
= num_rules
;
3447 rd
->alpha2
[0] = alpha2
[0];
3448 rd
->alpha2
[1] = alpha2
[1];
3450 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3452 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3453 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3455 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3461 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3467 BUG_ON(rule_idx
!= num_rules
);
3471 mutex_unlock(&cfg80211_mutex
);
3476 mutex_unlock(&cfg80211_mutex
);
3481 static int validate_scan_freqs(struct nlattr
*freqs
)
3483 struct nlattr
*attr1
, *attr2
;
3484 int n_channels
= 0, tmp1
, tmp2
;
3486 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3489 * Some hardware has a limited channel list for
3490 * scanning, and it is pretty much nonsensical
3491 * to scan for a channel twice, so disallow that
3492 * and don't require drivers to check that the
3493 * channel list they get isn't longer than what
3494 * they can scan, as long as they can scan all
3495 * the channels they registered at once.
3497 nla_for_each_nested(attr2
, freqs
, tmp2
)
3498 if (attr1
!= attr2
&&
3499 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3506 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3508 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3509 struct net_device
*dev
= info
->user_ptr
[1];
3510 struct cfg80211_scan_request
*request
;
3511 struct nlattr
*attr
;
3512 struct wiphy
*wiphy
;
3513 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3516 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3519 wiphy
= &rdev
->wiphy
;
3521 if (!rdev
->ops
->scan
)
3527 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3528 n_channels
= validate_scan_freqs(
3529 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3533 enum ieee80211_band band
;
3536 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3537 if (wiphy
->bands
[band
])
3538 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3541 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3542 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3545 if (n_ssids
> wiphy
->max_scan_ssids
)
3548 if (info
->attrs
[NL80211_ATTR_IE
])
3549 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3553 if (ie_len
> wiphy
->max_scan_ie_len
)
3556 request
= kzalloc(sizeof(*request
)
3557 + sizeof(*request
->ssids
) * n_ssids
3558 + sizeof(*request
->channels
) * n_channels
3559 + ie_len
, GFP_KERNEL
);
3564 request
->ssids
= (void *)&request
->channels
[n_channels
];
3565 request
->n_ssids
= n_ssids
;
3568 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3570 request
->ie
= (void *)(request
->channels
+ n_channels
);
3574 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3575 /* user specified, bail out if channel not found */
3576 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3577 struct ieee80211_channel
*chan
;
3579 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3586 /* ignore disabled channels */
3587 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3590 request
->channels
[i
] = chan
;
3594 enum ieee80211_band band
;
3597 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3599 if (!wiphy
->bands
[band
])
3601 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3602 struct ieee80211_channel
*chan
;
3604 chan
= &wiphy
->bands
[band
]->channels
[j
];
3606 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3609 request
->channels
[i
] = chan
;
3620 request
->n_channels
= i
;
3623 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3624 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3625 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3629 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3630 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3635 if (info
->attrs
[NL80211_ATTR_IE
]) {
3636 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3637 memcpy((void *)request
->ie
,
3638 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3642 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
3643 if (wiphy
->bands
[i
])
3645 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
3647 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
3648 nla_for_each_nested(attr
,
3649 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
3651 enum ieee80211_band band
= nla_type(attr
);
3653 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
3657 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
3660 &request
->rates
[band
]);
3667 nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
3670 request
->wiphy
= &rdev
->wiphy
;
3672 rdev
->scan_req
= request
;
3673 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3676 nl80211_send_scan_start(rdev
, dev
);
3680 rdev
->scan_req
= NULL
;
3687 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3688 struct genl_info
*info
)
3690 struct cfg80211_sched_scan_request
*request
;
3691 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3692 struct net_device
*dev
= info
->user_ptr
[1];
3693 struct nlattr
*attr
;
3694 struct wiphy
*wiphy
;
3695 int err
, tmp
, n_ssids
= 0, n_match_sets
= 0, n_channels
, i
;
3697 enum ieee80211_band band
;
3699 struct nlattr
*tb
[NL80211_SCHED_SCAN_MATCH_ATTR_MAX
+ 1];
3701 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3702 !rdev
->ops
->sched_scan_start
)
3705 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3708 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3711 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3715 wiphy
= &rdev
->wiphy
;
3717 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3718 n_channels
= validate_scan_freqs(
3719 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3725 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3726 if (wiphy
->bands
[band
])
3727 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3730 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3731 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3735 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
3738 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
])
3739 nla_for_each_nested(attr
,
3740 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
3744 if (n_match_sets
> wiphy
->max_match_sets
)
3747 if (info
->attrs
[NL80211_ATTR_IE
])
3748 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3752 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
3755 mutex_lock(&rdev
->sched_scan_mtx
);
3757 if (rdev
->sched_scan_req
) {
3762 request
= kzalloc(sizeof(*request
)
3763 + sizeof(*request
->ssids
) * n_ssids
3764 + sizeof(*request
->match_sets
) * n_match_sets
3765 + sizeof(*request
->channels
) * n_channels
3766 + ie_len
, GFP_KERNEL
);
3773 request
->ssids
= (void *)&request
->channels
[n_channels
];
3774 request
->n_ssids
= n_ssids
;
3777 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3779 request
->ie
= (void *)(request
->channels
+ n_channels
);
3784 request
->match_sets
= (void *)(request
->ie
+ ie_len
);
3785 else if (request
->ssids
)
3786 request
->match_sets
=
3787 (void *)(request
->ssids
+ n_ssids
);
3789 request
->match_sets
=
3790 (void *)(request
->channels
+ n_channels
);
3792 request
->n_match_sets
= n_match_sets
;
3795 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3796 /* user specified, bail out if channel not found */
3797 nla_for_each_nested(attr
,
3798 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3800 struct ieee80211_channel
*chan
;
3802 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3809 /* ignore disabled channels */
3810 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3813 request
->channels
[i
] = chan
;
3818 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3820 if (!wiphy
->bands
[band
])
3822 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3823 struct ieee80211_channel
*chan
;
3825 chan
= &wiphy
->bands
[band
]->channels
[j
];
3827 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3830 request
->channels
[i
] = chan
;
3841 request
->n_channels
= i
;
3844 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3845 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3847 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3851 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3852 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3859 if (info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
]) {
3860 nla_for_each_nested(attr
,
3861 info
->attrs
[NL80211_ATTR_SCHED_SCAN_MATCH
],
3863 struct nlattr
*ssid
;
3865 nla_parse(tb
, NL80211_SCHED_SCAN_MATCH_ATTR_MAX
,
3866 nla_data(attr
), nla_len(attr
),
3867 nl80211_match_policy
);
3868 ssid
= tb
[NL80211_ATTR_SCHED_SCAN_MATCH_SSID
];
3870 if (nla_len(ssid
) > IEEE80211_MAX_SSID_LEN
) {
3874 memcpy(request
->match_sets
[i
].ssid
.ssid
,
3875 nla_data(ssid
), nla_len(ssid
));
3876 request
->match_sets
[i
].ssid
.ssid_len
=
3883 if (info
->attrs
[NL80211_ATTR_IE
]) {
3884 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3885 memcpy((void *)request
->ie
,
3886 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3891 request
->wiphy
= &rdev
->wiphy
;
3892 request
->interval
= interval
;
3894 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3896 rdev
->sched_scan_req
= request
;
3897 nl80211_send_sched_scan(rdev
, dev
,
3898 NL80211_CMD_START_SCHED_SCAN
);
3905 mutex_unlock(&rdev
->sched_scan_mtx
);
3909 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3910 struct genl_info
*info
)
3912 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3915 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3916 !rdev
->ops
->sched_scan_stop
)
3919 mutex_lock(&rdev
->sched_scan_mtx
);
3920 err
= __cfg80211_stop_sched_scan(rdev
, false);
3921 mutex_unlock(&rdev
->sched_scan_mtx
);
3926 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
3928 struct cfg80211_registered_device
*rdev
,
3929 struct wireless_dev
*wdev
,
3930 struct cfg80211_internal_bss
*intbss
)
3932 struct cfg80211_bss
*res
= &intbss
->pub
;
3937 ASSERT_WDEV_LOCK(wdev
);
3939 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
3940 NL80211_CMD_NEW_SCAN_RESULTS
);
3944 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
3946 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3947 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3949 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3951 goto nla_put_failure
;
3952 if (!is_zero_ether_addr(res
->bssid
))
3953 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3954 if (res
->information_elements
&& res
->len_information_elements
)
3955 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3956 res
->len_information_elements
,
3957 res
->information_elements
);
3958 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3959 res
->beacon_ies
!= res
->information_elements
)
3960 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3961 res
->len_beacon_ies
, res
->beacon_ies
);
3963 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3964 if (res
->beacon_interval
)
3965 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3966 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3967 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3968 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3969 jiffies_to_msecs(jiffies
- intbss
->ts
));
3971 switch (rdev
->wiphy
.signal_type
) {
3972 case CFG80211_SIGNAL_TYPE_MBM
:
3973 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3975 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3976 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3982 switch (wdev
->iftype
) {
3983 case NL80211_IFTYPE_P2P_CLIENT
:
3984 case NL80211_IFTYPE_STATION
:
3985 if (intbss
== wdev
->current_bss
)
3986 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3987 NL80211_BSS_STATUS_ASSOCIATED
);
3988 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3989 if (intbss
!= wdev
->auth_bsses
[i
])
3991 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3992 NL80211_BSS_STATUS_AUTHENTICATED
);
3996 case NL80211_IFTYPE_ADHOC
:
3997 if (intbss
== wdev
->current_bss
)
3998 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3999 NL80211_BSS_STATUS_IBSS_JOINED
);
4005 nla_nest_end(msg
, bss
);
4007 return genlmsg_end(msg
, hdr
);
4010 genlmsg_cancel(msg
, hdr
);
4014 static int nl80211_dump_scan(struct sk_buff
*skb
,
4015 struct netlink_callback
*cb
)
4017 struct cfg80211_registered_device
*rdev
;
4018 struct net_device
*dev
;
4019 struct cfg80211_internal_bss
*scan
;
4020 struct wireless_dev
*wdev
;
4021 int start
= cb
->args
[1], idx
= 0;
4024 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
4028 wdev
= dev
->ieee80211_ptr
;
4031 spin_lock_bh(&rdev
->bss_lock
);
4032 cfg80211_bss_expire(rdev
);
4034 cb
->seq
= rdev
->bss_generation
;
4036 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
4039 if (nl80211_send_bss(skb
, cb
,
4040 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4041 rdev
, wdev
, scan
) < 0) {
4047 spin_unlock_bh(&rdev
->bss_lock
);
4051 nl80211_finish_netdev_dump(rdev
);
4056 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
4057 int flags
, struct net_device
*dev
,
4058 struct survey_info
*survey
)
4061 struct nlattr
*infoattr
;
4063 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
4064 NL80211_CMD_NEW_SURVEY_RESULTS
);
4068 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
4070 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
4072 goto nla_put_failure
;
4074 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
4075 survey
->channel
->center_freq
);
4076 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
4077 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
4079 if (survey
->filled
& SURVEY_INFO_IN_USE
)
4080 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
4081 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
4082 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
4083 survey
->channel_time
);
4084 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
4085 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
4086 survey
->channel_time_busy
);
4087 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
4088 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
4089 survey
->channel_time_ext_busy
);
4090 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
4091 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
4092 survey
->channel_time_rx
);
4093 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
4094 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
4095 survey
->channel_time_tx
);
4097 nla_nest_end(msg
, infoattr
);
4099 return genlmsg_end(msg
, hdr
);
4102 genlmsg_cancel(msg
, hdr
);
4106 static int nl80211_dump_survey(struct sk_buff
*skb
,
4107 struct netlink_callback
*cb
)
4109 struct survey_info survey
;
4110 struct cfg80211_registered_device
*dev
;
4111 struct net_device
*netdev
;
4112 int survey_idx
= cb
->args
[1];
4115 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4119 if (!dev
->ops
->dump_survey
) {
4125 struct ieee80211_channel
*chan
;
4127 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4134 /* Survey without a channel doesn't make sense */
4135 if (!survey
.channel
) {
4140 chan
= ieee80211_get_channel(&dev
->wiphy
,
4141 survey
.channel
->center_freq
);
4142 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4147 if (nl80211_send_survey(skb
,
4148 NETLINK_CB(cb
->skb
).pid
,
4149 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4157 cb
->args
[1] = survey_idx
;
4160 nl80211_finish_netdev_dump(dev
);
4164 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4166 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4169 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4171 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4172 NL80211_WPA_VERSION_2
));
4175 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4177 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4178 struct net_device
*dev
= info
->user_ptr
[1];
4179 struct ieee80211_channel
*chan
;
4180 const u8
*bssid
, *ssid
, *ie
= NULL
;
4181 int err
, ssid_len
, ie_len
= 0;
4182 enum nl80211_auth_type auth_type
;
4183 struct key_parse key
;
4184 bool local_state_change
;
4186 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4189 if (!info
->attrs
[NL80211_ATTR_MAC
])
4192 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4195 if (!info
->attrs
[NL80211_ATTR_SSID
])
4198 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4201 err
= nl80211_parse_key(info
, &key
);
4206 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4208 if (!key
.p
.key
|| !key
.p
.key_len
)
4210 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4211 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4212 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4213 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4225 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4226 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4235 if (!rdev
->ops
->auth
)
4238 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4239 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4242 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4243 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4244 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4245 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4248 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4249 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4251 if (info
->attrs
[NL80211_ATTR_IE
]) {
4252 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4253 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4256 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4257 if (!nl80211_valid_auth_type(auth_type
))
4260 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4262 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4263 ssid
, ssid_len
, ie
, ie_len
,
4264 key
.p
.key
, key
.p
.key_len
, key
.idx
,
4265 local_state_change
);
4268 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4269 struct genl_info
*info
,
4270 struct cfg80211_crypto_settings
*settings
,
4273 memset(settings
, 0, sizeof(*settings
));
4275 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4277 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4279 proto
= nla_get_u16(
4280 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4281 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4282 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4285 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4286 settings
->control_port_no_encrypt
= true;
4288 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4290 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4294 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4295 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4296 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4298 if (len
% sizeof(u32
))
4301 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4304 memcpy(settings
->ciphers_pairwise
, data
, len
);
4306 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4307 if (!cfg80211_supported_cipher_suite(
4309 settings
->ciphers_pairwise
[i
]))
4313 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4314 settings
->cipher_group
=
4315 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4316 if (!cfg80211_supported_cipher_suite(&rdev
->wiphy
,
4317 settings
->cipher_group
))
4321 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4322 settings
->wpa_versions
=
4323 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4324 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4328 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4332 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4333 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4334 settings
->n_akm_suites
= len
/ sizeof(u32
);
4336 if (len
% sizeof(u32
))
4339 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4342 memcpy(settings
->akm_suites
, data
, len
);
4348 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4350 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4351 struct net_device
*dev
= info
->user_ptr
[1];
4352 struct cfg80211_crypto_settings crypto
;
4353 struct ieee80211_channel
*chan
;
4354 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4355 int err
, ssid_len
, ie_len
= 0;
4356 bool use_mfp
= false;
4358 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4361 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4362 !info
->attrs
[NL80211_ATTR_SSID
] ||
4363 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4366 if (!rdev
->ops
->assoc
)
4369 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4370 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4373 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4375 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4376 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4377 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4380 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4381 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4383 if (info
->attrs
[NL80211_ATTR_IE
]) {
4384 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4385 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4388 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4389 enum nl80211_mfp mfp
=
4390 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4391 if (mfp
== NL80211_MFP_REQUIRED
)
4393 else if (mfp
!= NL80211_MFP_NO
)
4397 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4398 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4400 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4402 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4403 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4409 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4411 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4412 struct net_device
*dev
= info
->user_ptr
[1];
4413 const u8
*ie
= NULL
, *bssid
;
4416 bool local_state_change
;
4418 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4421 if (!info
->attrs
[NL80211_ATTR_MAC
])
4424 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4427 if (!rdev
->ops
->deauth
)
4430 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4431 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4434 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4436 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4437 if (reason_code
== 0) {
4438 /* Reason Code 0 is reserved */
4442 if (info
->attrs
[NL80211_ATTR_IE
]) {
4443 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4444 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4447 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4449 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4450 local_state_change
);
4453 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4455 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4456 struct net_device
*dev
= info
->user_ptr
[1];
4457 const u8
*ie
= NULL
, *bssid
;
4460 bool local_state_change
;
4462 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4465 if (!info
->attrs
[NL80211_ATTR_MAC
])
4468 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4471 if (!rdev
->ops
->disassoc
)
4474 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4475 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4478 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4480 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4481 if (reason_code
== 0) {
4482 /* Reason Code 0 is reserved */
4486 if (info
->attrs
[NL80211_ATTR_IE
]) {
4487 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4488 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4491 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4493 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4494 local_state_change
);
4498 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4499 int mcast_rate
[IEEE80211_NUM_BANDS
],
4502 struct wiphy
*wiphy
= &rdev
->wiphy
;
4506 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4507 struct ieee80211_supported_band
*sband
;
4509 sband
= wiphy
->bands
[band
];
4513 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4514 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4515 mcast_rate
[band
] = i
+ 1;
4525 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4527 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4528 struct net_device
*dev
= info
->user_ptr
[1];
4529 struct cfg80211_ibss_params ibss
;
4530 struct wiphy
*wiphy
;
4531 struct cfg80211_cached_keys
*connkeys
= NULL
;
4534 memset(&ibss
, 0, sizeof(ibss
));
4536 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4539 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4540 !info
->attrs
[NL80211_ATTR_SSID
] ||
4541 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4544 ibss
.beacon_interval
= 100;
4546 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4547 ibss
.beacon_interval
=
4548 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4549 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4553 if (!rdev
->ops
->join_ibss
)
4556 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4559 wiphy
= &rdev
->wiphy
;
4561 if (info
->attrs
[NL80211_ATTR_MAC
]) {
4562 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4564 if (!is_valid_ether_addr(ibss
.bssid
))
4567 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4568 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4570 if (info
->attrs
[NL80211_ATTR_IE
]) {
4571 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4572 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4575 ibss
.channel
= ieee80211_get_channel(wiphy
,
4576 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4577 if (!ibss
.channel
||
4578 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4579 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4582 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4583 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4585 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4587 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4589 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4590 struct ieee80211_supported_band
*sband
=
4591 wiphy
->bands
[ibss
.channel
->band
];
4594 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
4600 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4601 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4602 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4605 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4606 connkeys
= nl80211_parse_connkeys(rdev
,
4607 info
->attrs
[NL80211_ATTR_KEYS
]);
4608 if (IS_ERR(connkeys
))
4609 return PTR_ERR(connkeys
);
4612 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4618 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4620 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4621 struct net_device
*dev
= info
->user_ptr
[1];
4623 if (!rdev
->ops
->leave_ibss
)
4626 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4629 return cfg80211_leave_ibss(rdev
, dev
, false);
4632 #ifdef CONFIG_NL80211_TESTMODE
4633 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4637 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4639 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4642 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4646 if (rdev
->ops
->testmode_cmd
) {
4647 rdev
->testmode_info
= info
;
4648 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4649 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4650 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4651 rdev
->testmode_info
= NULL
;
4657 static int nl80211_testmode_dump(struct sk_buff
*skb
,
4658 struct netlink_callback
*cb
)
4660 struct cfg80211_registered_device
*dev
;
4668 * 0 is a valid index, but not valid for args[0],
4669 * so we need to offset by 1.
4671 phy_idx
= cb
->args
[0] - 1;
4673 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
4674 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
4678 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
])
4680 phy_idx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
]);
4681 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
4683 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
4687 data
= nla_data((void *)cb
->args
[1]);
4688 data_len
= nla_len((void *)cb
->args
[1]);
4691 mutex_lock(&cfg80211_mutex
);
4692 dev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
4694 mutex_unlock(&cfg80211_mutex
);
4697 cfg80211_lock_rdev(dev
);
4698 mutex_unlock(&cfg80211_mutex
);
4700 if (!dev
->ops
->testmode_dump
) {
4706 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
4707 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4708 NL80211_CMD_TESTMODE
);
4709 struct nlattr
*tmdata
;
4711 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) < 0) {
4712 genlmsg_cancel(skb
, hdr
);
4716 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4718 genlmsg_cancel(skb
, hdr
);
4721 err
= dev
->ops
->testmode_dump(&dev
->wiphy
, skb
, cb
,
4723 nla_nest_end(skb
, tmdata
);
4725 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
4726 genlmsg_cancel(skb
, hdr
);
4729 genlmsg_cancel(skb
, hdr
);
4733 genlmsg_end(skb
, hdr
);
4738 cb
->args
[0] = phy_idx
+ 1;
4740 cfg80211_unlock_rdev(dev
);
4744 static struct sk_buff
*
4745 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4746 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4748 struct sk_buff
*skb
;
4750 struct nlattr
*data
;
4752 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4756 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4762 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4763 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4765 ((void **)skb
->cb
)[0] = rdev
;
4766 ((void **)skb
->cb
)[1] = hdr
;
4767 ((void **)skb
->cb
)[2] = data
;
4776 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4779 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4781 if (WARN_ON(!rdev
->testmode_info
))
4784 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4785 rdev
->testmode_info
->snd_pid
,
4786 rdev
->testmode_info
->snd_seq
,
4789 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4791 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4793 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4794 void *hdr
= ((void **)skb
->cb
)[1];
4795 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4797 if (WARN_ON(!rdev
->testmode_info
)) {
4802 nla_nest_end(skb
, data
);
4803 genlmsg_end(skb
, hdr
);
4804 return genlmsg_reply(skb
, rdev
->testmode_info
);
4806 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4808 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4809 int approxlen
, gfp_t gfp
)
4811 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4813 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4815 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4817 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4819 void *hdr
= ((void **)skb
->cb
)[1];
4820 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4822 nla_nest_end(skb
, data
);
4823 genlmsg_end(skb
, hdr
);
4824 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4826 EXPORT_SYMBOL(cfg80211_testmode_event
);
4829 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4831 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4832 struct net_device
*dev
= info
->user_ptr
[1];
4833 struct cfg80211_connect_params connect
;
4834 struct wiphy
*wiphy
;
4835 struct cfg80211_cached_keys
*connkeys
= NULL
;
4838 memset(&connect
, 0, sizeof(connect
));
4840 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4843 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4844 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4847 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4849 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4850 if (!nl80211_valid_auth_type(connect
.auth_type
))
4853 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4855 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4857 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4858 NL80211_MAX_NR_CIPHER_SUITES
);
4862 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4863 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4866 wiphy
= &rdev
->wiphy
;
4868 if (info
->attrs
[NL80211_ATTR_MAC
])
4869 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4870 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4871 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4873 if (info
->attrs
[NL80211_ATTR_IE
]) {
4874 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4875 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4878 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4880 ieee80211_get_channel(wiphy
,
4881 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4882 if (!connect
.channel
||
4883 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4887 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4888 connkeys
= nl80211_parse_connkeys(rdev
,
4889 info
->attrs
[NL80211_ATTR_KEYS
]);
4890 if (IS_ERR(connkeys
))
4891 return PTR_ERR(connkeys
);
4894 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4900 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4903 struct net_device
*dev
= info
->user_ptr
[1];
4906 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4907 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4909 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4914 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4915 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4918 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4921 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4923 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4928 if (!info
->attrs
[NL80211_ATTR_PID
])
4931 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4933 net
= get_net_ns_by_pid(pid
);
4935 return PTR_ERR(net
);
4939 /* check if anything to do */
4940 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4941 err
= cfg80211_switch_netns(rdev
, net
);
4947 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4949 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4950 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4951 struct cfg80211_pmksa
*pmksa
) = NULL
;
4952 struct net_device
*dev
= info
->user_ptr
[1];
4953 struct cfg80211_pmksa pmksa
;
4955 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4957 if (!info
->attrs
[NL80211_ATTR_MAC
])
4960 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4963 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4964 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4966 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4967 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4970 switch (info
->genlhdr
->cmd
) {
4971 case NL80211_CMD_SET_PMKSA
:
4972 rdev_ops
= rdev
->ops
->set_pmksa
;
4974 case NL80211_CMD_DEL_PMKSA
:
4975 rdev_ops
= rdev
->ops
->del_pmksa
;
4985 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4988 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4990 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4991 struct net_device
*dev
= info
->user_ptr
[1];
4993 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4994 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4997 if (!rdev
->ops
->flush_pmksa
)
5000 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
5003 static int nl80211_tdls_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5005 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5006 struct net_device
*dev
= info
->user_ptr
[1];
5007 u8 action_code
, dialog_token
;
5011 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5012 !rdev
->ops
->tdls_mgmt
)
5015 if (!info
->attrs
[NL80211_ATTR_TDLS_ACTION
] ||
5016 !info
->attrs
[NL80211_ATTR_STATUS_CODE
] ||
5017 !info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
] ||
5018 !info
->attrs
[NL80211_ATTR_IE
] ||
5019 !info
->attrs
[NL80211_ATTR_MAC
])
5022 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5023 action_code
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_ACTION
]);
5024 status_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_STATUS_CODE
]);
5025 dialog_token
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_DIALOG_TOKEN
]);
5027 return rdev
->ops
->tdls_mgmt(&rdev
->wiphy
, dev
, peer
, action_code
,
5028 dialog_token
, status_code
,
5029 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
5030 nla_len(info
->attrs
[NL80211_ATTR_IE
]));
5033 static int nl80211_tdls_oper(struct sk_buff
*skb
, struct genl_info
*info
)
5035 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5036 struct net_device
*dev
= info
->user_ptr
[1];
5037 enum nl80211_tdls_operation operation
;
5040 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_TDLS
) ||
5041 !rdev
->ops
->tdls_oper
)
5044 if (!info
->attrs
[NL80211_ATTR_TDLS_OPERATION
] ||
5045 !info
->attrs
[NL80211_ATTR_MAC
])
5048 operation
= nla_get_u8(info
->attrs
[NL80211_ATTR_TDLS_OPERATION
]);
5049 peer
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
5051 return rdev
->ops
->tdls_oper(&rdev
->wiphy
, dev
, peer
, operation
);
5054 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
5055 struct genl_info
*info
)
5057 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5058 struct net_device
*dev
= info
->user_ptr
[1];
5059 struct ieee80211_channel
*chan
;
5060 struct sk_buff
*msg
;
5063 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5067 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
5068 !info
->attrs
[NL80211_ATTR_DURATION
])
5071 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5074 * We should be on that channel for at least one jiffie,
5075 * and more than 5 seconds seems excessive.
5077 if (!duration
|| !msecs_to_jiffies(duration
) ||
5078 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
5081 if (!rdev
->ops
->remain_on_channel
)
5084 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5085 channel_type
= nla_get_u32(
5086 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5087 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5088 channel_type
!= NL80211_CHAN_HT20
&&
5089 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5090 channel_type
!= NL80211_CHAN_HT40MINUS
)
5094 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5095 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5099 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5103 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5104 NL80211_CMD_REMAIN_ON_CHANNEL
);
5111 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
5112 channel_type
, duration
, &cookie
);
5117 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5119 genlmsg_end(msg
, hdr
);
5121 return genlmsg_reply(msg
, info
);
5130 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
5131 struct genl_info
*info
)
5133 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5134 struct net_device
*dev
= info
->user_ptr
[1];
5137 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5140 if (!rdev
->ops
->cancel_remain_on_channel
)
5143 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5145 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
5148 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
5149 u8
*rates
, u8 rates_len
)
5154 for (i
= 0; i
< rates_len
; i
++) {
5155 int rate
= (rates
[i
] & 0x7f) * 5;
5157 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5158 struct ieee80211_rate
*srate
=
5159 &sband
->bitrates
[ridx
];
5160 if (rate
== srate
->bitrate
) {
5165 if (ridx
== sband
->n_bitrates
)
5166 return 0; /* rate not found */
5172 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5173 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5174 .len
= NL80211_MAX_SUPP_RATES
},
5177 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5178 struct genl_info
*info
)
5180 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5181 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5182 struct cfg80211_bitrate_mask mask
;
5184 struct net_device
*dev
= info
->user_ptr
[1];
5185 struct nlattr
*tx_rates
;
5186 struct ieee80211_supported_band
*sband
;
5188 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5191 if (!rdev
->ops
->set_bitrate_mask
)
5194 memset(&mask
, 0, sizeof(mask
));
5195 /* Default to all rates enabled */
5196 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5197 sband
= rdev
->wiphy
.bands
[i
];
5198 mask
.control
[i
].legacy
=
5199 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5203 * The nested attribute uses enum nl80211_band as the index. This maps
5204 * directly to the enum ieee80211_band values used in cfg80211.
5206 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5208 enum ieee80211_band band
= nla_type(tx_rates
);
5209 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5211 sband
= rdev
->wiphy
.bands
[band
];
5214 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5215 nla_len(tx_rates
), nl80211_txattr_policy
);
5216 if (tb
[NL80211_TXRATE_LEGACY
]) {
5217 mask
.control
[band
].legacy
= rateset_to_mask(
5219 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5220 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5221 if (mask
.control
[band
].legacy
== 0)
5226 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5229 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5231 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5232 struct net_device
*dev
= info
->user_ptr
[1];
5233 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
5235 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
5238 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
5239 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
5241 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5242 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5243 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5244 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5245 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5246 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5247 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5250 /* not much point in registering if we can't reply */
5251 if (!rdev
->ops
->mgmt_tx
)
5254 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
5256 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
5257 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
5260 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5262 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5263 struct net_device
*dev
= info
->user_ptr
[1];
5264 struct ieee80211_channel
*chan
;
5265 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5266 bool channel_type_valid
= false;
5271 struct sk_buff
*msg
;
5272 unsigned int wait
= 0;
5276 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5277 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5280 if (!rdev
->ops
->mgmt_tx
)
5283 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5284 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5285 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5286 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5287 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5288 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5289 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5292 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5293 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5295 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5298 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5299 channel_type
= nla_get_u32(
5300 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5301 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5302 channel_type
!= NL80211_CHAN_HT20
&&
5303 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5304 channel_type
!= NL80211_CHAN_HT40MINUS
)
5306 channel_type_valid
= true;
5309 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5311 no_cck
= nla_get_flag(info
->attrs
[NL80211_ATTR_TX_NO_CCK_RATE
]);
5313 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5314 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5318 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5322 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5329 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
5330 channel_type_valid
, wait
,
5331 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
5332 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
5337 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5339 genlmsg_end(msg
, hdr
);
5340 return genlmsg_reply(msg
, info
);
5349 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
5351 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5352 struct net_device
*dev
= info
->user_ptr
[1];
5355 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5358 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5361 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5362 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5363 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5364 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5365 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5366 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5369 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5371 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
5374 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5376 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5377 struct wireless_dev
*wdev
;
5378 struct net_device
*dev
= info
->user_ptr
[1];
5383 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
5386 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
5388 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
5391 wdev
= dev
->ieee80211_ptr
;
5393 if (!rdev
->ops
->set_power_mgmt
)
5396 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
5398 if (state
== wdev
->ps
)
5401 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
5408 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5410 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5411 enum nl80211_ps_state ps_state
;
5412 struct wireless_dev
*wdev
;
5413 struct net_device
*dev
= info
->user_ptr
[1];
5414 struct sk_buff
*msg
;
5418 wdev
= dev
->ieee80211_ptr
;
5420 if (!rdev
->ops
->set_power_mgmt
)
5423 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5427 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5428 NL80211_CMD_GET_POWER_SAVE
);
5435 ps_state
= NL80211_PS_ENABLED
;
5437 ps_state
= NL80211_PS_DISABLED
;
5439 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5441 genlmsg_end(msg
, hdr
);
5442 return genlmsg_reply(msg
, info
);
5451 static struct nla_policy
5452 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5453 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5454 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5455 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5458 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5459 s32 threshold
, u32 hysteresis
)
5461 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5462 struct wireless_dev
*wdev
;
5463 struct net_device
*dev
= info
->user_ptr
[1];
5468 wdev
= dev
->ieee80211_ptr
;
5470 if (!rdev
->ops
->set_cqm_rssi_config
)
5473 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5474 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5477 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5478 threshold
, hysteresis
);
5481 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5483 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5487 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5493 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5494 nl80211_attr_cqm_policy
);
5498 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5499 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5502 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5503 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5504 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5512 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5514 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5515 struct net_device
*dev
= info
->user_ptr
[1];
5516 struct mesh_config cfg
;
5517 struct mesh_setup setup
;
5520 /* start with default */
5521 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5522 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5524 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5525 /* and parse parameters if given */
5526 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5531 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5532 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5535 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5536 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5538 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5539 /* parse additional setup parameters if given */
5540 err
= nl80211_parse_mesh_setup(info
, &setup
);
5545 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5548 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5550 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5551 struct net_device
*dev
= info
->user_ptr
[1];
5553 return cfg80211_leave_mesh(rdev
, dev
);
5556 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5558 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5559 struct sk_buff
*msg
;
5562 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5565 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5569 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5570 NL80211_CMD_GET_WOWLAN
);
5572 goto nla_put_failure
;
5575 struct nlattr
*nl_wowlan
;
5577 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5579 goto nla_put_failure
;
5581 if (rdev
->wowlan
->any
)
5582 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5583 if (rdev
->wowlan
->disconnect
)
5584 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5585 if (rdev
->wowlan
->magic_pkt
)
5586 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5587 if (rdev
->wowlan
->gtk_rekey_failure
)
5588 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
5589 if (rdev
->wowlan
->eap_identity_req
)
5590 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
5591 if (rdev
->wowlan
->four_way_handshake
)
5592 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
5593 if (rdev
->wowlan
->rfkill_release
)
5594 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
5595 if (rdev
->wowlan
->n_patterns
) {
5596 struct nlattr
*nl_pats
, *nl_pat
;
5599 nl_pats
= nla_nest_start(msg
,
5600 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5602 goto nla_put_failure
;
5604 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5605 nl_pat
= nla_nest_start(msg
, i
+ 1);
5607 goto nla_put_failure
;
5608 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5609 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5610 DIV_ROUND_UP(pat_len
, 8),
5611 rdev
->wowlan
->patterns
[i
].mask
);
5612 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5614 rdev
->wowlan
->patterns
[i
].pattern
);
5615 nla_nest_end(msg
, nl_pat
);
5617 nla_nest_end(msg
, nl_pats
);
5620 nla_nest_end(msg
, nl_wowlan
);
5623 genlmsg_end(msg
, hdr
);
5624 return genlmsg_reply(msg
, info
);
5631 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5633 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5634 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5635 struct cfg80211_wowlan no_triggers
= {};
5636 struct cfg80211_wowlan new_triggers
= {};
5637 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5640 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5643 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5646 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5647 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5648 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5649 nl80211_wowlan_policy
);
5653 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5654 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5656 new_triggers
.any
= true;
5659 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5660 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5662 new_triggers
.disconnect
= true;
5665 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5666 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5668 new_triggers
.magic_pkt
= true;
5671 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
5674 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
5675 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
5677 new_triggers
.gtk_rekey_failure
= true;
5680 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
5681 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
5683 new_triggers
.eap_identity_req
= true;
5686 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
5687 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
5689 new_triggers
.four_way_handshake
= true;
5692 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
5693 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
5695 new_triggers
.rfkill_release
= true;
5698 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5701 int rem
, pat_len
, mask_len
;
5702 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5704 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5707 if (n_patterns
> wowlan
->n_patterns
)
5710 new_triggers
.patterns
= kcalloc(n_patterns
,
5711 sizeof(new_triggers
.patterns
[0]),
5713 if (!new_triggers
.patterns
)
5716 new_triggers
.n_patterns
= n_patterns
;
5719 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5721 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5722 nla_data(pat
), nla_len(pat
), NULL
);
5724 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5725 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5727 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5728 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5729 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5732 if (pat_len
> wowlan
->pattern_max_len
||
5733 pat_len
< wowlan
->pattern_min_len
)
5736 new_triggers
.patterns
[i
].mask
=
5737 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5738 if (!new_triggers
.patterns
[i
].mask
) {
5742 new_triggers
.patterns
[i
].pattern
=
5743 new_triggers
.patterns
[i
].mask
+ mask_len
;
5744 memcpy(new_triggers
.patterns
[i
].mask
,
5745 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5747 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5748 memcpy(new_triggers
.patterns
[i
].pattern
,
5749 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5755 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5756 struct cfg80211_wowlan
*ntrig
;
5757 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5763 cfg80211_rdev_free_wowlan(rdev
);
5764 rdev
->wowlan
= ntrig
;
5767 cfg80211_rdev_free_wowlan(rdev
);
5768 rdev
->wowlan
= NULL
;
5773 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5774 kfree(new_triggers
.patterns
[i
].mask
);
5775 kfree(new_triggers
.patterns
);
5779 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
5781 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5782 struct net_device
*dev
= info
->user_ptr
[1];
5783 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5784 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
5785 struct cfg80211_gtk_rekey_data rekey_data
;
5788 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
5791 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
5792 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5793 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5794 nl80211_rekey_policy
);
5798 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
5800 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
5802 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
5805 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
5807 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
5809 memcpy(rekey_data
.replay_ctr
,
5810 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
5811 NL80211_REPLAY_CTR_LEN
);
5814 if (!wdev
->current_bss
) {
5819 if (!rdev
->ops
->set_rekey_data
) {
5824 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
5830 #define NL80211_FLAG_NEED_WIPHY 0x01
5831 #define NL80211_FLAG_NEED_NETDEV 0x02
5832 #define NL80211_FLAG_NEED_RTNL 0x04
5833 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5834 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5835 NL80211_FLAG_CHECK_NETDEV_UP)
5837 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5838 struct genl_info
*info
)
5840 struct cfg80211_registered_device
*rdev
;
5841 struct net_device
*dev
;
5843 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5848 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5849 rdev
= cfg80211_get_dev_from_info(info
);
5853 return PTR_ERR(rdev
);
5855 info
->user_ptr
[0] = rdev
;
5856 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5857 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5863 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5864 !netif_running(dev
)) {
5865 cfg80211_unlock_rdev(rdev
);
5871 info
->user_ptr
[0] = rdev
;
5872 info
->user_ptr
[1] = dev
;
5878 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5879 struct genl_info
*info
)
5881 if (info
->user_ptr
[0])
5882 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5883 if (info
->user_ptr
[1])
5884 dev_put(info
->user_ptr
[1]);
5885 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5889 static struct genl_ops nl80211_ops
[] = {
5891 .cmd
= NL80211_CMD_GET_WIPHY
,
5892 .doit
= nl80211_get_wiphy
,
5893 .dumpit
= nl80211_dump_wiphy
,
5894 .policy
= nl80211_policy
,
5895 /* can be retrieved by unprivileged users */
5896 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5899 .cmd
= NL80211_CMD_SET_WIPHY
,
5900 .doit
= nl80211_set_wiphy
,
5901 .policy
= nl80211_policy
,
5902 .flags
= GENL_ADMIN_PERM
,
5903 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5906 .cmd
= NL80211_CMD_GET_INTERFACE
,
5907 .doit
= nl80211_get_interface
,
5908 .dumpit
= nl80211_dump_interface
,
5909 .policy
= nl80211_policy
,
5910 /* can be retrieved by unprivileged users */
5911 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5914 .cmd
= NL80211_CMD_SET_INTERFACE
,
5915 .doit
= nl80211_set_interface
,
5916 .policy
= nl80211_policy
,
5917 .flags
= GENL_ADMIN_PERM
,
5918 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5919 NL80211_FLAG_NEED_RTNL
,
5922 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5923 .doit
= nl80211_new_interface
,
5924 .policy
= nl80211_policy
,
5925 .flags
= GENL_ADMIN_PERM
,
5926 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5927 NL80211_FLAG_NEED_RTNL
,
5930 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5931 .doit
= nl80211_del_interface
,
5932 .policy
= nl80211_policy
,
5933 .flags
= GENL_ADMIN_PERM
,
5934 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5935 NL80211_FLAG_NEED_RTNL
,
5938 .cmd
= NL80211_CMD_GET_KEY
,
5939 .doit
= nl80211_get_key
,
5940 .policy
= nl80211_policy
,
5941 .flags
= GENL_ADMIN_PERM
,
5942 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5943 NL80211_FLAG_NEED_RTNL
,
5946 .cmd
= NL80211_CMD_SET_KEY
,
5947 .doit
= nl80211_set_key
,
5948 .policy
= nl80211_policy
,
5949 .flags
= GENL_ADMIN_PERM
,
5950 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5951 NL80211_FLAG_NEED_RTNL
,
5954 .cmd
= NL80211_CMD_NEW_KEY
,
5955 .doit
= nl80211_new_key
,
5956 .policy
= nl80211_policy
,
5957 .flags
= GENL_ADMIN_PERM
,
5958 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5959 NL80211_FLAG_NEED_RTNL
,
5962 .cmd
= NL80211_CMD_DEL_KEY
,
5963 .doit
= nl80211_del_key
,
5964 .policy
= nl80211_policy
,
5965 .flags
= GENL_ADMIN_PERM
,
5966 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5967 NL80211_FLAG_NEED_RTNL
,
5970 .cmd
= NL80211_CMD_SET_BEACON
,
5971 .policy
= nl80211_policy
,
5972 .flags
= GENL_ADMIN_PERM
,
5973 .doit
= nl80211_addset_beacon
,
5974 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5975 NL80211_FLAG_NEED_RTNL
,
5978 .cmd
= NL80211_CMD_NEW_BEACON
,
5979 .policy
= nl80211_policy
,
5980 .flags
= GENL_ADMIN_PERM
,
5981 .doit
= nl80211_addset_beacon
,
5982 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5983 NL80211_FLAG_NEED_RTNL
,
5986 .cmd
= NL80211_CMD_DEL_BEACON
,
5987 .policy
= nl80211_policy
,
5988 .flags
= GENL_ADMIN_PERM
,
5989 .doit
= nl80211_del_beacon
,
5990 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5991 NL80211_FLAG_NEED_RTNL
,
5994 .cmd
= NL80211_CMD_GET_STATION
,
5995 .doit
= nl80211_get_station
,
5996 .dumpit
= nl80211_dump_station
,
5997 .policy
= nl80211_policy
,
5998 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5999 NL80211_FLAG_NEED_RTNL
,
6002 .cmd
= NL80211_CMD_SET_STATION
,
6003 .doit
= nl80211_set_station
,
6004 .policy
= nl80211_policy
,
6005 .flags
= GENL_ADMIN_PERM
,
6006 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6007 NL80211_FLAG_NEED_RTNL
,
6010 .cmd
= NL80211_CMD_NEW_STATION
,
6011 .doit
= nl80211_new_station
,
6012 .policy
= nl80211_policy
,
6013 .flags
= GENL_ADMIN_PERM
,
6014 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6015 NL80211_FLAG_NEED_RTNL
,
6018 .cmd
= NL80211_CMD_DEL_STATION
,
6019 .doit
= nl80211_del_station
,
6020 .policy
= nl80211_policy
,
6021 .flags
= GENL_ADMIN_PERM
,
6022 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6023 NL80211_FLAG_NEED_RTNL
,
6026 .cmd
= NL80211_CMD_GET_MPATH
,
6027 .doit
= nl80211_get_mpath
,
6028 .dumpit
= nl80211_dump_mpath
,
6029 .policy
= nl80211_policy
,
6030 .flags
= GENL_ADMIN_PERM
,
6031 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6032 NL80211_FLAG_NEED_RTNL
,
6035 .cmd
= NL80211_CMD_SET_MPATH
,
6036 .doit
= nl80211_set_mpath
,
6037 .policy
= nl80211_policy
,
6038 .flags
= GENL_ADMIN_PERM
,
6039 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6040 NL80211_FLAG_NEED_RTNL
,
6043 .cmd
= NL80211_CMD_NEW_MPATH
,
6044 .doit
= nl80211_new_mpath
,
6045 .policy
= nl80211_policy
,
6046 .flags
= GENL_ADMIN_PERM
,
6047 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6048 NL80211_FLAG_NEED_RTNL
,
6051 .cmd
= NL80211_CMD_DEL_MPATH
,
6052 .doit
= nl80211_del_mpath
,
6053 .policy
= nl80211_policy
,
6054 .flags
= GENL_ADMIN_PERM
,
6055 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6056 NL80211_FLAG_NEED_RTNL
,
6059 .cmd
= NL80211_CMD_SET_BSS
,
6060 .doit
= nl80211_set_bss
,
6061 .policy
= nl80211_policy
,
6062 .flags
= GENL_ADMIN_PERM
,
6063 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6064 NL80211_FLAG_NEED_RTNL
,
6067 .cmd
= NL80211_CMD_GET_REG
,
6068 .doit
= nl80211_get_reg
,
6069 .policy
= nl80211_policy
,
6070 /* can be retrieved by unprivileged users */
6073 .cmd
= NL80211_CMD_SET_REG
,
6074 .doit
= nl80211_set_reg
,
6075 .policy
= nl80211_policy
,
6076 .flags
= GENL_ADMIN_PERM
,
6079 .cmd
= NL80211_CMD_REQ_SET_REG
,
6080 .doit
= nl80211_req_set_reg
,
6081 .policy
= nl80211_policy
,
6082 .flags
= GENL_ADMIN_PERM
,
6085 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
6086 .doit
= nl80211_get_mesh_config
,
6087 .policy
= nl80211_policy
,
6088 /* can be retrieved by unprivileged users */
6089 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6090 NL80211_FLAG_NEED_RTNL
,
6093 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
6094 .doit
= nl80211_update_mesh_config
,
6095 .policy
= nl80211_policy
,
6096 .flags
= GENL_ADMIN_PERM
,
6097 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6098 NL80211_FLAG_NEED_RTNL
,
6101 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
6102 .doit
= nl80211_trigger_scan
,
6103 .policy
= nl80211_policy
,
6104 .flags
= GENL_ADMIN_PERM
,
6105 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6106 NL80211_FLAG_NEED_RTNL
,
6109 .cmd
= NL80211_CMD_GET_SCAN
,
6110 .policy
= nl80211_policy
,
6111 .dumpit
= nl80211_dump_scan
,
6114 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
6115 .doit
= nl80211_start_sched_scan
,
6116 .policy
= nl80211_policy
,
6117 .flags
= GENL_ADMIN_PERM
,
6118 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6119 NL80211_FLAG_NEED_RTNL
,
6122 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
6123 .doit
= nl80211_stop_sched_scan
,
6124 .policy
= nl80211_policy
,
6125 .flags
= GENL_ADMIN_PERM
,
6126 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6127 NL80211_FLAG_NEED_RTNL
,
6130 .cmd
= NL80211_CMD_AUTHENTICATE
,
6131 .doit
= nl80211_authenticate
,
6132 .policy
= nl80211_policy
,
6133 .flags
= GENL_ADMIN_PERM
,
6134 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6135 NL80211_FLAG_NEED_RTNL
,
6138 .cmd
= NL80211_CMD_ASSOCIATE
,
6139 .doit
= nl80211_associate
,
6140 .policy
= nl80211_policy
,
6141 .flags
= GENL_ADMIN_PERM
,
6142 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6143 NL80211_FLAG_NEED_RTNL
,
6146 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
6147 .doit
= nl80211_deauthenticate
,
6148 .policy
= nl80211_policy
,
6149 .flags
= GENL_ADMIN_PERM
,
6150 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6151 NL80211_FLAG_NEED_RTNL
,
6154 .cmd
= NL80211_CMD_DISASSOCIATE
,
6155 .doit
= nl80211_disassociate
,
6156 .policy
= nl80211_policy
,
6157 .flags
= GENL_ADMIN_PERM
,
6158 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6159 NL80211_FLAG_NEED_RTNL
,
6162 .cmd
= NL80211_CMD_JOIN_IBSS
,
6163 .doit
= nl80211_join_ibss
,
6164 .policy
= nl80211_policy
,
6165 .flags
= GENL_ADMIN_PERM
,
6166 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6167 NL80211_FLAG_NEED_RTNL
,
6170 .cmd
= NL80211_CMD_LEAVE_IBSS
,
6171 .doit
= nl80211_leave_ibss
,
6172 .policy
= nl80211_policy
,
6173 .flags
= GENL_ADMIN_PERM
,
6174 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6175 NL80211_FLAG_NEED_RTNL
,
6177 #ifdef CONFIG_NL80211_TESTMODE
6179 .cmd
= NL80211_CMD_TESTMODE
,
6180 .doit
= nl80211_testmode_do
,
6181 .dumpit
= nl80211_testmode_dump
,
6182 .policy
= nl80211_policy
,
6183 .flags
= GENL_ADMIN_PERM
,
6184 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6185 NL80211_FLAG_NEED_RTNL
,
6189 .cmd
= NL80211_CMD_CONNECT
,
6190 .doit
= nl80211_connect
,
6191 .policy
= nl80211_policy
,
6192 .flags
= GENL_ADMIN_PERM
,
6193 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6194 NL80211_FLAG_NEED_RTNL
,
6197 .cmd
= NL80211_CMD_DISCONNECT
,
6198 .doit
= nl80211_disconnect
,
6199 .policy
= nl80211_policy
,
6200 .flags
= GENL_ADMIN_PERM
,
6201 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6202 NL80211_FLAG_NEED_RTNL
,
6205 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
6206 .doit
= nl80211_wiphy_netns
,
6207 .policy
= nl80211_policy
,
6208 .flags
= GENL_ADMIN_PERM
,
6209 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6210 NL80211_FLAG_NEED_RTNL
,
6213 .cmd
= NL80211_CMD_GET_SURVEY
,
6214 .policy
= nl80211_policy
,
6215 .dumpit
= nl80211_dump_survey
,
6218 .cmd
= NL80211_CMD_SET_PMKSA
,
6219 .doit
= nl80211_setdel_pmksa
,
6220 .policy
= nl80211_policy
,
6221 .flags
= GENL_ADMIN_PERM
,
6222 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6223 NL80211_FLAG_NEED_RTNL
,
6226 .cmd
= NL80211_CMD_DEL_PMKSA
,
6227 .doit
= nl80211_setdel_pmksa
,
6228 .policy
= nl80211_policy
,
6229 .flags
= GENL_ADMIN_PERM
,
6230 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6231 NL80211_FLAG_NEED_RTNL
,
6234 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
6235 .doit
= nl80211_flush_pmksa
,
6236 .policy
= nl80211_policy
,
6237 .flags
= GENL_ADMIN_PERM
,
6238 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6239 NL80211_FLAG_NEED_RTNL
,
6242 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
6243 .doit
= nl80211_remain_on_channel
,
6244 .policy
= nl80211_policy
,
6245 .flags
= GENL_ADMIN_PERM
,
6246 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6247 NL80211_FLAG_NEED_RTNL
,
6250 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6251 .doit
= nl80211_cancel_remain_on_channel
,
6252 .policy
= nl80211_policy
,
6253 .flags
= GENL_ADMIN_PERM
,
6254 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6255 NL80211_FLAG_NEED_RTNL
,
6258 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
6259 .doit
= nl80211_set_tx_bitrate_mask
,
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_REGISTER_FRAME
,
6267 .doit
= nl80211_register_mgmt
,
6268 .policy
= nl80211_policy
,
6269 .flags
= GENL_ADMIN_PERM
,
6270 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6271 NL80211_FLAG_NEED_RTNL
,
6274 .cmd
= NL80211_CMD_FRAME
,
6275 .doit
= nl80211_tx_mgmt
,
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_FRAME_WAIT_CANCEL
,
6283 .doit
= nl80211_tx_mgmt_cancel_wait
,
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_SET_POWER_SAVE
,
6291 .doit
= nl80211_set_power_save
,
6292 .policy
= nl80211_policy
,
6293 .flags
= GENL_ADMIN_PERM
,
6294 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6295 NL80211_FLAG_NEED_RTNL
,
6298 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
6299 .doit
= nl80211_get_power_save
,
6300 .policy
= nl80211_policy
,
6301 /* can be retrieved by unprivileged users */
6302 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6303 NL80211_FLAG_NEED_RTNL
,
6306 .cmd
= NL80211_CMD_SET_CQM
,
6307 .doit
= nl80211_set_cqm
,
6308 .policy
= nl80211_policy
,
6309 .flags
= GENL_ADMIN_PERM
,
6310 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6311 NL80211_FLAG_NEED_RTNL
,
6314 .cmd
= NL80211_CMD_SET_CHANNEL
,
6315 .doit
= nl80211_set_channel
,
6316 .policy
= nl80211_policy
,
6317 .flags
= GENL_ADMIN_PERM
,
6318 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6319 NL80211_FLAG_NEED_RTNL
,
6322 .cmd
= NL80211_CMD_SET_WDS_PEER
,
6323 .doit
= nl80211_set_wds_peer
,
6324 .policy
= nl80211_policy
,
6325 .flags
= GENL_ADMIN_PERM
,
6326 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6327 NL80211_FLAG_NEED_RTNL
,
6330 .cmd
= NL80211_CMD_JOIN_MESH
,
6331 .doit
= nl80211_join_mesh
,
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_LEAVE_MESH
,
6339 .doit
= nl80211_leave_mesh
,
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_GET_WOWLAN
,
6347 .doit
= nl80211_get_wowlan
,
6348 .policy
= nl80211_policy
,
6349 /* can be retrieved by unprivileged users */
6350 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6351 NL80211_FLAG_NEED_RTNL
,
6354 .cmd
= NL80211_CMD_SET_WOWLAN
,
6355 .doit
= nl80211_set_wowlan
,
6356 .policy
= nl80211_policy
,
6357 .flags
= GENL_ADMIN_PERM
,
6358 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6359 NL80211_FLAG_NEED_RTNL
,
6362 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
6363 .doit
= nl80211_set_rekey_data
,
6364 .policy
= nl80211_policy
,
6365 .flags
= GENL_ADMIN_PERM
,
6366 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6367 NL80211_FLAG_NEED_RTNL
,
6370 .cmd
= NL80211_CMD_TDLS_MGMT
,
6371 .doit
= nl80211_tdls_mgmt
,
6372 .policy
= nl80211_policy
,
6373 .flags
= GENL_ADMIN_PERM
,
6374 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6375 NL80211_FLAG_NEED_RTNL
,
6378 .cmd
= NL80211_CMD_TDLS_OPER
,
6379 .doit
= nl80211_tdls_oper
,
6380 .policy
= nl80211_policy
,
6381 .flags
= GENL_ADMIN_PERM
,
6382 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6383 NL80211_FLAG_NEED_RTNL
,
6387 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
6391 /* multicast groups */
6392 static struct genl_multicast_group nl80211_config_mcgrp
= {
6395 static struct genl_multicast_group nl80211_scan_mcgrp
= {
6398 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
6399 .name
= "regulatory",
6402 /* notification functions */
6404 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
6406 struct sk_buff
*msg
;
6408 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6412 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
6417 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6418 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
6421 static int nl80211_add_scan_req(struct sk_buff
*msg
,
6422 struct cfg80211_registered_device
*rdev
)
6424 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
6425 struct nlattr
*nest
;
6428 ASSERT_RDEV_LOCK(rdev
);
6433 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
6435 goto nla_put_failure
;
6436 for (i
= 0; i
< req
->n_ssids
; i
++)
6437 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
6438 nla_nest_end(msg
, nest
);
6440 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
6442 goto nla_put_failure
;
6443 for (i
= 0; i
< req
->n_channels
; i
++)
6444 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
6445 nla_nest_end(msg
, nest
);
6448 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
6455 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
6456 struct cfg80211_registered_device
*rdev
,
6457 struct net_device
*netdev
,
6458 u32 pid
, u32 seq
, int flags
,
6463 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6467 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6468 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6470 /* ignore errors and send incomplete event anyway */
6471 nl80211_add_scan_req(msg
, rdev
);
6473 return genlmsg_end(msg
, hdr
);
6476 genlmsg_cancel(msg
, hdr
);
6481 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
6482 struct cfg80211_registered_device
*rdev
,
6483 struct net_device
*netdev
,
6484 u32 pid
, u32 seq
, int flags
, u32 cmd
)
6488 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6492 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6493 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6495 return genlmsg_end(msg
, hdr
);
6498 genlmsg_cancel(msg
, hdr
);
6502 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
6503 struct net_device
*netdev
)
6505 struct sk_buff
*msg
;
6507 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6511 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6512 NL80211_CMD_TRIGGER_SCAN
) < 0) {
6517 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6518 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6521 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
6522 struct net_device
*netdev
)
6524 struct sk_buff
*msg
;
6526 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6530 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6531 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6536 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6537 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6540 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6541 struct net_device
*netdev
)
6543 struct sk_buff
*msg
;
6545 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6549 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6550 NL80211_CMD_SCAN_ABORTED
) < 0) {
6555 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6556 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6559 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6560 struct net_device
*netdev
)
6562 struct sk_buff
*msg
;
6564 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6568 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6569 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6574 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6575 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6578 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6579 struct net_device
*netdev
, u32 cmd
)
6581 struct sk_buff
*msg
;
6583 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6587 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6592 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6593 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6597 * This can happen on global regulatory changes or device specific settings
6598 * based on custom world regulatory domains.
6600 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6602 struct sk_buff
*msg
;
6605 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6609 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6615 /* Userspace can always count this one always being set */
6616 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6618 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6619 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6620 NL80211_REGDOM_TYPE_WORLD
);
6621 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6622 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6623 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6624 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6626 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6627 NL80211_REGDOM_TYPE_INTERSECTION
);
6629 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6630 NL80211_REGDOM_TYPE_COUNTRY
);
6631 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6634 if (wiphy_idx_valid(request
->wiphy_idx
))
6635 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6637 if (genlmsg_end(msg
, hdr
) < 0) {
6643 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6650 genlmsg_cancel(msg
, hdr
);
6654 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6655 struct net_device
*netdev
,
6656 const u8
*buf
, size_t len
,
6657 enum nl80211_commands cmd
, gfp_t gfp
)
6659 struct sk_buff
*msg
;
6662 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6666 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6672 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6673 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6674 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6676 if (genlmsg_end(msg
, hdr
) < 0) {
6681 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6682 nl80211_mlme_mcgrp
.id
, gfp
);
6686 genlmsg_cancel(msg
, hdr
);
6690 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6691 struct net_device
*netdev
, const u8
*buf
,
6692 size_t len
, gfp_t gfp
)
6694 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6695 NL80211_CMD_AUTHENTICATE
, gfp
);
6698 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6699 struct net_device
*netdev
, const u8
*buf
,
6700 size_t len
, gfp_t gfp
)
6702 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6703 NL80211_CMD_ASSOCIATE
, gfp
);
6706 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6707 struct net_device
*netdev
, const u8
*buf
,
6708 size_t len
, gfp_t gfp
)
6710 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6711 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6714 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6715 struct net_device
*netdev
, const u8
*buf
,
6716 size_t len
, gfp_t gfp
)
6718 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6719 NL80211_CMD_DISASSOCIATE
, gfp
);
6722 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6723 struct net_device
*netdev
, const u8
*buf
,
6724 size_t len
, gfp_t gfp
)
6726 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6727 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6730 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6731 struct net_device
*netdev
, const u8
*buf
,
6732 size_t len
, gfp_t gfp
)
6734 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6735 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6738 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6739 struct net_device
*netdev
, int cmd
,
6740 const u8
*addr
, gfp_t gfp
)
6742 struct sk_buff
*msg
;
6745 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6749 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6755 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6756 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6757 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6758 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6760 if (genlmsg_end(msg
, hdr
) < 0) {
6765 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6766 nl80211_mlme_mcgrp
.id
, gfp
);
6770 genlmsg_cancel(msg
, hdr
);
6774 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6775 struct net_device
*netdev
, const u8
*addr
,
6778 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6782 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6783 struct net_device
*netdev
, const u8
*addr
,
6786 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6790 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6791 struct net_device
*netdev
, const u8
*bssid
,
6792 const u8
*req_ie
, size_t req_ie_len
,
6793 const u8
*resp_ie
, size_t resp_ie_len
,
6794 u16 status
, gfp_t gfp
)
6796 struct sk_buff
*msg
;
6799 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6803 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6809 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6810 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6812 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6813 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6815 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6817 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6819 if (genlmsg_end(msg
, hdr
) < 0) {
6824 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6825 nl80211_mlme_mcgrp
.id
, gfp
);
6829 genlmsg_cancel(msg
, hdr
);
6834 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6835 struct net_device
*netdev
, const u8
*bssid
,
6836 const u8
*req_ie
, size_t req_ie_len
,
6837 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6839 struct sk_buff
*msg
;
6842 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6846 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6852 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6853 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6854 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6856 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6858 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6860 if (genlmsg_end(msg
, hdr
) < 0) {
6865 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6866 nl80211_mlme_mcgrp
.id
, gfp
);
6870 genlmsg_cancel(msg
, hdr
);
6875 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6876 struct net_device
*netdev
, u16 reason
,
6877 const u8
*ie
, size_t ie_len
, bool from_ap
)
6879 struct sk_buff
*msg
;
6882 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6886 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6892 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6893 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6894 if (from_ap
&& reason
)
6895 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6897 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6899 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6901 if (genlmsg_end(msg
, hdr
) < 0) {
6906 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6907 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6911 genlmsg_cancel(msg
, hdr
);
6916 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6917 struct net_device
*netdev
, const u8
*bssid
,
6920 struct sk_buff
*msg
;
6923 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6927 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6933 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6934 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6935 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6937 if (genlmsg_end(msg
, hdr
) < 0) {
6942 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6943 nl80211_mlme_mcgrp
.id
, gfp
);
6947 genlmsg_cancel(msg
, hdr
);
6951 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6952 struct net_device
*netdev
,
6953 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6956 struct sk_buff
*msg
;
6959 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6963 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6969 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6970 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6971 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6973 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6975 if (genlmsg_end(msg
, hdr
) < 0) {
6980 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6981 nl80211_mlme_mcgrp
.id
, gfp
);
6985 genlmsg_cancel(msg
, hdr
);
6989 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6990 struct net_device
*netdev
, const u8
*addr
,
6991 enum nl80211_key_type key_type
, int key_id
,
6992 const u8
*tsc
, gfp_t gfp
)
6994 struct sk_buff
*msg
;
6997 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7001 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
7007 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7008 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7010 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7011 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
7013 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
7015 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
7017 if (genlmsg_end(msg
, hdr
) < 0) {
7022 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7023 nl80211_mlme_mcgrp
.id
, gfp
);
7027 genlmsg_cancel(msg
, hdr
);
7031 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
7032 struct ieee80211_channel
*channel_before
,
7033 struct ieee80211_channel
*channel_after
)
7035 struct sk_buff
*msg
;
7037 struct nlattr
*nl_freq
;
7039 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
7043 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
7050 * Since we are applying the beacon hint to a wiphy we know its
7051 * wiphy_idx is valid
7053 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
7056 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
7058 goto nla_put_failure
;
7059 if (nl80211_msg_put_channel(msg
, channel_before
))
7060 goto nla_put_failure
;
7061 nla_nest_end(msg
, nl_freq
);
7064 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
7066 goto nla_put_failure
;
7067 if (nl80211_msg_put_channel(msg
, channel_after
))
7068 goto nla_put_failure
;
7069 nla_nest_end(msg
, nl_freq
);
7071 if (genlmsg_end(msg
, hdr
) < 0) {
7077 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
7084 genlmsg_cancel(msg
, hdr
);
7088 static void nl80211_send_remain_on_chan_event(
7089 int cmd
, struct cfg80211_registered_device
*rdev
,
7090 struct net_device
*netdev
, u64 cookie
,
7091 struct ieee80211_channel
*chan
,
7092 enum nl80211_channel_type channel_type
,
7093 unsigned int duration
, gfp_t gfp
)
7095 struct sk_buff
*msg
;
7098 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7102 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
7108 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7109 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7110 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
7111 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
7112 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7114 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
7115 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
7117 if (genlmsg_end(msg
, hdr
) < 0) {
7122 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7123 nl80211_mlme_mcgrp
.id
, gfp
);
7127 genlmsg_cancel(msg
, hdr
);
7131 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
7132 struct net_device
*netdev
, u64 cookie
,
7133 struct ieee80211_channel
*chan
,
7134 enum nl80211_channel_type channel_type
,
7135 unsigned int duration
, gfp_t gfp
)
7137 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
7138 rdev
, netdev
, cookie
, chan
,
7139 channel_type
, duration
, gfp
);
7142 void nl80211_send_remain_on_channel_cancel(
7143 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
7144 u64 cookie
, struct ieee80211_channel
*chan
,
7145 enum nl80211_channel_type channel_type
, gfp_t gfp
)
7147 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
7148 rdev
, netdev
, cookie
, chan
,
7149 channel_type
, 0, gfp
);
7152 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
7153 struct net_device
*dev
, const u8
*mac_addr
,
7154 struct station_info
*sinfo
, gfp_t gfp
)
7156 struct sk_buff
*msg
;
7158 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7162 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
7167 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7168 nl80211_mlme_mcgrp
.id
, gfp
);
7171 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
7172 struct net_device
*dev
, const u8
*mac_addr
,
7175 struct sk_buff
*msg
;
7178 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7182 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
7188 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
7189 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
7191 if (genlmsg_end(msg
, hdr
) < 0) {
7196 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7197 nl80211_mlme_mcgrp
.id
, gfp
);
7201 genlmsg_cancel(msg
, hdr
);
7205 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
7206 struct net_device
*netdev
, u32 nlpid
,
7207 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
7209 struct sk_buff
*msg
;
7213 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7217 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
7223 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7224 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7225 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7226 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7228 err
= genlmsg_end(msg
, hdr
);
7234 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
7240 genlmsg_cancel(msg
, hdr
);
7245 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
7246 struct net_device
*netdev
, u64 cookie
,
7247 const u8
*buf
, size_t len
, bool ack
,
7250 struct sk_buff
*msg
;
7253 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7257 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
7263 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7264 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7265 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7266 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7268 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
7270 if (genlmsg_end(msg
, hdr
) < 0) {
7275 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
7279 genlmsg_cancel(msg
, hdr
);
7284 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
7285 struct net_device
*netdev
,
7286 enum nl80211_cqm_rssi_threshold_event rssi_event
,
7289 struct sk_buff
*msg
;
7290 struct nlattr
*pinfoattr
;
7293 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7297 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7303 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7304 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7306 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7308 goto nla_put_failure
;
7310 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
7313 nla_nest_end(msg
, pinfoattr
);
7315 if (genlmsg_end(msg
, hdr
) < 0) {
7320 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7321 nl80211_mlme_mcgrp
.id
, gfp
);
7325 genlmsg_cancel(msg
, hdr
);
7329 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
7330 struct net_device
*netdev
, const u8
*bssid
,
7331 const u8
*replay_ctr
, gfp_t gfp
)
7333 struct sk_buff
*msg
;
7334 struct nlattr
*rekey_attr
;
7337 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7347 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7348 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7349 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7351 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7353 goto nla_put_failure
;
7355 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
7356 NL80211_REPLAY_CTR_LEN
, replay_ctr
);
7358 nla_nest_end(msg
, rekey_attr
);
7360 if (genlmsg_end(msg
, hdr
) < 0) {
7365 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7366 nl80211_mlme_mcgrp
.id
, gfp
);
7370 genlmsg_cancel(msg
, hdr
);
7374 void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device
*rdev
,
7375 struct net_device
*netdev
, int index
,
7376 const u8
*bssid
, bool preauth
, gfp_t gfp
)
7378 struct sk_buff
*msg
;
7379 struct nlattr
*attr
;
7382 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7386 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE
);
7392 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7393 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7395 attr
= nla_nest_start(msg
, NL80211_ATTR_PMKSA_CANDIDATE
);
7397 goto nla_put_failure
;
7399 NLA_PUT_U32(msg
, NL80211_PMKSA_CANDIDATE_INDEX
, index
);
7400 NLA_PUT(msg
, NL80211_PMKSA_CANDIDATE_BSSID
, ETH_ALEN
, bssid
);
7402 NLA_PUT_FLAG(msg
, NL80211_PMKSA_CANDIDATE_PREAUTH
);
7404 nla_nest_end(msg
, attr
);
7406 if (genlmsg_end(msg
, hdr
) < 0) {
7411 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7412 nl80211_mlme_mcgrp
.id
, gfp
);
7416 genlmsg_cancel(msg
, hdr
);
7421 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
7422 struct net_device
*netdev
, const u8
*peer
,
7423 u32 num_packets
, gfp_t gfp
)
7425 struct sk_buff
*msg
;
7426 struct nlattr
*pinfoattr
;
7429 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7433 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7439 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7440 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7441 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
7443 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7445 goto nla_put_failure
;
7447 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
7449 nla_nest_end(msg
, pinfoattr
);
7451 if (genlmsg_end(msg
, hdr
) < 0) {
7456 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7457 nl80211_mlme_mcgrp
.id
, gfp
);
7461 genlmsg_cancel(msg
, hdr
);
7465 static int nl80211_netlink_notify(struct notifier_block
* nb
,
7466 unsigned long state
,
7469 struct netlink_notify
*notify
= _notify
;
7470 struct cfg80211_registered_device
*rdev
;
7471 struct wireless_dev
*wdev
;
7473 if (state
!= NETLINK_URELEASE
)
7478 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
7479 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
7480 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
7487 static struct notifier_block nl80211_netlink_notifier
= {
7488 .notifier_call
= nl80211_netlink_notify
,
7491 /* initialisation/exit functions */
7493 int nl80211_init(void)
7497 err
= genl_register_family_with_ops(&nl80211_fam
,
7498 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
7502 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
7506 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
7510 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
7514 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
7518 #ifdef CONFIG_NL80211_TESTMODE
7519 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
7524 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
7530 genl_unregister_family(&nl80211_fam
);
7534 void nl80211_exit(void)
7536 netlink_unregister_notifier(&nl80211_netlink_notifier
);
7537 genl_unregister_family(&nl80211_fam
);