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
,
60 .len
= BUS_ID_SIZE
-1 },
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 result
= PTR_ERR(rdev
);
454 mutex_lock(&rdev
->mtx
);
456 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
457 result
= cfg80211_dev_rename(
458 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
460 mutex_unlock(&cfg80211_mutex
);
465 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
466 struct ieee80211_txq_params txq_params
;
467 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
469 if (!rdev
->ops
->set_txq_params
) {
470 result
= -EOPNOTSUPP
;
474 nla_for_each_nested(nl_txq_params
,
475 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
477 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
478 nla_data(nl_txq_params
),
479 nla_len(nl_txq_params
),
481 result
= parse_txq_params(tb
, &txq_params
);
485 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
492 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
493 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
494 struct ieee80211_channel
*chan
;
495 struct ieee80211_sta_ht_cap
*ht_cap
;
498 if (!rdev
->ops
->set_channel
) {
499 result
= -EOPNOTSUPP
;
505 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
506 channel_type
= nla_get_u32(info
->attrs
[
507 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
508 if (channel_type
!= NL80211_CHAN_NO_HT
&&
509 channel_type
!= NL80211_CHAN_HT20
&&
510 channel_type
!= NL80211_CHAN_HT40PLUS
&&
511 channel_type
!= NL80211_CHAN_HT40MINUS
)
515 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
516 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
518 /* Primary channel not allowed */
519 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
522 if (channel_type
== NL80211_CHAN_HT40MINUS
&&
523 (chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
))
525 else if (channel_type
== NL80211_CHAN_HT40PLUS
&&
526 (chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
))
530 * At this point we know if that if HT40 was requested
531 * we are allowed to use it and the extension channel
535 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
537 /* no HT capabilities or intolerant */
538 if (channel_type
!= NL80211_CHAN_NO_HT
) {
539 if (!ht_cap
->ht_supported
)
541 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
542 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
546 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
554 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
555 retry_short
= nla_get_u8(
556 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
557 if (retry_short
== 0) {
561 changed
|= WIPHY_PARAM_RETRY_SHORT
;
564 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
565 retry_long
= nla_get_u8(
566 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
567 if (retry_long
== 0) {
571 changed
|= WIPHY_PARAM_RETRY_LONG
;
574 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
575 frag_threshold
= nla_get_u32(
576 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
577 if (frag_threshold
< 256) {
581 if (frag_threshold
!= (u32
) -1) {
583 * Fragments (apart from the last one) are required to
584 * have even length. Make the fragmentation code
585 * simpler by stripping LSB should someone try to use
586 * odd threshold value.
588 frag_threshold
&= ~0x1;
590 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
593 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
594 rts_threshold
= nla_get_u32(
595 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
596 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
600 u8 old_retry_short
, old_retry_long
;
601 u32 old_frag_threshold
, old_rts_threshold
;
603 if (!rdev
->ops
->set_wiphy_params
) {
604 result
= -EOPNOTSUPP
;
608 old_retry_short
= rdev
->wiphy
.retry_short
;
609 old_retry_long
= rdev
->wiphy
.retry_long
;
610 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
611 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
613 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
614 rdev
->wiphy
.retry_short
= retry_short
;
615 if (changed
& WIPHY_PARAM_RETRY_LONG
)
616 rdev
->wiphy
.retry_long
= retry_long
;
617 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
618 rdev
->wiphy
.frag_threshold
= frag_threshold
;
619 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
620 rdev
->wiphy
.rts_threshold
= rts_threshold
;
622 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
624 rdev
->wiphy
.retry_short
= old_retry_short
;
625 rdev
->wiphy
.retry_long
= old_retry_long
;
626 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
627 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
632 mutex_unlock(&rdev
->mtx
);
639 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
640 struct cfg80211_registered_device
*rdev
,
641 struct net_device
*dev
)
645 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
649 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
650 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
651 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
652 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
653 return genlmsg_end(msg
, hdr
);
656 genlmsg_cancel(msg
, hdr
);
660 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
664 int wp_start
= cb
->args
[0];
665 int if_start
= cb
->args
[1];
666 struct cfg80211_registered_device
*dev
;
667 struct wireless_dev
*wdev
;
669 mutex_lock(&cfg80211_mutex
);
670 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
671 if (wp_idx
< wp_start
) {
677 mutex_lock(&dev
->devlist_mtx
);
678 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
679 if (if_idx
< if_start
) {
683 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
684 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
685 dev
, wdev
->netdev
) < 0) {
686 mutex_unlock(&dev
->devlist_mtx
);
691 mutex_unlock(&dev
->devlist_mtx
);
696 mutex_unlock(&cfg80211_mutex
);
698 cb
->args
[0] = wp_idx
;
699 cb
->args
[1] = if_idx
;
704 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
707 struct cfg80211_registered_device
*dev
;
708 struct net_device
*netdev
;
711 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &dev
, &netdev
);
715 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
719 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
724 cfg80211_put_dev(dev
);
726 return genlmsg_unicast(msg
, info
->snd_pid
);
732 cfg80211_put_dev(dev
);
736 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
737 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
738 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
739 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
740 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
741 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
744 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
746 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
754 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
755 nla
, mntr_flags_policy
))
758 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
760 *mntrflags
|= (1<<flag
);
765 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
767 struct cfg80211_registered_device
*drv
;
768 struct vif_params params
;
770 enum nl80211_iftype otype
, ntype
;
771 struct net_device
*dev
;
772 u32 _flags
, *flags
= NULL
;
775 memset(¶ms
, 0, sizeof(params
));
779 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
783 ifindex
= dev
->ifindex
;
784 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
787 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
788 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
791 if (ntype
> NL80211_IFTYPE_MAX
) {
797 if (!drv
->ops
->change_virtual_intf
||
798 !(drv
->wiphy
.interface_modes
& (1 << ntype
))) {
803 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
804 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
808 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
809 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
813 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
814 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
818 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
828 err
= drv
->ops
->change_virtual_intf(&drv
->wiphy
, ifindex
,
829 ntype
, flags
, ¶ms
);
833 dev
= __dev_get_by_index(&init_net
, ifindex
);
834 WARN_ON(!dev
|| (!err
&& dev
->ieee80211_ptr
->iftype
!= ntype
));
836 if (dev
&& !err
&& (ntype
!= otype
)) {
837 if (otype
== NL80211_IFTYPE_ADHOC
)
838 cfg80211_clear_ibss(dev
, false);
842 cfg80211_put_dev(drv
);
848 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
850 struct cfg80211_registered_device
*drv
;
851 struct vif_params params
;
853 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
856 memset(¶ms
, 0, sizeof(params
));
858 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
861 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
862 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
863 if (type
> NL80211_IFTYPE_MAX
)
869 drv
= cfg80211_get_dev_from_info(info
);
875 if (!drv
->ops
->add_virtual_intf
||
876 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
881 if (type
== NL80211_IFTYPE_MESH_POINT
&&
882 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
883 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
884 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
887 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
888 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
890 err
= drv
->ops
->add_virtual_intf(&drv
->wiphy
,
891 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
892 type
, err
? NULL
: &flags
, ¶ms
);
895 cfg80211_put_dev(drv
);
901 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
903 struct cfg80211_registered_device
*drv
;
905 struct net_device
*dev
;
909 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
912 ifindex
= dev
->ifindex
;
915 if (!drv
->ops
->del_virtual_intf
) {
920 err
= drv
->ops
->del_virtual_intf(&drv
->wiphy
, ifindex
);
923 cfg80211_put_dev(drv
);
929 struct get_key_cookie
{
934 static void get_key_callback(void *c
, struct key_params
*params
)
936 struct get_key_cookie
*cookie
= c
;
939 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
940 params
->key_len
, params
->key
);
943 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
944 params
->seq_len
, params
->seq
);
947 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
955 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
957 struct cfg80211_registered_device
*drv
;
959 struct net_device
*dev
;
962 struct get_key_cookie cookie
= {
968 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
969 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
974 if (info
->attrs
[NL80211_ATTR_MAC
])
975 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
979 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
983 if (!drv
->ops
->get_key
) {
988 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
994 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
995 NL80211_CMD_NEW_KEY
);
1004 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1005 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1007 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1009 err
= drv
->ops
->get_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
,
1010 &cookie
, get_key_callback
);
1016 goto nla_put_failure
;
1018 genlmsg_end(msg
, hdr
);
1019 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1026 cfg80211_put_dev(drv
);
1034 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1036 struct cfg80211_registered_device
*drv
;
1038 struct net_device
*dev
;
1040 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1043 if (!info
->attrs
[NL80211_ATTR_KEY_IDX
])
1046 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1048 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
]) {
1049 if (key_idx
< 4 || key_idx
> 5)
1051 } else if (key_idx
> 3)
1054 /* currently only support setting default key */
1055 if (!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
] &&
1056 !info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
])
1061 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1065 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT
])
1066 func
= drv
->ops
->set_default_key
;
1068 func
= drv
->ops
->set_default_mgmt_key
;
1075 err
= func(&drv
->wiphy
, dev
, key_idx
);
1076 #ifdef CONFIG_WIRELESS_EXT
1078 if (func
== drv
->ops
->set_default_key
)
1079 dev
->ieee80211_ptr
->wext
.default_key
= key_idx
;
1081 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key_idx
;
1086 cfg80211_put_dev(drv
);
1095 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1097 struct cfg80211_registered_device
*drv
;
1099 struct net_device
*dev
;
1100 struct key_params params
;
1102 u8
*mac_addr
= NULL
;
1104 memset(¶ms
, 0, sizeof(params
));
1106 if (!info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
1109 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
1110 params
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
1111 params
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
1114 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
1115 params
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
1116 params
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
1119 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1120 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1122 params
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
1124 if (info
->attrs
[NL80211_ATTR_MAC
])
1125 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1127 if (cfg80211_validate_key_settings(¶ms
, key_idx
, mac_addr
))
1132 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1136 for (i
= 0; i
< drv
->wiphy
.n_cipher_suites
; i
++)
1137 if (params
.cipher
== drv
->wiphy
.cipher_suites
[i
])
1139 if (i
== drv
->wiphy
.n_cipher_suites
) {
1144 if (!drv
->ops
->add_key
) {
1149 err
= drv
->ops
->add_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
, ¶ms
);
1152 cfg80211_put_dev(drv
);
1160 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1162 struct cfg80211_registered_device
*drv
;
1164 struct net_device
*dev
;
1166 u8
*mac_addr
= NULL
;
1168 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1169 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1174 if (info
->attrs
[NL80211_ATTR_MAC
])
1175 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1179 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1183 if (!drv
->ops
->del_key
) {
1188 err
= drv
->ops
->del_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
);
1190 #ifdef CONFIG_WIRELESS_EXT
1192 if (key_idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1193 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1194 else if (key_idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1195 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1200 cfg80211_put_dev(drv
);
1209 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1211 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1212 struct beacon_parameters
*info
);
1213 struct cfg80211_registered_device
*drv
;
1215 struct net_device
*dev
;
1216 struct beacon_parameters params
;
1219 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1224 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1228 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1233 switch (info
->genlhdr
->cmd
) {
1234 case NL80211_CMD_NEW_BEACON
:
1235 /* these are required for NEW_BEACON */
1236 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1237 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1238 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1243 call
= drv
->ops
->add_beacon
;
1245 case NL80211_CMD_SET_BEACON
:
1246 call
= drv
->ops
->set_beacon
;
1259 memset(¶ms
, 0, sizeof(params
));
1261 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1263 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1267 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1268 params
.dtim_period
=
1269 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1273 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1274 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1276 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1280 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1281 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1283 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1292 err
= call(&drv
->wiphy
, dev
, ¶ms
);
1295 cfg80211_put_dev(drv
);
1303 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1305 struct cfg80211_registered_device
*drv
;
1307 struct net_device
*dev
;
1311 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1315 if (!drv
->ops
->del_beacon
) {
1320 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1324 err
= drv
->ops
->del_beacon(&drv
->wiphy
, dev
);
1327 cfg80211_put_dev(drv
);
1335 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1336 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1337 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1338 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1339 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1342 static int parse_station_flags(struct genl_info
*info
,
1343 struct station_parameters
*params
)
1345 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1350 * Try parsing the new attribute first so userspace
1351 * can specify both for older kernels.
1353 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1355 struct nl80211_sta_flag_update
*sta_flags
;
1357 sta_flags
= nla_data(nla
);
1358 params
->sta_flags_mask
= sta_flags
->mask
;
1359 params
->sta_flags_set
= sta_flags
->set
;
1360 if ((params
->sta_flags_mask
|
1361 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1366 /* if present, parse the old attribute */
1368 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1372 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1373 nla
, sta_flags_policy
))
1376 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1377 params
->sta_flags_mask
&= ~1;
1379 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1381 params
->sta_flags_set
|= (1<<flag
);
1386 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1388 int modulation
, streams
, bitrate
;
1390 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1391 return rate
->legacy
;
1393 /* the formula below does only work for MCS values smaller than 32 */
1394 if (rate
->mcs
>= 32)
1397 modulation
= rate
->mcs
& 7;
1398 streams
= (rate
->mcs
>> 3) + 1;
1400 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1404 bitrate
*= (modulation
+ 1);
1405 else if (modulation
== 4)
1406 bitrate
*= (modulation
+ 2);
1408 bitrate
*= (modulation
+ 3);
1412 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1413 bitrate
= (bitrate
/ 9) * 10;
1415 /* do NOT round down here */
1416 return (bitrate
+ 50000) / 100000;
1419 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1420 int flags
, struct net_device
*dev
,
1421 u8
*mac_addr
, struct station_info
*sinfo
)
1424 struct nlattr
*sinfoattr
, *txrate
;
1427 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1431 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1432 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1434 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1436 goto nla_put_failure
;
1437 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1438 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1439 sinfo
->inactive_time
);
1440 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1441 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1443 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1444 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1446 if (sinfo
->filled
& STATION_INFO_LLID
)
1447 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1449 if (sinfo
->filled
& STATION_INFO_PLID
)
1450 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1452 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1453 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1454 sinfo
->plink_state
);
1455 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1456 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1458 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1459 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1461 goto nla_put_failure
;
1463 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1464 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1466 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1468 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1469 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1471 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1472 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1473 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1474 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1476 nla_nest_end(msg
, txrate
);
1478 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1479 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1481 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1482 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1484 nla_nest_end(msg
, sinfoattr
);
1486 return genlmsg_end(msg
, hdr
);
1489 genlmsg_cancel(msg
, hdr
);
1493 static int nl80211_dump_station(struct sk_buff
*skb
,
1494 struct netlink_callback
*cb
)
1496 struct station_info sinfo
;
1497 struct cfg80211_registered_device
*dev
;
1498 struct net_device
*netdev
;
1499 u8 mac_addr
[ETH_ALEN
];
1500 int ifidx
= cb
->args
[0];
1501 int sta_idx
= cb
->args
[1];
1505 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1506 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1511 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1514 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1521 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1527 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1533 if (!dev
->ops
->dump_station
) {
1539 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1546 if (nl80211_send_station(skb
,
1547 NETLINK_CB(cb
->skb
).pid
,
1548 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1558 cb
->args
[1] = sta_idx
;
1561 cfg80211_put_dev(dev
);
1568 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1570 struct cfg80211_registered_device
*drv
;
1572 struct net_device
*dev
;
1573 struct station_info sinfo
;
1574 struct sk_buff
*msg
;
1575 u8
*mac_addr
= NULL
;
1577 memset(&sinfo
, 0, sizeof(sinfo
));
1579 if (!info
->attrs
[NL80211_ATTR_MAC
])
1582 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1586 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1590 if (!drv
->ops
->get_station
) {
1595 err
= drv
->ops
->get_station(&drv
->wiphy
, dev
, mac_addr
, &sinfo
);
1599 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1603 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1604 dev
, mac_addr
, &sinfo
) < 0)
1607 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1613 cfg80211_put_dev(drv
);
1622 * Get vlan interface making sure it is on the right wiphy.
1624 static int get_vlan(struct nlattr
*vlanattr
,
1625 struct cfg80211_registered_device
*rdev
,
1626 struct net_device
**vlan
)
1631 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1634 if (!(*vlan
)->ieee80211_ptr
)
1636 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1642 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1644 struct cfg80211_registered_device
*drv
;
1646 struct net_device
*dev
;
1647 struct station_parameters params
;
1648 u8
*mac_addr
= NULL
;
1650 memset(¶ms
, 0, sizeof(params
));
1652 params
.listen_interval
= -1;
1654 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1657 if (!info
->attrs
[NL80211_ATTR_MAC
])
1660 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1662 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1663 params
.supported_rates
=
1664 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1665 params
.supported_rates_len
=
1666 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1669 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1670 params
.listen_interval
=
1671 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1673 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1675 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1677 if (parse_station_flags(info
, ¶ms
))
1680 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1681 params
.plink_action
=
1682 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1686 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1690 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1694 if (!drv
->ops
->change_station
) {
1699 err
= drv
->ops
->change_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1703 dev_put(params
.vlan
);
1704 cfg80211_put_dev(drv
);
1712 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1714 struct cfg80211_registered_device
*drv
;
1716 struct net_device
*dev
;
1717 struct station_parameters params
;
1718 u8
*mac_addr
= NULL
;
1720 memset(¶ms
, 0, sizeof(params
));
1722 if (!info
->attrs
[NL80211_ATTR_MAC
])
1725 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
1728 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1731 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1734 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1735 params
.supported_rates
=
1736 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1737 params
.supported_rates_len
=
1738 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1739 params
.listen_interval
=
1740 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1741 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1742 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1744 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1746 if (parse_station_flags(info
, ¶ms
))
1751 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1755 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1756 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
1761 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1765 if (!drv
->ops
->add_station
) {
1770 if (!netif_running(dev
)) {
1775 err
= drv
->ops
->add_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1779 dev_put(params
.vlan
);
1780 cfg80211_put_dev(drv
);
1788 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
1790 struct cfg80211_registered_device
*drv
;
1792 struct net_device
*dev
;
1793 u8
*mac_addr
= NULL
;
1795 if (info
->attrs
[NL80211_ATTR_MAC
])
1796 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1800 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1804 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1805 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
1810 if (!drv
->ops
->del_station
) {
1815 err
= drv
->ops
->del_station(&drv
->wiphy
, dev
, mac_addr
);
1818 cfg80211_put_dev(drv
);
1826 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1827 int flags
, struct net_device
*dev
,
1828 u8
*dst
, u8
*next_hop
,
1829 struct mpath_info
*pinfo
)
1832 struct nlattr
*pinfoattr
;
1834 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1838 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1839 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
1840 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
1842 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
1844 goto nla_put_failure
;
1845 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
1846 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
1848 if (pinfo
->filled
& MPATH_INFO_DSN
)
1849 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
1851 if (pinfo
->filled
& MPATH_INFO_METRIC
)
1852 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
1854 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
1855 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
1857 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
1858 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
1860 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
1861 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
1862 pinfo
->discovery_timeout
);
1863 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
1864 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
1865 pinfo
->discovery_retries
);
1867 nla_nest_end(msg
, pinfoattr
);
1869 return genlmsg_end(msg
, hdr
);
1872 genlmsg_cancel(msg
, hdr
);
1876 static int nl80211_dump_mpath(struct sk_buff
*skb
,
1877 struct netlink_callback
*cb
)
1879 struct mpath_info pinfo
;
1880 struct cfg80211_registered_device
*dev
;
1881 struct net_device
*netdev
;
1883 u8 next_hop
[ETH_ALEN
];
1884 int ifidx
= cb
->args
[0];
1885 int path_idx
= cb
->args
[1];
1889 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1890 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1895 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1898 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1905 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1911 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1917 if (!dev
->ops
->dump_mpath
) {
1922 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1928 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
1929 dst
, next_hop
, &pinfo
);
1935 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
1936 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1937 netdev
, dst
, next_hop
,
1946 cb
->args
[1] = path_idx
;
1949 cfg80211_put_dev(dev
);
1956 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1958 struct cfg80211_registered_device
*drv
;
1960 struct net_device
*dev
;
1961 struct mpath_info pinfo
;
1962 struct sk_buff
*msg
;
1964 u8 next_hop
[ETH_ALEN
];
1966 memset(&pinfo
, 0, sizeof(pinfo
));
1968 if (!info
->attrs
[NL80211_ATTR_MAC
])
1971 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1975 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1979 if (!drv
->ops
->get_mpath
) {
1984 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1989 err
= drv
->ops
->get_mpath(&drv
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
1993 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1997 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1998 dev
, dst
, next_hop
, &pinfo
) < 0)
2001 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2007 cfg80211_put_dev(drv
);
2015 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2017 struct cfg80211_registered_device
*drv
;
2019 struct net_device
*dev
;
2021 u8
*next_hop
= NULL
;
2023 if (!info
->attrs
[NL80211_ATTR_MAC
])
2026 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2029 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2030 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2034 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2038 if (!drv
->ops
->change_mpath
) {
2043 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2048 if (!netif_running(dev
)) {
2053 err
= drv
->ops
->change_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
2056 cfg80211_put_dev(drv
);
2063 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2065 struct cfg80211_registered_device
*drv
;
2067 struct net_device
*dev
;
2069 u8
*next_hop
= NULL
;
2071 if (!info
->attrs
[NL80211_ATTR_MAC
])
2074 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2077 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2078 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2082 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2086 if (!drv
->ops
->add_mpath
) {
2091 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2096 if (!netif_running(dev
)) {
2101 err
= drv
->ops
->add_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
2104 cfg80211_put_dev(drv
);
2112 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2114 struct cfg80211_registered_device
*drv
;
2116 struct net_device
*dev
;
2119 if (info
->attrs
[NL80211_ATTR_MAC
])
2120 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2124 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2128 if (!drv
->ops
->del_mpath
) {
2133 err
= drv
->ops
->del_mpath(&drv
->wiphy
, dev
, dst
);
2136 cfg80211_put_dev(drv
);
2144 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2146 struct cfg80211_registered_device
*drv
;
2148 struct net_device
*dev
;
2149 struct bss_parameters params
;
2151 memset(¶ms
, 0, sizeof(params
));
2152 /* default to not changing parameters */
2153 params
.use_cts_prot
= -1;
2154 params
.use_short_preamble
= -1;
2155 params
.use_short_slot_time
= -1;
2157 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2158 params
.use_cts_prot
=
2159 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2160 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2161 params
.use_short_preamble
=
2162 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2163 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2164 params
.use_short_slot_time
=
2165 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2166 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2167 params
.basic_rates
=
2168 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2169 params
.basic_rates_len
=
2170 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2175 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2179 if (!drv
->ops
->change_bss
) {
2184 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2189 err
= drv
->ops
->change_bss(&drv
->wiphy
, dev
, ¶ms
);
2192 cfg80211_put_dev(drv
);
2200 static const struct nla_policy
2201 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2202 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2203 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2204 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2205 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2206 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2207 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2210 static int parse_reg_rule(struct nlattr
*tb
[],
2211 struct ieee80211_reg_rule
*reg_rule
)
2213 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2214 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2216 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2218 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2220 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2222 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2224 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2227 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2229 freq_range
->start_freq_khz
=
2230 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2231 freq_range
->end_freq_khz
=
2232 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2233 freq_range
->max_bandwidth_khz
=
2234 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2236 power_rule
->max_eirp
=
2237 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2239 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2240 power_rule
->max_antenna_gain
=
2241 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2246 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2252 * You should only get this when cfg80211 hasn't yet initialized
2253 * completely when built-in to the kernel right between the time
2254 * window between nl80211_init() and regulatory_init(), if that is
2257 mutex_lock(&cfg80211_mutex
);
2258 if (unlikely(!cfg80211_regdomain
)) {
2259 mutex_unlock(&cfg80211_mutex
);
2260 return -EINPROGRESS
;
2262 mutex_unlock(&cfg80211_mutex
);
2264 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2267 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2269 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2270 /* We ignore world regdom requests with the old regdom setup */
2271 if (is_world_regdom(data
))
2275 r
= regulatory_hint_user(data
);
2280 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2281 struct genl_info
*info
)
2283 struct cfg80211_registered_device
*drv
;
2284 struct mesh_config cur_params
;
2286 struct net_device
*dev
;
2288 struct nlattr
*pinfoattr
;
2289 struct sk_buff
*msg
;
2293 /* Look up our device */
2294 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2298 if (!drv
->ops
->get_mesh_params
) {
2303 /* Get the mesh params */
2304 err
= drv
->ops
->get_mesh_params(&drv
->wiphy
, dev
, &cur_params
);
2308 /* Draw up a netlink message to send back */
2309 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2314 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2315 NL80211_CMD_GET_MESH_PARAMS
);
2317 goto nla_put_failure
;
2318 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2320 goto nla_put_failure
;
2321 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2322 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2323 cur_params
.dot11MeshRetryTimeout
);
2324 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2325 cur_params
.dot11MeshConfirmTimeout
);
2326 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2327 cur_params
.dot11MeshHoldingTimeout
);
2328 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2329 cur_params
.dot11MeshMaxPeerLinks
);
2330 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2331 cur_params
.dot11MeshMaxRetries
);
2332 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2333 cur_params
.dot11MeshTTL
);
2334 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2335 cur_params
.auto_open_plinks
);
2336 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2337 cur_params
.dot11MeshHWMPmaxPREQretries
);
2338 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2339 cur_params
.path_refresh_time
);
2340 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2341 cur_params
.min_discovery_timeout
);
2342 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2343 cur_params
.dot11MeshHWMPactivePathTimeout
);
2344 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2345 cur_params
.dot11MeshHWMPpreqMinInterval
);
2346 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2347 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2348 nla_nest_end(msg
, pinfoattr
);
2349 genlmsg_end(msg
, hdr
);
2350 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2354 genlmsg_cancel(msg
, hdr
);
2358 cfg80211_put_dev(drv
);
2366 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2368 if (table[attr_num]) {\
2369 cfg.param = nla_fn(table[attr_num]); \
2370 mask |= (1 << (attr_num - 1)); \
2374 static struct nla_policy
2375 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2376 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2377 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2378 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2379 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2380 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2381 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2382 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2384 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2385 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2386 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2387 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2388 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2389 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2392 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2396 struct cfg80211_registered_device
*drv
;
2397 struct net_device
*dev
;
2398 struct mesh_config cfg
;
2399 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2400 struct nlattr
*parent_attr
;
2402 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2405 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2406 parent_attr
, nl80211_meshconf_params_policy
))
2411 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2415 if (!drv
->ops
->set_mesh_params
) {
2420 /* This makes sure that there aren't more than 32 mesh config
2421 * parameters (otherwise our bitfield scheme would not work.) */
2422 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2424 /* Fill in the params struct */
2426 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2427 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2428 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2429 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2430 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2431 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2432 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2433 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2434 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2435 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2436 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2437 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2438 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2439 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2440 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2441 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2443 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2444 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2445 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2446 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2448 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2449 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2451 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2452 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2454 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2455 dot11MeshHWMPnetDiameterTraversalTime
,
2456 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2460 err
= drv
->ops
->set_mesh_params(&drv
->wiphy
, dev
, &cfg
, mask
);
2464 cfg80211_put_dev(drv
);
2472 #undef FILL_IN_MESH_PARAM_IF_SET
2474 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2476 struct sk_buff
*msg
;
2478 struct nlattr
*nl_reg_rules
;
2482 mutex_lock(&cfg80211_mutex
);
2484 if (!cfg80211_regdomain
)
2487 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2493 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2494 NL80211_CMD_GET_REG
);
2496 goto nla_put_failure
;
2498 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2499 cfg80211_regdomain
->alpha2
);
2501 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2503 goto nla_put_failure
;
2505 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2506 struct nlattr
*nl_reg_rule
;
2507 const struct ieee80211_reg_rule
*reg_rule
;
2508 const struct ieee80211_freq_range
*freq_range
;
2509 const struct ieee80211_power_rule
*power_rule
;
2511 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2512 freq_range
= ®_rule
->freq_range
;
2513 power_rule
= ®_rule
->power_rule
;
2515 nl_reg_rule
= nla_nest_start(msg
, i
);
2517 goto nla_put_failure
;
2519 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2521 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2522 freq_range
->start_freq_khz
);
2523 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2524 freq_range
->end_freq_khz
);
2525 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2526 freq_range
->max_bandwidth_khz
);
2527 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2528 power_rule
->max_antenna_gain
);
2529 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2530 power_rule
->max_eirp
);
2532 nla_nest_end(msg
, nl_reg_rule
);
2535 nla_nest_end(msg
, nl_reg_rules
);
2537 genlmsg_end(msg
, hdr
);
2538 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2542 genlmsg_cancel(msg
, hdr
);
2545 mutex_unlock(&cfg80211_mutex
);
2549 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2551 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2552 struct nlattr
*nl_reg_rule
;
2553 char *alpha2
= NULL
;
2554 int rem_reg_rules
= 0, r
= 0;
2555 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2556 struct ieee80211_regdomain
*rd
= NULL
;
2558 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2561 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2564 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2566 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2569 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2573 if (!reg_is_valid_request(alpha2
))
2576 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2577 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2579 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2583 rd
->n_reg_rules
= num_rules
;
2584 rd
->alpha2
[0] = alpha2
[0];
2585 rd
->alpha2
[1] = alpha2
[1];
2587 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2589 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2590 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2592 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2598 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
)
2602 BUG_ON(rule_idx
!= num_rules
);
2604 mutex_lock(&cfg80211_mutex
);
2606 mutex_unlock(&cfg80211_mutex
);
2614 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2616 struct cfg80211_registered_device
*drv
;
2617 struct net_device
*dev
;
2618 struct cfg80211_scan_request
*request
;
2619 struct cfg80211_ssid
*ssid
;
2620 struct ieee80211_channel
*channel
;
2621 struct nlattr
*attr
;
2622 struct wiphy
*wiphy
;
2623 int err
, tmp
, n_ssids
= 0, n_channels
= 0, i
;
2624 enum ieee80211_band band
;
2627 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2632 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2636 wiphy
= &drv
->wiphy
;
2638 if (!drv
->ops
->scan
) {
2643 if (!netif_running(dev
)) {
2648 if (drv
->scan_req
) {
2653 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2654 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
)
2661 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2662 if (wiphy
->bands
[band
])
2663 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2666 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2667 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2670 if (n_ssids
> wiphy
->max_scan_ssids
) {
2675 if (info
->attrs
[NL80211_ATTR_IE
])
2676 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2680 if (ie_len
> wiphy
->max_scan_ie_len
) {
2685 request
= kzalloc(sizeof(*request
)
2686 + sizeof(*ssid
) * n_ssids
2687 + sizeof(channel
) * n_channels
2688 + ie_len
, GFP_KERNEL
);
2694 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
2695 request
->n_channels
= n_channels
;
2697 request
->ssids
= (void *)(request
->channels
+ n_channels
);
2698 request
->n_ssids
= n_ssids
;
2701 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
2703 request
->ie
= (void *)(request
->channels
+ n_channels
);
2706 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2707 /* user specified, bail out if channel not found */
2708 request
->n_channels
= n_channels
;
2710 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
2711 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
2712 if (!request
->channels
[i
]) {
2721 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2723 if (!wiphy
->bands
[band
])
2725 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2726 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2733 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
2734 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
2735 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2739 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
2740 request
->ssids
[i
].ssid_len
= nla_len(attr
);
2745 if (info
->attrs
[NL80211_ATTR_IE
]) {
2746 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2747 memcpy((void *)request
->ie
,
2748 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
2752 request
->ifidx
= dev
->ifindex
;
2753 request
->wiphy
= &drv
->wiphy
;
2755 drv
->scan_req
= request
;
2756 err
= drv
->ops
->scan(&drv
->wiphy
, dev
, request
);
2760 drv
->scan_req
= NULL
;
2764 cfg80211_put_dev(drv
);
2772 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
2773 struct cfg80211_registered_device
*rdev
,
2774 struct net_device
*dev
,
2775 struct cfg80211_bss
*res
)
2780 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
2781 NL80211_CMD_NEW_SCAN_RESULTS
);
2785 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
2786 rdev
->bss_generation
);
2787 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2789 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
2791 goto nla_put_failure
;
2792 if (!is_zero_ether_addr(res
->bssid
))
2793 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
2794 if (res
->information_elements
&& res
->len_information_elements
)
2795 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
2796 res
->len_information_elements
,
2797 res
->information_elements
);
2799 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
2800 if (res
->beacon_interval
)
2801 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
2802 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
2803 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
2805 switch (rdev
->wiphy
.signal_type
) {
2806 case CFG80211_SIGNAL_TYPE_MBM
:
2807 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
2809 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2810 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
2816 nla_nest_end(msg
, bss
);
2818 return genlmsg_end(msg
, hdr
);
2821 genlmsg_cancel(msg
, hdr
);
2825 static int nl80211_dump_scan(struct sk_buff
*skb
,
2826 struct netlink_callback
*cb
)
2828 struct cfg80211_registered_device
*dev
;
2829 struct net_device
*netdev
;
2830 struct cfg80211_internal_bss
*scan
;
2831 int ifidx
= cb
->args
[0];
2832 int start
= cb
->args
[1], idx
= 0;
2836 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2837 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2842 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2845 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2848 cb
->args
[0] = ifidx
;
2851 netdev
= dev_get_by_index(&init_net
, ifidx
);
2855 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2858 goto out_put_netdev
;
2861 spin_lock_bh(&dev
->bss_lock
);
2862 cfg80211_bss_expire(dev
);
2864 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
2867 if (nl80211_send_bss(skb
,
2868 NETLINK_CB(cb
->skb
).pid
,
2869 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2870 dev
, netdev
, &scan
->pub
) < 0) {
2877 spin_unlock_bh(&dev
->bss_lock
);
2881 cfg80211_put_dev(dev
);
2888 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
2890 return auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
||
2891 auth_type
== NL80211_AUTHTYPE_SHARED_KEY
||
2892 auth_type
== NL80211_AUTHTYPE_FT
||
2893 auth_type
== NL80211_AUTHTYPE_NETWORK_EAP
;
2896 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2898 struct cfg80211_registered_device
*drv
;
2899 struct net_device
*dev
;
2900 struct cfg80211_auth_request req
;
2901 struct wiphy
*wiphy
;
2904 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2907 if (!info
->attrs
[NL80211_ATTR_MAC
])
2910 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
2915 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2919 if (!drv
->ops
->auth
) {
2924 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2929 if (!netif_running(dev
)) {
2934 wiphy
= &drv
->wiphy
;
2935 memset(&req
, 0, sizeof(req
));
2937 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2939 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2940 req
.chan
= ieee80211_get_channel(
2942 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2949 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2950 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2951 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2954 if (info
->attrs
[NL80211_ATTR_IE
]) {
2955 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2956 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2959 req
.auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2960 if (!nl80211_valid_auth_type(req
.auth_type
)) {
2965 err
= drv
->ops
->auth(&drv
->wiphy
, dev
, &req
);
2968 cfg80211_put_dev(drv
);
2975 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
2977 struct cfg80211_registered_device
*drv
;
2978 struct net_device
*dev
;
2979 struct cfg80211_assoc_request req
;
2980 struct wiphy
*wiphy
;
2983 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2986 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
2987 !info
->attrs
[NL80211_ATTR_SSID
])
2992 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2996 if (!drv
->ops
->assoc
) {
3001 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3006 if (!netif_running(dev
)) {
3011 wiphy
= &drv
->wiphy
;
3012 memset(&req
, 0, sizeof(req
));
3014 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3016 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3017 req
.chan
= ieee80211_get_channel(
3019 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3026 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3027 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3029 if (info
->attrs
[NL80211_ATTR_IE
]) {
3030 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3031 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3034 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3035 enum nl80211_mfp use_mfp
=
3036 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3037 if (use_mfp
== NL80211_MFP_REQUIRED
)
3039 else if (use_mfp
!= NL80211_MFP_NO
) {
3045 req
.control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3047 err
= drv
->ops
->assoc(&drv
->wiphy
, dev
, &req
);
3050 cfg80211_put_dev(drv
);
3057 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3059 struct cfg80211_registered_device
*drv
;
3060 struct net_device
*dev
;
3061 struct cfg80211_deauth_request req
;
3062 struct wiphy
*wiphy
;
3065 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3068 if (!info
->attrs
[NL80211_ATTR_MAC
])
3071 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3076 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3080 if (!drv
->ops
->deauth
) {
3085 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3090 if (!netif_running(dev
)) {
3095 wiphy
= &drv
->wiphy
;
3096 memset(&req
, 0, sizeof(req
));
3098 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3100 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3101 if (req
.reason_code
== 0) {
3102 /* Reason Code 0 is reserved */
3107 if (info
->attrs
[NL80211_ATTR_IE
]) {
3108 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3109 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3112 err
= drv
->ops
->deauth(&drv
->wiphy
, dev
, &req
);
3115 cfg80211_put_dev(drv
);
3122 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3124 struct cfg80211_registered_device
*drv
;
3125 struct net_device
*dev
;
3126 struct cfg80211_disassoc_request req
;
3127 struct wiphy
*wiphy
;
3130 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3133 if (!info
->attrs
[NL80211_ATTR_MAC
])
3136 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3141 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3145 if (!drv
->ops
->disassoc
) {
3150 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3155 if (!netif_running(dev
)) {
3160 wiphy
= &drv
->wiphy
;
3161 memset(&req
, 0, sizeof(req
));
3163 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3165 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3166 if (req
.reason_code
== 0) {
3167 /* Reason Code 0 is reserved */
3172 if (info
->attrs
[NL80211_ATTR_IE
]) {
3173 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3174 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3177 err
= drv
->ops
->disassoc(&drv
->wiphy
, dev
, &req
);
3180 cfg80211_put_dev(drv
);
3187 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3189 struct cfg80211_registered_device
*drv
;
3190 struct net_device
*dev
;
3191 struct cfg80211_ibss_params ibss
;
3192 struct wiphy
*wiphy
;
3195 memset(&ibss
, 0, sizeof(ibss
));
3197 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3200 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3201 !info
->attrs
[NL80211_ATTR_SSID
] ||
3202 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3205 ibss
.beacon_interval
= 100;
3207 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3208 ibss
.beacon_interval
=
3209 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3210 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3216 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3220 if (!drv
->ops
->join_ibss
) {
3225 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3230 if (!netif_running(dev
)) {
3235 wiphy
= &drv
->wiphy
;
3237 if (info
->attrs
[NL80211_ATTR_MAC
])
3238 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3239 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3240 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3242 if (info
->attrs
[NL80211_ATTR_IE
]) {
3243 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3244 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3247 ibss
.channel
= ieee80211_get_channel(wiphy
,
3248 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3249 if (!ibss
.channel
||
3250 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3251 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3256 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3258 err
= cfg80211_join_ibss(drv
, dev
, &ibss
);
3261 cfg80211_put_dev(drv
);
3268 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3270 struct cfg80211_registered_device
*drv
;
3271 struct net_device
*dev
;
3276 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3280 if (!drv
->ops
->leave_ibss
) {
3285 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3290 if (!netif_running(dev
)) {
3295 err
= cfg80211_leave_ibss(drv
, dev
, false);
3298 cfg80211_put_dev(drv
);
3305 static struct genl_ops nl80211_ops
[] = {
3307 .cmd
= NL80211_CMD_GET_WIPHY
,
3308 .doit
= nl80211_get_wiphy
,
3309 .dumpit
= nl80211_dump_wiphy
,
3310 .policy
= nl80211_policy
,
3311 /* can be retrieved by unprivileged users */
3314 .cmd
= NL80211_CMD_SET_WIPHY
,
3315 .doit
= nl80211_set_wiphy
,
3316 .policy
= nl80211_policy
,
3317 .flags
= GENL_ADMIN_PERM
,
3320 .cmd
= NL80211_CMD_GET_INTERFACE
,
3321 .doit
= nl80211_get_interface
,
3322 .dumpit
= nl80211_dump_interface
,
3323 .policy
= nl80211_policy
,
3324 /* can be retrieved by unprivileged users */
3327 .cmd
= NL80211_CMD_SET_INTERFACE
,
3328 .doit
= nl80211_set_interface
,
3329 .policy
= nl80211_policy
,
3330 .flags
= GENL_ADMIN_PERM
,
3333 .cmd
= NL80211_CMD_NEW_INTERFACE
,
3334 .doit
= nl80211_new_interface
,
3335 .policy
= nl80211_policy
,
3336 .flags
= GENL_ADMIN_PERM
,
3339 .cmd
= NL80211_CMD_DEL_INTERFACE
,
3340 .doit
= nl80211_del_interface
,
3341 .policy
= nl80211_policy
,
3342 .flags
= GENL_ADMIN_PERM
,
3345 .cmd
= NL80211_CMD_GET_KEY
,
3346 .doit
= nl80211_get_key
,
3347 .policy
= nl80211_policy
,
3348 .flags
= GENL_ADMIN_PERM
,
3351 .cmd
= NL80211_CMD_SET_KEY
,
3352 .doit
= nl80211_set_key
,
3353 .policy
= nl80211_policy
,
3354 .flags
= GENL_ADMIN_PERM
,
3357 .cmd
= NL80211_CMD_NEW_KEY
,
3358 .doit
= nl80211_new_key
,
3359 .policy
= nl80211_policy
,
3360 .flags
= GENL_ADMIN_PERM
,
3363 .cmd
= NL80211_CMD_DEL_KEY
,
3364 .doit
= nl80211_del_key
,
3365 .policy
= nl80211_policy
,
3366 .flags
= GENL_ADMIN_PERM
,
3369 .cmd
= NL80211_CMD_SET_BEACON
,
3370 .policy
= nl80211_policy
,
3371 .flags
= GENL_ADMIN_PERM
,
3372 .doit
= nl80211_addset_beacon
,
3375 .cmd
= NL80211_CMD_NEW_BEACON
,
3376 .policy
= nl80211_policy
,
3377 .flags
= GENL_ADMIN_PERM
,
3378 .doit
= nl80211_addset_beacon
,
3381 .cmd
= NL80211_CMD_DEL_BEACON
,
3382 .policy
= nl80211_policy
,
3383 .flags
= GENL_ADMIN_PERM
,
3384 .doit
= nl80211_del_beacon
,
3387 .cmd
= NL80211_CMD_GET_STATION
,
3388 .doit
= nl80211_get_station
,
3389 .dumpit
= nl80211_dump_station
,
3390 .policy
= nl80211_policy
,
3393 .cmd
= NL80211_CMD_SET_STATION
,
3394 .doit
= nl80211_set_station
,
3395 .policy
= nl80211_policy
,
3396 .flags
= GENL_ADMIN_PERM
,
3399 .cmd
= NL80211_CMD_NEW_STATION
,
3400 .doit
= nl80211_new_station
,
3401 .policy
= nl80211_policy
,
3402 .flags
= GENL_ADMIN_PERM
,
3405 .cmd
= NL80211_CMD_DEL_STATION
,
3406 .doit
= nl80211_del_station
,
3407 .policy
= nl80211_policy
,
3408 .flags
= GENL_ADMIN_PERM
,
3411 .cmd
= NL80211_CMD_GET_MPATH
,
3412 .doit
= nl80211_get_mpath
,
3413 .dumpit
= nl80211_dump_mpath
,
3414 .policy
= nl80211_policy
,
3415 .flags
= GENL_ADMIN_PERM
,
3418 .cmd
= NL80211_CMD_SET_MPATH
,
3419 .doit
= nl80211_set_mpath
,
3420 .policy
= nl80211_policy
,
3421 .flags
= GENL_ADMIN_PERM
,
3424 .cmd
= NL80211_CMD_NEW_MPATH
,
3425 .doit
= nl80211_new_mpath
,
3426 .policy
= nl80211_policy
,
3427 .flags
= GENL_ADMIN_PERM
,
3430 .cmd
= NL80211_CMD_DEL_MPATH
,
3431 .doit
= nl80211_del_mpath
,
3432 .policy
= nl80211_policy
,
3433 .flags
= GENL_ADMIN_PERM
,
3436 .cmd
= NL80211_CMD_SET_BSS
,
3437 .doit
= nl80211_set_bss
,
3438 .policy
= nl80211_policy
,
3439 .flags
= GENL_ADMIN_PERM
,
3442 .cmd
= NL80211_CMD_GET_REG
,
3443 .doit
= nl80211_get_reg
,
3444 .policy
= nl80211_policy
,
3445 /* can be retrieved by unprivileged users */
3448 .cmd
= NL80211_CMD_SET_REG
,
3449 .doit
= nl80211_set_reg
,
3450 .policy
= nl80211_policy
,
3451 .flags
= GENL_ADMIN_PERM
,
3454 .cmd
= NL80211_CMD_REQ_SET_REG
,
3455 .doit
= nl80211_req_set_reg
,
3456 .policy
= nl80211_policy
,
3457 .flags
= GENL_ADMIN_PERM
,
3460 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
3461 .doit
= nl80211_get_mesh_params
,
3462 .policy
= nl80211_policy
,
3463 /* can be retrieved by unprivileged users */
3466 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
3467 .doit
= nl80211_set_mesh_params
,
3468 .policy
= nl80211_policy
,
3469 .flags
= GENL_ADMIN_PERM
,
3472 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
3473 .doit
= nl80211_trigger_scan
,
3474 .policy
= nl80211_policy
,
3475 .flags
= GENL_ADMIN_PERM
,
3478 .cmd
= NL80211_CMD_GET_SCAN
,
3479 .policy
= nl80211_policy
,
3480 .dumpit
= nl80211_dump_scan
,
3483 .cmd
= NL80211_CMD_AUTHENTICATE
,
3484 .doit
= nl80211_authenticate
,
3485 .policy
= nl80211_policy
,
3486 .flags
= GENL_ADMIN_PERM
,
3489 .cmd
= NL80211_CMD_ASSOCIATE
,
3490 .doit
= nl80211_associate
,
3491 .policy
= nl80211_policy
,
3492 .flags
= GENL_ADMIN_PERM
,
3495 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
3496 .doit
= nl80211_deauthenticate
,
3497 .policy
= nl80211_policy
,
3498 .flags
= GENL_ADMIN_PERM
,
3501 .cmd
= NL80211_CMD_DISASSOCIATE
,
3502 .doit
= nl80211_disassociate
,
3503 .policy
= nl80211_policy
,
3504 .flags
= GENL_ADMIN_PERM
,
3507 .cmd
= NL80211_CMD_JOIN_IBSS
,
3508 .doit
= nl80211_join_ibss
,
3509 .policy
= nl80211_policy
,
3510 .flags
= GENL_ADMIN_PERM
,
3513 .cmd
= NL80211_CMD_LEAVE_IBSS
,
3514 .doit
= nl80211_leave_ibss
,
3515 .policy
= nl80211_policy
,
3516 .flags
= GENL_ADMIN_PERM
,
3519 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
3523 /* multicast groups */
3524 static struct genl_multicast_group nl80211_config_mcgrp
= {
3527 static struct genl_multicast_group nl80211_scan_mcgrp
= {
3530 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
3531 .name
= "regulatory",
3534 /* notification functions */
3536 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
3538 struct sk_buff
*msg
;
3540 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3544 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
3549 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
3552 static int nl80211_send_scan_donemsg(struct sk_buff
*msg
,
3553 struct cfg80211_registered_device
*rdev
,
3554 struct net_device
*netdev
,
3555 u32 pid
, u32 seq
, int flags
,
3560 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
3564 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3565 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3567 /* XXX: we should probably bounce back the request? */
3569 return genlmsg_end(msg
, hdr
);
3572 genlmsg_cancel(msg
, hdr
);
3576 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
3577 struct net_device
*netdev
)
3579 struct sk_buff
*msg
;
3581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3585 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3586 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
3591 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3594 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
3595 struct net_device
*netdev
)
3597 struct sk_buff
*msg
;
3599 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3603 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3604 NL80211_CMD_SCAN_ABORTED
) < 0) {
3609 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3613 * This can happen on global regulatory changes or device specific settings
3614 * based on custom world regulatory domains.
3616 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
3618 struct sk_buff
*msg
;
3621 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3625 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
3631 /* Userspace can always count this one always being set */
3632 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
3634 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
3635 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3636 NL80211_REGDOM_TYPE_WORLD
);
3637 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
3638 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3639 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
3640 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
3642 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3643 NL80211_REGDOM_TYPE_INTERSECTION
);
3645 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3646 NL80211_REGDOM_TYPE_COUNTRY
);
3647 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
3650 if (wiphy_idx_valid(request
->wiphy_idx
))
3651 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
3653 if (genlmsg_end(msg
, hdr
) < 0) {
3658 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
3663 genlmsg_cancel(msg
, hdr
);
3667 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
3668 struct net_device
*netdev
,
3669 const u8
*buf
, size_t len
,
3670 enum nl80211_commands cmd
)
3672 struct sk_buff
*msg
;
3675 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3679 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3685 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3686 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3687 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
3689 if (genlmsg_end(msg
, hdr
) < 0) {
3694 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3698 genlmsg_cancel(msg
, hdr
);
3702 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
3703 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3705 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3706 NL80211_CMD_AUTHENTICATE
);
3709 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
3710 struct net_device
*netdev
, const u8
*buf
,
3713 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
, NL80211_CMD_ASSOCIATE
);
3716 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
3717 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3719 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3720 NL80211_CMD_DEAUTHENTICATE
);
3723 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
3724 struct net_device
*netdev
, const u8
*buf
,
3727 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3728 NL80211_CMD_DISASSOCIATE
);
3731 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
3732 struct net_device
*netdev
, int cmd
,
3735 struct sk_buff
*msg
;
3738 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3742 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3748 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3749 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3750 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
3751 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3753 if (genlmsg_end(msg
, hdr
) < 0) {
3758 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3762 genlmsg_cancel(msg
, hdr
);
3766 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
3767 struct net_device
*netdev
, const u8
*addr
)
3769 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
3773 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
3774 struct net_device
*netdev
, const u8
*addr
)
3776 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
, addr
);
3779 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
3780 struct net_device
*netdev
, const u8
*bssid
,
3783 struct sk_buff
*msg
;
3786 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
3790 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
3796 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3797 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3798 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
3800 if (genlmsg_end(msg
, hdr
) < 0) {
3805 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
3809 genlmsg_cancel(msg
, hdr
);
3813 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
3814 struct net_device
*netdev
, const u8
*addr
,
3815 enum nl80211_key_type key_type
, int key_id
,
3818 struct sk_buff
*msg
;
3821 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3825 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
3831 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3832 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3834 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3835 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
3836 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
3838 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
3840 if (genlmsg_end(msg
, hdr
) < 0) {
3845 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
3849 genlmsg_cancel(msg
, hdr
);
3853 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
3854 struct ieee80211_channel
*channel_before
,
3855 struct ieee80211_channel
*channel_after
)
3857 struct sk_buff
*msg
;
3859 struct nlattr
*nl_freq
;
3861 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
3865 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
3872 * Since we are applying the beacon hint to a wiphy we know its
3873 * wiphy_idx is valid
3875 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
3878 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
3880 goto nla_put_failure
;
3881 if (nl80211_msg_put_channel(msg
, channel_before
))
3882 goto nla_put_failure
;
3883 nla_nest_end(msg
, nl_freq
);
3886 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
3888 goto nla_put_failure
;
3889 if (nl80211_msg_put_channel(msg
, channel_after
))
3890 goto nla_put_failure
;
3891 nla_nest_end(msg
, nl_freq
);
3893 if (genlmsg_end(msg
, hdr
) < 0) {
3898 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_ATOMIC
);
3903 genlmsg_cancel(msg
, hdr
);
3907 /* initialisation/exit functions */
3909 int nl80211_init(void)
3913 err
= genl_register_family(&nl80211_fam
);
3917 for (i
= 0; i
< ARRAY_SIZE(nl80211_ops
); i
++) {
3918 err
= genl_register_ops(&nl80211_fam
, &nl80211_ops
[i
]);
3923 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
3927 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
3931 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
3935 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
3941 genl_unregister_family(&nl80211_fam
);
3945 void nl80211_exit(void)
3947 genl_unregister_family(&nl80211_fam
);