2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006, 2007 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
},
65 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
66 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
67 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
69 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
71 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
72 .len
= WLAN_MAX_KEY_LEN
},
73 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
74 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
77 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
78 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
79 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
80 .len
= IEEE80211_MAX_DATA_LEN
},
81 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
82 .len
= IEEE80211_MAX_DATA_LEN
},
83 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
84 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
85 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
86 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
87 .len
= NL80211_MAX_SUPP_RATES
},
88 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
89 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
91 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
92 .len
= IEEE80211_MAX_MESH_ID_LEN
},
93 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
95 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
96 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
98 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
99 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
100 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
101 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
102 .len
= NL80211_MAX_SUPP_RATES
},
104 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
106 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
107 .len
= NL80211_HT_CAPABILITY_LEN
},
109 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
111 .len
= IEEE80211_MAX_DATA_LEN
},
112 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
113 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
115 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
116 .len
= IEEE80211_MAX_SSID_LEN
},
117 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
118 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
122 static bool is_valid_ie_attr(const struct nlattr
*attr
)
130 pos
= nla_data(attr
);
151 /* message building helper */
152 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
155 /* since there is no private header just add the generic one */
156 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
159 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
160 struct ieee80211_channel
*chan
)
162 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
165 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
166 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
167 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
168 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
169 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
170 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
171 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
172 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
174 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
175 DBM_TO_MBM(chan
->max_power
));
183 /* netlink command implementations */
185 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
186 struct cfg80211_registered_device
*dev
)
189 struct nlattr
*nl_bands
, *nl_band
;
190 struct nlattr
*nl_freqs
, *nl_freq
;
191 struct nlattr
*nl_rates
, *nl_rate
;
192 struct nlattr
*nl_modes
;
193 struct nlattr
*nl_cmds
;
194 enum ieee80211_band band
;
195 struct ieee80211_channel
*chan
;
196 struct ieee80211_rate
*rate
;
198 u16 ifmodes
= dev
->wiphy
.interface_modes
;
200 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
204 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
205 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
206 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
207 dev
->wiphy
.max_scan_ssids
);
208 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
209 dev
->wiphy
.max_scan_ie_len
);
211 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
213 goto nla_put_failure
;
218 NLA_PUT_FLAG(msg
, i
);
223 nla_nest_end(msg
, nl_modes
);
225 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
227 goto nla_put_failure
;
229 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
230 if (!dev
->wiphy
.bands
[band
])
233 nl_band
= nla_nest_start(msg
, band
);
235 goto nla_put_failure
;
238 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
239 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
240 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
241 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
242 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
243 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
244 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
245 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
246 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
247 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
250 /* add frequencies */
251 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
253 goto nla_put_failure
;
255 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
256 nl_freq
= nla_nest_start(msg
, i
);
258 goto nla_put_failure
;
260 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
262 if (nl80211_msg_put_channel(msg
, chan
))
263 goto nla_put_failure
;
265 nla_nest_end(msg
, nl_freq
);
268 nla_nest_end(msg
, nl_freqs
);
271 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
273 goto nla_put_failure
;
275 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
276 nl_rate
= nla_nest_start(msg
, i
);
278 goto nla_put_failure
;
280 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
281 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
283 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
285 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
287 nla_nest_end(msg
, nl_rate
);
290 nla_nest_end(msg
, nl_rates
);
292 nla_nest_end(msg
, nl_band
);
294 nla_nest_end(msg
, nl_bands
);
296 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
298 goto nla_put_failure
;
303 if (dev->ops->op) { \
305 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
309 CMD(add_virtual_intf
, NEW_INTERFACE
);
310 CMD(change_virtual_intf
, SET_INTERFACE
);
311 CMD(add_key
, NEW_KEY
);
312 CMD(add_beacon
, NEW_BEACON
);
313 CMD(add_station
, NEW_STATION
);
314 CMD(add_mpath
, NEW_MPATH
);
315 CMD(set_mesh_params
, SET_MESH_PARAMS
);
316 CMD(change_bss
, SET_BSS
);
317 CMD(auth
, AUTHENTICATE
);
318 CMD(assoc
, ASSOCIATE
);
319 CMD(deauth
, DEAUTHENTICATE
);
320 CMD(disassoc
, DISASSOCIATE
);
323 nla_nest_end(msg
, nl_cmds
);
325 return genlmsg_end(msg
, hdr
);
328 genlmsg_cancel(msg
, hdr
);
332 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
335 int start
= cb
->args
[0];
336 struct cfg80211_registered_device
*dev
;
338 mutex_lock(&cfg80211_mutex
);
339 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
342 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
343 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
349 mutex_unlock(&cfg80211_mutex
);
356 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
359 struct cfg80211_registered_device
*dev
;
361 dev
= cfg80211_get_dev_from_info(info
);
365 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
369 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
372 cfg80211_put_dev(dev
);
374 return genlmsg_unicast(msg
, info
->snd_pid
);
379 cfg80211_put_dev(dev
);
383 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
384 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
385 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
386 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
387 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
388 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
391 static int parse_txq_params(struct nlattr
*tb
[],
392 struct ieee80211_txq_params
*txq_params
)
394 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
395 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
396 !tb
[NL80211_TXQ_ATTR_AIFS
])
399 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
400 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
401 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
402 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
403 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
408 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
410 struct cfg80211_registered_device
*rdev
;
411 int result
= 0, rem_txq_params
= 0;
412 struct nlattr
*nl_txq_params
;
416 mutex_lock(&cfg80211_mutex
);
418 rdev
= __cfg80211_drv_from_info(info
);
420 result
= PTR_ERR(rdev
);
424 mutex_lock(&rdev
->mtx
);
426 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
427 result
= cfg80211_dev_rename(
428 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
430 mutex_unlock(&cfg80211_mutex
);
435 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
436 struct ieee80211_txq_params txq_params
;
437 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
439 if (!rdev
->ops
->set_txq_params
) {
440 result
= -EOPNOTSUPP
;
444 nla_for_each_nested(nl_txq_params
,
445 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
447 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
448 nla_data(nl_txq_params
),
449 nla_len(nl_txq_params
),
451 result
= parse_txq_params(tb
, &txq_params
);
455 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
462 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
463 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
464 struct ieee80211_channel
*chan
;
465 struct ieee80211_sta_ht_cap
*ht_cap
;
468 if (!rdev
->ops
->set_channel
) {
469 result
= -EOPNOTSUPP
;
475 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
476 channel_type
= nla_get_u32(info
->attrs
[
477 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
478 if (channel_type
!= NL80211_CHAN_NO_HT
&&
479 channel_type
!= NL80211_CHAN_HT20
&&
480 channel_type
!= NL80211_CHAN_HT40PLUS
&&
481 channel_type
!= NL80211_CHAN_HT40MINUS
)
485 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
486 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
488 /* Primary channel not allowed */
489 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
492 if (channel_type
== NL80211_CHAN_HT40MINUS
)
493 sec_freq
= freq
- 20;
494 else if (channel_type
== NL80211_CHAN_HT40PLUS
)
495 sec_freq
= freq
+ 20;
499 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
501 /* no HT capabilities */
502 if (channel_type
!= NL80211_CHAN_NO_HT
&&
503 !ht_cap
->ht_supported
)
507 struct ieee80211_channel
*schan
;
509 /* no 40 MHz capabilities */
510 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
511 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
514 schan
= ieee80211_get_channel(&rdev
->wiphy
, sec_freq
);
516 /* Secondary channel not allowed */
517 if (!schan
|| schan
->flags
& IEEE80211_CHAN_DISABLED
)
521 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
529 mutex_unlock(&rdev
->mtx
);
536 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
537 struct net_device
*dev
)
541 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
545 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
546 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
547 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
548 return genlmsg_end(msg
, hdr
);
551 genlmsg_cancel(msg
, hdr
);
555 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
559 int wp_start
= cb
->args
[0];
560 int if_start
= cb
->args
[1];
561 struct cfg80211_registered_device
*dev
;
562 struct wireless_dev
*wdev
;
564 mutex_lock(&cfg80211_mutex
);
565 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
566 if (wp_idx
< wp_start
) {
572 mutex_lock(&dev
->devlist_mtx
);
573 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
574 if (if_idx
< if_start
) {
578 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
579 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
581 mutex_unlock(&dev
->devlist_mtx
);
586 mutex_unlock(&dev
->devlist_mtx
);
591 mutex_unlock(&cfg80211_mutex
);
593 cb
->args
[0] = wp_idx
;
594 cb
->args
[1] = if_idx
;
599 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
602 struct cfg80211_registered_device
*dev
;
603 struct net_device
*netdev
;
606 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &dev
, &netdev
);
610 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
614 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0, netdev
) < 0)
618 cfg80211_put_dev(dev
);
620 return genlmsg_unicast(msg
, info
->snd_pid
);
626 cfg80211_put_dev(dev
);
630 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
631 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
632 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
633 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
634 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
635 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
638 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
640 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
648 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
649 nla
, mntr_flags_policy
))
652 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
654 *mntrflags
|= (1<<flag
);
659 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
661 struct cfg80211_registered_device
*drv
;
662 struct vif_params params
;
664 enum nl80211_iftype type
;
665 struct net_device
*dev
;
666 u32 _flags
, *flags
= NULL
;
669 memset(¶ms
, 0, sizeof(params
));
673 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
677 ifindex
= dev
->ifindex
;
678 type
= dev
->ieee80211_ptr
->iftype
;
681 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
682 enum nl80211_iftype ntype
;
684 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
688 if (type
> NL80211_IFTYPE_MAX
) {
694 if (!drv
->ops
->change_virtual_intf
||
695 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
700 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
701 if (type
!= NL80211_IFTYPE_MESH_POINT
) {
705 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
706 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
710 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
711 if (type
!= NL80211_IFTYPE_MONITOR
) {
715 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
725 err
= drv
->ops
->change_virtual_intf(&drv
->wiphy
, ifindex
,
726 type
, flags
, ¶ms
);
730 dev
= __dev_get_by_index(&init_net
, ifindex
);
731 WARN_ON(!dev
|| (!err
&& dev
->ieee80211_ptr
->iftype
!= type
));
734 cfg80211_put_dev(drv
);
740 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
742 struct cfg80211_registered_device
*drv
;
743 struct vif_params params
;
745 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
748 memset(¶ms
, 0, sizeof(params
));
750 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
753 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
754 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
755 if (type
> NL80211_IFTYPE_MAX
)
761 drv
= cfg80211_get_dev_from_info(info
);
767 if (!drv
->ops
->add_virtual_intf
||
768 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
773 if (type
== NL80211_IFTYPE_MESH_POINT
&&
774 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
775 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
776 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
779 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
780 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
782 err
= drv
->ops
->add_virtual_intf(&drv
->wiphy
,
783 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
784 type
, err
? NULL
: &flags
, ¶ms
);
787 cfg80211_put_dev(drv
);
793 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
795 struct cfg80211_registered_device
*drv
;
797 struct net_device
*dev
;
801 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
804 ifindex
= dev
->ifindex
;
807 if (!drv
->ops
->del_virtual_intf
) {
812 err
= drv
->ops
->del_virtual_intf(&drv
->wiphy
, ifindex
);
815 cfg80211_put_dev(drv
);
821 struct get_key_cookie
{
826 static void get_key_callback(void *c
, struct key_params
*params
)
828 struct get_key_cookie
*cookie
= c
;
831 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
832 params
->key_len
, params
->key
);
835 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
836 params
->seq_len
, params
->seq
);
839 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
847 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
849 struct cfg80211_registered_device
*drv
;
851 struct net_device
*dev
;
854 struct get_key_cookie cookie
= {
860 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
861 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
866 if (info
->attrs
[NL80211_ATTR_MAC
])
867 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
871 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
875 if (!drv
->ops
->get_key
) {
880 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
886 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
887 NL80211_CMD_NEW_KEY
);
896 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
897 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
899 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
901 err
= drv
->ops
->get_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
,
902 &cookie
, get_key_callback
);
908 goto nla_put_failure
;
910 genlmsg_end(msg
, hdr
);
911 err
= genlmsg_unicast(msg
, info
->snd_pid
);
918 cfg80211_put_dev(drv
);
926 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
928 struct cfg80211_registered_device
*drv
;
930 struct net_device
*dev
;
932 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
935 if (!info
->attrs
[NL80211_ATTR_KEY_IDX
])
938 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
940 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
]) {
941 if (key_idx
< 4 || key_idx
> 5)
943 } else if (key_idx
> 3)
946 /* currently only support setting default key */
947 if (!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
] &&
948 !info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
])
953 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
957 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT
])
958 func
= drv
->ops
->set_default_key
;
960 func
= drv
->ops
->set_default_mgmt_key
;
967 err
= func(&drv
->wiphy
, dev
, key_idx
);
970 cfg80211_put_dev(drv
);
979 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
981 struct cfg80211_registered_device
*drv
;
983 struct net_device
*dev
;
984 struct key_params params
;
988 memset(¶ms
, 0, sizeof(params
));
990 if (!info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
993 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
994 params
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
995 params
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
998 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
999 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1001 params
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
1003 if (info
->attrs
[NL80211_ATTR_MAC
])
1004 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1010 * Disallow pairwise keys with non-zero index unless it's WEP
1011 * (because current deployments use pairwise WEP keys with
1012 * non-zero indizes but 802.11i clearly specifies to use zero)
1014 if (mac_addr
&& key_idx
&&
1015 params
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1016 params
.cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1019 /* TODO: add definitions for the lengths to linux/ieee80211.h */
1020 switch (params
.cipher
) {
1021 case WLAN_CIPHER_SUITE_WEP40
:
1022 if (params
.key_len
!= 5)
1025 case WLAN_CIPHER_SUITE_TKIP
:
1026 if (params
.key_len
!= 32)
1029 case WLAN_CIPHER_SUITE_CCMP
:
1030 if (params
.key_len
!= 16)
1033 case WLAN_CIPHER_SUITE_WEP104
:
1034 if (params
.key_len
!= 13)
1037 case WLAN_CIPHER_SUITE_AES_CMAC
:
1038 if (params
.key_len
!= 16)
1047 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1051 if (!drv
->ops
->add_key
) {
1056 err
= drv
->ops
->add_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
, ¶ms
);
1059 cfg80211_put_dev(drv
);
1067 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1069 struct cfg80211_registered_device
*drv
;
1071 struct net_device
*dev
;
1073 u8
*mac_addr
= NULL
;
1075 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1076 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1081 if (info
->attrs
[NL80211_ATTR_MAC
])
1082 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1086 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1090 if (!drv
->ops
->del_key
) {
1095 err
= drv
->ops
->del_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
);
1098 cfg80211_put_dev(drv
);
1107 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1109 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1110 struct beacon_parameters
*info
);
1111 struct cfg80211_registered_device
*drv
;
1113 struct net_device
*dev
;
1114 struct beacon_parameters params
;
1117 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1122 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1126 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1131 switch (info
->genlhdr
->cmd
) {
1132 case NL80211_CMD_NEW_BEACON
:
1133 /* these are required for NEW_BEACON */
1134 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1135 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1136 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1141 call
= drv
->ops
->add_beacon
;
1143 case NL80211_CMD_SET_BEACON
:
1144 call
= drv
->ops
->set_beacon
;
1157 memset(¶ms
, 0, sizeof(params
));
1159 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1161 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1165 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1166 params
.dtim_period
=
1167 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1171 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1172 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1174 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1178 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1179 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1181 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1190 err
= call(&drv
->wiphy
, dev
, ¶ms
);
1193 cfg80211_put_dev(drv
);
1201 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1203 struct cfg80211_registered_device
*drv
;
1205 struct net_device
*dev
;
1209 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1213 if (!drv
->ops
->del_beacon
) {
1218 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1222 err
= drv
->ops
->del_beacon(&drv
->wiphy
, dev
);
1225 cfg80211_put_dev(drv
);
1233 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1234 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1235 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1236 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1239 static int parse_station_flags(struct nlattr
*nla
, u32
*staflags
)
1241 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1249 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1250 nla
, sta_flags_policy
))
1253 *staflags
= STATION_FLAG_CHANGED
;
1255 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1257 *staflags
|= (1<<flag
);
1262 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1264 int modulation
, streams
, bitrate
;
1266 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1267 return rate
->legacy
;
1269 /* the formula below does only work for MCS values smaller than 32 */
1270 if (rate
->mcs
>= 32)
1273 modulation
= rate
->mcs
& 7;
1274 streams
= (rate
->mcs
>> 3) + 1;
1276 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1280 bitrate
*= (modulation
+ 1);
1281 else if (modulation
== 4)
1282 bitrate
*= (modulation
+ 2);
1284 bitrate
*= (modulation
+ 3);
1288 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1289 bitrate
= (bitrate
/ 9) * 10;
1291 /* do NOT round down here */
1292 return (bitrate
+ 50000) / 100000;
1295 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1296 int flags
, struct net_device
*dev
,
1297 u8
*mac_addr
, struct station_info
*sinfo
)
1300 struct nlattr
*sinfoattr
, *txrate
;
1303 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1307 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1308 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1310 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1312 goto nla_put_failure
;
1313 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1314 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1315 sinfo
->inactive_time
);
1316 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1317 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1319 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1320 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1322 if (sinfo
->filled
& STATION_INFO_LLID
)
1323 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1325 if (sinfo
->filled
& STATION_INFO_PLID
)
1326 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1328 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1329 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1330 sinfo
->plink_state
);
1331 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1332 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1334 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1335 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1337 goto nla_put_failure
;
1339 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1340 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1342 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1344 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1345 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1347 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1348 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1349 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1350 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1352 nla_nest_end(msg
, txrate
);
1354 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1355 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1357 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1358 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1360 nla_nest_end(msg
, sinfoattr
);
1362 return genlmsg_end(msg
, hdr
);
1365 genlmsg_cancel(msg
, hdr
);
1369 static int nl80211_dump_station(struct sk_buff
*skb
,
1370 struct netlink_callback
*cb
)
1372 struct station_info sinfo
;
1373 struct cfg80211_registered_device
*dev
;
1374 struct net_device
*netdev
;
1375 u8 mac_addr
[ETH_ALEN
];
1376 int ifidx
= cb
->args
[0];
1377 int sta_idx
= cb
->args
[1];
1381 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1382 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1387 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1390 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1397 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1403 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1409 if (!dev
->ops
->dump_station
) {
1415 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1422 if (nl80211_send_station(skb
,
1423 NETLINK_CB(cb
->skb
).pid
,
1424 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1434 cb
->args
[1] = sta_idx
;
1437 cfg80211_put_dev(dev
);
1444 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1446 struct cfg80211_registered_device
*drv
;
1448 struct net_device
*dev
;
1449 struct station_info sinfo
;
1450 struct sk_buff
*msg
;
1451 u8
*mac_addr
= NULL
;
1453 memset(&sinfo
, 0, sizeof(sinfo
));
1455 if (!info
->attrs
[NL80211_ATTR_MAC
])
1458 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1462 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1466 if (!drv
->ops
->get_station
) {
1471 err
= drv
->ops
->get_station(&drv
->wiphy
, dev
, mac_addr
, &sinfo
);
1475 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1479 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1480 dev
, mac_addr
, &sinfo
) < 0)
1483 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1489 cfg80211_put_dev(drv
);
1498 * Get vlan interface making sure it is on the right wiphy.
1500 static int get_vlan(struct nlattr
*vlanattr
,
1501 struct cfg80211_registered_device
*rdev
,
1502 struct net_device
**vlan
)
1507 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1510 if (!(*vlan
)->ieee80211_ptr
)
1512 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1518 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1520 struct cfg80211_registered_device
*drv
;
1522 struct net_device
*dev
;
1523 struct station_parameters params
;
1524 u8
*mac_addr
= NULL
;
1526 memset(¶ms
, 0, sizeof(params
));
1528 params
.listen_interval
= -1;
1530 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1533 if (!info
->attrs
[NL80211_ATTR_MAC
])
1536 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1538 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1539 params
.supported_rates
=
1540 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1541 params
.supported_rates_len
=
1542 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1545 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1546 params
.listen_interval
=
1547 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1549 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1551 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1553 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1554 ¶ms
.station_flags
))
1557 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1558 params
.plink_action
=
1559 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1563 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1567 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1571 if (!drv
->ops
->change_station
) {
1576 err
= drv
->ops
->change_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1580 dev_put(params
.vlan
);
1581 cfg80211_put_dev(drv
);
1589 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1591 struct cfg80211_registered_device
*drv
;
1593 struct net_device
*dev
;
1594 struct station_parameters params
;
1595 u8
*mac_addr
= NULL
;
1597 memset(¶ms
, 0, sizeof(params
));
1599 if (!info
->attrs
[NL80211_ATTR_MAC
])
1602 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
1605 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1608 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1611 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1612 params
.supported_rates
=
1613 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1614 params
.supported_rates_len
=
1615 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1616 params
.listen_interval
=
1617 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1618 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1619 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1621 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1623 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1624 ¶ms
.station_flags
))
1629 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1633 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1637 if (!drv
->ops
->add_station
) {
1642 if (!netif_running(dev
)) {
1647 err
= drv
->ops
->add_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1651 dev_put(params
.vlan
);
1652 cfg80211_put_dev(drv
);
1660 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
1662 struct cfg80211_registered_device
*drv
;
1664 struct net_device
*dev
;
1665 u8
*mac_addr
= NULL
;
1667 if (info
->attrs
[NL80211_ATTR_MAC
])
1668 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1672 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1676 if (!drv
->ops
->del_station
) {
1681 err
= drv
->ops
->del_station(&drv
->wiphy
, dev
, mac_addr
);
1684 cfg80211_put_dev(drv
);
1692 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1693 int flags
, struct net_device
*dev
,
1694 u8
*dst
, u8
*next_hop
,
1695 struct mpath_info
*pinfo
)
1698 struct nlattr
*pinfoattr
;
1700 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1704 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1705 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
1706 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
1708 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
1710 goto nla_put_failure
;
1711 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
1712 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
1714 if (pinfo
->filled
& MPATH_INFO_DSN
)
1715 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
1717 if (pinfo
->filled
& MPATH_INFO_METRIC
)
1718 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
1720 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
1721 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
1723 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
1724 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
1726 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
1727 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
1728 pinfo
->discovery_timeout
);
1729 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
1730 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
1731 pinfo
->discovery_retries
);
1733 nla_nest_end(msg
, pinfoattr
);
1735 return genlmsg_end(msg
, hdr
);
1738 genlmsg_cancel(msg
, hdr
);
1742 static int nl80211_dump_mpath(struct sk_buff
*skb
,
1743 struct netlink_callback
*cb
)
1745 struct mpath_info pinfo
;
1746 struct cfg80211_registered_device
*dev
;
1747 struct net_device
*netdev
;
1749 u8 next_hop
[ETH_ALEN
];
1750 int ifidx
= cb
->args
[0];
1751 int path_idx
= cb
->args
[1];
1755 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1756 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1761 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1764 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1771 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1777 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1783 if (!dev
->ops
->dump_mpath
) {
1788 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1794 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
1795 dst
, next_hop
, &pinfo
);
1801 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
1802 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1803 netdev
, dst
, next_hop
,
1812 cb
->args
[1] = path_idx
;
1815 cfg80211_put_dev(dev
);
1822 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1824 struct cfg80211_registered_device
*drv
;
1826 struct net_device
*dev
;
1827 struct mpath_info pinfo
;
1828 struct sk_buff
*msg
;
1830 u8 next_hop
[ETH_ALEN
];
1832 memset(&pinfo
, 0, sizeof(pinfo
));
1834 if (!info
->attrs
[NL80211_ATTR_MAC
])
1837 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1841 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1845 if (!drv
->ops
->get_mpath
) {
1850 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1855 err
= drv
->ops
->get_mpath(&drv
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
1859 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1863 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1864 dev
, dst
, next_hop
, &pinfo
) < 0)
1867 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1873 cfg80211_put_dev(drv
);
1881 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1883 struct cfg80211_registered_device
*drv
;
1885 struct net_device
*dev
;
1887 u8
*next_hop
= NULL
;
1889 if (!info
->attrs
[NL80211_ATTR_MAC
])
1892 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
1895 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1896 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
1900 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1904 if (!drv
->ops
->change_mpath
) {
1909 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1914 if (!netif_running(dev
)) {
1919 err
= drv
->ops
->change_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
1922 cfg80211_put_dev(drv
);
1929 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1931 struct cfg80211_registered_device
*drv
;
1933 struct net_device
*dev
;
1935 u8
*next_hop
= NULL
;
1937 if (!info
->attrs
[NL80211_ATTR_MAC
])
1940 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
1943 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1944 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
1948 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1952 if (!drv
->ops
->add_mpath
) {
1957 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1962 if (!netif_running(dev
)) {
1967 err
= drv
->ops
->add_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
1970 cfg80211_put_dev(drv
);
1978 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1980 struct cfg80211_registered_device
*drv
;
1982 struct net_device
*dev
;
1985 if (info
->attrs
[NL80211_ATTR_MAC
])
1986 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1990 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1994 if (!drv
->ops
->del_mpath
) {
1999 err
= drv
->ops
->del_mpath(&drv
->wiphy
, dev
, dst
);
2002 cfg80211_put_dev(drv
);
2010 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2012 struct cfg80211_registered_device
*drv
;
2014 struct net_device
*dev
;
2015 struct bss_parameters params
;
2017 memset(¶ms
, 0, sizeof(params
));
2018 /* default to not changing parameters */
2019 params
.use_cts_prot
= -1;
2020 params
.use_short_preamble
= -1;
2021 params
.use_short_slot_time
= -1;
2023 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2024 params
.use_cts_prot
=
2025 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2026 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2027 params
.use_short_preamble
=
2028 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2029 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2030 params
.use_short_slot_time
=
2031 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2032 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2033 params
.basic_rates
=
2034 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2035 params
.basic_rates_len
=
2036 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2041 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2045 if (!drv
->ops
->change_bss
) {
2050 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2055 err
= drv
->ops
->change_bss(&drv
->wiphy
, dev
, ¶ms
);
2058 cfg80211_put_dev(drv
);
2066 static const struct nla_policy
2067 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2068 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2069 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2070 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2071 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2072 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2073 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2076 static int parse_reg_rule(struct nlattr
*tb
[],
2077 struct ieee80211_reg_rule
*reg_rule
)
2079 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2080 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2082 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2084 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2086 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2088 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2090 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2093 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2095 freq_range
->start_freq_khz
=
2096 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2097 freq_range
->end_freq_khz
=
2098 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2099 freq_range
->max_bandwidth_khz
=
2100 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2102 power_rule
->max_eirp
=
2103 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2105 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2106 power_rule
->max_antenna_gain
=
2107 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2112 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2118 * You should only get this when cfg80211 hasn't yet initialized
2119 * completely when built-in to the kernel right between the time
2120 * window between nl80211_init() and regulatory_init(), if that is
2123 mutex_lock(&cfg80211_mutex
);
2124 if (unlikely(!cfg80211_regdomain
)) {
2125 mutex_unlock(&cfg80211_mutex
);
2126 return -EINPROGRESS
;
2128 mutex_unlock(&cfg80211_mutex
);
2130 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2133 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2135 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2136 /* We ignore world regdom requests with the old regdom setup */
2137 if (is_world_regdom(data
))
2141 r
= regulatory_hint_user(data
);
2146 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2147 struct genl_info
*info
)
2149 struct cfg80211_registered_device
*drv
;
2150 struct mesh_config cur_params
;
2152 struct net_device
*dev
;
2154 struct nlattr
*pinfoattr
;
2155 struct sk_buff
*msg
;
2159 /* Look up our device */
2160 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2164 if (!drv
->ops
->get_mesh_params
) {
2169 /* Get the mesh params */
2170 err
= drv
->ops
->get_mesh_params(&drv
->wiphy
, dev
, &cur_params
);
2174 /* Draw up a netlink message to send back */
2175 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2180 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2181 NL80211_CMD_GET_MESH_PARAMS
);
2183 goto nla_put_failure
;
2184 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2186 goto nla_put_failure
;
2187 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2188 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2189 cur_params
.dot11MeshRetryTimeout
);
2190 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2191 cur_params
.dot11MeshConfirmTimeout
);
2192 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2193 cur_params
.dot11MeshHoldingTimeout
);
2194 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2195 cur_params
.dot11MeshMaxPeerLinks
);
2196 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2197 cur_params
.dot11MeshMaxRetries
);
2198 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2199 cur_params
.dot11MeshTTL
);
2200 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2201 cur_params
.auto_open_plinks
);
2202 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2203 cur_params
.dot11MeshHWMPmaxPREQretries
);
2204 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2205 cur_params
.path_refresh_time
);
2206 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2207 cur_params
.min_discovery_timeout
);
2208 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2209 cur_params
.dot11MeshHWMPactivePathTimeout
);
2210 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2211 cur_params
.dot11MeshHWMPpreqMinInterval
);
2212 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2213 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2214 nla_nest_end(msg
, pinfoattr
);
2215 genlmsg_end(msg
, hdr
);
2216 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2220 genlmsg_cancel(msg
, hdr
);
2224 cfg80211_put_dev(drv
);
2232 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2234 if (table[attr_num]) {\
2235 cfg.param = nla_fn(table[attr_num]); \
2236 mask |= (1 << (attr_num - 1)); \
2240 static struct nla_policy
2241 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2242 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2243 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2244 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2245 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2246 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2247 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2248 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2250 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2251 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2252 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2253 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2254 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2255 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2258 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2262 struct cfg80211_registered_device
*drv
;
2263 struct net_device
*dev
;
2264 struct mesh_config cfg
;
2265 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2266 struct nlattr
*parent_attr
;
2268 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2271 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2272 parent_attr
, nl80211_meshconf_params_policy
))
2277 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2281 if (!drv
->ops
->set_mesh_params
) {
2286 /* This makes sure that there aren't more than 32 mesh config
2287 * parameters (otherwise our bitfield scheme would not work.) */
2288 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2290 /* Fill in the params struct */
2292 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2293 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2294 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2295 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2296 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2297 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2298 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2299 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2300 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2301 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2302 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2303 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2304 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2305 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2306 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2307 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2309 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2310 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2311 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2312 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2314 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2315 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2317 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2318 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2320 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2321 dot11MeshHWMPnetDiameterTraversalTime
,
2322 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2326 err
= drv
->ops
->set_mesh_params(&drv
->wiphy
, dev
, &cfg
, mask
);
2330 cfg80211_put_dev(drv
);
2338 #undef FILL_IN_MESH_PARAM_IF_SET
2340 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2342 struct sk_buff
*msg
;
2344 struct nlattr
*nl_reg_rules
;
2348 mutex_lock(&cfg80211_mutex
);
2350 if (!cfg80211_regdomain
)
2353 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2359 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2360 NL80211_CMD_GET_REG
);
2362 goto nla_put_failure
;
2364 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2365 cfg80211_regdomain
->alpha2
);
2367 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2369 goto nla_put_failure
;
2371 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2372 struct nlattr
*nl_reg_rule
;
2373 const struct ieee80211_reg_rule
*reg_rule
;
2374 const struct ieee80211_freq_range
*freq_range
;
2375 const struct ieee80211_power_rule
*power_rule
;
2377 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2378 freq_range
= ®_rule
->freq_range
;
2379 power_rule
= ®_rule
->power_rule
;
2381 nl_reg_rule
= nla_nest_start(msg
, i
);
2383 goto nla_put_failure
;
2385 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2387 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2388 freq_range
->start_freq_khz
);
2389 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2390 freq_range
->end_freq_khz
);
2391 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2392 freq_range
->max_bandwidth_khz
);
2393 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2394 power_rule
->max_antenna_gain
);
2395 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2396 power_rule
->max_eirp
);
2398 nla_nest_end(msg
, nl_reg_rule
);
2401 nla_nest_end(msg
, nl_reg_rules
);
2403 genlmsg_end(msg
, hdr
);
2404 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2408 genlmsg_cancel(msg
, hdr
);
2411 mutex_unlock(&cfg80211_mutex
);
2415 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2417 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2418 struct nlattr
*nl_reg_rule
;
2419 char *alpha2
= NULL
;
2420 int rem_reg_rules
= 0, r
= 0;
2421 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2422 struct ieee80211_regdomain
*rd
= NULL
;
2424 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2427 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2430 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2432 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2435 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2439 if (!reg_is_valid_request(alpha2
))
2442 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2443 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2445 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2449 rd
->n_reg_rules
= num_rules
;
2450 rd
->alpha2
[0] = alpha2
[0];
2451 rd
->alpha2
[1] = alpha2
[1];
2453 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2455 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2456 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2458 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2464 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
)
2468 BUG_ON(rule_idx
!= num_rules
);
2470 mutex_lock(&cfg80211_mutex
);
2472 mutex_unlock(&cfg80211_mutex
);
2480 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2482 struct cfg80211_registered_device
*drv
;
2483 struct net_device
*dev
;
2484 struct cfg80211_scan_request
*request
;
2485 struct cfg80211_ssid
*ssid
;
2486 struct ieee80211_channel
*channel
;
2487 struct nlattr
*attr
;
2488 struct wiphy
*wiphy
;
2489 int err
, tmp
, n_ssids
= 0, n_channels
= 0, i
;
2490 enum ieee80211_band band
;
2493 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2498 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2502 wiphy
= &drv
->wiphy
;
2504 if (!drv
->ops
->scan
) {
2509 if (!netif_running(dev
)) {
2514 if (drv
->scan_req
) {
2519 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2520 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
)
2527 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2528 if (wiphy
->bands
[band
])
2529 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2532 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2533 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2536 if (n_ssids
> wiphy
->max_scan_ssids
) {
2541 if (info
->attrs
[NL80211_ATTR_IE
])
2542 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2546 if (ie_len
> wiphy
->max_scan_ie_len
) {
2551 request
= kzalloc(sizeof(*request
)
2552 + sizeof(*ssid
) * n_ssids
2553 + sizeof(channel
) * n_channels
2554 + ie_len
, GFP_KERNEL
);
2560 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
2561 request
->n_channels
= n_channels
;
2563 request
->ssids
= (void *)(request
->channels
+ n_channels
);
2564 request
->n_ssids
= n_ssids
;
2567 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
2569 request
->ie
= (void *)(request
->channels
+ n_channels
);
2572 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2573 /* user specified, bail out if channel not found */
2574 request
->n_channels
= n_channels
;
2576 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
2577 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
2578 if (!request
->channels
[i
]) {
2587 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2589 if (!wiphy
->bands
[band
])
2591 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2592 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2599 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
2600 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
2601 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2605 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
2606 request
->ssids
[i
].ssid_len
= nla_len(attr
);
2611 if (info
->attrs
[NL80211_ATTR_IE
]) {
2612 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2613 memcpy((void *)request
->ie
,
2614 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
2618 request
->ifidx
= dev
->ifindex
;
2619 request
->wiphy
= &drv
->wiphy
;
2621 drv
->scan_req
= request
;
2622 err
= drv
->ops
->scan(&drv
->wiphy
, dev
, request
);
2626 drv
->scan_req
= NULL
;
2630 cfg80211_put_dev(drv
);
2638 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
2639 struct cfg80211_registered_device
*rdev
,
2640 struct net_device
*dev
,
2641 struct cfg80211_bss
*res
)
2646 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
2647 NL80211_CMD_NEW_SCAN_RESULTS
);
2651 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
2652 rdev
->bss_generation
);
2653 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2655 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
2657 goto nla_put_failure
;
2658 if (!is_zero_ether_addr(res
->bssid
))
2659 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
2660 if (res
->information_elements
&& res
->len_information_elements
)
2661 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
2662 res
->len_information_elements
,
2663 res
->information_elements
);
2665 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
2666 if (res
->beacon_interval
)
2667 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
2668 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
2669 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
2671 switch (rdev
->wiphy
.signal_type
) {
2672 case CFG80211_SIGNAL_TYPE_MBM
:
2673 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
2675 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2676 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
2682 nla_nest_end(msg
, bss
);
2684 return genlmsg_end(msg
, hdr
);
2687 genlmsg_cancel(msg
, hdr
);
2691 static int nl80211_dump_scan(struct sk_buff
*skb
,
2692 struct netlink_callback
*cb
)
2694 struct cfg80211_registered_device
*dev
;
2695 struct net_device
*netdev
;
2696 struct cfg80211_internal_bss
*scan
;
2697 int ifidx
= cb
->args
[0];
2698 int start
= cb
->args
[1], idx
= 0;
2702 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2703 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2708 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2711 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2714 cb
->args
[0] = ifidx
;
2717 netdev
= dev_get_by_index(&init_net
, ifidx
);
2721 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2724 goto out_put_netdev
;
2727 spin_lock_bh(&dev
->bss_lock
);
2728 cfg80211_bss_expire(dev
);
2730 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
2733 if (nl80211_send_bss(skb
,
2734 NETLINK_CB(cb
->skb
).pid
,
2735 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2736 dev
, netdev
, &scan
->pub
) < 0) {
2743 spin_unlock_bh(&dev
->bss_lock
);
2747 cfg80211_put_dev(dev
);
2754 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
2756 return auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
||
2757 auth_type
== NL80211_AUTHTYPE_SHARED_KEY
||
2758 auth_type
== NL80211_AUTHTYPE_FT
||
2759 auth_type
== NL80211_AUTHTYPE_NETWORK_EAP
;
2762 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2764 struct cfg80211_registered_device
*drv
;
2765 struct net_device
*dev
;
2766 struct cfg80211_auth_request req
;
2767 struct wiphy
*wiphy
;
2770 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2773 if (!info
->attrs
[NL80211_ATTR_MAC
])
2776 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
2781 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2785 if (!drv
->ops
->auth
) {
2790 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2795 if (!netif_running(dev
)) {
2800 wiphy
= &drv
->wiphy
;
2801 memset(&req
, 0, sizeof(req
));
2803 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2805 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2806 req
.chan
= ieee80211_get_channel(
2808 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2815 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2816 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2817 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2820 if (info
->attrs
[NL80211_ATTR_IE
]) {
2821 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2822 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2825 req
.auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2826 if (!nl80211_valid_auth_type(req
.auth_type
)) {
2831 err
= drv
->ops
->auth(&drv
->wiphy
, dev
, &req
);
2834 cfg80211_put_dev(drv
);
2841 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
2843 struct cfg80211_registered_device
*drv
;
2844 struct net_device
*dev
;
2845 struct cfg80211_assoc_request req
;
2846 struct wiphy
*wiphy
;
2849 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2852 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
2853 !info
->attrs
[NL80211_ATTR_SSID
])
2858 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2862 if (!drv
->ops
->assoc
) {
2867 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2872 if (!netif_running(dev
)) {
2877 wiphy
= &drv
->wiphy
;
2878 memset(&req
, 0, sizeof(req
));
2880 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2882 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2883 req
.chan
= ieee80211_get_channel(
2885 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2892 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2893 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2895 if (info
->attrs
[NL80211_ATTR_IE
]) {
2896 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2897 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2900 err
= drv
->ops
->assoc(&drv
->wiphy
, dev
, &req
);
2903 cfg80211_put_dev(drv
);
2910 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2912 struct cfg80211_registered_device
*drv
;
2913 struct net_device
*dev
;
2914 struct cfg80211_deauth_request req
;
2915 struct wiphy
*wiphy
;
2918 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2921 if (!info
->attrs
[NL80211_ATTR_MAC
])
2924 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
2929 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2933 if (!drv
->ops
->deauth
) {
2938 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2943 if (!netif_running(dev
)) {
2948 wiphy
= &drv
->wiphy
;
2949 memset(&req
, 0, sizeof(req
));
2951 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2953 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
2954 if (req
.reason_code
== 0) {
2955 /* Reason Code 0 is reserved */
2960 if (info
->attrs
[NL80211_ATTR_IE
]) {
2961 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2962 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2965 err
= drv
->ops
->deauth(&drv
->wiphy
, dev
, &req
);
2968 cfg80211_put_dev(drv
);
2975 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
2977 struct cfg80211_registered_device
*drv
;
2978 struct net_device
*dev
;
2979 struct cfg80211_disassoc_request req
;
2980 struct wiphy
*wiphy
;
2983 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2986 if (!info
->attrs
[NL80211_ATTR_MAC
])
2989 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
2994 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2998 if (!drv
->ops
->disassoc
) {
3003 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3008 if (!netif_running(dev
)) {
3013 wiphy
= &drv
->wiphy
;
3014 memset(&req
, 0, sizeof(req
));
3016 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3018 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3019 if (req
.reason_code
== 0) {
3020 /* Reason Code 0 is reserved */
3025 if (info
->attrs
[NL80211_ATTR_IE
]) {
3026 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3027 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3030 err
= drv
->ops
->disassoc(&drv
->wiphy
, dev
, &req
);
3033 cfg80211_put_dev(drv
);
3040 static struct genl_ops nl80211_ops
[] = {
3042 .cmd
= NL80211_CMD_GET_WIPHY
,
3043 .doit
= nl80211_get_wiphy
,
3044 .dumpit
= nl80211_dump_wiphy
,
3045 .policy
= nl80211_policy
,
3046 /* can be retrieved by unprivileged users */
3049 .cmd
= NL80211_CMD_SET_WIPHY
,
3050 .doit
= nl80211_set_wiphy
,
3051 .policy
= nl80211_policy
,
3052 .flags
= GENL_ADMIN_PERM
,
3055 .cmd
= NL80211_CMD_GET_INTERFACE
,
3056 .doit
= nl80211_get_interface
,
3057 .dumpit
= nl80211_dump_interface
,
3058 .policy
= nl80211_policy
,
3059 /* can be retrieved by unprivileged users */
3062 .cmd
= NL80211_CMD_SET_INTERFACE
,
3063 .doit
= nl80211_set_interface
,
3064 .policy
= nl80211_policy
,
3065 .flags
= GENL_ADMIN_PERM
,
3068 .cmd
= NL80211_CMD_NEW_INTERFACE
,
3069 .doit
= nl80211_new_interface
,
3070 .policy
= nl80211_policy
,
3071 .flags
= GENL_ADMIN_PERM
,
3074 .cmd
= NL80211_CMD_DEL_INTERFACE
,
3075 .doit
= nl80211_del_interface
,
3076 .policy
= nl80211_policy
,
3077 .flags
= GENL_ADMIN_PERM
,
3080 .cmd
= NL80211_CMD_GET_KEY
,
3081 .doit
= nl80211_get_key
,
3082 .policy
= nl80211_policy
,
3083 .flags
= GENL_ADMIN_PERM
,
3086 .cmd
= NL80211_CMD_SET_KEY
,
3087 .doit
= nl80211_set_key
,
3088 .policy
= nl80211_policy
,
3089 .flags
= GENL_ADMIN_PERM
,
3092 .cmd
= NL80211_CMD_NEW_KEY
,
3093 .doit
= nl80211_new_key
,
3094 .policy
= nl80211_policy
,
3095 .flags
= GENL_ADMIN_PERM
,
3098 .cmd
= NL80211_CMD_DEL_KEY
,
3099 .doit
= nl80211_del_key
,
3100 .policy
= nl80211_policy
,
3101 .flags
= GENL_ADMIN_PERM
,
3104 .cmd
= NL80211_CMD_SET_BEACON
,
3105 .policy
= nl80211_policy
,
3106 .flags
= GENL_ADMIN_PERM
,
3107 .doit
= nl80211_addset_beacon
,
3110 .cmd
= NL80211_CMD_NEW_BEACON
,
3111 .policy
= nl80211_policy
,
3112 .flags
= GENL_ADMIN_PERM
,
3113 .doit
= nl80211_addset_beacon
,
3116 .cmd
= NL80211_CMD_DEL_BEACON
,
3117 .policy
= nl80211_policy
,
3118 .flags
= GENL_ADMIN_PERM
,
3119 .doit
= nl80211_del_beacon
,
3122 .cmd
= NL80211_CMD_GET_STATION
,
3123 .doit
= nl80211_get_station
,
3124 .dumpit
= nl80211_dump_station
,
3125 .policy
= nl80211_policy
,
3128 .cmd
= NL80211_CMD_SET_STATION
,
3129 .doit
= nl80211_set_station
,
3130 .policy
= nl80211_policy
,
3131 .flags
= GENL_ADMIN_PERM
,
3134 .cmd
= NL80211_CMD_NEW_STATION
,
3135 .doit
= nl80211_new_station
,
3136 .policy
= nl80211_policy
,
3137 .flags
= GENL_ADMIN_PERM
,
3140 .cmd
= NL80211_CMD_DEL_STATION
,
3141 .doit
= nl80211_del_station
,
3142 .policy
= nl80211_policy
,
3143 .flags
= GENL_ADMIN_PERM
,
3146 .cmd
= NL80211_CMD_GET_MPATH
,
3147 .doit
= nl80211_get_mpath
,
3148 .dumpit
= nl80211_dump_mpath
,
3149 .policy
= nl80211_policy
,
3150 .flags
= GENL_ADMIN_PERM
,
3153 .cmd
= NL80211_CMD_SET_MPATH
,
3154 .doit
= nl80211_set_mpath
,
3155 .policy
= nl80211_policy
,
3156 .flags
= GENL_ADMIN_PERM
,
3159 .cmd
= NL80211_CMD_NEW_MPATH
,
3160 .doit
= nl80211_new_mpath
,
3161 .policy
= nl80211_policy
,
3162 .flags
= GENL_ADMIN_PERM
,
3165 .cmd
= NL80211_CMD_DEL_MPATH
,
3166 .doit
= nl80211_del_mpath
,
3167 .policy
= nl80211_policy
,
3168 .flags
= GENL_ADMIN_PERM
,
3171 .cmd
= NL80211_CMD_SET_BSS
,
3172 .doit
= nl80211_set_bss
,
3173 .policy
= nl80211_policy
,
3174 .flags
= GENL_ADMIN_PERM
,
3177 .cmd
= NL80211_CMD_GET_REG
,
3178 .doit
= nl80211_get_reg
,
3179 .policy
= nl80211_policy
,
3180 /* can be retrieved by unprivileged users */
3183 .cmd
= NL80211_CMD_SET_REG
,
3184 .doit
= nl80211_set_reg
,
3185 .policy
= nl80211_policy
,
3186 .flags
= GENL_ADMIN_PERM
,
3189 .cmd
= NL80211_CMD_REQ_SET_REG
,
3190 .doit
= nl80211_req_set_reg
,
3191 .policy
= nl80211_policy
,
3192 .flags
= GENL_ADMIN_PERM
,
3195 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
3196 .doit
= nl80211_get_mesh_params
,
3197 .policy
= nl80211_policy
,
3198 /* can be retrieved by unprivileged users */
3201 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
3202 .doit
= nl80211_set_mesh_params
,
3203 .policy
= nl80211_policy
,
3204 .flags
= GENL_ADMIN_PERM
,
3207 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
3208 .doit
= nl80211_trigger_scan
,
3209 .policy
= nl80211_policy
,
3210 .flags
= GENL_ADMIN_PERM
,
3213 .cmd
= NL80211_CMD_GET_SCAN
,
3214 .policy
= nl80211_policy
,
3215 .dumpit
= nl80211_dump_scan
,
3218 .cmd
= NL80211_CMD_AUTHENTICATE
,
3219 .doit
= nl80211_authenticate
,
3220 .policy
= nl80211_policy
,
3221 .flags
= GENL_ADMIN_PERM
,
3224 .cmd
= NL80211_CMD_ASSOCIATE
,
3225 .doit
= nl80211_associate
,
3226 .policy
= nl80211_policy
,
3227 .flags
= GENL_ADMIN_PERM
,
3230 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
3231 .doit
= nl80211_deauthenticate
,
3232 .policy
= nl80211_policy
,
3233 .flags
= GENL_ADMIN_PERM
,
3236 .cmd
= NL80211_CMD_DISASSOCIATE
,
3237 .doit
= nl80211_disassociate
,
3238 .policy
= nl80211_policy
,
3239 .flags
= GENL_ADMIN_PERM
,
3242 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
3246 /* multicast groups */
3247 static struct genl_multicast_group nl80211_config_mcgrp
= {
3250 static struct genl_multicast_group nl80211_scan_mcgrp
= {
3253 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
3254 .name
= "regulatory",
3257 /* notification functions */
3259 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
3261 struct sk_buff
*msg
;
3263 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3267 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
3272 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
3275 static int nl80211_send_scan_donemsg(struct sk_buff
*msg
,
3276 struct cfg80211_registered_device
*rdev
,
3277 struct net_device
*netdev
,
3278 u32 pid
, u32 seq
, int flags
,
3283 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
3287 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3288 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3290 /* XXX: we should probably bounce back the request? */
3292 return genlmsg_end(msg
, hdr
);
3295 genlmsg_cancel(msg
, hdr
);
3299 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
3300 struct net_device
*netdev
)
3302 struct sk_buff
*msg
;
3304 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3308 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3309 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
3314 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3317 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
3318 struct net_device
*netdev
)
3320 struct sk_buff
*msg
;
3322 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3326 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3327 NL80211_CMD_SCAN_ABORTED
) < 0) {
3332 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3336 * This can happen on global regulatory changes or device specific settings
3337 * based on custom world regulatory domains.
3339 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
3341 struct sk_buff
*msg
;
3344 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3348 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
3354 /* Userspace can always count this one always being set */
3355 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
3357 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
3358 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3359 NL80211_REGDOM_TYPE_WORLD
);
3360 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
3361 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3362 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
3363 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
3365 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3366 NL80211_REGDOM_TYPE_INTERSECTION
);
3368 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3369 NL80211_REGDOM_TYPE_COUNTRY
);
3370 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
3373 if (wiphy_idx_valid(request
->wiphy_idx
))
3374 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
3376 if (genlmsg_end(msg
, hdr
) < 0) {
3381 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
3386 genlmsg_cancel(msg
, hdr
);
3390 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
3391 struct net_device
*netdev
,
3392 const u8
*buf
, size_t len
,
3393 enum nl80211_commands cmd
)
3395 struct sk_buff
*msg
;
3398 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
3402 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3408 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3409 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3410 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
3412 if (genlmsg_end(msg
, hdr
) < 0) {
3417 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3421 genlmsg_cancel(msg
, hdr
);
3425 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
3426 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3428 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3429 NL80211_CMD_AUTHENTICATE
);
3432 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
3433 struct net_device
*netdev
, const u8
*buf
,
3436 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
, NL80211_CMD_ASSOCIATE
);
3439 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
3440 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3442 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3443 NL80211_CMD_DEAUTHENTICATE
);
3446 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
3447 struct net_device
*netdev
, const u8
*buf
,
3450 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3451 NL80211_CMD_DISASSOCIATE
);
3454 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
3455 struct net_device
*netdev
, const u8
*addr
,
3456 enum nl80211_key_type key_type
, int key_id
,
3459 struct sk_buff
*msg
;
3462 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3466 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
3472 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3473 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3475 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
3476 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
3477 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
3479 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
3481 if (genlmsg_end(msg
, hdr
) < 0) {
3486 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
3490 genlmsg_cancel(msg
, hdr
);
3494 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
3495 struct ieee80211_channel
*channel_before
,
3496 struct ieee80211_channel
*channel_after
)
3498 struct sk_buff
*msg
;
3500 struct nlattr
*nl_freq
;
3502 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
3506 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
3513 * Since we are applying the beacon hint to a wiphy we know its
3514 * wiphy_idx is valid
3516 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
3519 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
3521 goto nla_put_failure
;
3522 if (nl80211_msg_put_channel(msg
, channel_before
))
3523 goto nla_put_failure
;
3524 nla_nest_end(msg
, nl_freq
);
3527 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
3529 goto nla_put_failure
;
3530 if (nl80211_msg_put_channel(msg
, channel_after
))
3531 goto nla_put_failure
;
3532 nla_nest_end(msg
, nl_freq
);
3534 if (genlmsg_end(msg
, hdr
) < 0) {
3539 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_ATOMIC
);
3544 genlmsg_cancel(msg
, hdr
);
3548 /* initialisation/exit functions */
3550 int nl80211_init(void)
3554 err
= genl_register_family(&nl80211_fam
);
3558 for (i
= 0; i
< ARRAY_SIZE(nl80211_ops
); i
++) {
3559 err
= genl_register_ops(&nl80211_fam
, &nl80211_ops
[i
]);
3564 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
3568 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
3572 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
3576 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
3582 genl_unregister_family(&nl80211_fam
);
3586 void nl80211_exit(void)
3588 genl_unregister_family(&nl80211_fam
);