2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/if_ether.h>
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/netlink.h>
16 #include <linux/etherdevice.h>
17 #include <net/genetlink.h>
18 #include <net/cfg80211.h>
23 /* the netlink family */
24 static struct genl_family nl80211_fam
= {
25 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
26 .name
= "nl80211", /* have users key off the name instead */
27 .hdrsize
= 0, /* no private header */
28 .version
= 1, /* no particular meaning now */
29 .maxattr
= NL80211_ATTR_MAX
,
32 /* internal helper: get drv and dev */
33 static int get_drv_dev_by_info_ifindex(struct nlattr
**attrs
,
34 struct cfg80211_registered_device
**drv
,
35 struct net_device
**dev
)
39 if (!attrs
[NL80211_ATTR_IFINDEX
])
42 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
43 *dev
= dev_get_by_index(&init_net
, ifindex
);
47 *drv
= cfg80211_get_dev_from_ifindex(ifindex
);
56 /* policy for the attributes */
57 static struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] __read_mostly
= {
58 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
59 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
61 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
62 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
63 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
64 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
65 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
66 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
67 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
69 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
70 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
73 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
75 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
76 .len
= WLAN_MAX_KEY_LEN
},
77 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
78 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
79 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
80 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
82 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
83 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
84 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
85 .len
= IEEE80211_MAX_DATA_LEN
},
86 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
87 .len
= IEEE80211_MAX_DATA_LEN
},
88 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
89 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
90 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
91 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
92 .len
= NL80211_MAX_SUPP_RATES
},
93 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
94 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
95 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
96 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
97 .len
= IEEE80211_MAX_MESH_ID_LEN
},
98 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
101 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
103 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
104 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
105 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
106 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
107 .len
= NL80211_MAX_SUPP_RATES
},
109 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
111 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
112 .len
= NL80211_HT_CAPABILITY_LEN
},
114 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
115 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
116 .len
= IEEE80211_MAX_DATA_LEN
},
117 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
118 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
120 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
121 .len
= IEEE80211_MAX_SSID_LEN
},
122 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
123 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
124 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
125 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
126 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
127 [NL80211_ATTR_STA_FLAGS2
] = {
128 .len
= sizeof(struct nl80211_sta_flag_update
),
130 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
134 static bool is_valid_ie_attr(const struct nlattr
*attr
)
142 pos
= nla_data(attr
);
163 /* message building helper */
164 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
167 /* since there is no private header just add the generic one */
168 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
171 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
172 struct ieee80211_channel
*chan
)
174 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
177 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
178 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
179 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
180 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
181 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
182 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
183 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
184 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
186 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
187 DBM_TO_MBM(chan
->max_power
));
195 /* netlink command implementations */
197 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
198 struct cfg80211_registered_device
*dev
)
201 struct nlattr
*nl_bands
, *nl_band
;
202 struct nlattr
*nl_freqs
, *nl_freq
;
203 struct nlattr
*nl_rates
, *nl_rate
;
204 struct nlattr
*nl_modes
;
205 struct nlattr
*nl_cmds
;
206 enum ieee80211_band band
;
207 struct ieee80211_channel
*chan
;
208 struct ieee80211_rate
*rate
;
210 u16 ifmodes
= dev
->wiphy
.interface_modes
;
212 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
216 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
217 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
219 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
220 dev
->wiphy
.retry_short
);
221 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
222 dev
->wiphy
.retry_long
);
223 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
224 dev
->wiphy
.frag_threshold
);
225 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
226 dev
->wiphy
.rts_threshold
);
228 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
229 dev
->wiphy
.max_scan_ssids
);
230 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
231 dev
->wiphy
.max_scan_ie_len
);
233 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
234 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
235 dev
->wiphy
.cipher_suites
);
237 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
239 goto nla_put_failure
;
244 NLA_PUT_FLAG(msg
, i
);
249 nla_nest_end(msg
, nl_modes
);
251 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
253 goto nla_put_failure
;
255 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
256 if (!dev
->wiphy
.bands
[band
])
259 nl_band
= nla_nest_start(msg
, band
);
261 goto nla_put_failure
;
264 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
265 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
266 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
267 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
268 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
269 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
270 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
271 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
272 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
273 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
276 /* add frequencies */
277 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
279 goto nla_put_failure
;
281 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
282 nl_freq
= nla_nest_start(msg
, i
);
284 goto nla_put_failure
;
286 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
288 if (nl80211_msg_put_channel(msg
, chan
))
289 goto nla_put_failure
;
291 nla_nest_end(msg
, nl_freq
);
294 nla_nest_end(msg
, nl_freqs
);
297 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
299 goto nla_put_failure
;
301 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
302 nl_rate
= nla_nest_start(msg
, i
);
304 goto nla_put_failure
;
306 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
307 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
309 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
311 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
313 nla_nest_end(msg
, nl_rate
);
316 nla_nest_end(msg
, nl_rates
);
318 nla_nest_end(msg
, nl_band
);
320 nla_nest_end(msg
, nl_bands
);
322 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
324 goto nla_put_failure
;
329 if (dev->ops->op) { \
331 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
335 CMD(add_virtual_intf
, NEW_INTERFACE
);
336 CMD(change_virtual_intf
, SET_INTERFACE
);
337 CMD(add_key
, NEW_KEY
);
338 CMD(add_beacon
, NEW_BEACON
);
339 CMD(add_station
, NEW_STATION
);
340 CMD(add_mpath
, NEW_MPATH
);
341 CMD(set_mesh_params
, SET_MESH_PARAMS
);
342 CMD(change_bss
, SET_BSS
);
343 CMD(auth
, AUTHENTICATE
);
344 CMD(assoc
, ASSOCIATE
);
345 CMD(deauth
, DEAUTHENTICATE
);
346 CMD(disassoc
, DISASSOCIATE
);
347 CMD(join_ibss
, JOIN_IBSS
);
350 nla_nest_end(msg
, nl_cmds
);
352 return genlmsg_end(msg
, hdr
);
355 genlmsg_cancel(msg
, hdr
);
359 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
362 int start
= cb
->args
[0];
363 struct cfg80211_registered_device
*dev
;
365 mutex_lock(&cfg80211_mutex
);
366 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
369 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
370 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
376 mutex_unlock(&cfg80211_mutex
);
383 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
386 struct cfg80211_registered_device
*dev
;
388 dev
= cfg80211_get_dev_from_info(info
);
392 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
396 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
399 cfg80211_put_dev(dev
);
401 return genlmsg_unicast(msg
, info
->snd_pid
);
406 cfg80211_put_dev(dev
);
410 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
411 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
412 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
413 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
414 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
415 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
418 static int parse_txq_params(struct nlattr
*tb
[],
419 struct ieee80211_txq_params
*txq_params
)
421 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
422 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
423 !tb
[NL80211_TXQ_ATTR_AIFS
])
426 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
427 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
428 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
429 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
430 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
435 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
437 struct cfg80211_registered_device
*rdev
;
438 int result
= 0, rem_txq_params
= 0;
439 struct nlattr
*nl_txq_params
;
441 u8 retry_short
= 0, retry_long
= 0;
442 u32 frag_threshold
= 0, rts_threshold
= 0;
446 mutex_lock(&cfg80211_mutex
);
448 rdev
= __cfg80211_drv_from_info(info
);
450 mutex_unlock(&cfg80211_mutex
);
451 result
= PTR_ERR(rdev
);
455 mutex_lock(&rdev
->mtx
);
457 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
458 result
= cfg80211_dev_rename(
459 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
461 mutex_unlock(&cfg80211_mutex
);
466 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
467 struct ieee80211_txq_params txq_params
;
468 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
470 if (!rdev
->ops
->set_txq_params
) {
471 result
= -EOPNOTSUPP
;
475 nla_for_each_nested(nl_txq_params
,
476 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
478 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
479 nla_data(nl_txq_params
),
480 nla_len(nl_txq_params
),
482 result
= parse_txq_params(tb
, &txq_params
);
486 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
493 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
494 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
495 struct ieee80211_channel
*chan
;
496 struct ieee80211_sta_ht_cap
*ht_cap
;
499 if (!rdev
->ops
->set_channel
) {
500 result
= -EOPNOTSUPP
;
506 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
507 channel_type
= nla_get_u32(info
->attrs
[
508 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
509 if (channel_type
!= NL80211_CHAN_NO_HT
&&
510 channel_type
!= NL80211_CHAN_HT20
&&
511 channel_type
!= NL80211_CHAN_HT40PLUS
&&
512 channel_type
!= NL80211_CHAN_HT40MINUS
)
516 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
517 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
519 /* Primary channel not allowed */
520 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
523 if (channel_type
== NL80211_CHAN_HT40MINUS
&&
524 (chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
))
526 else if (channel_type
== NL80211_CHAN_HT40PLUS
&&
527 (chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
))
531 * At this point we know if that if HT40 was requested
532 * we are allowed to use it and the extension channel
536 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
538 /* no HT capabilities or intolerant */
539 if (channel_type
!= NL80211_CHAN_NO_HT
) {
540 if (!ht_cap
->ht_supported
)
542 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
543 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
547 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
555 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
556 retry_short
= nla_get_u8(
557 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
558 if (retry_short
== 0) {
562 changed
|= WIPHY_PARAM_RETRY_SHORT
;
565 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
566 retry_long
= nla_get_u8(
567 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
568 if (retry_long
== 0) {
572 changed
|= WIPHY_PARAM_RETRY_LONG
;
575 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
576 frag_threshold
= nla_get_u32(
577 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
578 if (frag_threshold
< 256) {
582 if (frag_threshold
!= (u32
) -1) {
584 * Fragments (apart from the last one) are required to
585 * have even length. Make the fragmentation code
586 * simpler by stripping LSB should someone try to use
587 * odd threshold value.
589 frag_threshold
&= ~0x1;
591 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
594 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
595 rts_threshold
= nla_get_u32(
596 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
597 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
601 u8 old_retry_short
, old_retry_long
;
602 u32 old_frag_threshold
, old_rts_threshold
;
604 if (!rdev
->ops
->set_wiphy_params
) {
605 result
= -EOPNOTSUPP
;
609 old_retry_short
= rdev
->wiphy
.retry_short
;
610 old_retry_long
= rdev
->wiphy
.retry_long
;
611 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
612 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
614 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
615 rdev
->wiphy
.retry_short
= retry_short
;
616 if (changed
& WIPHY_PARAM_RETRY_LONG
)
617 rdev
->wiphy
.retry_long
= retry_long
;
618 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
619 rdev
->wiphy
.frag_threshold
= frag_threshold
;
620 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
621 rdev
->wiphy
.rts_threshold
= rts_threshold
;
623 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
625 rdev
->wiphy
.retry_short
= old_retry_short
;
626 rdev
->wiphy
.retry_long
= old_retry_long
;
627 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
628 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
633 mutex_unlock(&rdev
->mtx
);
640 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
641 struct cfg80211_registered_device
*rdev
,
642 struct net_device
*dev
)
646 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
650 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
651 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
652 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
653 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
654 return genlmsg_end(msg
, hdr
);
657 genlmsg_cancel(msg
, hdr
);
661 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
665 int wp_start
= cb
->args
[0];
666 int if_start
= cb
->args
[1];
667 struct cfg80211_registered_device
*dev
;
668 struct wireless_dev
*wdev
;
670 mutex_lock(&cfg80211_mutex
);
671 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
672 if (wp_idx
< wp_start
) {
678 mutex_lock(&dev
->devlist_mtx
);
679 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
680 if (if_idx
< if_start
) {
684 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
685 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
686 dev
, wdev
->netdev
) < 0) {
687 mutex_unlock(&dev
->devlist_mtx
);
692 mutex_unlock(&dev
->devlist_mtx
);
697 mutex_unlock(&cfg80211_mutex
);
699 cb
->args
[0] = wp_idx
;
700 cb
->args
[1] = if_idx
;
705 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
708 struct cfg80211_registered_device
*dev
;
709 struct net_device
*netdev
;
712 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &dev
, &netdev
);
716 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
720 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
725 cfg80211_put_dev(dev
);
727 return genlmsg_unicast(msg
, info
->snd_pid
);
733 cfg80211_put_dev(dev
);
737 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
738 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
739 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
740 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
741 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
742 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
745 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
747 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
755 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
756 nla
, mntr_flags_policy
))
759 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
761 *mntrflags
|= (1<<flag
);
766 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
768 struct cfg80211_registered_device
*drv
;
769 struct vif_params params
;
771 enum nl80211_iftype otype
, ntype
;
772 struct net_device
*dev
;
773 u32 _flags
, *flags
= NULL
;
776 memset(¶ms
, 0, sizeof(params
));
780 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
784 ifindex
= dev
->ifindex
;
785 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
788 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
789 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
792 if (ntype
> NL80211_IFTYPE_MAX
) {
798 if (!drv
->ops
->change_virtual_intf
||
799 !(drv
->wiphy
.interface_modes
& (1 << ntype
))) {
804 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
805 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
809 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
810 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
814 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
815 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
819 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
829 err
= drv
->ops
->change_virtual_intf(&drv
->wiphy
, ifindex
,
830 ntype
, flags
, ¶ms
);
834 dev
= __dev_get_by_index(&init_net
, ifindex
);
835 WARN_ON(!dev
|| (!err
&& dev
->ieee80211_ptr
->iftype
!= ntype
));
837 if (dev
&& !err
&& (ntype
!= otype
)) {
838 if (otype
== NL80211_IFTYPE_ADHOC
)
839 cfg80211_clear_ibss(dev
, false);
843 cfg80211_put_dev(drv
);
849 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
851 struct cfg80211_registered_device
*drv
;
852 struct vif_params params
;
854 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
857 memset(¶ms
, 0, sizeof(params
));
859 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
862 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
863 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
864 if (type
> NL80211_IFTYPE_MAX
)
870 drv
= cfg80211_get_dev_from_info(info
);
876 if (!drv
->ops
->add_virtual_intf
||
877 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
882 if (type
== NL80211_IFTYPE_MESH_POINT
&&
883 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
884 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
885 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
888 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
889 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
891 err
= drv
->ops
->add_virtual_intf(&drv
->wiphy
,
892 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
893 type
, err
? NULL
: &flags
, ¶ms
);
896 cfg80211_put_dev(drv
);
902 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
904 struct cfg80211_registered_device
*drv
;
906 struct net_device
*dev
;
910 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
913 ifindex
= dev
->ifindex
;
916 if (!drv
->ops
->del_virtual_intf
) {
921 err
= drv
->ops
->del_virtual_intf(&drv
->wiphy
, ifindex
);
924 cfg80211_put_dev(drv
);
930 struct get_key_cookie
{
935 static void get_key_callback(void *c
, struct key_params
*params
)
937 struct get_key_cookie
*cookie
= c
;
940 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
941 params
->key_len
, params
->key
);
944 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
945 params
->seq_len
, params
->seq
);
948 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
956 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
958 struct cfg80211_registered_device
*drv
;
960 struct net_device
*dev
;
963 struct get_key_cookie cookie
= {
969 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
970 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
975 if (info
->attrs
[NL80211_ATTR_MAC
])
976 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
980 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
984 if (!drv
->ops
->get_key
) {
989 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
995 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
996 NL80211_CMD_NEW_KEY
);
1005 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1006 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1008 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1010 err
= drv
->ops
->get_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
,
1011 &cookie
, get_key_callback
);
1017 goto nla_put_failure
;
1019 genlmsg_end(msg
, hdr
);
1020 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1028 cfg80211_put_dev(drv
);
1036 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1038 struct cfg80211_registered_device
*drv
;
1040 struct net_device
*dev
;
1042 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1045 if (!info
->attrs
[NL80211_ATTR_KEY_IDX
])
1048 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1050 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
]) {
1051 if (key_idx
< 4 || key_idx
> 5)
1053 } else if (key_idx
> 3)
1056 /* currently only support setting default key */
1057 if (!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
] &&
1058 !info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
])
1063 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1067 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT
])
1068 func
= drv
->ops
->set_default_key
;
1070 func
= drv
->ops
->set_default_mgmt_key
;
1077 err
= func(&drv
->wiphy
, dev
, key_idx
);
1078 #ifdef CONFIG_WIRELESS_EXT
1080 if (func
== drv
->ops
->set_default_key
)
1081 dev
->ieee80211_ptr
->wext
.default_key
= key_idx
;
1083 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key_idx
;
1088 cfg80211_put_dev(drv
);
1097 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1099 struct cfg80211_registered_device
*drv
;
1101 struct net_device
*dev
;
1102 struct key_params params
;
1104 u8
*mac_addr
= NULL
;
1106 memset(¶ms
, 0, sizeof(params
));
1108 if (!info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
1111 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
1112 params
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
1113 params
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
1116 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
1117 params
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
1118 params
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
1121 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1122 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1124 params
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
1126 if (info
->attrs
[NL80211_ATTR_MAC
])
1127 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1129 if (cfg80211_validate_key_settings(¶ms
, key_idx
, mac_addr
))
1134 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1138 for (i
= 0; i
< drv
->wiphy
.n_cipher_suites
; i
++)
1139 if (params
.cipher
== drv
->wiphy
.cipher_suites
[i
])
1141 if (i
== drv
->wiphy
.n_cipher_suites
) {
1146 if (!drv
->ops
->add_key
) {
1151 err
= drv
->ops
->add_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
, ¶ms
);
1154 cfg80211_put_dev(drv
);
1162 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1164 struct cfg80211_registered_device
*drv
;
1166 struct net_device
*dev
;
1168 u8
*mac_addr
= NULL
;
1170 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1171 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1176 if (info
->attrs
[NL80211_ATTR_MAC
])
1177 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1181 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1185 if (!drv
->ops
->del_key
) {
1190 err
= drv
->ops
->del_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
);
1192 #ifdef CONFIG_WIRELESS_EXT
1194 if (key_idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1195 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1196 else if (key_idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1197 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1202 cfg80211_put_dev(drv
);
1211 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1213 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1214 struct beacon_parameters
*info
);
1215 struct cfg80211_registered_device
*drv
;
1217 struct net_device
*dev
;
1218 struct beacon_parameters params
;
1221 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1226 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1230 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1235 switch (info
->genlhdr
->cmd
) {
1236 case NL80211_CMD_NEW_BEACON
:
1237 /* these are required for NEW_BEACON */
1238 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1239 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1240 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1245 call
= drv
->ops
->add_beacon
;
1247 case NL80211_CMD_SET_BEACON
:
1248 call
= drv
->ops
->set_beacon
;
1261 memset(¶ms
, 0, sizeof(params
));
1263 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1265 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1269 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1270 params
.dtim_period
=
1271 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1275 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1276 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1278 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1282 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1283 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1285 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1294 err
= call(&drv
->wiphy
, dev
, ¶ms
);
1297 cfg80211_put_dev(drv
);
1305 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1307 struct cfg80211_registered_device
*drv
;
1309 struct net_device
*dev
;
1313 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1317 if (!drv
->ops
->del_beacon
) {
1322 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1326 err
= drv
->ops
->del_beacon(&drv
->wiphy
, dev
);
1329 cfg80211_put_dev(drv
);
1337 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1338 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1339 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1340 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1341 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1344 static int parse_station_flags(struct genl_info
*info
,
1345 struct station_parameters
*params
)
1347 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1352 * Try parsing the new attribute first so userspace
1353 * can specify both for older kernels.
1355 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1357 struct nl80211_sta_flag_update
*sta_flags
;
1359 sta_flags
= nla_data(nla
);
1360 params
->sta_flags_mask
= sta_flags
->mask
;
1361 params
->sta_flags_set
= sta_flags
->set
;
1362 if ((params
->sta_flags_mask
|
1363 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1368 /* if present, parse the old attribute */
1370 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1374 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1375 nla
, sta_flags_policy
))
1378 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1379 params
->sta_flags_mask
&= ~1;
1381 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1383 params
->sta_flags_set
|= (1<<flag
);
1388 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1390 int modulation
, streams
, bitrate
;
1392 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1393 return rate
->legacy
;
1395 /* the formula below does only work for MCS values smaller than 32 */
1396 if (rate
->mcs
>= 32)
1399 modulation
= rate
->mcs
& 7;
1400 streams
= (rate
->mcs
>> 3) + 1;
1402 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1406 bitrate
*= (modulation
+ 1);
1407 else if (modulation
== 4)
1408 bitrate
*= (modulation
+ 2);
1410 bitrate
*= (modulation
+ 3);
1414 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1415 bitrate
= (bitrate
/ 9) * 10;
1417 /* do NOT round down here */
1418 return (bitrate
+ 50000) / 100000;
1421 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1422 int flags
, struct net_device
*dev
,
1423 u8
*mac_addr
, struct station_info
*sinfo
)
1426 struct nlattr
*sinfoattr
, *txrate
;
1429 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1433 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1434 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1436 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1438 goto nla_put_failure
;
1439 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1440 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1441 sinfo
->inactive_time
);
1442 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1443 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1445 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1446 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1448 if (sinfo
->filled
& STATION_INFO_LLID
)
1449 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1451 if (sinfo
->filled
& STATION_INFO_PLID
)
1452 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1454 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1455 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1456 sinfo
->plink_state
);
1457 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1458 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1460 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1461 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1463 goto nla_put_failure
;
1465 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1466 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1468 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1470 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1471 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1473 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1474 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1475 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1476 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1478 nla_nest_end(msg
, txrate
);
1480 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1481 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1483 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1484 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1486 nla_nest_end(msg
, sinfoattr
);
1488 return genlmsg_end(msg
, hdr
);
1491 genlmsg_cancel(msg
, hdr
);
1495 static int nl80211_dump_station(struct sk_buff
*skb
,
1496 struct netlink_callback
*cb
)
1498 struct station_info sinfo
;
1499 struct cfg80211_registered_device
*dev
;
1500 struct net_device
*netdev
;
1501 u8 mac_addr
[ETH_ALEN
];
1502 int ifidx
= cb
->args
[0];
1503 int sta_idx
= cb
->args
[1];
1507 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1508 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1513 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1516 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1523 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1529 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1535 if (!dev
->ops
->dump_station
) {
1541 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1548 if (nl80211_send_station(skb
,
1549 NETLINK_CB(cb
->skb
).pid
,
1550 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1560 cb
->args
[1] = sta_idx
;
1563 cfg80211_put_dev(dev
);
1570 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1572 struct cfg80211_registered_device
*drv
;
1574 struct net_device
*dev
;
1575 struct station_info sinfo
;
1576 struct sk_buff
*msg
;
1577 u8
*mac_addr
= NULL
;
1579 memset(&sinfo
, 0, sizeof(sinfo
));
1581 if (!info
->attrs
[NL80211_ATTR_MAC
])
1584 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1588 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1592 if (!drv
->ops
->get_station
) {
1597 err
= drv
->ops
->get_station(&drv
->wiphy
, dev
, mac_addr
, &sinfo
);
1601 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1605 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1606 dev
, mac_addr
, &sinfo
) < 0)
1609 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1615 cfg80211_put_dev(drv
);
1624 * Get vlan interface making sure it is on the right wiphy.
1626 static int get_vlan(struct nlattr
*vlanattr
,
1627 struct cfg80211_registered_device
*rdev
,
1628 struct net_device
**vlan
)
1633 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1636 if (!(*vlan
)->ieee80211_ptr
)
1638 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1644 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1646 struct cfg80211_registered_device
*drv
;
1648 struct net_device
*dev
;
1649 struct station_parameters params
;
1650 u8
*mac_addr
= NULL
;
1652 memset(¶ms
, 0, sizeof(params
));
1654 params
.listen_interval
= -1;
1656 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1659 if (!info
->attrs
[NL80211_ATTR_MAC
])
1662 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1664 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1665 params
.supported_rates
=
1666 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1667 params
.supported_rates_len
=
1668 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1671 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1672 params
.listen_interval
=
1673 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1675 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1677 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1679 if (parse_station_flags(info
, ¶ms
))
1682 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1683 params
.plink_action
=
1684 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1688 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1692 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1696 /* validate settings */
1699 switch (dev
->ieee80211_ptr
->iftype
) {
1700 case NL80211_IFTYPE_AP
:
1701 case NL80211_IFTYPE_AP_VLAN
:
1702 /* disallow mesh-specific things */
1703 if (params
.plink_action
)
1706 case NL80211_IFTYPE_STATION
:
1707 /* disallow everything but AUTHORIZED flag */
1708 if (params
.plink_action
)
1712 if (params
.supported_rates
)
1716 if (params
.listen_interval
>= 0)
1718 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1721 case NL80211_IFTYPE_MESH_POINT
:
1722 /* disallow things mesh doesn't support */
1727 if (params
.listen_interval
>= 0)
1729 if (params
.supported_rates
)
1731 if (params
.sta_flags_mask
)
1741 if (!drv
->ops
->change_station
) {
1746 err
= drv
->ops
->change_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1750 dev_put(params
.vlan
);
1751 cfg80211_put_dev(drv
);
1759 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1761 struct cfg80211_registered_device
*drv
;
1763 struct net_device
*dev
;
1764 struct station_parameters params
;
1765 u8
*mac_addr
= NULL
;
1767 memset(¶ms
, 0, sizeof(params
));
1769 if (!info
->attrs
[NL80211_ATTR_MAC
])
1772 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1775 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1778 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1779 params
.supported_rates
=
1780 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1781 params
.supported_rates_len
=
1782 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1783 params
.listen_interval
=
1784 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1786 if (info
->attrs
[NL80211_ATTR_STA_AID
]) {
1787 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1788 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
1792 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1794 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1796 if (parse_station_flags(info
, ¶ms
))
1801 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1805 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1809 /* validate settings */
1812 switch (dev
->ieee80211_ptr
->iftype
) {
1813 case NL80211_IFTYPE_AP
:
1814 case NL80211_IFTYPE_AP_VLAN
:
1815 /* all ok but must have AID */
1819 case NL80211_IFTYPE_MESH_POINT
:
1820 /* disallow things mesh doesn't support */
1827 if (params
.listen_interval
>= 0)
1829 if (params
.supported_rates
)
1831 if (params
.sta_flags_mask
)
1841 if (!drv
->ops
->add_station
) {
1846 if (!netif_running(dev
)) {
1851 err
= drv
->ops
->add_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1855 dev_put(params
.vlan
);
1856 cfg80211_put_dev(drv
);
1864 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
1866 struct cfg80211_registered_device
*drv
;
1868 struct net_device
*dev
;
1869 u8
*mac_addr
= NULL
;
1871 if (info
->attrs
[NL80211_ATTR_MAC
])
1872 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1876 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1880 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1881 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
1882 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1887 if (!drv
->ops
->del_station
) {
1892 err
= drv
->ops
->del_station(&drv
->wiphy
, dev
, mac_addr
);
1895 cfg80211_put_dev(drv
);
1903 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1904 int flags
, struct net_device
*dev
,
1905 u8
*dst
, u8
*next_hop
,
1906 struct mpath_info
*pinfo
)
1909 struct nlattr
*pinfoattr
;
1911 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1915 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1916 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
1917 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
1919 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
1921 goto nla_put_failure
;
1922 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
1923 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
1925 if (pinfo
->filled
& MPATH_INFO_DSN
)
1926 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
1928 if (pinfo
->filled
& MPATH_INFO_METRIC
)
1929 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
1931 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
1932 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
1934 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
1935 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
1937 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
1938 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
1939 pinfo
->discovery_timeout
);
1940 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
1941 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
1942 pinfo
->discovery_retries
);
1944 nla_nest_end(msg
, pinfoattr
);
1946 return genlmsg_end(msg
, hdr
);
1949 genlmsg_cancel(msg
, hdr
);
1953 static int nl80211_dump_mpath(struct sk_buff
*skb
,
1954 struct netlink_callback
*cb
)
1956 struct mpath_info pinfo
;
1957 struct cfg80211_registered_device
*dev
;
1958 struct net_device
*netdev
;
1960 u8 next_hop
[ETH_ALEN
];
1961 int ifidx
= cb
->args
[0];
1962 int path_idx
= cb
->args
[1];
1966 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1967 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1972 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1975 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1982 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1988 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1994 if (!dev
->ops
->dump_mpath
) {
1999 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2005 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2006 dst
, next_hop
, &pinfo
);
2012 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2013 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2014 netdev
, dst
, next_hop
,
2023 cb
->args
[1] = path_idx
;
2026 cfg80211_put_dev(dev
);
2033 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2035 struct cfg80211_registered_device
*drv
;
2037 struct net_device
*dev
;
2038 struct mpath_info pinfo
;
2039 struct sk_buff
*msg
;
2041 u8 next_hop
[ETH_ALEN
];
2043 memset(&pinfo
, 0, sizeof(pinfo
));
2045 if (!info
->attrs
[NL80211_ATTR_MAC
])
2048 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2052 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2056 if (!drv
->ops
->get_mpath
) {
2061 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2066 err
= drv
->ops
->get_mpath(&drv
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2070 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2074 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2075 dev
, dst
, next_hop
, &pinfo
) < 0)
2078 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2084 cfg80211_put_dev(drv
);
2092 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2094 struct cfg80211_registered_device
*drv
;
2096 struct net_device
*dev
;
2098 u8
*next_hop
= NULL
;
2100 if (!info
->attrs
[NL80211_ATTR_MAC
])
2103 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2106 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2107 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2111 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2115 if (!drv
->ops
->change_mpath
) {
2120 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2125 if (!netif_running(dev
)) {
2130 err
= drv
->ops
->change_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
2133 cfg80211_put_dev(drv
);
2140 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2142 struct cfg80211_registered_device
*drv
;
2144 struct net_device
*dev
;
2146 u8
*next_hop
= NULL
;
2148 if (!info
->attrs
[NL80211_ATTR_MAC
])
2151 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2154 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2155 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2159 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2163 if (!drv
->ops
->add_mpath
) {
2168 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2173 if (!netif_running(dev
)) {
2178 err
= drv
->ops
->add_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
2181 cfg80211_put_dev(drv
);
2189 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2191 struct cfg80211_registered_device
*drv
;
2193 struct net_device
*dev
;
2196 if (info
->attrs
[NL80211_ATTR_MAC
])
2197 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2201 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2205 if (!drv
->ops
->del_mpath
) {
2210 err
= drv
->ops
->del_mpath(&drv
->wiphy
, dev
, dst
);
2213 cfg80211_put_dev(drv
);
2221 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2223 struct cfg80211_registered_device
*drv
;
2225 struct net_device
*dev
;
2226 struct bss_parameters params
;
2228 memset(¶ms
, 0, sizeof(params
));
2229 /* default to not changing parameters */
2230 params
.use_cts_prot
= -1;
2231 params
.use_short_preamble
= -1;
2232 params
.use_short_slot_time
= -1;
2234 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2235 params
.use_cts_prot
=
2236 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2237 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2238 params
.use_short_preamble
=
2239 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2240 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2241 params
.use_short_slot_time
=
2242 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2243 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2244 params
.basic_rates
=
2245 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2246 params
.basic_rates_len
=
2247 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2252 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2256 if (!drv
->ops
->change_bss
) {
2261 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2266 err
= drv
->ops
->change_bss(&drv
->wiphy
, dev
, ¶ms
);
2269 cfg80211_put_dev(drv
);
2277 static const struct nla_policy
2278 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2279 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2280 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2281 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2282 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2283 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2284 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2287 static int parse_reg_rule(struct nlattr
*tb
[],
2288 struct ieee80211_reg_rule
*reg_rule
)
2290 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2291 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2293 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2295 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2297 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2299 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2301 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2304 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2306 freq_range
->start_freq_khz
=
2307 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2308 freq_range
->end_freq_khz
=
2309 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2310 freq_range
->max_bandwidth_khz
=
2311 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2313 power_rule
->max_eirp
=
2314 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2316 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2317 power_rule
->max_antenna_gain
=
2318 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2323 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2329 * You should only get this when cfg80211 hasn't yet initialized
2330 * completely when built-in to the kernel right between the time
2331 * window between nl80211_init() and regulatory_init(), if that is
2334 mutex_lock(&cfg80211_mutex
);
2335 if (unlikely(!cfg80211_regdomain
)) {
2336 mutex_unlock(&cfg80211_mutex
);
2337 return -EINPROGRESS
;
2339 mutex_unlock(&cfg80211_mutex
);
2341 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2344 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2346 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2347 /* We ignore world regdom requests with the old regdom setup */
2348 if (is_world_regdom(data
))
2352 r
= regulatory_hint_user(data
);
2357 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2358 struct genl_info
*info
)
2360 struct cfg80211_registered_device
*drv
;
2361 struct mesh_config cur_params
;
2363 struct net_device
*dev
;
2365 struct nlattr
*pinfoattr
;
2366 struct sk_buff
*msg
;
2370 /* Look up our device */
2371 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2375 if (!drv
->ops
->get_mesh_params
) {
2380 /* Get the mesh params */
2381 err
= drv
->ops
->get_mesh_params(&drv
->wiphy
, dev
, &cur_params
);
2385 /* Draw up a netlink message to send back */
2386 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2391 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2392 NL80211_CMD_GET_MESH_PARAMS
);
2394 goto nla_put_failure
;
2395 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2397 goto nla_put_failure
;
2398 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2399 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2400 cur_params
.dot11MeshRetryTimeout
);
2401 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2402 cur_params
.dot11MeshConfirmTimeout
);
2403 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2404 cur_params
.dot11MeshHoldingTimeout
);
2405 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2406 cur_params
.dot11MeshMaxPeerLinks
);
2407 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2408 cur_params
.dot11MeshMaxRetries
);
2409 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2410 cur_params
.dot11MeshTTL
);
2411 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2412 cur_params
.auto_open_plinks
);
2413 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2414 cur_params
.dot11MeshHWMPmaxPREQretries
);
2415 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2416 cur_params
.path_refresh_time
);
2417 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2418 cur_params
.min_discovery_timeout
);
2419 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2420 cur_params
.dot11MeshHWMPactivePathTimeout
);
2421 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2422 cur_params
.dot11MeshHWMPpreqMinInterval
);
2423 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2424 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2425 nla_nest_end(msg
, pinfoattr
);
2426 genlmsg_end(msg
, hdr
);
2427 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2431 genlmsg_cancel(msg
, hdr
);
2435 cfg80211_put_dev(drv
);
2443 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2445 if (table[attr_num]) {\
2446 cfg.param = nla_fn(table[attr_num]); \
2447 mask |= (1 << (attr_num - 1)); \
2451 static struct nla_policy
2452 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2453 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2454 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2455 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2456 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2457 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2458 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2459 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2461 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2462 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2463 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2464 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2465 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2466 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2469 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2473 struct cfg80211_registered_device
*drv
;
2474 struct net_device
*dev
;
2475 struct mesh_config cfg
;
2476 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2477 struct nlattr
*parent_attr
;
2479 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2482 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2483 parent_attr
, nl80211_meshconf_params_policy
))
2488 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2492 if (!drv
->ops
->set_mesh_params
) {
2497 /* This makes sure that there aren't more than 32 mesh config
2498 * parameters (otherwise our bitfield scheme would not work.) */
2499 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2501 /* Fill in the params struct */
2503 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2504 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2505 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2506 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2507 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2508 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2509 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2510 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2511 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2512 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2513 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2514 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2515 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2516 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2517 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2518 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2520 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2521 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2522 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2523 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2525 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2526 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2528 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2529 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2531 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2532 dot11MeshHWMPnetDiameterTraversalTime
,
2533 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2537 err
= drv
->ops
->set_mesh_params(&drv
->wiphy
, dev
, &cfg
, mask
);
2541 cfg80211_put_dev(drv
);
2549 #undef FILL_IN_MESH_PARAM_IF_SET
2551 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2553 struct sk_buff
*msg
;
2555 struct nlattr
*nl_reg_rules
;
2559 mutex_lock(&cfg80211_mutex
);
2561 if (!cfg80211_regdomain
)
2564 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2570 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2571 NL80211_CMD_GET_REG
);
2573 goto nla_put_failure
;
2575 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2576 cfg80211_regdomain
->alpha2
);
2578 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2580 goto nla_put_failure
;
2582 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2583 struct nlattr
*nl_reg_rule
;
2584 const struct ieee80211_reg_rule
*reg_rule
;
2585 const struct ieee80211_freq_range
*freq_range
;
2586 const struct ieee80211_power_rule
*power_rule
;
2588 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2589 freq_range
= ®_rule
->freq_range
;
2590 power_rule
= ®_rule
->power_rule
;
2592 nl_reg_rule
= nla_nest_start(msg
, i
);
2594 goto nla_put_failure
;
2596 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2598 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2599 freq_range
->start_freq_khz
);
2600 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2601 freq_range
->end_freq_khz
);
2602 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2603 freq_range
->max_bandwidth_khz
);
2604 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2605 power_rule
->max_antenna_gain
);
2606 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2607 power_rule
->max_eirp
);
2609 nla_nest_end(msg
, nl_reg_rule
);
2612 nla_nest_end(msg
, nl_reg_rules
);
2614 genlmsg_end(msg
, hdr
);
2615 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2619 genlmsg_cancel(msg
, hdr
);
2622 mutex_unlock(&cfg80211_mutex
);
2626 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2628 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2629 struct nlattr
*nl_reg_rule
;
2630 char *alpha2
= NULL
;
2631 int rem_reg_rules
= 0, r
= 0;
2632 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2633 struct ieee80211_regdomain
*rd
= NULL
;
2635 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2638 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2641 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2643 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2646 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2650 mutex_lock(&cfg80211_mutex
);
2652 if (!reg_is_valid_request(alpha2
)) {
2657 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2658 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2660 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2666 rd
->n_reg_rules
= num_rules
;
2667 rd
->alpha2
[0] = alpha2
[0];
2668 rd
->alpha2
[1] = alpha2
[1];
2670 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2672 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2673 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2675 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2681 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2687 BUG_ON(rule_idx
!= num_rules
);
2691 mutex_unlock(&cfg80211_mutex
);
2696 mutex_unlock(&cfg80211_mutex
);
2701 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2703 struct cfg80211_registered_device
*drv
;
2704 struct net_device
*dev
;
2705 struct cfg80211_scan_request
*request
;
2706 struct cfg80211_ssid
*ssid
;
2707 struct ieee80211_channel
*channel
;
2708 struct nlattr
*attr
;
2709 struct wiphy
*wiphy
;
2710 int err
, tmp
, n_ssids
= 0, n_channels
= 0, i
;
2711 enum ieee80211_band band
;
2714 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2719 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2723 wiphy
= &drv
->wiphy
;
2725 if (!drv
->ops
->scan
) {
2730 if (!netif_running(dev
)) {
2735 if (drv
->scan_req
) {
2740 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2741 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
)
2748 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2749 if (wiphy
->bands
[band
])
2750 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2753 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2754 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2757 if (n_ssids
> wiphy
->max_scan_ssids
) {
2762 if (info
->attrs
[NL80211_ATTR_IE
])
2763 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2767 if (ie_len
> wiphy
->max_scan_ie_len
) {
2772 request
= kzalloc(sizeof(*request
)
2773 + sizeof(*ssid
) * n_ssids
2774 + sizeof(channel
) * n_channels
2775 + ie_len
, GFP_KERNEL
);
2781 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
2782 request
->n_channels
= n_channels
;
2784 request
->ssids
= (void *)(request
->channels
+ n_channels
);
2785 request
->n_ssids
= n_ssids
;
2788 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
2790 request
->ie
= (void *)(request
->channels
+ n_channels
);
2793 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2794 /* user specified, bail out if channel not found */
2795 request
->n_channels
= n_channels
;
2797 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
2798 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
2799 if (!request
->channels
[i
]) {
2808 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2810 if (!wiphy
->bands
[band
])
2812 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2813 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2820 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
2821 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
2822 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2826 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
2827 request
->ssids
[i
].ssid_len
= nla_len(attr
);
2832 if (info
->attrs
[NL80211_ATTR_IE
]) {
2833 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2834 memcpy((void *)request
->ie
,
2835 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
2839 request
->ifidx
= dev
->ifindex
;
2840 request
->wiphy
= &drv
->wiphy
;
2842 drv
->scan_req
= request
;
2843 err
= drv
->ops
->scan(&drv
->wiphy
, dev
, request
);
2847 drv
->scan_req
= NULL
;
2851 cfg80211_put_dev(drv
);
2859 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
2860 struct cfg80211_registered_device
*rdev
,
2861 struct net_device
*dev
,
2862 struct cfg80211_bss
*res
)
2867 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
2868 NL80211_CMD_NEW_SCAN_RESULTS
);
2872 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
2873 rdev
->bss_generation
);
2874 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2876 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
2878 goto nla_put_failure
;
2879 if (!is_zero_ether_addr(res
->bssid
))
2880 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
2881 if (res
->information_elements
&& res
->len_information_elements
)
2882 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
2883 res
->len_information_elements
,
2884 res
->information_elements
);
2886 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
2887 if (res
->beacon_interval
)
2888 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
2889 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
2890 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
2892 switch (rdev
->wiphy
.signal_type
) {
2893 case CFG80211_SIGNAL_TYPE_MBM
:
2894 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
2896 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2897 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
2903 nla_nest_end(msg
, bss
);
2905 return genlmsg_end(msg
, hdr
);
2908 genlmsg_cancel(msg
, hdr
);
2912 static int nl80211_dump_scan(struct sk_buff
*skb
,
2913 struct netlink_callback
*cb
)
2915 struct cfg80211_registered_device
*dev
;
2916 struct net_device
*netdev
;
2917 struct cfg80211_internal_bss
*scan
;
2918 int ifidx
= cb
->args
[0];
2919 int start
= cb
->args
[1], idx
= 0;
2923 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2924 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2929 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2932 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2935 cb
->args
[0] = ifidx
;
2938 netdev
= dev_get_by_index(&init_net
, ifidx
);
2942 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2945 goto out_put_netdev
;
2948 spin_lock_bh(&dev
->bss_lock
);
2949 cfg80211_bss_expire(dev
);
2951 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
2954 if (nl80211_send_bss(skb
,
2955 NETLINK_CB(cb
->skb
).pid
,
2956 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2957 dev
, netdev
, &scan
->pub
) < 0) {
2964 spin_unlock_bh(&dev
->bss_lock
);
2968 cfg80211_put_dev(dev
);
2975 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
2977 return auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
||
2978 auth_type
== NL80211_AUTHTYPE_SHARED_KEY
||
2979 auth_type
== NL80211_AUTHTYPE_FT
||
2980 auth_type
== NL80211_AUTHTYPE_NETWORK_EAP
;
2983 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2985 struct cfg80211_registered_device
*drv
;
2986 struct net_device
*dev
;
2987 struct cfg80211_auth_request req
;
2988 struct wiphy
*wiphy
;
2991 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2994 if (!info
->attrs
[NL80211_ATTR_MAC
])
2997 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3002 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3006 if (!drv
->ops
->auth
) {
3011 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3016 if (!netif_running(dev
)) {
3021 wiphy
= &drv
->wiphy
;
3022 memset(&req
, 0, sizeof(req
));
3024 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3026 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3027 req
.chan
= ieee80211_get_channel(
3029 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3036 if (info
->attrs
[NL80211_ATTR_SSID
]) {
3037 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3038 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3041 if (info
->attrs
[NL80211_ATTR_IE
]) {
3042 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3043 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3046 req
.auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3047 if (!nl80211_valid_auth_type(req
.auth_type
)) {
3052 err
= drv
->ops
->auth(&drv
->wiphy
, dev
, &req
);
3055 cfg80211_put_dev(drv
);
3062 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3064 struct cfg80211_registered_device
*drv
;
3065 struct net_device
*dev
;
3066 struct cfg80211_assoc_request req
;
3067 struct wiphy
*wiphy
;
3070 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3073 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3074 !info
->attrs
[NL80211_ATTR_SSID
])
3079 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3083 if (!drv
->ops
->assoc
) {
3088 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3093 if (!netif_running(dev
)) {
3098 wiphy
= &drv
->wiphy
;
3099 memset(&req
, 0, sizeof(req
));
3101 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3103 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3104 req
.chan
= ieee80211_get_channel(
3106 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3113 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3114 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3116 if (info
->attrs
[NL80211_ATTR_IE
]) {
3117 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3118 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3121 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3122 enum nl80211_mfp use_mfp
=
3123 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3124 if (use_mfp
== NL80211_MFP_REQUIRED
)
3126 else if (use_mfp
!= NL80211_MFP_NO
) {
3132 req
.control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3134 err
= drv
->ops
->assoc(&drv
->wiphy
, dev
, &req
);
3137 cfg80211_put_dev(drv
);
3144 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3146 struct cfg80211_registered_device
*drv
;
3147 struct net_device
*dev
;
3148 struct cfg80211_deauth_request req
;
3149 struct wiphy
*wiphy
;
3152 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3155 if (!info
->attrs
[NL80211_ATTR_MAC
])
3158 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3163 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3167 if (!drv
->ops
->deauth
) {
3172 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3177 if (!netif_running(dev
)) {
3182 wiphy
= &drv
->wiphy
;
3183 memset(&req
, 0, sizeof(req
));
3185 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3187 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3188 if (req
.reason_code
== 0) {
3189 /* Reason Code 0 is reserved */
3194 if (info
->attrs
[NL80211_ATTR_IE
]) {
3195 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3196 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3199 err
= drv
->ops
->deauth(&drv
->wiphy
, dev
, &req
);
3202 cfg80211_put_dev(drv
);
3209 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3211 struct cfg80211_registered_device
*drv
;
3212 struct net_device
*dev
;
3213 struct cfg80211_disassoc_request req
;
3214 struct wiphy
*wiphy
;
3217 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3220 if (!info
->attrs
[NL80211_ATTR_MAC
])
3223 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3228 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3232 if (!drv
->ops
->disassoc
) {
3237 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3242 if (!netif_running(dev
)) {
3247 wiphy
= &drv
->wiphy
;
3248 memset(&req
, 0, sizeof(req
));
3250 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3252 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3253 if (req
.reason_code
== 0) {
3254 /* Reason Code 0 is reserved */
3259 if (info
->attrs
[NL80211_ATTR_IE
]) {
3260 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3261 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3264 err
= drv
->ops
->disassoc(&drv
->wiphy
, dev
, &req
);
3267 cfg80211_put_dev(drv
);
3274 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3276 struct cfg80211_registered_device
*drv
;
3277 struct net_device
*dev
;
3278 struct cfg80211_ibss_params ibss
;
3279 struct wiphy
*wiphy
;
3282 memset(&ibss
, 0, sizeof(ibss
));
3284 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3287 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3288 !info
->attrs
[NL80211_ATTR_SSID
] ||
3289 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3292 ibss
.beacon_interval
= 100;
3294 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3295 ibss
.beacon_interval
=
3296 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3297 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3303 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3307 if (!drv
->ops
->join_ibss
) {
3312 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3317 if (!netif_running(dev
)) {
3322 wiphy
= &drv
->wiphy
;
3324 if (info
->attrs
[NL80211_ATTR_MAC
])
3325 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3326 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3327 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3329 if (info
->attrs
[NL80211_ATTR_IE
]) {
3330 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3331 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3334 ibss
.channel
= ieee80211_get_channel(wiphy
,
3335 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3336 if (!ibss
.channel
||
3337 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3338 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3343 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3345 err
= cfg80211_join_ibss(drv
, dev
, &ibss
);
3348 cfg80211_put_dev(drv
);
3355 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3357 struct cfg80211_registered_device
*drv
;
3358 struct net_device
*dev
;
3363 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3367 if (!drv
->ops
->leave_ibss
) {
3372 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3377 if (!netif_running(dev
)) {
3382 err
= cfg80211_leave_ibss(drv
, dev
, false);
3385 cfg80211_put_dev(drv
);
3392 static struct genl_ops nl80211_ops
[] = {
3394 .cmd
= NL80211_CMD_GET_WIPHY
,
3395 .doit
= nl80211_get_wiphy
,
3396 .dumpit
= nl80211_dump_wiphy
,
3397 .policy
= nl80211_policy
,
3398 /* can be retrieved by unprivileged users */
3401 .cmd
= NL80211_CMD_SET_WIPHY
,
3402 .doit
= nl80211_set_wiphy
,
3403 .policy
= nl80211_policy
,
3404 .flags
= GENL_ADMIN_PERM
,
3407 .cmd
= NL80211_CMD_GET_INTERFACE
,
3408 .doit
= nl80211_get_interface
,
3409 .dumpit
= nl80211_dump_interface
,
3410 .policy
= nl80211_policy
,
3411 /* can be retrieved by unprivileged users */
3414 .cmd
= NL80211_CMD_SET_INTERFACE
,
3415 .doit
= nl80211_set_interface
,
3416 .policy
= nl80211_policy
,
3417 .flags
= GENL_ADMIN_PERM
,
3420 .cmd
= NL80211_CMD_NEW_INTERFACE
,
3421 .doit
= nl80211_new_interface
,
3422 .policy
= nl80211_policy
,
3423 .flags
= GENL_ADMIN_PERM
,
3426 .cmd
= NL80211_CMD_DEL_INTERFACE
,
3427 .doit
= nl80211_del_interface
,
3428 .policy
= nl80211_policy
,
3429 .flags
= GENL_ADMIN_PERM
,
3432 .cmd
= NL80211_CMD_GET_KEY
,
3433 .doit
= nl80211_get_key
,
3434 .policy
= nl80211_policy
,
3435 .flags
= GENL_ADMIN_PERM
,
3438 .cmd
= NL80211_CMD_SET_KEY
,
3439 .doit
= nl80211_set_key
,
3440 .policy
= nl80211_policy
,
3441 .flags
= GENL_ADMIN_PERM
,
3444 .cmd
= NL80211_CMD_NEW_KEY
,
3445 .doit
= nl80211_new_key
,
3446 .policy
= nl80211_policy
,
3447 .flags
= GENL_ADMIN_PERM
,
3450 .cmd
= NL80211_CMD_DEL_KEY
,
3451 .doit
= nl80211_del_key
,
3452 .policy
= nl80211_policy
,
3453 .flags
= GENL_ADMIN_PERM
,
3456 .cmd
= NL80211_CMD_SET_BEACON
,
3457 .policy
= nl80211_policy
,
3458 .flags
= GENL_ADMIN_PERM
,
3459 .doit
= nl80211_addset_beacon
,
3462 .cmd
= NL80211_CMD_NEW_BEACON
,
3463 .policy
= nl80211_policy
,
3464 .flags
= GENL_ADMIN_PERM
,
3465 .doit
= nl80211_addset_beacon
,
3468 .cmd
= NL80211_CMD_DEL_BEACON
,
3469 .policy
= nl80211_policy
,
3470 .flags
= GENL_ADMIN_PERM
,
3471 .doit
= nl80211_del_beacon
,
3474 .cmd
= NL80211_CMD_GET_STATION
,
3475 .doit
= nl80211_get_station
,
3476 .dumpit
= nl80211_dump_station
,
3477 .policy
= nl80211_policy
,
3480 .cmd
= NL80211_CMD_SET_STATION
,
3481 .doit
= nl80211_set_station
,
3482 .policy
= nl80211_policy
,
3483 .flags
= GENL_ADMIN_PERM
,
3486 .cmd
= NL80211_CMD_NEW_STATION
,
3487 .doit
= nl80211_new_station
,
3488 .policy
= nl80211_policy
,
3489 .flags
= GENL_ADMIN_PERM
,
3492 .cmd
= NL80211_CMD_DEL_STATION
,
3493 .doit
= nl80211_del_station
,
3494 .policy
= nl80211_policy
,
3495 .flags
= GENL_ADMIN_PERM
,
3498 .cmd
= NL80211_CMD_GET_MPATH
,
3499 .doit
= nl80211_get_mpath
,
3500 .dumpit
= nl80211_dump_mpath
,
3501 .policy
= nl80211_policy
,
3502 .flags
= GENL_ADMIN_PERM
,
3505 .cmd
= NL80211_CMD_SET_MPATH
,
3506 .doit
= nl80211_set_mpath
,
3507 .policy
= nl80211_policy
,
3508 .flags
= GENL_ADMIN_PERM
,
3511 .cmd
= NL80211_CMD_NEW_MPATH
,
3512 .doit
= nl80211_new_mpath
,
3513 .policy
= nl80211_policy
,
3514 .flags
= GENL_ADMIN_PERM
,
3517 .cmd
= NL80211_CMD_DEL_MPATH
,
3518 .doit
= nl80211_del_mpath
,
3519 .policy
= nl80211_policy
,
3520 .flags
= GENL_ADMIN_PERM
,
3523 .cmd
= NL80211_CMD_SET_BSS
,
3524 .doit
= nl80211_set_bss
,
3525 .policy
= nl80211_policy
,
3526 .flags
= GENL_ADMIN_PERM
,
3529 .cmd
= NL80211_CMD_GET_REG
,
3530 .doit
= nl80211_get_reg
,
3531 .policy
= nl80211_policy
,
3532 /* can be retrieved by unprivileged users */
3535 .cmd
= NL80211_CMD_SET_REG
,
3536 .doit
= nl80211_set_reg
,
3537 .policy
= nl80211_policy
,
3538 .flags
= GENL_ADMIN_PERM
,
3541 .cmd
= NL80211_CMD_REQ_SET_REG
,
3542 .doit
= nl80211_req_set_reg
,
3543 .policy
= nl80211_policy
,
3544 .flags
= GENL_ADMIN_PERM
,
3547 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
3548 .doit
= nl80211_get_mesh_params
,
3549 .policy
= nl80211_policy
,
3550 /* can be retrieved by unprivileged users */
3553 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
3554 .doit
= nl80211_set_mesh_params
,
3555 .policy
= nl80211_policy
,
3556 .flags
= GENL_ADMIN_PERM
,
3559 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
3560 .doit
= nl80211_trigger_scan
,
3561 .policy
= nl80211_policy
,
3562 .flags
= GENL_ADMIN_PERM
,
3565 .cmd
= NL80211_CMD_GET_SCAN
,
3566 .policy
= nl80211_policy
,
3567 .dumpit
= nl80211_dump_scan
,
3570 .cmd
= NL80211_CMD_AUTHENTICATE
,
3571 .doit
= nl80211_authenticate
,
3572 .policy
= nl80211_policy
,
3573 .flags
= GENL_ADMIN_PERM
,
3576 .cmd
= NL80211_CMD_ASSOCIATE
,
3577 .doit
= nl80211_associate
,
3578 .policy
= nl80211_policy
,
3579 .flags
= GENL_ADMIN_PERM
,
3582 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
3583 .doit
= nl80211_deauthenticate
,
3584 .policy
= nl80211_policy
,
3585 .flags
= GENL_ADMIN_PERM
,
3588 .cmd
= NL80211_CMD_DISASSOCIATE
,
3589 .doit
= nl80211_disassociate
,
3590 .policy
= nl80211_policy
,
3591 .flags
= GENL_ADMIN_PERM
,
3594 .cmd
= NL80211_CMD_JOIN_IBSS
,
3595 .doit
= nl80211_join_ibss
,
3596 .policy
= nl80211_policy
,
3597 .flags
= GENL_ADMIN_PERM
,
3600 .cmd
= NL80211_CMD_LEAVE_IBSS
,
3601 .doit
= nl80211_leave_ibss
,
3602 .policy
= nl80211_policy
,
3603 .flags
= GENL_ADMIN_PERM
,
3606 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
3610 /* multicast groups */
3611 static struct genl_multicast_group nl80211_config_mcgrp
= {
3614 static struct genl_multicast_group nl80211_scan_mcgrp
= {
3617 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
3618 .name
= "regulatory",
3621 /* notification functions */
3623 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
3625 struct sk_buff
*msg
;
3627 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3631 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
3636 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
3639 static int nl80211_add_scan_req(struct sk_buff
*msg
,
3640 struct cfg80211_registered_device
*rdev
)
3642 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
3643 struct nlattr
*nest
;
3649 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
3651 goto nla_put_failure
;
3652 for (i
= 0; i
< req
->n_ssids
; i
++)
3653 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
3654 nla_nest_end(msg
, nest
);
3656 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
3658 goto nla_put_failure
;
3659 for (i
= 0; i
< req
->n_channels
; i
++)
3660 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
3661 nla_nest_end(msg
, nest
);
3664 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
3671 static int nl80211_send_scan_donemsg(struct sk_buff
*msg
,
3672 struct cfg80211_registered_device
*rdev
,
3673 struct net_device
*netdev
,
3674 u32 pid
, u32 seq
, int flags
,
3679 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
3683 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3684 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3686 /* ignore errors and send incomplete event anyway */
3687 nl80211_add_scan_req(msg
, rdev
);
3689 return genlmsg_end(msg
, hdr
);
3692 genlmsg_cancel(msg
, hdr
);
3696 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
3697 struct net_device
*netdev
)
3699 struct sk_buff
*msg
;
3701 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3705 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3706 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
3711 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3714 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
3715 struct net_device
*netdev
)
3717 struct sk_buff
*msg
;
3719 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3723 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3724 NL80211_CMD_SCAN_ABORTED
) < 0) {
3729 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3733 * This can happen on global regulatory changes or device specific settings
3734 * based on custom world regulatory domains.
3736 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
3738 struct sk_buff
*msg
;
3741 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3745 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
3751 /* Userspace can always count this one always being set */
3752 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
3754 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
3755 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3756 NL80211_REGDOM_TYPE_WORLD
);
3757 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
3758 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3759 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
3760 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
3762 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3763 NL80211_REGDOM_TYPE_INTERSECTION
);
3765 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3766 NL80211_REGDOM_TYPE_COUNTRY
);
3767 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
3770 if (wiphy_idx_valid(request
->wiphy_idx
))
3771 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
3773 if (genlmsg_end(msg
, hdr
) < 0) {
3778 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
3783 genlmsg_cancel(msg
, hdr
);
3787 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
3788 struct net_device
*netdev
,
3789 const u8
*buf
, size_t len
,
3790 enum nl80211_commands cmd
)
3792 struct sk_buff
*msg
;
3795 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3799 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3805 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3806 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3807 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
3809 if (genlmsg_end(msg
, hdr
) < 0) {
3814 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3818 genlmsg_cancel(msg
, hdr
);
3822 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
3823 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3825 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3826 NL80211_CMD_AUTHENTICATE
);
3829 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
3830 struct net_device
*netdev
, const u8
*buf
,
3833 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
, NL80211_CMD_ASSOCIATE
);
3836 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
3837 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3839 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3840 NL80211_CMD_DEAUTHENTICATE
);
3843 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
3844 struct net_device
*netdev
, const u8
*buf
,
3847 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3848 NL80211_CMD_DISASSOCIATE
);
3851 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
3852 struct net_device
*netdev
, int cmd
,
3855 struct sk_buff
*msg
;
3858 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3862 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3868 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3869 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3870 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
3871 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3873 if (genlmsg_end(msg
, hdr
) < 0) {
3878 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3882 genlmsg_cancel(msg
, hdr
);
3886 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
3887 struct net_device
*netdev
, const u8
*addr
)
3889 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
3893 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
3894 struct net_device
*netdev
, const u8
*addr
)
3896 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
, addr
);
3899 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
3900 struct net_device
*netdev
, const u8
*bssid
,
3903 struct sk_buff
*msg
;
3906 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
3910 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
3916 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3917 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3918 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
3920 if (genlmsg_end(msg
, hdr
) < 0) {
3925 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
3929 genlmsg_cancel(msg
, hdr
);
3933 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
3934 struct net_device
*netdev
, const u8
*addr
,
3935 enum nl80211_key_type key_type
, int key_id
,
3938 struct sk_buff
*msg
;
3941 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3945 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
3951 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3952 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3954 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3955 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
3956 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
3958 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
3960 if (genlmsg_end(msg
, hdr
) < 0) {
3965 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3969 genlmsg_cancel(msg
, hdr
);
3973 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
3974 struct ieee80211_channel
*channel_before
,
3975 struct ieee80211_channel
*channel_after
)
3977 struct sk_buff
*msg
;
3979 struct nlattr
*nl_freq
;
3981 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3985 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
3992 * Since we are applying the beacon hint to a wiphy we know its
3993 * wiphy_idx is valid
3995 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
3998 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
4000 goto nla_put_failure
;
4001 if (nl80211_msg_put_channel(msg
, channel_before
))
4002 goto nla_put_failure
;
4003 nla_nest_end(msg
, nl_freq
);
4006 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
4008 goto nla_put_failure
;
4009 if (nl80211_msg_put_channel(msg
, channel_after
))
4010 goto nla_put_failure
;
4011 nla_nest_end(msg
, nl_freq
);
4013 if (genlmsg_end(msg
, hdr
) < 0) {
4018 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_ATOMIC
);
4023 genlmsg_cancel(msg
, hdr
);
4027 /* initialisation/exit functions */
4029 int nl80211_init(void)
4033 err
= genl_register_family_with_ops(&nl80211_fam
,
4034 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
4038 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
4042 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
4046 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
4050 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
4056 genl_unregister_family(&nl80211_fam
);
4060 void nl80211_exit(void)
4062 genl_unregister_family(&nl80211_fam
);