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
},
81 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
82 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
83 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
84 .len
= IEEE80211_MAX_DATA_LEN
},
85 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
86 .len
= IEEE80211_MAX_DATA_LEN
},
87 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
88 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
89 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
90 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
91 .len
= NL80211_MAX_SUPP_RATES
},
92 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
93 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
94 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
95 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
96 .len
= IEEE80211_MAX_MESH_ID_LEN
},
97 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
99 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
100 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
102 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
103 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
104 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
105 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
106 .len
= NL80211_MAX_SUPP_RATES
},
108 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
110 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
111 .len
= NL80211_HT_CAPABILITY_LEN
},
113 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
114 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
115 .len
= IEEE80211_MAX_DATA_LEN
},
116 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
117 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
119 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
120 .len
= IEEE80211_MAX_SSID_LEN
},
121 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
122 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
123 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
124 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
125 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
129 static bool is_valid_ie_attr(const struct nlattr
*attr
)
137 pos
= nla_data(attr
);
158 /* message building helper */
159 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
162 /* since there is no private header just add the generic one */
163 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
166 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
167 struct ieee80211_channel
*chan
)
169 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
172 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
173 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
174 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
175 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
176 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
177 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
178 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
179 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
181 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
182 DBM_TO_MBM(chan
->max_power
));
190 /* netlink command implementations */
192 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
193 struct cfg80211_registered_device
*dev
)
196 struct nlattr
*nl_bands
, *nl_band
;
197 struct nlattr
*nl_freqs
, *nl_freq
;
198 struct nlattr
*nl_rates
, *nl_rate
;
199 struct nlattr
*nl_modes
;
200 struct nlattr
*nl_cmds
;
201 enum ieee80211_band band
;
202 struct ieee80211_channel
*chan
;
203 struct ieee80211_rate
*rate
;
205 u16 ifmodes
= dev
->wiphy
.interface_modes
;
207 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
211 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
212 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
214 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
215 dev
->wiphy
.retry_short
);
216 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
217 dev
->wiphy
.retry_long
);
218 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
219 dev
->wiphy
.frag_threshold
);
220 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
221 dev
->wiphy
.rts_threshold
);
223 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
224 dev
->wiphy
.max_scan_ssids
);
225 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
226 dev
->wiphy
.max_scan_ie_len
);
228 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
229 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
230 dev
->wiphy
.cipher_suites
);
232 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
234 goto nla_put_failure
;
239 NLA_PUT_FLAG(msg
, i
);
244 nla_nest_end(msg
, nl_modes
);
246 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
248 goto nla_put_failure
;
250 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
251 if (!dev
->wiphy
.bands
[band
])
254 nl_band
= nla_nest_start(msg
, band
);
256 goto nla_put_failure
;
259 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
260 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
261 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
262 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
263 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
264 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
265 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
266 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
267 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
268 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
271 /* add frequencies */
272 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
274 goto nla_put_failure
;
276 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
277 nl_freq
= nla_nest_start(msg
, i
);
279 goto nla_put_failure
;
281 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
283 if (nl80211_msg_put_channel(msg
, chan
))
284 goto nla_put_failure
;
286 nla_nest_end(msg
, nl_freq
);
289 nla_nest_end(msg
, nl_freqs
);
292 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
294 goto nla_put_failure
;
296 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
297 nl_rate
= nla_nest_start(msg
, i
);
299 goto nla_put_failure
;
301 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
302 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
304 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
306 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
308 nla_nest_end(msg
, nl_rate
);
311 nla_nest_end(msg
, nl_rates
);
313 nla_nest_end(msg
, nl_band
);
315 nla_nest_end(msg
, nl_bands
);
317 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
319 goto nla_put_failure
;
324 if (dev->ops->op) { \
326 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
330 CMD(add_virtual_intf
, NEW_INTERFACE
);
331 CMD(change_virtual_intf
, SET_INTERFACE
);
332 CMD(add_key
, NEW_KEY
);
333 CMD(add_beacon
, NEW_BEACON
);
334 CMD(add_station
, NEW_STATION
);
335 CMD(add_mpath
, NEW_MPATH
);
336 CMD(set_mesh_params
, SET_MESH_PARAMS
);
337 CMD(change_bss
, SET_BSS
);
338 CMD(auth
, AUTHENTICATE
);
339 CMD(assoc
, ASSOCIATE
);
340 CMD(deauth
, DEAUTHENTICATE
);
341 CMD(disassoc
, DISASSOCIATE
);
342 CMD(join_ibss
, JOIN_IBSS
);
345 nla_nest_end(msg
, nl_cmds
);
347 return genlmsg_end(msg
, hdr
);
350 genlmsg_cancel(msg
, hdr
);
354 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
357 int start
= cb
->args
[0];
358 struct cfg80211_registered_device
*dev
;
360 mutex_lock(&cfg80211_mutex
);
361 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
364 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
365 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
371 mutex_unlock(&cfg80211_mutex
);
378 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
381 struct cfg80211_registered_device
*dev
;
383 dev
= cfg80211_get_dev_from_info(info
);
387 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
391 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
394 cfg80211_put_dev(dev
);
396 return genlmsg_unicast(msg
, info
->snd_pid
);
401 cfg80211_put_dev(dev
);
405 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
406 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
407 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
408 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
409 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
410 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
413 static int parse_txq_params(struct nlattr
*tb
[],
414 struct ieee80211_txq_params
*txq_params
)
416 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
417 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
418 !tb
[NL80211_TXQ_ATTR_AIFS
])
421 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
422 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
423 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
424 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
425 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
430 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
432 struct cfg80211_registered_device
*rdev
;
433 int result
= 0, rem_txq_params
= 0;
434 struct nlattr
*nl_txq_params
;
436 u8 retry_short
= 0, retry_long
= 0;
437 u32 frag_threshold
= 0, rts_threshold
= 0;
441 mutex_lock(&cfg80211_mutex
);
443 rdev
= __cfg80211_drv_from_info(info
);
445 result
= PTR_ERR(rdev
);
449 mutex_lock(&rdev
->mtx
);
451 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
452 result
= cfg80211_dev_rename(
453 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
455 mutex_unlock(&cfg80211_mutex
);
460 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
461 struct ieee80211_txq_params txq_params
;
462 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
464 if (!rdev
->ops
->set_txq_params
) {
465 result
= -EOPNOTSUPP
;
469 nla_for_each_nested(nl_txq_params
,
470 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
472 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
473 nla_data(nl_txq_params
),
474 nla_len(nl_txq_params
),
476 result
= parse_txq_params(tb
, &txq_params
);
480 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
487 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
488 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
489 struct ieee80211_channel
*chan
;
490 struct ieee80211_sta_ht_cap
*ht_cap
;
493 if (!rdev
->ops
->set_channel
) {
494 result
= -EOPNOTSUPP
;
500 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
501 channel_type
= nla_get_u32(info
->attrs
[
502 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
503 if (channel_type
!= NL80211_CHAN_NO_HT
&&
504 channel_type
!= NL80211_CHAN_HT20
&&
505 channel_type
!= NL80211_CHAN_HT40PLUS
&&
506 channel_type
!= NL80211_CHAN_HT40MINUS
)
510 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
511 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
513 /* Primary channel not allowed */
514 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
517 if (channel_type
== NL80211_CHAN_HT40MINUS
)
518 sec_freq
= freq
- 20;
519 else if (channel_type
== NL80211_CHAN_HT40PLUS
)
520 sec_freq
= freq
+ 20;
524 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
526 /* no HT capabilities */
527 if (channel_type
!= NL80211_CHAN_NO_HT
&&
528 !ht_cap
->ht_supported
)
532 struct ieee80211_channel
*schan
;
534 /* no 40 MHz capabilities */
535 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
536 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
539 schan
= ieee80211_get_channel(&rdev
->wiphy
, sec_freq
);
541 /* Secondary channel not allowed */
542 if (!schan
|| schan
->flags
& IEEE80211_CHAN_DISABLED
)
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_GOODSIZE
, 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_GOODSIZE
, 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_IDX
])
1115 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1117 params
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
1119 if (info
->attrs
[NL80211_ATTR_MAC
])
1120 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1122 if (cfg80211_validate_key_settings(¶ms
, key_idx
, mac_addr
))
1127 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1131 for (i
= 0; i
< drv
->wiphy
.n_cipher_suites
; i
++)
1132 if (params
.cipher
== drv
->wiphy
.cipher_suites
[i
])
1134 if (i
== drv
->wiphy
.n_cipher_suites
) {
1139 if (!drv
->ops
->add_key
) {
1144 err
= drv
->ops
->add_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
, ¶ms
);
1147 cfg80211_put_dev(drv
);
1155 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1157 struct cfg80211_registered_device
*drv
;
1159 struct net_device
*dev
;
1161 u8
*mac_addr
= NULL
;
1163 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1164 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1169 if (info
->attrs
[NL80211_ATTR_MAC
])
1170 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1174 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1178 if (!drv
->ops
->del_key
) {
1183 err
= drv
->ops
->del_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
);
1185 #ifdef CONFIG_WIRELESS_EXT
1187 if (key_idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1188 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1189 else if (key_idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1190 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1195 cfg80211_put_dev(drv
);
1204 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1206 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1207 struct beacon_parameters
*info
);
1208 struct cfg80211_registered_device
*drv
;
1210 struct net_device
*dev
;
1211 struct beacon_parameters params
;
1214 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1219 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1223 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1228 switch (info
->genlhdr
->cmd
) {
1229 case NL80211_CMD_NEW_BEACON
:
1230 /* these are required for NEW_BEACON */
1231 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1232 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1233 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1238 call
= drv
->ops
->add_beacon
;
1240 case NL80211_CMD_SET_BEACON
:
1241 call
= drv
->ops
->set_beacon
;
1254 memset(¶ms
, 0, sizeof(params
));
1256 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1258 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1262 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1263 params
.dtim_period
=
1264 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1268 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1269 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1271 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1275 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1276 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1278 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1287 err
= call(&drv
->wiphy
, dev
, ¶ms
);
1290 cfg80211_put_dev(drv
);
1298 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1300 struct cfg80211_registered_device
*drv
;
1302 struct net_device
*dev
;
1306 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1310 if (!drv
->ops
->del_beacon
) {
1315 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1319 err
= drv
->ops
->del_beacon(&drv
->wiphy
, dev
);
1322 cfg80211_put_dev(drv
);
1330 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1331 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1332 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1333 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1336 static int parse_station_flags(struct nlattr
*nla
, u32
*staflags
)
1338 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1346 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1347 nla
, sta_flags_policy
))
1350 *staflags
= STATION_FLAG_CHANGED
;
1352 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1354 *staflags
|= (1<<flag
);
1359 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1361 int modulation
, streams
, bitrate
;
1363 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1364 return rate
->legacy
;
1366 /* the formula below does only work for MCS values smaller than 32 */
1367 if (rate
->mcs
>= 32)
1370 modulation
= rate
->mcs
& 7;
1371 streams
= (rate
->mcs
>> 3) + 1;
1373 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1377 bitrate
*= (modulation
+ 1);
1378 else if (modulation
== 4)
1379 bitrate
*= (modulation
+ 2);
1381 bitrate
*= (modulation
+ 3);
1385 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1386 bitrate
= (bitrate
/ 9) * 10;
1388 /* do NOT round down here */
1389 return (bitrate
+ 50000) / 100000;
1392 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1393 int flags
, struct net_device
*dev
,
1394 u8
*mac_addr
, struct station_info
*sinfo
)
1397 struct nlattr
*sinfoattr
, *txrate
;
1400 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1404 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1405 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1407 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1409 goto nla_put_failure
;
1410 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1411 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1412 sinfo
->inactive_time
);
1413 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1414 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1416 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1417 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1419 if (sinfo
->filled
& STATION_INFO_LLID
)
1420 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1422 if (sinfo
->filled
& STATION_INFO_PLID
)
1423 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1425 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1426 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1427 sinfo
->plink_state
);
1428 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1429 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1431 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1432 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1434 goto nla_put_failure
;
1436 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1437 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1439 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1441 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1442 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1444 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1445 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1446 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1447 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1449 nla_nest_end(msg
, txrate
);
1451 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1452 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1454 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1455 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1457 nla_nest_end(msg
, sinfoattr
);
1459 return genlmsg_end(msg
, hdr
);
1462 genlmsg_cancel(msg
, hdr
);
1466 static int nl80211_dump_station(struct sk_buff
*skb
,
1467 struct netlink_callback
*cb
)
1469 struct station_info sinfo
;
1470 struct cfg80211_registered_device
*dev
;
1471 struct net_device
*netdev
;
1472 u8 mac_addr
[ETH_ALEN
];
1473 int ifidx
= cb
->args
[0];
1474 int sta_idx
= cb
->args
[1];
1478 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1479 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1484 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1487 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1494 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1500 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1506 if (!dev
->ops
->dump_station
) {
1512 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1519 if (nl80211_send_station(skb
,
1520 NETLINK_CB(cb
->skb
).pid
,
1521 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1531 cb
->args
[1] = sta_idx
;
1534 cfg80211_put_dev(dev
);
1541 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1543 struct cfg80211_registered_device
*drv
;
1545 struct net_device
*dev
;
1546 struct station_info sinfo
;
1547 struct sk_buff
*msg
;
1548 u8
*mac_addr
= NULL
;
1550 memset(&sinfo
, 0, sizeof(sinfo
));
1552 if (!info
->attrs
[NL80211_ATTR_MAC
])
1555 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1559 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1563 if (!drv
->ops
->get_station
) {
1568 err
= drv
->ops
->get_station(&drv
->wiphy
, dev
, mac_addr
, &sinfo
);
1572 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1576 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1577 dev
, mac_addr
, &sinfo
) < 0)
1580 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1586 cfg80211_put_dev(drv
);
1595 * Get vlan interface making sure it is on the right wiphy.
1597 static int get_vlan(struct nlattr
*vlanattr
,
1598 struct cfg80211_registered_device
*rdev
,
1599 struct net_device
**vlan
)
1604 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1607 if (!(*vlan
)->ieee80211_ptr
)
1609 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1615 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1617 struct cfg80211_registered_device
*drv
;
1619 struct net_device
*dev
;
1620 struct station_parameters params
;
1621 u8
*mac_addr
= NULL
;
1623 memset(¶ms
, 0, sizeof(params
));
1625 params
.listen_interval
= -1;
1627 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1630 if (!info
->attrs
[NL80211_ATTR_MAC
])
1633 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1635 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1636 params
.supported_rates
=
1637 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1638 params
.supported_rates_len
=
1639 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1642 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1643 params
.listen_interval
=
1644 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1646 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1648 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1650 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1651 ¶ms
.station_flags
))
1654 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1655 params
.plink_action
=
1656 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1660 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1664 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1668 if (!drv
->ops
->change_station
) {
1673 err
= drv
->ops
->change_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1677 dev_put(params
.vlan
);
1678 cfg80211_put_dev(drv
);
1686 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1688 struct cfg80211_registered_device
*drv
;
1690 struct net_device
*dev
;
1691 struct station_parameters params
;
1692 u8
*mac_addr
= NULL
;
1694 memset(¶ms
, 0, sizeof(params
));
1696 if (!info
->attrs
[NL80211_ATTR_MAC
])
1699 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
1702 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1705 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1708 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1709 params
.supported_rates
=
1710 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1711 params
.supported_rates_len
=
1712 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1713 params
.listen_interval
=
1714 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1715 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1716 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1718 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1720 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1721 ¶ms
.station_flags
))
1726 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1730 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1731 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
1736 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1740 if (!drv
->ops
->add_station
) {
1745 if (!netif_running(dev
)) {
1750 err
= drv
->ops
->add_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1754 dev_put(params
.vlan
);
1755 cfg80211_put_dev(drv
);
1763 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
1765 struct cfg80211_registered_device
*drv
;
1767 struct net_device
*dev
;
1768 u8
*mac_addr
= NULL
;
1770 if (info
->attrs
[NL80211_ATTR_MAC
])
1771 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1775 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1779 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1780 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
1785 if (!drv
->ops
->del_station
) {
1790 err
= drv
->ops
->del_station(&drv
->wiphy
, dev
, mac_addr
);
1793 cfg80211_put_dev(drv
);
1801 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1802 int flags
, struct net_device
*dev
,
1803 u8
*dst
, u8
*next_hop
,
1804 struct mpath_info
*pinfo
)
1807 struct nlattr
*pinfoattr
;
1809 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1813 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1814 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
1815 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
1817 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
1819 goto nla_put_failure
;
1820 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
1821 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
1823 if (pinfo
->filled
& MPATH_INFO_DSN
)
1824 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
1826 if (pinfo
->filled
& MPATH_INFO_METRIC
)
1827 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
1829 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
1830 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
1832 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
1833 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
1835 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
1836 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
1837 pinfo
->discovery_timeout
);
1838 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
1839 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
1840 pinfo
->discovery_retries
);
1842 nla_nest_end(msg
, pinfoattr
);
1844 return genlmsg_end(msg
, hdr
);
1847 genlmsg_cancel(msg
, hdr
);
1851 static int nl80211_dump_mpath(struct sk_buff
*skb
,
1852 struct netlink_callback
*cb
)
1854 struct mpath_info pinfo
;
1855 struct cfg80211_registered_device
*dev
;
1856 struct net_device
*netdev
;
1858 u8 next_hop
[ETH_ALEN
];
1859 int ifidx
= cb
->args
[0];
1860 int path_idx
= cb
->args
[1];
1864 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1865 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1870 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1873 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1880 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1886 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1892 if (!dev
->ops
->dump_mpath
) {
1897 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1903 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
1904 dst
, next_hop
, &pinfo
);
1910 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
1911 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1912 netdev
, dst
, next_hop
,
1921 cb
->args
[1] = path_idx
;
1924 cfg80211_put_dev(dev
);
1931 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1933 struct cfg80211_registered_device
*drv
;
1935 struct net_device
*dev
;
1936 struct mpath_info pinfo
;
1937 struct sk_buff
*msg
;
1939 u8 next_hop
[ETH_ALEN
];
1941 memset(&pinfo
, 0, sizeof(pinfo
));
1943 if (!info
->attrs
[NL80211_ATTR_MAC
])
1946 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1950 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1954 if (!drv
->ops
->get_mpath
) {
1959 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1964 err
= drv
->ops
->get_mpath(&drv
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
1968 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1972 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1973 dev
, dst
, next_hop
, &pinfo
) < 0)
1976 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1982 cfg80211_put_dev(drv
);
1990 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1992 struct cfg80211_registered_device
*drv
;
1994 struct net_device
*dev
;
1996 u8
*next_hop
= NULL
;
1998 if (!info
->attrs
[NL80211_ATTR_MAC
])
2001 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2004 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2005 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2009 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2013 if (!drv
->ops
->change_mpath
) {
2018 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2023 if (!netif_running(dev
)) {
2028 err
= drv
->ops
->change_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
2031 cfg80211_put_dev(drv
);
2038 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2040 struct cfg80211_registered_device
*drv
;
2042 struct net_device
*dev
;
2044 u8
*next_hop
= NULL
;
2046 if (!info
->attrs
[NL80211_ATTR_MAC
])
2049 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2052 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2053 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2057 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2061 if (!drv
->ops
->add_mpath
) {
2066 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2071 if (!netif_running(dev
)) {
2076 err
= drv
->ops
->add_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
2079 cfg80211_put_dev(drv
);
2087 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2089 struct cfg80211_registered_device
*drv
;
2091 struct net_device
*dev
;
2094 if (info
->attrs
[NL80211_ATTR_MAC
])
2095 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2099 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2103 if (!drv
->ops
->del_mpath
) {
2108 err
= drv
->ops
->del_mpath(&drv
->wiphy
, dev
, dst
);
2111 cfg80211_put_dev(drv
);
2119 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2121 struct cfg80211_registered_device
*drv
;
2123 struct net_device
*dev
;
2124 struct bss_parameters params
;
2126 memset(¶ms
, 0, sizeof(params
));
2127 /* default to not changing parameters */
2128 params
.use_cts_prot
= -1;
2129 params
.use_short_preamble
= -1;
2130 params
.use_short_slot_time
= -1;
2132 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2133 params
.use_cts_prot
=
2134 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2135 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2136 params
.use_short_preamble
=
2137 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2138 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2139 params
.use_short_slot_time
=
2140 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2141 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2142 params
.basic_rates
=
2143 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2144 params
.basic_rates_len
=
2145 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2150 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2154 if (!drv
->ops
->change_bss
) {
2159 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2164 err
= drv
->ops
->change_bss(&drv
->wiphy
, dev
, ¶ms
);
2167 cfg80211_put_dev(drv
);
2175 static const struct nla_policy
2176 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2177 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2178 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2179 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2180 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2181 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2182 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2185 static int parse_reg_rule(struct nlattr
*tb
[],
2186 struct ieee80211_reg_rule
*reg_rule
)
2188 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2189 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2191 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2193 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2195 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2197 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2199 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2202 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2204 freq_range
->start_freq_khz
=
2205 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2206 freq_range
->end_freq_khz
=
2207 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2208 freq_range
->max_bandwidth_khz
=
2209 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2211 power_rule
->max_eirp
=
2212 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2214 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2215 power_rule
->max_antenna_gain
=
2216 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2221 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2227 * You should only get this when cfg80211 hasn't yet initialized
2228 * completely when built-in to the kernel right between the time
2229 * window between nl80211_init() and regulatory_init(), if that is
2232 mutex_lock(&cfg80211_mutex
);
2233 if (unlikely(!cfg80211_regdomain
)) {
2234 mutex_unlock(&cfg80211_mutex
);
2235 return -EINPROGRESS
;
2237 mutex_unlock(&cfg80211_mutex
);
2239 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2242 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2244 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2245 /* We ignore world regdom requests with the old regdom setup */
2246 if (is_world_regdom(data
))
2250 r
= regulatory_hint_user(data
);
2255 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2256 struct genl_info
*info
)
2258 struct cfg80211_registered_device
*drv
;
2259 struct mesh_config cur_params
;
2261 struct net_device
*dev
;
2263 struct nlattr
*pinfoattr
;
2264 struct sk_buff
*msg
;
2268 /* Look up our device */
2269 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2273 if (!drv
->ops
->get_mesh_params
) {
2278 /* Get the mesh params */
2279 err
= drv
->ops
->get_mesh_params(&drv
->wiphy
, dev
, &cur_params
);
2283 /* Draw up a netlink message to send back */
2284 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2289 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2290 NL80211_CMD_GET_MESH_PARAMS
);
2292 goto nla_put_failure
;
2293 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2295 goto nla_put_failure
;
2296 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2297 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2298 cur_params
.dot11MeshRetryTimeout
);
2299 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2300 cur_params
.dot11MeshConfirmTimeout
);
2301 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2302 cur_params
.dot11MeshHoldingTimeout
);
2303 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2304 cur_params
.dot11MeshMaxPeerLinks
);
2305 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2306 cur_params
.dot11MeshMaxRetries
);
2307 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2308 cur_params
.dot11MeshTTL
);
2309 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2310 cur_params
.auto_open_plinks
);
2311 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2312 cur_params
.dot11MeshHWMPmaxPREQretries
);
2313 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2314 cur_params
.path_refresh_time
);
2315 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2316 cur_params
.min_discovery_timeout
);
2317 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2318 cur_params
.dot11MeshHWMPactivePathTimeout
);
2319 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2320 cur_params
.dot11MeshHWMPpreqMinInterval
);
2321 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2322 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2323 nla_nest_end(msg
, pinfoattr
);
2324 genlmsg_end(msg
, hdr
);
2325 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2329 genlmsg_cancel(msg
, hdr
);
2333 cfg80211_put_dev(drv
);
2341 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2343 if (table[attr_num]) {\
2344 cfg.param = nla_fn(table[attr_num]); \
2345 mask |= (1 << (attr_num - 1)); \
2349 static struct nla_policy
2350 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2351 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2352 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2353 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2354 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2355 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2356 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2357 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2359 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2360 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2361 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2362 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2363 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2364 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2367 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2371 struct cfg80211_registered_device
*drv
;
2372 struct net_device
*dev
;
2373 struct mesh_config cfg
;
2374 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2375 struct nlattr
*parent_attr
;
2377 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2380 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2381 parent_attr
, nl80211_meshconf_params_policy
))
2386 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2390 if (!drv
->ops
->set_mesh_params
) {
2395 /* This makes sure that there aren't more than 32 mesh config
2396 * parameters (otherwise our bitfield scheme would not work.) */
2397 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2399 /* Fill in the params struct */
2401 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2402 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2403 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2404 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2405 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2406 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2407 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2408 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2409 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2410 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2411 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2412 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2413 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2414 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2415 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2416 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2418 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2419 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2420 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2421 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2423 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2424 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2426 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2427 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2429 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2430 dot11MeshHWMPnetDiameterTraversalTime
,
2431 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2435 err
= drv
->ops
->set_mesh_params(&drv
->wiphy
, dev
, &cfg
, mask
);
2439 cfg80211_put_dev(drv
);
2447 #undef FILL_IN_MESH_PARAM_IF_SET
2449 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2451 struct sk_buff
*msg
;
2453 struct nlattr
*nl_reg_rules
;
2457 mutex_lock(&cfg80211_mutex
);
2459 if (!cfg80211_regdomain
)
2462 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2468 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2469 NL80211_CMD_GET_REG
);
2471 goto nla_put_failure
;
2473 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2474 cfg80211_regdomain
->alpha2
);
2476 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2478 goto nla_put_failure
;
2480 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2481 struct nlattr
*nl_reg_rule
;
2482 const struct ieee80211_reg_rule
*reg_rule
;
2483 const struct ieee80211_freq_range
*freq_range
;
2484 const struct ieee80211_power_rule
*power_rule
;
2486 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2487 freq_range
= ®_rule
->freq_range
;
2488 power_rule
= ®_rule
->power_rule
;
2490 nl_reg_rule
= nla_nest_start(msg
, i
);
2492 goto nla_put_failure
;
2494 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2496 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2497 freq_range
->start_freq_khz
);
2498 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2499 freq_range
->end_freq_khz
);
2500 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2501 freq_range
->max_bandwidth_khz
);
2502 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2503 power_rule
->max_antenna_gain
);
2504 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2505 power_rule
->max_eirp
);
2507 nla_nest_end(msg
, nl_reg_rule
);
2510 nla_nest_end(msg
, nl_reg_rules
);
2512 genlmsg_end(msg
, hdr
);
2513 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2517 genlmsg_cancel(msg
, hdr
);
2520 mutex_unlock(&cfg80211_mutex
);
2524 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2526 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2527 struct nlattr
*nl_reg_rule
;
2528 char *alpha2
= NULL
;
2529 int rem_reg_rules
= 0, r
= 0;
2530 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2531 struct ieee80211_regdomain
*rd
= NULL
;
2533 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2536 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2539 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2541 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2544 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2548 if (!reg_is_valid_request(alpha2
))
2551 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2552 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2554 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2558 rd
->n_reg_rules
= num_rules
;
2559 rd
->alpha2
[0] = alpha2
[0];
2560 rd
->alpha2
[1] = alpha2
[1];
2562 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2564 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2565 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2567 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2573 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
)
2577 BUG_ON(rule_idx
!= num_rules
);
2579 mutex_lock(&cfg80211_mutex
);
2581 mutex_unlock(&cfg80211_mutex
);
2589 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2591 struct cfg80211_registered_device
*drv
;
2592 struct net_device
*dev
;
2593 struct cfg80211_scan_request
*request
;
2594 struct cfg80211_ssid
*ssid
;
2595 struct ieee80211_channel
*channel
;
2596 struct nlattr
*attr
;
2597 struct wiphy
*wiphy
;
2598 int err
, tmp
, n_ssids
= 0, n_channels
= 0, i
;
2599 enum ieee80211_band band
;
2602 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2607 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2611 wiphy
= &drv
->wiphy
;
2613 if (!drv
->ops
->scan
) {
2618 if (!netif_running(dev
)) {
2623 if (drv
->scan_req
) {
2628 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2629 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
)
2636 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2637 if (wiphy
->bands
[band
])
2638 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2641 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2642 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2645 if (n_ssids
> wiphy
->max_scan_ssids
) {
2650 if (info
->attrs
[NL80211_ATTR_IE
])
2651 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2655 if (ie_len
> wiphy
->max_scan_ie_len
) {
2660 request
= kzalloc(sizeof(*request
)
2661 + sizeof(*ssid
) * n_ssids
2662 + sizeof(channel
) * n_channels
2663 + ie_len
, GFP_KERNEL
);
2669 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
2670 request
->n_channels
= n_channels
;
2672 request
->ssids
= (void *)(request
->channels
+ n_channels
);
2673 request
->n_ssids
= n_ssids
;
2676 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
2678 request
->ie
= (void *)(request
->channels
+ n_channels
);
2681 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2682 /* user specified, bail out if channel not found */
2683 request
->n_channels
= n_channels
;
2685 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
2686 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
2687 if (!request
->channels
[i
]) {
2696 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2698 if (!wiphy
->bands
[band
])
2700 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2701 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2708 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
2709 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
2710 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2714 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
2715 request
->ssids
[i
].ssid_len
= nla_len(attr
);
2720 if (info
->attrs
[NL80211_ATTR_IE
]) {
2721 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2722 memcpy((void *)request
->ie
,
2723 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
2727 request
->ifidx
= dev
->ifindex
;
2728 request
->wiphy
= &drv
->wiphy
;
2730 drv
->scan_req
= request
;
2731 err
= drv
->ops
->scan(&drv
->wiphy
, dev
, request
);
2735 drv
->scan_req
= NULL
;
2739 cfg80211_put_dev(drv
);
2747 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
2748 struct cfg80211_registered_device
*rdev
,
2749 struct net_device
*dev
,
2750 struct cfg80211_bss
*res
)
2755 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
2756 NL80211_CMD_NEW_SCAN_RESULTS
);
2760 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
2761 rdev
->bss_generation
);
2762 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2764 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
2766 goto nla_put_failure
;
2767 if (!is_zero_ether_addr(res
->bssid
))
2768 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
2769 if (res
->information_elements
&& res
->len_information_elements
)
2770 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
2771 res
->len_information_elements
,
2772 res
->information_elements
);
2774 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
2775 if (res
->beacon_interval
)
2776 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
2777 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
2778 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
2780 switch (rdev
->wiphy
.signal_type
) {
2781 case CFG80211_SIGNAL_TYPE_MBM
:
2782 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
2784 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2785 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
2791 nla_nest_end(msg
, bss
);
2793 return genlmsg_end(msg
, hdr
);
2796 genlmsg_cancel(msg
, hdr
);
2800 static int nl80211_dump_scan(struct sk_buff
*skb
,
2801 struct netlink_callback
*cb
)
2803 struct cfg80211_registered_device
*dev
;
2804 struct net_device
*netdev
;
2805 struct cfg80211_internal_bss
*scan
;
2806 int ifidx
= cb
->args
[0];
2807 int start
= cb
->args
[1], idx
= 0;
2811 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2812 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2817 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2820 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2823 cb
->args
[0] = ifidx
;
2826 netdev
= dev_get_by_index(&init_net
, ifidx
);
2830 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2833 goto out_put_netdev
;
2836 spin_lock_bh(&dev
->bss_lock
);
2837 cfg80211_bss_expire(dev
);
2839 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
2842 if (nl80211_send_bss(skb
,
2843 NETLINK_CB(cb
->skb
).pid
,
2844 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2845 dev
, netdev
, &scan
->pub
) < 0) {
2852 spin_unlock_bh(&dev
->bss_lock
);
2856 cfg80211_put_dev(dev
);
2863 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
2865 return auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
||
2866 auth_type
== NL80211_AUTHTYPE_SHARED_KEY
||
2867 auth_type
== NL80211_AUTHTYPE_FT
||
2868 auth_type
== NL80211_AUTHTYPE_NETWORK_EAP
;
2871 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2873 struct cfg80211_registered_device
*drv
;
2874 struct net_device
*dev
;
2875 struct cfg80211_auth_request req
;
2876 struct wiphy
*wiphy
;
2879 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2882 if (!info
->attrs
[NL80211_ATTR_MAC
])
2885 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
2890 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2894 if (!drv
->ops
->auth
) {
2899 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2904 if (!netif_running(dev
)) {
2909 wiphy
= &drv
->wiphy
;
2910 memset(&req
, 0, sizeof(req
));
2912 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2914 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2915 req
.chan
= ieee80211_get_channel(
2917 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2924 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2925 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2926 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2929 if (info
->attrs
[NL80211_ATTR_IE
]) {
2930 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2931 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2934 req
.auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2935 if (!nl80211_valid_auth_type(req
.auth_type
)) {
2940 err
= drv
->ops
->auth(&drv
->wiphy
, dev
, &req
);
2943 cfg80211_put_dev(drv
);
2950 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
2952 struct cfg80211_registered_device
*drv
;
2953 struct net_device
*dev
;
2954 struct cfg80211_assoc_request req
;
2955 struct wiphy
*wiphy
;
2958 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2961 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
2962 !info
->attrs
[NL80211_ATTR_SSID
])
2967 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2971 if (!drv
->ops
->assoc
) {
2976 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2981 if (!netif_running(dev
)) {
2986 wiphy
= &drv
->wiphy
;
2987 memset(&req
, 0, sizeof(req
));
2989 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2991 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2992 req
.chan
= ieee80211_get_channel(
2994 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3001 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3002 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3004 if (info
->attrs
[NL80211_ATTR_IE
]) {
3005 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3006 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3009 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3010 enum nl80211_mfp use_mfp
=
3011 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3012 if (use_mfp
== NL80211_MFP_REQUIRED
)
3014 else if (use_mfp
!= NL80211_MFP_NO
) {
3020 err
= drv
->ops
->assoc(&drv
->wiphy
, dev
, &req
);
3023 cfg80211_put_dev(drv
);
3030 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3032 struct cfg80211_registered_device
*drv
;
3033 struct net_device
*dev
;
3034 struct cfg80211_deauth_request req
;
3035 struct wiphy
*wiphy
;
3038 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3041 if (!info
->attrs
[NL80211_ATTR_MAC
])
3044 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3049 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3053 if (!drv
->ops
->deauth
) {
3058 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3063 if (!netif_running(dev
)) {
3068 wiphy
= &drv
->wiphy
;
3069 memset(&req
, 0, sizeof(req
));
3071 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3073 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3074 if (req
.reason_code
== 0) {
3075 /* Reason Code 0 is reserved */
3080 if (info
->attrs
[NL80211_ATTR_IE
]) {
3081 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3082 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3085 err
= drv
->ops
->deauth(&drv
->wiphy
, dev
, &req
);
3088 cfg80211_put_dev(drv
);
3095 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3097 struct cfg80211_registered_device
*drv
;
3098 struct net_device
*dev
;
3099 struct cfg80211_disassoc_request req
;
3100 struct wiphy
*wiphy
;
3103 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3106 if (!info
->attrs
[NL80211_ATTR_MAC
])
3109 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3114 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3118 if (!drv
->ops
->disassoc
) {
3123 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3128 if (!netif_running(dev
)) {
3133 wiphy
= &drv
->wiphy
;
3134 memset(&req
, 0, sizeof(req
));
3136 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3138 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3139 if (req
.reason_code
== 0) {
3140 /* Reason Code 0 is reserved */
3145 if (info
->attrs
[NL80211_ATTR_IE
]) {
3146 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3147 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3150 err
= drv
->ops
->disassoc(&drv
->wiphy
, dev
, &req
);
3153 cfg80211_put_dev(drv
);
3160 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3162 struct cfg80211_registered_device
*drv
;
3163 struct net_device
*dev
;
3164 struct cfg80211_ibss_params ibss
;
3165 struct wiphy
*wiphy
;
3168 memset(&ibss
, 0, sizeof(ibss
));
3170 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3173 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3174 !info
->attrs
[NL80211_ATTR_SSID
] ||
3175 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3178 ibss
.beacon_interval
= 100;
3180 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3181 ibss
.beacon_interval
=
3182 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3183 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3189 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3193 if (!drv
->ops
->join_ibss
) {
3198 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3203 if (!netif_running(dev
)) {
3208 wiphy
= &drv
->wiphy
;
3210 if (info
->attrs
[NL80211_ATTR_MAC
])
3211 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3212 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3213 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3215 if (info
->attrs
[NL80211_ATTR_IE
]) {
3216 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3217 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3220 ibss
.channel
= ieee80211_get_channel(wiphy
,
3221 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3222 if (!ibss
.channel
||
3223 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3224 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3229 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3231 err
= cfg80211_join_ibss(drv
, dev
, &ibss
);
3234 cfg80211_put_dev(drv
);
3241 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3243 struct cfg80211_registered_device
*drv
;
3244 struct net_device
*dev
;
3249 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
3253 if (!drv
->ops
->leave_ibss
) {
3258 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3263 if (!netif_running(dev
)) {
3268 err
= cfg80211_leave_ibss(drv
, dev
, false);
3271 cfg80211_put_dev(drv
);
3278 static struct genl_ops nl80211_ops
[] = {
3280 .cmd
= NL80211_CMD_GET_WIPHY
,
3281 .doit
= nl80211_get_wiphy
,
3282 .dumpit
= nl80211_dump_wiphy
,
3283 .policy
= nl80211_policy
,
3284 /* can be retrieved by unprivileged users */
3287 .cmd
= NL80211_CMD_SET_WIPHY
,
3288 .doit
= nl80211_set_wiphy
,
3289 .policy
= nl80211_policy
,
3290 .flags
= GENL_ADMIN_PERM
,
3293 .cmd
= NL80211_CMD_GET_INTERFACE
,
3294 .doit
= nl80211_get_interface
,
3295 .dumpit
= nl80211_dump_interface
,
3296 .policy
= nl80211_policy
,
3297 /* can be retrieved by unprivileged users */
3300 .cmd
= NL80211_CMD_SET_INTERFACE
,
3301 .doit
= nl80211_set_interface
,
3302 .policy
= nl80211_policy
,
3303 .flags
= GENL_ADMIN_PERM
,
3306 .cmd
= NL80211_CMD_NEW_INTERFACE
,
3307 .doit
= nl80211_new_interface
,
3308 .policy
= nl80211_policy
,
3309 .flags
= GENL_ADMIN_PERM
,
3312 .cmd
= NL80211_CMD_DEL_INTERFACE
,
3313 .doit
= nl80211_del_interface
,
3314 .policy
= nl80211_policy
,
3315 .flags
= GENL_ADMIN_PERM
,
3318 .cmd
= NL80211_CMD_GET_KEY
,
3319 .doit
= nl80211_get_key
,
3320 .policy
= nl80211_policy
,
3321 .flags
= GENL_ADMIN_PERM
,
3324 .cmd
= NL80211_CMD_SET_KEY
,
3325 .doit
= nl80211_set_key
,
3326 .policy
= nl80211_policy
,
3327 .flags
= GENL_ADMIN_PERM
,
3330 .cmd
= NL80211_CMD_NEW_KEY
,
3331 .doit
= nl80211_new_key
,
3332 .policy
= nl80211_policy
,
3333 .flags
= GENL_ADMIN_PERM
,
3336 .cmd
= NL80211_CMD_DEL_KEY
,
3337 .doit
= nl80211_del_key
,
3338 .policy
= nl80211_policy
,
3339 .flags
= GENL_ADMIN_PERM
,
3342 .cmd
= NL80211_CMD_SET_BEACON
,
3343 .policy
= nl80211_policy
,
3344 .flags
= GENL_ADMIN_PERM
,
3345 .doit
= nl80211_addset_beacon
,
3348 .cmd
= NL80211_CMD_NEW_BEACON
,
3349 .policy
= nl80211_policy
,
3350 .flags
= GENL_ADMIN_PERM
,
3351 .doit
= nl80211_addset_beacon
,
3354 .cmd
= NL80211_CMD_DEL_BEACON
,
3355 .policy
= nl80211_policy
,
3356 .flags
= GENL_ADMIN_PERM
,
3357 .doit
= nl80211_del_beacon
,
3360 .cmd
= NL80211_CMD_GET_STATION
,
3361 .doit
= nl80211_get_station
,
3362 .dumpit
= nl80211_dump_station
,
3363 .policy
= nl80211_policy
,
3366 .cmd
= NL80211_CMD_SET_STATION
,
3367 .doit
= nl80211_set_station
,
3368 .policy
= nl80211_policy
,
3369 .flags
= GENL_ADMIN_PERM
,
3372 .cmd
= NL80211_CMD_NEW_STATION
,
3373 .doit
= nl80211_new_station
,
3374 .policy
= nl80211_policy
,
3375 .flags
= GENL_ADMIN_PERM
,
3378 .cmd
= NL80211_CMD_DEL_STATION
,
3379 .doit
= nl80211_del_station
,
3380 .policy
= nl80211_policy
,
3381 .flags
= GENL_ADMIN_PERM
,
3384 .cmd
= NL80211_CMD_GET_MPATH
,
3385 .doit
= nl80211_get_mpath
,
3386 .dumpit
= nl80211_dump_mpath
,
3387 .policy
= nl80211_policy
,
3388 .flags
= GENL_ADMIN_PERM
,
3391 .cmd
= NL80211_CMD_SET_MPATH
,
3392 .doit
= nl80211_set_mpath
,
3393 .policy
= nl80211_policy
,
3394 .flags
= GENL_ADMIN_PERM
,
3397 .cmd
= NL80211_CMD_NEW_MPATH
,
3398 .doit
= nl80211_new_mpath
,
3399 .policy
= nl80211_policy
,
3400 .flags
= GENL_ADMIN_PERM
,
3403 .cmd
= NL80211_CMD_DEL_MPATH
,
3404 .doit
= nl80211_del_mpath
,
3405 .policy
= nl80211_policy
,
3406 .flags
= GENL_ADMIN_PERM
,
3409 .cmd
= NL80211_CMD_SET_BSS
,
3410 .doit
= nl80211_set_bss
,
3411 .policy
= nl80211_policy
,
3412 .flags
= GENL_ADMIN_PERM
,
3415 .cmd
= NL80211_CMD_GET_REG
,
3416 .doit
= nl80211_get_reg
,
3417 .policy
= nl80211_policy
,
3418 /* can be retrieved by unprivileged users */
3421 .cmd
= NL80211_CMD_SET_REG
,
3422 .doit
= nl80211_set_reg
,
3423 .policy
= nl80211_policy
,
3424 .flags
= GENL_ADMIN_PERM
,
3427 .cmd
= NL80211_CMD_REQ_SET_REG
,
3428 .doit
= nl80211_req_set_reg
,
3429 .policy
= nl80211_policy
,
3430 .flags
= GENL_ADMIN_PERM
,
3433 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
3434 .doit
= nl80211_get_mesh_params
,
3435 .policy
= nl80211_policy
,
3436 /* can be retrieved by unprivileged users */
3439 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
3440 .doit
= nl80211_set_mesh_params
,
3441 .policy
= nl80211_policy
,
3442 .flags
= GENL_ADMIN_PERM
,
3445 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
3446 .doit
= nl80211_trigger_scan
,
3447 .policy
= nl80211_policy
,
3448 .flags
= GENL_ADMIN_PERM
,
3451 .cmd
= NL80211_CMD_GET_SCAN
,
3452 .policy
= nl80211_policy
,
3453 .dumpit
= nl80211_dump_scan
,
3456 .cmd
= NL80211_CMD_AUTHENTICATE
,
3457 .doit
= nl80211_authenticate
,
3458 .policy
= nl80211_policy
,
3459 .flags
= GENL_ADMIN_PERM
,
3462 .cmd
= NL80211_CMD_ASSOCIATE
,
3463 .doit
= nl80211_associate
,
3464 .policy
= nl80211_policy
,
3465 .flags
= GENL_ADMIN_PERM
,
3468 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
3469 .doit
= nl80211_deauthenticate
,
3470 .policy
= nl80211_policy
,
3471 .flags
= GENL_ADMIN_PERM
,
3474 .cmd
= NL80211_CMD_DISASSOCIATE
,
3475 .doit
= nl80211_disassociate
,
3476 .policy
= nl80211_policy
,
3477 .flags
= GENL_ADMIN_PERM
,
3480 .cmd
= NL80211_CMD_JOIN_IBSS
,
3481 .doit
= nl80211_join_ibss
,
3482 .policy
= nl80211_policy
,
3483 .flags
= GENL_ADMIN_PERM
,
3486 .cmd
= NL80211_CMD_LEAVE_IBSS
,
3487 .doit
= nl80211_leave_ibss
,
3488 .policy
= nl80211_policy
,
3489 .flags
= GENL_ADMIN_PERM
,
3492 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
3496 /* multicast groups */
3497 static struct genl_multicast_group nl80211_config_mcgrp
= {
3500 static struct genl_multicast_group nl80211_scan_mcgrp
= {
3503 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
3504 .name
= "regulatory",
3507 /* notification functions */
3509 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
3511 struct sk_buff
*msg
;
3513 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3517 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
3522 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
3525 static int nl80211_send_scan_donemsg(struct sk_buff
*msg
,
3526 struct cfg80211_registered_device
*rdev
,
3527 struct net_device
*netdev
,
3528 u32 pid
, u32 seq
, int flags
,
3533 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
3537 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3538 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3540 /* XXX: we should probably bounce back the request? */
3542 return genlmsg_end(msg
, hdr
);
3545 genlmsg_cancel(msg
, hdr
);
3549 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
3550 struct net_device
*netdev
)
3552 struct sk_buff
*msg
;
3554 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3558 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3559 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
3564 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3567 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
3568 struct net_device
*netdev
)
3570 struct sk_buff
*msg
;
3572 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3576 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3577 NL80211_CMD_SCAN_ABORTED
) < 0) {
3582 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3586 * This can happen on global regulatory changes or device specific settings
3587 * based on custom world regulatory domains.
3589 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
3591 struct sk_buff
*msg
;
3594 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3598 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
3604 /* Userspace can always count this one always being set */
3605 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
3607 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
3608 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3609 NL80211_REGDOM_TYPE_WORLD
);
3610 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
3611 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3612 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
3613 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
3615 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3616 NL80211_REGDOM_TYPE_INTERSECTION
);
3618 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3619 NL80211_REGDOM_TYPE_COUNTRY
);
3620 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
3623 if (wiphy_idx_valid(request
->wiphy_idx
))
3624 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
3626 if (genlmsg_end(msg
, hdr
) < 0) {
3631 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
3636 genlmsg_cancel(msg
, hdr
);
3640 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
3641 struct net_device
*netdev
,
3642 const u8
*buf
, size_t len
,
3643 enum nl80211_commands cmd
)
3645 struct sk_buff
*msg
;
3648 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
3652 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3658 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3659 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3660 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
3662 if (genlmsg_end(msg
, hdr
) < 0) {
3667 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3671 genlmsg_cancel(msg
, hdr
);
3675 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
3676 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3678 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3679 NL80211_CMD_AUTHENTICATE
);
3682 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
3683 struct net_device
*netdev
, const u8
*buf
,
3686 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
, NL80211_CMD_ASSOCIATE
);
3689 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
3690 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3692 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3693 NL80211_CMD_DEAUTHENTICATE
);
3696 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
3697 struct net_device
*netdev
, const u8
*buf
,
3700 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3701 NL80211_CMD_DISASSOCIATE
);
3704 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
3705 struct net_device
*netdev
, int cmd
,
3708 struct sk_buff
*msg
;
3711 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
3715 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3721 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3722 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3723 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
3724 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3726 if (genlmsg_end(msg
, hdr
) < 0) {
3731 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3735 genlmsg_cancel(msg
, hdr
);
3739 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
3740 struct net_device
*netdev
, const u8
*addr
)
3742 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
3746 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
3747 struct net_device
*netdev
, const u8
*addr
)
3749 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
, addr
);
3752 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
3753 struct net_device
*netdev
, const u8
*bssid
,
3756 struct sk_buff
*msg
;
3759 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
3763 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
3769 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3770 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3771 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
3773 if (genlmsg_end(msg
, hdr
) < 0) {
3778 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
3782 genlmsg_cancel(msg
, hdr
);
3786 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
3787 struct net_device
*netdev
, const u8
*addr
,
3788 enum nl80211_key_type key_type
, int key_id
,
3791 struct sk_buff
*msg
;
3794 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3798 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
3804 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3805 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3807 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3808 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
3809 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
3811 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
3813 if (genlmsg_end(msg
, hdr
) < 0) {
3818 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
3822 genlmsg_cancel(msg
, hdr
);
3826 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
3827 struct ieee80211_channel
*channel_before
,
3828 struct ieee80211_channel
*channel_after
)
3830 struct sk_buff
*msg
;
3832 struct nlattr
*nl_freq
;
3834 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
3838 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
3845 * Since we are applying the beacon hint to a wiphy we know its
3846 * wiphy_idx is valid
3848 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
3851 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
3853 goto nla_put_failure
;
3854 if (nl80211_msg_put_channel(msg
, channel_before
))
3855 goto nla_put_failure
;
3856 nla_nest_end(msg
, nl_freq
);
3859 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
3861 goto nla_put_failure
;
3862 if (nl80211_msg_put_channel(msg
, channel_after
))
3863 goto nla_put_failure
;
3864 nla_nest_end(msg
, nl_freq
);
3866 if (genlmsg_end(msg
, hdr
) < 0) {
3871 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_ATOMIC
);
3876 genlmsg_cancel(msg
, hdr
);
3880 /* initialisation/exit functions */
3882 int nl80211_init(void)
3886 err
= genl_register_family(&nl80211_fam
);
3890 for (i
= 0; i
< ARRAY_SIZE(nl80211_ops
); i
++) {
3891 err
= genl_register_ops(&nl80211_fam
, &nl80211_ops
[i
]);
3896 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
3900 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
3904 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
3908 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
3914 genl_unregister_family(&nl80211_fam
);
3918 void nl80211_exit(void)
3920 genl_unregister_family(&nl80211_fam
);