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 /* netlink command implementations */
161 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
162 struct cfg80211_registered_device
*dev
)
165 struct nlattr
*nl_bands
, *nl_band
;
166 struct nlattr
*nl_freqs
, *nl_freq
;
167 struct nlattr
*nl_rates
, *nl_rate
;
168 struct nlattr
*nl_modes
;
169 struct nlattr
*nl_cmds
;
170 enum ieee80211_band band
;
171 struct ieee80211_channel
*chan
;
172 struct ieee80211_rate
*rate
;
174 u16 ifmodes
= dev
->wiphy
.interface_modes
;
176 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
180 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
181 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
182 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
183 dev
->wiphy
.max_scan_ssids
);
185 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
187 goto nla_put_failure
;
192 NLA_PUT_FLAG(msg
, i
);
197 nla_nest_end(msg
, nl_modes
);
199 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
201 goto nla_put_failure
;
203 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
204 if (!dev
->wiphy
.bands
[band
])
207 nl_band
= nla_nest_start(msg
, band
);
209 goto nla_put_failure
;
212 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
213 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
214 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
215 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
216 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
217 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
218 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
219 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
220 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
221 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
224 /* add frequencies */
225 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
227 goto nla_put_failure
;
229 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
230 nl_freq
= nla_nest_start(msg
, i
);
232 goto nla_put_failure
;
234 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
235 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
238 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
239 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
240 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
241 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
242 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
243 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
244 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
245 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
247 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
248 DBM_TO_MBM(chan
->max_power
));
250 nla_nest_end(msg
, nl_freq
);
253 nla_nest_end(msg
, nl_freqs
);
256 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
258 goto nla_put_failure
;
260 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
261 nl_rate
= nla_nest_start(msg
, i
);
263 goto nla_put_failure
;
265 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
266 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
268 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
270 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
272 nla_nest_end(msg
, nl_rate
);
275 nla_nest_end(msg
, nl_rates
);
277 nla_nest_end(msg
, nl_band
);
279 nla_nest_end(msg
, nl_bands
);
281 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
283 goto nla_put_failure
;
288 if (dev->ops->op) { \
290 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
294 CMD(add_virtual_intf
, NEW_INTERFACE
);
295 CMD(change_virtual_intf
, SET_INTERFACE
);
296 CMD(add_key
, NEW_KEY
);
297 CMD(add_beacon
, NEW_BEACON
);
298 CMD(add_station
, NEW_STATION
);
299 CMD(add_mpath
, NEW_MPATH
);
300 CMD(set_mesh_params
, SET_MESH_PARAMS
);
301 CMD(change_bss
, SET_BSS
);
302 CMD(auth
, AUTHENTICATE
);
303 CMD(assoc
, ASSOCIATE
);
304 CMD(deauth
, DEAUTHENTICATE
);
305 CMD(disassoc
, DISASSOCIATE
);
308 nla_nest_end(msg
, nl_cmds
);
310 return genlmsg_end(msg
, hdr
);
313 genlmsg_cancel(msg
, hdr
);
317 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
320 int start
= cb
->args
[0];
321 struct cfg80211_registered_device
*dev
;
323 mutex_lock(&cfg80211_mutex
);
324 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
327 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
328 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
334 mutex_unlock(&cfg80211_mutex
);
341 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
344 struct cfg80211_registered_device
*dev
;
346 dev
= cfg80211_get_dev_from_info(info
);
350 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
354 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
357 cfg80211_put_dev(dev
);
359 return genlmsg_unicast(msg
, info
->snd_pid
);
364 cfg80211_put_dev(dev
);
368 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
369 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
370 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
371 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
372 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
373 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
376 static int parse_txq_params(struct nlattr
*tb
[],
377 struct ieee80211_txq_params
*txq_params
)
379 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
380 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
381 !tb
[NL80211_TXQ_ATTR_AIFS
])
384 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
385 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
386 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
387 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
388 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
393 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
395 struct cfg80211_registered_device
*rdev
;
396 int result
= 0, rem_txq_params
= 0;
397 struct nlattr
*nl_txq_params
;
401 mutex_lock(&cfg80211_mutex
);
403 rdev
= __cfg80211_drv_from_info(info
);
405 result
= PTR_ERR(rdev
);
409 mutex_lock(&rdev
->mtx
);
411 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
412 result
= cfg80211_dev_rename(
413 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
415 mutex_unlock(&cfg80211_mutex
);
420 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
421 struct ieee80211_txq_params txq_params
;
422 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
424 if (!rdev
->ops
->set_txq_params
) {
425 result
= -EOPNOTSUPP
;
429 nla_for_each_nested(nl_txq_params
,
430 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
432 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
433 nla_data(nl_txq_params
),
434 nla_len(nl_txq_params
),
436 result
= parse_txq_params(tb
, &txq_params
);
440 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
447 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
448 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
449 struct ieee80211_channel
*chan
;
450 struct ieee80211_sta_ht_cap
*ht_cap
;
453 if (!rdev
->ops
->set_channel
) {
454 result
= -EOPNOTSUPP
;
460 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
461 channel_type
= nla_get_u32(info
->attrs
[
462 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
463 if (channel_type
!= NL80211_CHAN_NO_HT
&&
464 channel_type
!= NL80211_CHAN_HT20
&&
465 channel_type
!= NL80211_CHAN_HT40PLUS
&&
466 channel_type
!= NL80211_CHAN_HT40MINUS
)
470 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
471 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
473 /* Primary channel not allowed */
474 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
477 if (channel_type
== NL80211_CHAN_HT40MINUS
)
478 sec_freq
= freq
- 20;
479 else if (channel_type
== NL80211_CHAN_HT40PLUS
)
480 sec_freq
= freq
+ 20;
484 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
486 /* no HT capabilities */
487 if (channel_type
!= NL80211_CHAN_NO_HT
&&
488 !ht_cap
->ht_supported
)
492 struct ieee80211_channel
*schan
;
494 /* no 40 MHz capabilities */
495 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
496 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
499 schan
= ieee80211_get_channel(&rdev
->wiphy
, sec_freq
);
501 /* Secondary channel not allowed */
502 if (!schan
|| schan
->flags
& IEEE80211_CHAN_DISABLED
)
506 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
514 mutex_unlock(&rdev
->mtx
);
521 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
522 struct net_device
*dev
)
526 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
530 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
531 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
532 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
533 return genlmsg_end(msg
, hdr
);
536 genlmsg_cancel(msg
, hdr
);
540 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
544 int wp_start
= cb
->args
[0];
545 int if_start
= cb
->args
[1];
546 struct cfg80211_registered_device
*dev
;
547 struct wireless_dev
*wdev
;
549 mutex_lock(&cfg80211_mutex
);
550 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
551 if (wp_idx
< wp_start
) {
557 mutex_lock(&dev
->devlist_mtx
);
558 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
559 if (if_idx
< if_start
) {
563 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
564 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
566 mutex_unlock(&dev
->devlist_mtx
);
571 mutex_unlock(&dev
->devlist_mtx
);
576 mutex_unlock(&cfg80211_mutex
);
578 cb
->args
[0] = wp_idx
;
579 cb
->args
[1] = if_idx
;
584 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
587 struct cfg80211_registered_device
*dev
;
588 struct net_device
*netdev
;
591 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &dev
, &netdev
);
595 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
599 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0, netdev
) < 0)
603 cfg80211_put_dev(dev
);
605 return genlmsg_unicast(msg
, info
->snd_pid
);
611 cfg80211_put_dev(dev
);
615 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
616 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
617 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
618 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
619 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
620 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
623 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
625 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
633 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
634 nla
, mntr_flags_policy
))
637 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
639 *mntrflags
|= (1<<flag
);
644 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
646 struct cfg80211_registered_device
*drv
;
647 struct vif_params params
;
649 enum nl80211_iftype type
;
650 struct net_device
*dev
;
651 u32 _flags
, *flags
= NULL
;
654 memset(¶ms
, 0, sizeof(params
));
658 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
662 ifindex
= dev
->ifindex
;
663 type
= dev
->ieee80211_ptr
->iftype
;
666 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
667 enum nl80211_iftype ntype
;
669 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
673 if (type
> NL80211_IFTYPE_MAX
) {
679 if (!drv
->ops
->change_virtual_intf
||
680 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
685 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
686 if (type
!= NL80211_IFTYPE_MESH_POINT
) {
690 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
691 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
695 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
696 if (type
!= NL80211_IFTYPE_MONITOR
) {
700 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
710 err
= drv
->ops
->change_virtual_intf(&drv
->wiphy
, ifindex
,
711 type
, flags
, ¶ms
);
715 dev
= __dev_get_by_index(&init_net
, ifindex
);
716 WARN_ON(!dev
|| (!err
&& dev
->ieee80211_ptr
->iftype
!= type
));
719 cfg80211_put_dev(drv
);
725 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
727 struct cfg80211_registered_device
*drv
;
728 struct vif_params params
;
730 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
733 memset(¶ms
, 0, sizeof(params
));
735 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
738 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
739 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
740 if (type
> NL80211_IFTYPE_MAX
)
746 drv
= cfg80211_get_dev_from_info(info
);
752 if (!drv
->ops
->add_virtual_intf
||
753 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
758 if (type
== NL80211_IFTYPE_MESH_POINT
&&
759 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
760 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
761 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
764 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
765 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
767 err
= drv
->ops
->add_virtual_intf(&drv
->wiphy
,
768 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
769 type
, err
? NULL
: &flags
, ¶ms
);
772 cfg80211_put_dev(drv
);
778 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
780 struct cfg80211_registered_device
*drv
;
782 struct net_device
*dev
;
786 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
789 ifindex
= dev
->ifindex
;
792 if (!drv
->ops
->del_virtual_intf
) {
797 err
= drv
->ops
->del_virtual_intf(&drv
->wiphy
, ifindex
);
800 cfg80211_put_dev(drv
);
806 struct get_key_cookie
{
811 static void get_key_callback(void *c
, struct key_params
*params
)
813 struct get_key_cookie
*cookie
= c
;
816 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
817 params
->key_len
, params
->key
);
820 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
821 params
->seq_len
, params
->seq
);
824 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
832 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
834 struct cfg80211_registered_device
*drv
;
836 struct net_device
*dev
;
839 struct get_key_cookie cookie
= {
845 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
846 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
851 if (info
->attrs
[NL80211_ATTR_MAC
])
852 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
856 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
860 if (!drv
->ops
->get_key
) {
865 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
871 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
872 NL80211_CMD_NEW_KEY
);
881 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
882 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
884 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
886 err
= drv
->ops
->get_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
,
887 &cookie
, get_key_callback
);
893 goto nla_put_failure
;
895 genlmsg_end(msg
, hdr
);
896 err
= genlmsg_unicast(msg
, info
->snd_pid
);
903 cfg80211_put_dev(drv
);
911 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
913 struct cfg80211_registered_device
*drv
;
915 struct net_device
*dev
;
917 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
920 if (!info
->attrs
[NL80211_ATTR_KEY_IDX
])
923 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
925 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
]) {
926 if (key_idx
< 4 || key_idx
> 5)
928 } else if (key_idx
> 3)
931 /* currently only support setting default key */
932 if (!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
] &&
933 !info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
])
938 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
942 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT
])
943 func
= drv
->ops
->set_default_key
;
945 func
= drv
->ops
->set_default_mgmt_key
;
952 err
= func(&drv
->wiphy
, dev
, key_idx
);
955 cfg80211_put_dev(drv
);
964 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
966 struct cfg80211_registered_device
*drv
;
968 struct net_device
*dev
;
969 struct key_params params
;
973 memset(¶ms
, 0, sizeof(params
));
975 if (!info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
978 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
979 params
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
980 params
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
983 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
984 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
986 params
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
988 if (info
->attrs
[NL80211_ATTR_MAC
])
989 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
995 * Disallow pairwise keys with non-zero index unless it's WEP
996 * (because current deployments use pairwise WEP keys with
997 * non-zero indizes but 802.11i clearly specifies to use zero)
999 if (mac_addr
&& key_idx
&&
1000 params
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
1001 params
.cipher
!= WLAN_CIPHER_SUITE_WEP104
)
1004 /* TODO: add definitions for the lengths to linux/ieee80211.h */
1005 switch (params
.cipher
) {
1006 case WLAN_CIPHER_SUITE_WEP40
:
1007 if (params
.key_len
!= 5)
1010 case WLAN_CIPHER_SUITE_TKIP
:
1011 if (params
.key_len
!= 32)
1014 case WLAN_CIPHER_SUITE_CCMP
:
1015 if (params
.key_len
!= 16)
1018 case WLAN_CIPHER_SUITE_WEP104
:
1019 if (params
.key_len
!= 13)
1022 case WLAN_CIPHER_SUITE_AES_CMAC
:
1023 if (params
.key_len
!= 16)
1032 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1036 if (!drv
->ops
->add_key
) {
1041 err
= drv
->ops
->add_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
, ¶ms
);
1044 cfg80211_put_dev(drv
);
1052 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1054 struct cfg80211_registered_device
*drv
;
1056 struct net_device
*dev
;
1058 u8
*mac_addr
= NULL
;
1060 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1061 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1066 if (info
->attrs
[NL80211_ATTR_MAC
])
1067 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1071 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1075 if (!drv
->ops
->del_key
) {
1080 err
= drv
->ops
->del_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
);
1083 cfg80211_put_dev(drv
);
1092 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1094 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1095 struct beacon_parameters
*info
);
1096 struct cfg80211_registered_device
*drv
;
1098 struct net_device
*dev
;
1099 struct beacon_parameters params
;
1102 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1107 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1111 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1116 switch (info
->genlhdr
->cmd
) {
1117 case NL80211_CMD_NEW_BEACON
:
1118 /* these are required for NEW_BEACON */
1119 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1120 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1121 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1126 call
= drv
->ops
->add_beacon
;
1128 case NL80211_CMD_SET_BEACON
:
1129 call
= drv
->ops
->set_beacon
;
1142 memset(¶ms
, 0, sizeof(params
));
1144 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1146 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1150 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1151 params
.dtim_period
=
1152 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1156 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1157 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1159 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1163 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1164 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1166 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1175 err
= call(&drv
->wiphy
, dev
, ¶ms
);
1178 cfg80211_put_dev(drv
);
1186 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1188 struct cfg80211_registered_device
*drv
;
1190 struct net_device
*dev
;
1194 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1198 if (!drv
->ops
->del_beacon
) {
1203 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1207 err
= drv
->ops
->del_beacon(&drv
->wiphy
, dev
);
1210 cfg80211_put_dev(drv
);
1218 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1219 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1220 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1221 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1224 static int parse_station_flags(struct nlattr
*nla
, u32
*staflags
)
1226 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1234 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1235 nla
, sta_flags_policy
))
1238 *staflags
= STATION_FLAG_CHANGED
;
1240 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1242 *staflags
|= (1<<flag
);
1247 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1249 int modulation
, streams
, bitrate
;
1251 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1252 return rate
->legacy
;
1254 /* the formula below does only work for MCS values smaller than 32 */
1255 if (rate
->mcs
>= 32)
1258 modulation
= rate
->mcs
& 7;
1259 streams
= (rate
->mcs
>> 3) + 1;
1261 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1265 bitrate
*= (modulation
+ 1);
1266 else if (modulation
== 4)
1267 bitrate
*= (modulation
+ 2);
1269 bitrate
*= (modulation
+ 3);
1273 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1274 bitrate
= (bitrate
/ 9) * 10;
1276 /* do NOT round down here */
1277 return (bitrate
+ 50000) / 100000;
1280 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1281 int flags
, struct net_device
*dev
,
1282 u8
*mac_addr
, struct station_info
*sinfo
)
1285 struct nlattr
*sinfoattr
, *txrate
;
1288 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1292 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1293 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1295 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1297 goto nla_put_failure
;
1298 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1299 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1300 sinfo
->inactive_time
);
1301 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1302 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1304 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1305 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1307 if (sinfo
->filled
& STATION_INFO_LLID
)
1308 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1310 if (sinfo
->filled
& STATION_INFO_PLID
)
1311 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1313 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1314 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1315 sinfo
->plink_state
);
1316 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1317 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1319 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1320 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1322 goto nla_put_failure
;
1324 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1325 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1327 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1329 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1330 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1332 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1333 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1334 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1335 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1337 nla_nest_end(msg
, txrate
);
1339 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1340 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1342 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1343 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1345 nla_nest_end(msg
, sinfoattr
);
1347 return genlmsg_end(msg
, hdr
);
1350 genlmsg_cancel(msg
, hdr
);
1354 static int nl80211_dump_station(struct sk_buff
*skb
,
1355 struct netlink_callback
*cb
)
1357 struct station_info sinfo
;
1358 struct cfg80211_registered_device
*dev
;
1359 struct net_device
*netdev
;
1360 u8 mac_addr
[ETH_ALEN
];
1361 int ifidx
= cb
->args
[0];
1362 int sta_idx
= cb
->args
[1];
1366 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1367 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1372 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1375 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1382 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1388 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1394 if (!dev
->ops
->dump_station
) {
1400 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1407 if (nl80211_send_station(skb
,
1408 NETLINK_CB(cb
->skb
).pid
,
1409 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1419 cb
->args
[1] = sta_idx
;
1422 cfg80211_put_dev(dev
);
1429 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1431 struct cfg80211_registered_device
*drv
;
1433 struct net_device
*dev
;
1434 struct station_info sinfo
;
1435 struct sk_buff
*msg
;
1436 u8
*mac_addr
= NULL
;
1438 memset(&sinfo
, 0, sizeof(sinfo
));
1440 if (!info
->attrs
[NL80211_ATTR_MAC
])
1443 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1447 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1451 if (!drv
->ops
->get_station
) {
1456 err
= drv
->ops
->get_station(&drv
->wiphy
, dev
, mac_addr
, &sinfo
);
1460 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1464 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1465 dev
, mac_addr
, &sinfo
) < 0)
1468 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1474 cfg80211_put_dev(drv
);
1483 * Get vlan interface making sure it is on the right wiphy.
1485 static int get_vlan(struct nlattr
*vlanattr
,
1486 struct cfg80211_registered_device
*rdev
,
1487 struct net_device
**vlan
)
1492 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1495 if (!(*vlan
)->ieee80211_ptr
)
1497 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1503 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1505 struct cfg80211_registered_device
*drv
;
1507 struct net_device
*dev
;
1508 struct station_parameters params
;
1509 u8
*mac_addr
= NULL
;
1511 memset(¶ms
, 0, sizeof(params
));
1513 params
.listen_interval
= -1;
1515 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1518 if (!info
->attrs
[NL80211_ATTR_MAC
])
1521 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1523 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1524 params
.supported_rates
=
1525 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1526 params
.supported_rates_len
=
1527 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1530 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1531 params
.listen_interval
=
1532 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1534 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1536 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1538 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1539 ¶ms
.station_flags
))
1542 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1543 params
.plink_action
=
1544 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1548 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1552 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1556 if (!drv
->ops
->change_station
) {
1561 err
= drv
->ops
->change_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1565 dev_put(params
.vlan
);
1566 cfg80211_put_dev(drv
);
1574 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1576 struct cfg80211_registered_device
*drv
;
1578 struct net_device
*dev
;
1579 struct station_parameters params
;
1580 u8
*mac_addr
= NULL
;
1582 memset(¶ms
, 0, sizeof(params
));
1584 if (!info
->attrs
[NL80211_ATTR_MAC
])
1587 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
1590 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1593 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1596 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1597 params
.supported_rates
=
1598 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1599 params
.supported_rates_len
=
1600 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1601 params
.listen_interval
=
1602 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1603 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1604 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1606 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1608 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1609 ¶ms
.station_flags
))
1614 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1618 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1622 if (!drv
->ops
->add_station
) {
1627 if (!netif_running(dev
)) {
1632 err
= drv
->ops
->add_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1636 dev_put(params
.vlan
);
1637 cfg80211_put_dev(drv
);
1645 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
1647 struct cfg80211_registered_device
*drv
;
1649 struct net_device
*dev
;
1650 u8
*mac_addr
= NULL
;
1652 if (info
->attrs
[NL80211_ATTR_MAC
])
1653 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1657 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1661 if (!drv
->ops
->del_station
) {
1666 err
= drv
->ops
->del_station(&drv
->wiphy
, dev
, mac_addr
);
1669 cfg80211_put_dev(drv
);
1677 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1678 int flags
, struct net_device
*dev
,
1679 u8
*dst
, u8
*next_hop
,
1680 struct mpath_info
*pinfo
)
1683 struct nlattr
*pinfoattr
;
1685 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1689 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1690 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
1691 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
1693 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
1695 goto nla_put_failure
;
1696 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
1697 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
1699 if (pinfo
->filled
& MPATH_INFO_DSN
)
1700 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
1702 if (pinfo
->filled
& MPATH_INFO_METRIC
)
1703 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
1705 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
1706 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
1708 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
1709 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
1711 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
1712 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
1713 pinfo
->discovery_timeout
);
1714 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
1715 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
1716 pinfo
->discovery_retries
);
1718 nla_nest_end(msg
, pinfoattr
);
1720 return genlmsg_end(msg
, hdr
);
1723 genlmsg_cancel(msg
, hdr
);
1727 static int nl80211_dump_mpath(struct sk_buff
*skb
,
1728 struct netlink_callback
*cb
)
1730 struct mpath_info pinfo
;
1731 struct cfg80211_registered_device
*dev
;
1732 struct net_device
*netdev
;
1734 u8 next_hop
[ETH_ALEN
];
1735 int ifidx
= cb
->args
[0];
1736 int path_idx
= cb
->args
[1];
1740 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1741 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1746 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1749 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1756 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1762 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1768 if (!dev
->ops
->dump_mpath
) {
1773 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1779 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
1780 dst
, next_hop
, &pinfo
);
1786 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
1787 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1788 netdev
, dst
, next_hop
,
1797 cb
->args
[1] = path_idx
;
1800 cfg80211_put_dev(dev
);
1807 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1809 struct cfg80211_registered_device
*drv
;
1811 struct net_device
*dev
;
1812 struct mpath_info pinfo
;
1813 struct sk_buff
*msg
;
1815 u8 next_hop
[ETH_ALEN
];
1817 memset(&pinfo
, 0, sizeof(pinfo
));
1819 if (!info
->attrs
[NL80211_ATTR_MAC
])
1822 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1826 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1830 if (!drv
->ops
->get_mpath
) {
1835 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1840 err
= drv
->ops
->get_mpath(&drv
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
1844 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1848 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1849 dev
, dst
, next_hop
, &pinfo
) < 0)
1852 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1858 cfg80211_put_dev(drv
);
1866 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1868 struct cfg80211_registered_device
*drv
;
1870 struct net_device
*dev
;
1872 u8
*next_hop
= NULL
;
1874 if (!info
->attrs
[NL80211_ATTR_MAC
])
1877 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
1880 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1881 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
1885 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1889 if (!drv
->ops
->change_mpath
) {
1894 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1899 if (!netif_running(dev
)) {
1904 err
= drv
->ops
->change_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
1907 cfg80211_put_dev(drv
);
1914 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1916 struct cfg80211_registered_device
*drv
;
1918 struct net_device
*dev
;
1920 u8
*next_hop
= NULL
;
1922 if (!info
->attrs
[NL80211_ATTR_MAC
])
1925 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
1928 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1929 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
1933 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1937 if (!drv
->ops
->add_mpath
) {
1942 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1947 if (!netif_running(dev
)) {
1952 err
= drv
->ops
->add_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
1955 cfg80211_put_dev(drv
);
1963 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1965 struct cfg80211_registered_device
*drv
;
1967 struct net_device
*dev
;
1970 if (info
->attrs
[NL80211_ATTR_MAC
])
1971 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1975 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1979 if (!drv
->ops
->del_mpath
) {
1984 err
= drv
->ops
->del_mpath(&drv
->wiphy
, dev
, dst
);
1987 cfg80211_put_dev(drv
);
1995 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
1997 struct cfg80211_registered_device
*drv
;
1999 struct net_device
*dev
;
2000 struct bss_parameters params
;
2002 memset(¶ms
, 0, sizeof(params
));
2003 /* default to not changing parameters */
2004 params
.use_cts_prot
= -1;
2005 params
.use_short_preamble
= -1;
2006 params
.use_short_slot_time
= -1;
2008 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2009 params
.use_cts_prot
=
2010 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2011 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2012 params
.use_short_preamble
=
2013 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2014 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2015 params
.use_short_slot_time
=
2016 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2017 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2018 params
.basic_rates
=
2019 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2020 params
.basic_rates_len
=
2021 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2026 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2030 if (!drv
->ops
->change_bss
) {
2035 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2040 err
= drv
->ops
->change_bss(&drv
->wiphy
, dev
, ¶ms
);
2043 cfg80211_put_dev(drv
);
2051 static const struct nla_policy
2052 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2053 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2054 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2055 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2056 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2057 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2058 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2061 static int parse_reg_rule(struct nlattr
*tb
[],
2062 struct ieee80211_reg_rule
*reg_rule
)
2064 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2065 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2067 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2069 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2071 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2073 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2075 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2078 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2080 freq_range
->start_freq_khz
=
2081 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2082 freq_range
->end_freq_khz
=
2083 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2084 freq_range
->max_bandwidth_khz
=
2085 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2087 power_rule
->max_eirp
=
2088 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2090 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2091 power_rule
->max_antenna_gain
=
2092 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2097 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2103 * You should only get this when cfg80211 hasn't yet initialized
2104 * completely when built-in to the kernel right between the time
2105 * window between nl80211_init() and regulatory_init(), if that is
2108 mutex_lock(&cfg80211_mutex
);
2109 if (unlikely(!cfg80211_regdomain
)) {
2110 mutex_unlock(&cfg80211_mutex
);
2111 return -EINPROGRESS
;
2113 mutex_unlock(&cfg80211_mutex
);
2115 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2118 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2120 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2121 /* We ignore world regdom requests with the old regdom setup */
2122 if (is_world_regdom(data
))
2126 r
= regulatory_hint_user(data
);
2131 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2132 struct genl_info
*info
)
2134 struct cfg80211_registered_device
*drv
;
2135 struct mesh_config cur_params
;
2137 struct net_device
*dev
;
2139 struct nlattr
*pinfoattr
;
2140 struct sk_buff
*msg
;
2144 /* Look up our device */
2145 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2149 if (!drv
->ops
->get_mesh_params
) {
2154 /* Get the mesh params */
2155 err
= drv
->ops
->get_mesh_params(&drv
->wiphy
, dev
, &cur_params
);
2159 /* Draw up a netlink message to send back */
2160 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2165 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2166 NL80211_CMD_GET_MESH_PARAMS
);
2168 goto nla_put_failure
;
2169 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2171 goto nla_put_failure
;
2172 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2173 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2174 cur_params
.dot11MeshRetryTimeout
);
2175 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2176 cur_params
.dot11MeshConfirmTimeout
);
2177 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2178 cur_params
.dot11MeshHoldingTimeout
);
2179 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2180 cur_params
.dot11MeshMaxPeerLinks
);
2181 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2182 cur_params
.dot11MeshMaxRetries
);
2183 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2184 cur_params
.dot11MeshTTL
);
2185 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2186 cur_params
.auto_open_plinks
);
2187 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2188 cur_params
.dot11MeshHWMPmaxPREQretries
);
2189 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2190 cur_params
.path_refresh_time
);
2191 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2192 cur_params
.min_discovery_timeout
);
2193 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2194 cur_params
.dot11MeshHWMPactivePathTimeout
);
2195 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2196 cur_params
.dot11MeshHWMPpreqMinInterval
);
2197 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2198 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2199 nla_nest_end(msg
, pinfoattr
);
2200 genlmsg_end(msg
, hdr
);
2201 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2205 genlmsg_cancel(msg
, hdr
);
2209 cfg80211_put_dev(drv
);
2217 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2219 if (table[attr_num]) {\
2220 cfg.param = nla_fn(table[attr_num]); \
2221 mask |= (1 << (attr_num - 1)); \
2225 static struct nla_policy
2226 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2227 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2228 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2229 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2230 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2231 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2232 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2233 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2235 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2236 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2237 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2238 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2239 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2240 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2243 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2247 struct cfg80211_registered_device
*drv
;
2248 struct net_device
*dev
;
2249 struct mesh_config cfg
;
2250 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2251 struct nlattr
*parent_attr
;
2253 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2256 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2257 parent_attr
, nl80211_meshconf_params_policy
))
2262 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2266 if (!drv
->ops
->set_mesh_params
) {
2271 /* This makes sure that there aren't more than 32 mesh config
2272 * parameters (otherwise our bitfield scheme would not work.) */
2273 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2275 /* Fill in the params struct */
2277 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2278 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2279 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2280 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2281 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2282 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2283 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2284 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2285 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2286 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2287 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2288 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2289 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2290 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2291 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2292 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2294 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2295 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2296 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2297 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2299 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2300 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2302 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2303 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2305 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2306 dot11MeshHWMPnetDiameterTraversalTime
,
2307 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2311 err
= drv
->ops
->set_mesh_params(&drv
->wiphy
, dev
, &cfg
, mask
);
2315 cfg80211_put_dev(drv
);
2323 #undef FILL_IN_MESH_PARAM_IF_SET
2325 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2327 struct sk_buff
*msg
;
2329 struct nlattr
*nl_reg_rules
;
2333 mutex_lock(&cfg80211_mutex
);
2335 if (!cfg80211_regdomain
)
2338 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2344 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2345 NL80211_CMD_GET_REG
);
2347 goto nla_put_failure
;
2349 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2350 cfg80211_regdomain
->alpha2
);
2352 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2354 goto nla_put_failure
;
2356 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2357 struct nlattr
*nl_reg_rule
;
2358 const struct ieee80211_reg_rule
*reg_rule
;
2359 const struct ieee80211_freq_range
*freq_range
;
2360 const struct ieee80211_power_rule
*power_rule
;
2362 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2363 freq_range
= ®_rule
->freq_range
;
2364 power_rule
= ®_rule
->power_rule
;
2366 nl_reg_rule
= nla_nest_start(msg
, i
);
2368 goto nla_put_failure
;
2370 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2372 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2373 freq_range
->start_freq_khz
);
2374 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2375 freq_range
->end_freq_khz
);
2376 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2377 freq_range
->max_bandwidth_khz
);
2378 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2379 power_rule
->max_antenna_gain
);
2380 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2381 power_rule
->max_eirp
);
2383 nla_nest_end(msg
, nl_reg_rule
);
2386 nla_nest_end(msg
, nl_reg_rules
);
2388 genlmsg_end(msg
, hdr
);
2389 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2393 genlmsg_cancel(msg
, hdr
);
2396 mutex_unlock(&cfg80211_mutex
);
2400 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2402 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2403 struct nlattr
*nl_reg_rule
;
2404 char *alpha2
= NULL
;
2405 int rem_reg_rules
= 0, r
= 0;
2406 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2407 struct ieee80211_regdomain
*rd
= NULL
;
2409 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2412 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2415 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2417 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2420 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2424 if (!reg_is_valid_request(alpha2
))
2427 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2428 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2430 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2434 rd
->n_reg_rules
= num_rules
;
2435 rd
->alpha2
[0] = alpha2
[0];
2436 rd
->alpha2
[1] = alpha2
[1];
2438 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2440 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2441 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2443 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2449 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
)
2453 BUG_ON(rule_idx
!= num_rules
);
2455 mutex_lock(&cfg80211_mutex
);
2457 mutex_unlock(&cfg80211_mutex
);
2465 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2467 struct cfg80211_registered_device
*drv
;
2468 struct net_device
*dev
;
2469 struct cfg80211_scan_request
*request
;
2470 struct cfg80211_ssid
*ssid
;
2471 struct ieee80211_channel
*channel
;
2472 struct nlattr
*attr
;
2473 struct wiphy
*wiphy
;
2474 int err
, tmp
, n_ssids
= 0, n_channels
= 0, i
;
2475 enum ieee80211_band band
;
2478 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2483 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2487 wiphy
= &drv
->wiphy
;
2489 if (!drv
->ops
->scan
) {
2494 if (!netif_running(dev
)) {
2499 if (drv
->scan_req
) {
2504 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2505 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
)
2512 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2513 if (wiphy
->bands
[band
])
2514 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2517 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2518 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2521 if (n_ssids
> wiphy
->max_scan_ssids
) {
2526 if (info
->attrs
[NL80211_ATTR_IE
])
2527 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2531 request
= kzalloc(sizeof(*request
)
2532 + sizeof(*ssid
) * n_ssids
2533 + sizeof(channel
) * n_channels
2534 + ie_len
, GFP_KERNEL
);
2540 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
2541 request
->n_channels
= n_channels
;
2543 request
->ssids
= (void *)(request
->channels
+ n_channels
);
2544 request
->n_ssids
= n_ssids
;
2547 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
2549 request
->ie
= (void *)(request
->channels
+ n_channels
);
2552 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2553 /* user specified, bail out if channel not found */
2554 request
->n_channels
= n_channels
;
2556 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
2557 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
2558 if (!request
->channels
[i
]) {
2567 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2569 if (!wiphy
->bands
[band
])
2571 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2572 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2579 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
2580 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
2581 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2585 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
2586 request
->ssids
[i
].ssid_len
= nla_len(attr
);
2591 if (info
->attrs
[NL80211_ATTR_IE
]) {
2592 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2593 memcpy(request
->ie
, nla_data(info
->attrs
[NL80211_ATTR_IE
]),
2597 request
->ifidx
= dev
->ifindex
;
2598 request
->wiphy
= &drv
->wiphy
;
2600 drv
->scan_req
= request
;
2601 err
= drv
->ops
->scan(&drv
->wiphy
, dev
, request
);
2605 drv
->scan_req
= NULL
;
2609 cfg80211_put_dev(drv
);
2617 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
2618 struct cfg80211_registered_device
*rdev
,
2619 struct net_device
*dev
,
2620 struct cfg80211_bss
*res
)
2625 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
2626 NL80211_CMD_NEW_SCAN_RESULTS
);
2630 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
2631 rdev
->bss_generation
);
2632 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2634 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
2636 goto nla_put_failure
;
2637 if (!is_zero_ether_addr(res
->bssid
))
2638 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
2639 if (res
->information_elements
&& res
->len_information_elements
)
2640 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
2641 res
->len_information_elements
,
2642 res
->information_elements
);
2644 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
2645 if (res
->beacon_interval
)
2646 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
2647 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
2648 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
2650 switch (rdev
->wiphy
.signal_type
) {
2651 case CFG80211_SIGNAL_TYPE_MBM
:
2652 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
2654 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2655 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
2661 nla_nest_end(msg
, bss
);
2663 return genlmsg_end(msg
, hdr
);
2666 genlmsg_cancel(msg
, hdr
);
2670 static int nl80211_dump_scan(struct sk_buff
*skb
,
2671 struct netlink_callback
*cb
)
2673 struct cfg80211_registered_device
*dev
;
2674 struct net_device
*netdev
;
2675 struct cfg80211_internal_bss
*scan
;
2676 int ifidx
= cb
->args
[0];
2677 int start
= cb
->args
[1], idx
= 0;
2681 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2682 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2687 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2690 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2693 cb
->args
[0] = ifidx
;
2696 netdev
= dev_get_by_index(&init_net
, ifidx
);
2700 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2703 goto out_put_netdev
;
2706 spin_lock_bh(&dev
->bss_lock
);
2707 cfg80211_bss_expire(dev
);
2709 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
2712 if (nl80211_send_bss(skb
,
2713 NETLINK_CB(cb
->skb
).pid
,
2714 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2715 dev
, netdev
, &scan
->pub
) < 0) {
2722 spin_unlock_bh(&dev
->bss_lock
);
2726 cfg80211_put_dev(dev
);
2733 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
2735 return auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
||
2736 auth_type
== NL80211_AUTHTYPE_SHARED_KEY
||
2737 auth_type
== NL80211_AUTHTYPE_FT
||
2738 auth_type
== NL80211_AUTHTYPE_NETWORK_EAP
;
2741 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2743 struct cfg80211_registered_device
*drv
;
2744 struct net_device
*dev
;
2745 struct cfg80211_auth_request req
;
2746 struct wiphy
*wiphy
;
2749 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2752 if (!info
->attrs
[NL80211_ATTR_MAC
])
2755 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
2760 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2764 if (!drv
->ops
->auth
) {
2769 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2774 if (!netif_running(dev
)) {
2779 wiphy
= &drv
->wiphy
;
2780 memset(&req
, 0, sizeof(req
));
2782 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2784 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2785 req
.chan
= ieee80211_get_channel(
2787 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2794 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2795 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2796 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2799 if (info
->attrs
[NL80211_ATTR_IE
]) {
2800 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2801 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2804 req
.auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2805 if (!nl80211_valid_auth_type(req
.auth_type
)) {
2810 err
= drv
->ops
->auth(&drv
->wiphy
, dev
, &req
);
2813 cfg80211_put_dev(drv
);
2820 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
2822 struct cfg80211_registered_device
*drv
;
2823 struct net_device
*dev
;
2824 struct cfg80211_assoc_request req
;
2825 struct wiphy
*wiphy
;
2828 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2831 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
2832 !info
->attrs
[NL80211_ATTR_SSID
])
2837 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2841 if (!drv
->ops
->assoc
) {
2846 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2851 if (!netif_running(dev
)) {
2856 wiphy
= &drv
->wiphy
;
2857 memset(&req
, 0, sizeof(req
));
2859 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2861 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2862 req
.chan
= ieee80211_get_channel(
2864 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2871 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2872 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2874 if (info
->attrs
[NL80211_ATTR_IE
]) {
2875 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2876 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2879 err
= drv
->ops
->assoc(&drv
->wiphy
, dev
, &req
);
2882 cfg80211_put_dev(drv
);
2889 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2891 struct cfg80211_registered_device
*drv
;
2892 struct net_device
*dev
;
2893 struct cfg80211_deauth_request req
;
2894 struct wiphy
*wiphy
;
2897 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2900 if (!info
->attrs
[NL80211_ATTR_MAC
])
2903 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
2908 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2912 if (!drv
->ops
->deauth
) {
2917 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2922 if (!netif_running(dev
)) {
2927 wiphy
= &drv
->wiphy
;
2928 memset(&req
, 0, sizeof(req
));
2930 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2932 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
2933 if (req
.reason_code
== 0) {
2934 /* Reason Code 0 is reserved */
2939 if (info
->attrs
[NL80211_ATTR_IE
]) {
2940 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2941 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2944 err
= drv
->ops
->deauth(&drv
->wiphy
, dev
, &req
);
2947 cfg80211_put_dev(drv
);
2954 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
2956 struct cfg80211_registered_device
*drv
;
2957 struct net_device
*dev
;
2958 struct cfg80211_disassoc_request req
;
2959 struct wiphy
*wiphy
;
2962 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2965 if (!info
->attrs
[NL80211_ATTR_MAC
])
2968 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
2973 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2977 if (!drv
->ops
->disassoc
) {
2982 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2987 if (!netif_running(dev
)) {
2992 wiphy
= &drv
->wiphy
;
2993 memset(&req
, 0, sizeof(req
));
2995 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2997 req
.reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
2998 if (req
.reason_code
== 0) {
2999 /* Reason Code 0 is reserved */
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 err
= drv
->ops
->disassoc(&drv
->wiphy
, dev
, &req
);
3012 cfg80211_put_dev(drv
);
3019 static struct genl_ops nl80211_ops
[] = {
3021 .cmd
= NL80211_CMD_GET_WIPHY
,
3022 .doit
= nl80211_get_wiphy
,
3023 .dumpit
= nl80211_dump_wiphy
,
3024 .policy
= nl80211_policy
,
3025 /* can be retrieved by unprivileged users */
3028 .cmd
= NL80211_CMD_SET_WIPHY
,
3029 .doit
= nl80211_set_wiphy
,
3030 .policy
= nl80211_policy
,
3031 .flags
= GENL_ADMIN_PERM
,
3034 .cmd
= NL80211_CMD_GET_INTERFACE
,
3035 .doit
= nl80211_get_interface
,
3036 .dumpit
= nl80211_dump_interface
,
3037 .policy
= nl80211_policy
,
3038 /* can be retrieved by unprivileged users */
3041 .cmd
= NL80211_CMD_SET_INTERFACE
,
3042 .doit
= nl80211_set_interface
,
3043 .policy
= nl80211_policy
,
3044 .flags
= GENL_ADMIN_PERM
,
3047 .cmd
= NL80211_CMD_NEW_INTERFACE
,
3048 .doit
= nl80211_new_interface
,
3049 .policy
= nl80211_policy
,
3050 .flags
= GENL_ADMIN_PERM
,
3053 .cmd
= NL80211_CMD_DEL_INTERFACE
,
3054 .doit
= nl80211_del_interface
,
3055 .policy
= nl80211_policy
,
3056 .flags
= GENL_ADMIN_PERM
,
3059 .cmd
= NL80211_CMD_GET_KEY
,
3060 .doit
= nl80211_get_key
,
3061 .policy
= nl80211_policy
,
3062 .flags
= GENL_ADMIN_PERM
,
3065 .cmd
= NL80211_CMD_SET_KEY
,
3066 .doit
= nl80211_set_key
,
3067 .policy
= nl80211_policy
,
3068 .flags
= GENL_ADMIN_PERM
,
3071 .cmd
= NL80211_CMD_NEW_KEY
,
3072 .doit
= nl80211_new_key
,
3073 .policy
= nl80211_policy
,
3074 .flags
= GENL_ADMIN_PERM
,
3077 .cmd
= NL80211_CMD_DEL_KEY
,
3078 .doit
= nl80211_del_key
,
3079 .policy
= nl80211_policy
,
3080 .flags
= GENL_ADMIN_PERM
,
3083 .cmd
= NL80211_CMD_SET_BEACON
,
3084 .policy
= nl80211_policy
,
3085 .flags
= GENL_ADMIN_PERM
,
3086 .doit
= nl80211_addset_beacon
,
3089 .cmd
= NL80211_CMD_NEW_BEACON
,
3090 .policy
= nl80211_policy
,
3091 .flags
= GENL_ADMIN_PERM
,
3092 .doit
= nl80211_addset_beacon
,
3095 .cmd
= NL80211_CMD_DEL_BEACON
,
3096 .policy
= nl80211_policy
,
3097 .flags
= GENL_ADMIN_PERM
,
3098 .doit
= nl80211_del_beacon
,
3101 .cmd
= NL80211_CMD_GET_STATION
,
3102 .doit
= nl80211_get_station
,
3103 .dumpit
= nl80211_dump_station
,
3104 .policy
= nl80211_policy
,
3107 .cmd
= NL80211_CMD_SET_STATION
,
3108 .doit
= nl80211_set_station
,
3109 .policy
= nl80211_policy
,
3110 .flags
= GENL_ADMIN_PERM
,
3113 .cmd
= NL80211_CMD_NEW_STATION
,
3114 .doit
= nl80211_new_station
,
3115 .policy
= nl80211_policy
,
3116 .flags
= GENL_ADMIN_PERM
,
3119 .cmd
= NL80211_CMD_DEL_STATION
,
3120 .doit
= nl80211_del_station
,
3121 .policy
= nl80211_policy
,
3122 .flags
= GENL_ADMIN_PERM
,
3125 .cmd
= NL80211_CMD_GET_MPATH
,
3126 .doit
= nl80211_get_mpath
,
3127 .dumpit
= nl80211_dump_mpath
,
3128 .policy
= nl80211_policy
,
3129 .flags
= GENL_ADMIN_PERM
,
3132 .cmd
= NL80211_CMD_SET_MPATH
,
3133 .doit
= nl80211_set_mpath
,
3134 .policy
= nl80211_policy
,
3135 .flags
= GENL_ADMIN_PERM
,
3138 .cmd
= NL80211_CMD_NEW_MPATH
,
3139 .doit
= nl80211_new_mpath
,
3140 .policy
= nl80211_policy
,
3141 .flags
= GENL_ADMIN_PERM
,
3144 .cmd
= NL80211_CMD_DEL_MPATH
,
3145 .doit
= nl80211_del_mpath
,
3146 .policy
= nl80211_policy
,
3147 .flags
= GENL_ADMIN_PERM
,
3150 .cmd
= NL80211_CMD_SET_BSS
,
3151 .doit
= nl80211_set_bss
,
3152 .policy
= nl80211_policy
,
3153 .flags
= GENL_ADMIN_PERM
,
3156 .cmd
= NL80211_CMD_GET_REG
,
3157 .doit
= nl80211_get_reg
,
3158 .policy
= nl80211_policy
,
3159 /* can be retrieved by unprivileged users */
3162 .cmd
= NL80211_CMD_SET_REG
,
3163 .doit
= nl80211_set_reg
,
3164 .policy
= nl80211_policy
,
3165 .flags
= GENL_ADMIN_PERM
,
3168 .cmd
= NL80211_CMD_REQ_SET_REG
,
3169 .doit
= nl80211_req_set_reg
,
3170 .policy
= nl80211_policy
,
3171 .flags
= GENL_ADMIN_PERM
,
3174 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
3175 .doit
= nl80211_get_mesh_params
,
3176 .policy
= nl80211_policy
,
3177 /* can be retrieved by unprivileged users */
3180 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
3181 .doit
= nl80211_set_mesh_params
,
3182 .policy
= nl80211_policy
,
3183 .flags
= GENL_ADMIN_PERM
,
3186 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
3187 .doit
= nl80211_trigger_scan
,
3188 .policy
= nl80211_policy
,
3189 .flags
= GENL_ADMIN_PERM
,
3192 .cmd
= NL80211_CMD_GET_SCAN
,
3193 .policy
= nl80211_policy
,
3194 .dumpit
= nl80211_dump_scan
,
3197 .cmd
= NL80211_CMD_AUTHENTICATE
,
3198 .doit
= nl80211_authenticate
,
3199 .policy
= nl80211_policy
,
3200 .flags
= GENL_ADMIN_PERM
,
3203 .cmd
= NL80211_CMD_ASSOCIATE
,
3204 .doit
= nl80211_associate
,
3205 .policy
= nl80211_policy
,
3206 .flags
= GENL_ADMIN_PERM
,
3209 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
3210 .doit
= nl80211_deauthenticate
,
3211 .policy
= nl80211_policy
,
3212 .flags
= GENL_ADMIN_PERM
,
3215 .cmd
= NL80211_CMD_DISASSOCIATE
,
3216 .doit
= nl80211_disassociate
,
3217 .policy
= nl80211_policy
,
3218 .flags
= GENL_ADMIN_PERM
,
3221 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
3225 /* multicast groups */
3226 static struct genl_multicast_group nl80211_config_mcgrp
= {
3229 static struct genl_multicast_group nl80211_scan_mcgrp
= {
3232 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
3233 .name
= "regulatory",
3236 /* notification functions */
3238 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
3240 struct sk_buff
*msg
;
3242 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3246 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
3251 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
3254 static int nl80211_send_scan_donemsg(struct sk_buff
*msg
,
3255 struct cfg80211_registered_device
*rdev
,
3256 struct net_device
*netdev
,
3257 u32 pid
, u32 seq
, int flags
,
3262 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
3266 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3267 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3269 /* XXX: we should probably bounce back the request? */
3271 return genlmsg_end(msg
, hdr
);
3274 genlmsg_cancel(msg
, hdr
);
3278 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
3279 struct net_device
*netdev
)
3281 struct sk_buff
*msg
;
3283 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3287 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3288 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
3293 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3296 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
3297 struct net_device
*netdev
)
3299 struct sk_buff
*msg
;
3301 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3305 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3306 NL80211_CMD_SCAN_ABORTED
) < 0) {
3311 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3315 * This can happen on global regulatory changes or device specific settings
3316 * based on custom world regulatory domains.
3318 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
3320 struct sk_buff
*msg
;
3323 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3327 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
3333 /* Userspace can always count this one always being set */
3334 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
3336 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
3337 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3338 NL80211_REGDOM_TYPE_WORLD
);
3339 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
3340 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3341 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
3342 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
3344 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3345 NL80211_REGDOM_TYPE_INTERSECTION
);
3347 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3348 NL80211_REGDOM_TYPE_COUNTRY
);
3349 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
3352 if (wiphy_idx_valid(request
->wiphy_idx
))
3353 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
3355 if (genlmsg_end(msg
, hdr
) < 0) {
3360 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
3365 genlmsg_cancel(msg
, hdr
);
3369 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
3370 struct net_device
*netdev
,
3371 const u8
*buf
, size_t len
,
3372 enum nl80211_commands cmd
)
3374 struct sk_buff
*msg
;
3377 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_ATOMIC
);
3381 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3387 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3388 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3389 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
3391 if (genlmsg_end(msg
, hdr
) < 0) {
3396 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_ATOMIC
);
3400 genlmsg_cancel(msg
, hdr
);
3404 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
3405 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3407 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3408 NL80211_CMD_AUTHENTICATE
);
3411 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
3412 struct net_device
*netdev
, const u8
*buf
,
3415 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
, NL80211_CMD_ASSOCIATE
);
3418 void nl80211_send_rx_deauth(struct cfg80211_registered_device
*rdev
,
3419 struct net_device
*netdev
, const u8
*buf
,
3422 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3423 NL80211_CMD_DEAUTHENTICATE
);
3426 void nl80211_send_rx_disassoc(struct cfg80211_registered_device
*rdev
,
3427 struct net_device
*netdev
, const u8
*buf
,
3430 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3431 NL80211_CMD_DISASSOCIATE
);
3434 /* initialisation/exit functions */
3436 int nl80211_init(void)
3440 err
= genl_register_family(&nl80211_fam
);
3444 for (i
= 0; i
< ARRAY_SIZE(nl80211_ops
); i
++) {
3445 err
= genl_register_ops(&nl80211_fam
, &nl80211_ops
[i
]);
3450 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
3454 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
3458 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
3462 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
3468 genl_unregister_family(&nl80211_fam
);
3472 void nl80211_exit(void)
3474 genl_unregister_family(&nl80211_fam
);