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
},
121 /* message building helper */
122 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
125 /* since there is no private header just add the generic one */
126 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
129 /* netlink command implementations */
131 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
132 struct cfg80211_registered_device
*dev
)
135 struct nlattr
*nl_bands
, *nl_band
;
136 struct nlattr
*nl_freqs
, *nl_freq
;
137 struct nlattr
*nl_rates
, *nl_rate
;
138 struct nlattr
*nl_modes
;
139 struct nlattr
*nl_cmds
;
140 enum ieee80211_band band
;
141 struct ieee80211_channel
*chan
;
142 struct ieee80211_rate
*rate
;
144 u16 ifmodes
= dev
->wiphy
.interface_modes
;
146 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
150 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
151 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
152 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
153 dev
->wiphy
.max_scan_ssids
);
155 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
157 goto nla_put_failure
;
162 NLA_PUT_FLAG(msg
, i
);
167 nla_nest_end(msg
, nl_modes
);
169 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
171 goto nla_put_failure
;
173 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
174 if (!dev
->wiphy
.bands
[band
])
177 nl_band
= nla_nest_start(msg
, band
);
179 goto nla_put_failure
;
182 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
183 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
184 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
185 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
186 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
187 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
188 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
189 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
190 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
191 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
194 /* add frequencies */
195 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
197 goto nla_put_failure
;
199 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
200 nl_freq
= nla_nest_start(msg
, i
);
202 goto nla_put_failure
;
204 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
205 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
208 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
209 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
210 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
211 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
212 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
213 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
214 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
215 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
217 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
218 DBM_TO_MBM(chan
->max_power
));
220 nla_nest_end(msg
, nl_freq
);
223 nla_nest_end(msg
, nl_freqs
);
226 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
228 goto nla_put_failure
;
230 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
231 nl_rate
= nla_nest_start(msg
, i
);
233 goto nla_put_failure
;
235 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
236 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
238 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
240 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
242 nla_nest_end(msg
, nl_rate
);
245 nla_nest_end(msg
, nl_rates
);
247 nla_nest_end(msg
, nl_band
);
249 nla_nest_end(msg
, nl_bands
);
251 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
253 goto nla_put_failure
;
258 if (dev->ops->op) { \
260 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
264 CMD(add_virtual_intf
, NEW_INTERFACE
);
265 CMD(change_virtual_intf
, SET_INTERFACE
);
266 CMD(add_key
, NEW_KEY
);
267 CMD(add_beacon
, NEW_BEACON
);
268 CMD(add_station
, NEW_STATION
);
269 CMD(add_mpath
, NEW_MPATH
);
270 CMD(set_mesh_params
, SET_MESH_PARAMS
);
271 CMD(change_bss
, SET_BSS
);
272 CMD(auth
, AUTHENTICATE
);
273 CMD(assoc
, ASSOCIATE
);
274 CMD(deauth
, DEAUTHENTICATE
);
275 CMD(disassoc
, DISASSOCIATE
);
278 nla_nest_end(msg
, nl_cmds
);
280 return genlmsg_end(msg
, hdr
);
283 genlmsg_cancel(msg
, hdr
);
287 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
290 int start
= cb
->args
[0];
291 struct cfg80211_registered_device
*dev
;
293 mutex_lock(&cfg80211_mutex
);
294 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
297 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
298 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
304 mutex_unlock(&cfg80211_mutex
);
311 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
314 struct cfg80211_registered_device
*dev
;
316 dev
= cfg80211_get_dev_from_info(info
);
320 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
324 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
327 cfg80211_put_dev(dev
);
329 return genlmsg_unicast(msg
, info
->snd_pid
);
334 cfg80211_put_dev(dev
);
338 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
339 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
340 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
341 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
342 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
343 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
346 static int parse_txq_params(struct nlattr
*tb
[],
347 struct ieee80211_txq_params
*txq_params
)
349 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
350 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
351 !tb
[NL80211_TXQ_ATTR_AIFS
])
354 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
355 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
356 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
357 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
358 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
363 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
365 struct cfg80211_registered_device
*rdev
;
366 int result
= 0, rem_txq_params
= 0;
367 struct nlattr
*nl_txq_params
;
371 mutex_lock(&cfg80211_mutex
);
373 rdev
= __cfg80211_drv_from_info(info
);
375 result
= PTR_ERR(rdev
);
379 mutex_lock(&rdev
->mtx
);
381 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
382 result
= cfg80211_dev_rename(
383 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
385 mutex_unlock(&cfg80211_mutex
);
390 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
391 struct ieee80211_txq_params txq_params
;
392 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
394 if (!rdev
->ops
->set_txq_params
) {
395 result
= -EOPNOTSUPP
;
399 nla_for_each_nested(nl_txq_params
,
400 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
402 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
403 nla_data(nl_txq_params
),
404 nla_len(nl_txq_params
),
406 result
= parse_txq_params(tb
, &txq_params
);
410 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
417 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
418 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
419 struct ieee80211_channel
*chan
;
420 struct ieee80211_sta_ht_cap
*ht_cap
;
423 if (!rdev
->ops
->set_channel
) {
424 result
= -EOPNOTSUPP
;
430 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
431 channel_type
= nla_get_u32(info
->attrs
[
432 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
433 if (channel_type
!= NL80211_CHAN_NO_HT
&&
434 channel_type
!= NL80211_CHAN_HT20
&&
435 channel_type
!= NL80211_CHAN_HT40PLUS
&&
436 channel_type
!= NL80211_CHAN_HT40MINUS
)
440 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
441 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
443 /* Primary channel not allowed */
444 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
447 if (channel_type
== NL80211_CHAN_HT40MINUS
)
448 sec_freq
= freq
- 20;
449 else if (channel_type
== NL80211_CHAN_HT40PLUS
)
450 sec_freq
= freq
+ 20;
454 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
456 /* no HT capabilities */
457 if (channel_type
!= NL80211_CHAN_NO_HT
&&
458 !ht_cap
->ht_supported
)
462 struct ieee80211_channel
*schan
;
464 /* no 40 MHz capabilities */
465 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
466 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
469 schan
= ieee80211_get_channel(&rdev
->wiphy
, sec_freq
);
471 /* Secondary channel not allowed */
472 if (!schan
|| schan
->flags
& IEEE80211_CHAN_DISABLED
)
476 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
484 mutex_unlock(&rdev
->mtx
);
491 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
492 struct net_device
*dev
)
496 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
500 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
501 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
502 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
503 return genlmsg_end(msg
, hdr
);
506 genlmsg_cancel(msg
, hdr
);
510 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
514 int wp_start
= cb
->args
[0];
515 int if_start
= cb
->args
[1];
516 struct cfg80211_registered_device
*dev
;
517 struct wireless_dev
*wdev
;
519 mutex_lock(&cfg80211_mutex
);
520 list_for_each_entry(dev
, &cfg80211_drv_list
, list
) {
521 if (wp_idx
< wp_start
) {
527 mutex_lock(&dev
->devlist_mtx
);
528 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
529 if (if_idx
< if_start
) {
533 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
534 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
536 mutex_unlock(&dev
->devlist_mtx
);
541 mutex_unlock(&dev
->devlist_mtx
);
546 mutex_unlock(&cfg80211_mutex
);
548 cb
->args
[0] = wp_idx
;
549 cb
->args
[1] = if_idx
;
554 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
557 struct cfg80211_registered_device
*dev
;
558 struct net_device
*netdev
;
561 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &dev
, &netdev
);
565 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
569 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0, netdev
) < 0)
573 cfg80211_put_dev(dev
);
575 return genlmsg_unicast(msg
, info
->snd_pid
);
581 cfg80211_put_dev(dev
);
585 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
586 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
587 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
588 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
589 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
590 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
593 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
595 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
603 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
604 nla
, mntr_flags_policy
))
607 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
609 *mntrflags
|= (1<<flag
);
614 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
616 struct cfg80211_registered_device
*drv
;
617 struct vif_params params
;
619 enum nl80211_iftype type
;
620 struct net_device
*dev
;
621 u32 _flags
, *flags
= NULL
;
624 memset(¶ms
, 0, sizeof(params
));
628 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
632 ifindex
= dev
->ifindex
;
633 type
= dev
->ieee80211_ptr
->iftype
;
636 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
637 enum nl80211_iftype ntype
;
639 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
643 if (type
> NL80211_IFTYPE_MAX
) {
649 if (!drv
->ops
->change_virtual_intf
||
650 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
655 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
656 if (type
!= NL80211_IFTYPE_MESH_POINT
) {
660 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
661 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
665 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
666 if (type
!= NL80211_IFTYPE_MONITOR
) {
670 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
680 err
= drv
->ops
->change_virtual_intf(&drv
->wiphy
, ifindex
,
681 type
, flags
, ¶ms
);
685 dev
= __dev_get_by_index(&init_net
, ifindex
);
686 WARN_ON(!dev
|| (!err
&& dev
->ieee80211_ptr
->iftype
!= type
));
689 cfg80211_put_dev(drv
);
695 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
697 struct cfg80211_registered_device
*drv
;
698 struct vif_params params
;
700 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
703 memset(¶ms
, 0, sizeof(params
));
705 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
708 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
709 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
710 if (type
> NL80211_IFTYPE_MAX
)
716 drv
= cfg80211_get_dev_from_info(info
);
722 if (!drv
->ops
->add_virtual_intf
||
723 !(drv
->wiphy
.interface_modes
& (1 << type
))) {
728 if (type
== NL80211_IFTYPE_MESH_POINT
&&
729 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
730 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
731 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
734 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
735 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
737 err
= drv
->ops
->add_virtual_intf(&drv
->wiphy
,
738 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
739 type
, err
? NULL
: &flags
, ¶ms
);
742 cfg80211_put_dev(drv
);
748 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
750 struct cfg80211_registered_device
*drv
;
752 struct net_device
*dev
;
756 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
759 ifindex
= dev
->ifindex
;
762 if (!drv
->ops
->del_virtual_intf
) {
767 err
= drv
->ops
->del_virtual_intf(&drv
->wiphy
, ifindex
);
770 cfg80211_put_dev(drv
);
776 struct get_key_cookie
{
781 static void get_key_callback(void *c
, struct key_params
*params
)
783 struct get_key_cookie
*cookie
= c
;
786 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
787 params
->key_len
, params
->key
);
790 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
791 params
->seq_len
, params
->seq
);
794 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
802 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
804 struct cfg80211_registered_device
*drv
;
806 struct net_device
*dev
;
809 struct get_key_cookie cookie
= {
815 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
816 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
821 if (info
->attrs
[NL80211_ATTR_MAC
])
822 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
826 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
830 if (!drv
->ops
->get_key
) {
835 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
841 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
842 NL80211_CMD_NEW_KEY
);
851 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
852 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
854 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
856 err
= drv
->ops
->get_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
,
857 &cookie
, get_key_callback
);
863 goto nla_put_failure
;
865 genlmsg_end(msg
, hdr
);
866 err
= genlmsg_unicast(msg
, info
->snd_pid
);
873 cfg80211_put_dev(drv
);
881 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
883 struct cfg80211_registered_device
*drv
;
885 struct net_device
*dev
;
887 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
890 if (!info
->attrs
[NL80211_ATTR_KEY_IDX
])
893 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
895 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
]) {
896 if (key_idx
< 4 || key_idx
> 5)
898 } else if (key_idx
> 3)
901 /* currently only support setting default key */
902 if (!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
] &&
903 !info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
])
908 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
912 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT
])
913 func
= drv
->ops
->set_default_key
;
915 func
= drv
->ops
->set_default_mgmt_key
;
922 err
= func(&drv
->wiphy
, dev
, key_idx
);
925 cfg80211_put_dev(drv
);
934 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
936 struct cfg80211_registered_device
*drv
;
938 struct net_device
*dev
;
939 struct key_params params
;
943 memset(¶ms
, 0, sizeof(params
));
945 if (!info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
948 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
949 params
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
950 params
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
953 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
954 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
956 params
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
958 if (info
->attrs
[NL80211_ATTR_MAC
])
959 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
965 * Disallow pairwise keys with non-zero index unless it's WEP
966 * (because current deployments use pairwise WEP keys with
967 * non-zero indizes but 802.11i clearly specifies to use zero)
969 if (mac_addr
&& key_idx
&&
970 params
.cipher
!= WLAN_CIPHER_SUITE_WEP40
&&
971 params
.cipher
!= WLAN_CIPHER_SUITE_WEP104
)
974 /* TODO: add definitions for the lengths to linux/ieee80211.h */
975 switch (params
.cipher
) {
976 case WLAN_CIPHER_SUITE_WEP40
:
977 if (params
.key_len
!= 5)
980 case WLAN_CIPHER_SUITE_TKIP
:
981 if (params
.key_len
!= 32)
984 case WLAN_CIPHER_SUITE_CCMP
:
985 if (params
.key_len
!= 16)
988 case WLAN_CIPHER_SUITE_WEP104
:
989 if (params
.key_len
!= 13)
992 case WLAN_CIPHER_SUITE_AES_CMAC
:
993 if (params
.key_len
!= 16)
1002 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1006 if (!drv
->ops
->add_key
) {
1011 err
= drv
->ops
->add_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
, ¶ms
);
1014 cfg80211_put_dev(drv
);
1022 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1024 struct cfg80211_registered_device
*drv
;
1026 struct net_device
*dev
;
1028 u8
*mac_addr
= NULL
;
1030 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1031 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1036 if (info
->attrs
[NL80211_ATTR_MAC
])
1037 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1041 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1045 if (!drv
->ops
->del_key
) {
1050 err
= drv
->ops
->del_key(&drv
->wiphy
, dev
, key_idx
, mac_addr
);
1053 cfg80211_put_dev(drv
);
1062 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1064 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1065 struct beacon_parameters
*info
);
1066 struct cfg80211_registered_device
*drv
;
1068 struct net_device
*dev
;
1069 struct beacon_parameters params
;
1074 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1078 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1083 switch (info
->genlhdr
->cmd
) {
1084 case NL80211_CMD_NEW_BEACON
:
1085 /* these are required for NEW_BEACON */
1086 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1087 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1088 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1093 call
= drv
->ops
->add_beacon
;
1095 case NL80211_CMD_SET_BEACON
:
1096 call
= drv
->ops
->set_beacon
;
1109 memset(¶ms
, 0, sizeof(params
));
1111 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1113 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1117 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1118 params
.dtim_period
=
1119 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1123 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1124 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1126 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1130 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1131 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1133 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1142 err
= call(&drv
->wiphy
, dev
, ¶ms
);
1145 cfg80211_put_dev(drv
);
1153 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1155 struct cfg80211_registered_device
*drv
;
1157 struct net_device
*dev
;
1161 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1165 if (!drv
->ops
->del_beacon
) {
1170 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1174 err
= drv
->ops
->del_beacon(&drv
->wiphy
, dev
);
1177 cfg80211_put_dev(drv
);
1185 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1186 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1187 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1188 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1191 static int parse_station_flags(struct nlattr
*nla
, u32
*staflags
)
1193 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1201 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1202 nla
, sta_flags_policy
))
1205 *staflags
= STATION_FLAG_CHANGED
;
1207 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1209 *staflags
|= (1<<flag
);
1214 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1216 int modulation
, streams
, bitrate
;
1218 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1219 return rate
->legacy
;
1221 /* the formula below does only work for MCS values smaller than 32 */
1222 if (rate
->mcs
>= 32)
1225 modulation
= rate
->mcs
& 7;
1226 streams
= (rate
->mcs
>> 3) + 1;
1228 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1232 bitrate
*= (modulation
+ 1);
1233 else if (modulation
== 4)
1234 bitrate
*= (modulation
+ 2);
1236 bitrate
*= (modulation
+ 3);
1240 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1241 bitrate
= (bitrate
/ 9) * 10;
1243 /* do NOT round down here */
1244 return (bitrate
+ 50000) / 100000;
1247 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1248 int flags
, struct net_device
*dev
,
1249 u8
*mac_addr
, struct station_info
*sinfo
)
1252 struct nlattr
*sinfoattr
, *txrate
;
1255 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1259 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1260 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1262 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1264 goto nla_put_failure
;
1265 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1266 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1267 sinfo
->inactive_time
);
1268 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1269 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1271 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1272 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1274 if (sinfo
->filled
& STATION_INFO_LLID
)
1275 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1277 if (sinfo
->filled
& STATION_INFO_PLID
)
1278 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1280 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1281 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1282 sinfo
->plink_state
);
1283 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1284 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1286 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1287 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1289 goto nla_put_failure
;
1291 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1292 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1294 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1296 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1297 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1299 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1300 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1301 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1302 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1304 nla_nest_end(msg
, txrate
);
1306 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1307 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1309 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1310 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1312 nla_nest_end(msg
, sinfoattr
);
1314 return genlmsg_end(msg
, hdr
);
1317 genlmsg_cancel(msg
, hdr
);
1321 static int nl80211_dump_station(struct sk_buff
*skb
,
1322 struct netlink_callback
*cb
)
1324 struct station_info sinfo
;
1325 struct cfg80211_registered_device
*dev
;
1326 struct net_device
*netdev
;
1327 u8 mac_addr
[ETH_ALEN
];
1328 int ifidx
= cb
->args
[0];
1329 int sta_idx
= cb
->args
[1];
1333 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1334 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1339 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1342 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1349 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1355 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1361 if (!dev
->ops
->dump_station
) {
1367 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1374 if (nl80211_send_station(skb
,
1375 NETLINK_CB(cb
->skb
).pid
,
1376 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1386 cb
->args
[1] = sta_idx
;
1389 cfg80211_put_dev(dev
);
1396 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1398 struct cfg80211_registered_device
*drv
;
1400 struct net_device
*dev
;
1401 struct station_info sinfo
;
1402 struct sk_buff
*msg
;
1403 u8
*mac_addr
= NULL
;
1405 memset(&sinfo
, 0, sizeof(sinfo
));
1407 if (!info
->attrs
[NL80211_ATTR_MAC
])
1410 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1414 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1418 if (!drv
->ops
->get_station
) {
1423 err
= drv
->ops
->get_station(&drv
->wiphy
, dev
, mac_addr
, &sinfo
);
1427 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1431 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1432 dev
, mac_addr
, &sinfo
) < 0)
1435 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1441 cfg80211_put_dev(drv
);
1450 * Get vlan interface making sure it is on the right wiphy.
1452 static int get_vlan(struct nlattr
*vlanattr
,
1453 struct cfg80211_registered_device
*rdev
,
1454 struct net_device
**vlan
)
1459 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1462 if (!(*vlan
)->ieee80211_ptr
)
1464 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1470 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1472 struct cfg80211_registered_device
*drv
;
1474 struct net_device
*dev
;
1475 struct station_parameters params
;
1476 u8
*mac_addr
= NULL
;
1478 memset(¶ms
, 0, sizeof(params
));
1480 params
.listen_interval
= -1;
1482 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1485 if (!info
->attrs
[NL80211_ATTR_MAC
])
1488 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1490 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1491 params
.supported_rates
=
1492 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1493 params
.supported_rates_len
=
1494 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1497 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1498 params
.listen_interval
=
1499 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1501 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1503 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1505 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1506 ¶ms
.station_flags
))
1509 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1510 params
.plink_action
=
1511 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1515 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1519 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1523 if (!drv
->ops
->change_station
) {
1528 err
= drv
->ops
->change_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1532 dev_put(params
.vlan
);
1533 cfg80211_put_dev(drv
);
1541 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1543 struct cfg80211_registered_device
*drv
;
1545 struct net_device
*dev
;
1546 struct station_parameters params
;
1547 u8
*mac_addr
= NULL
;
1549 memset(¶ms
, 0, sizeof(params
));
1551 if (!info
->attrs
[NL80211_ATTR_MAC
])
1554 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
1557 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1560 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1563 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1564 params
.supported_rates
=
1565 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1566 params
.supported_rates_len
=
1567 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1568 params
.listen_interval
=
1569 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1570 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1571 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1573 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1575 if (parse_station_flags(info
->attrs
[NL80211_ATTR_STA_FLAGS
],
1576 ¶ms
.station_flags
))
1581 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1585 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], drv
, ¶ms
.vlan
);
1589 if (!drv
->ops
->add_station
) {
1594 if (!netif_running(dev
)) {
1599 err
= drv
->ops
->add_station(&drv
->wiphy
, dev
, mac_addr
, ¶ms
);
1603 dev_put(params
.vlan
);
1604 cfg80211_put_dev(drv
);
1612 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
1614 struct cfg80211_registered_device
*drv
;
1616 struct net_device
*dev
;
1617 u8
*mac_addr
= NULL
;
1619 if (info
->attrs
[NL80211_ATTR_MAC
])
1620 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1624 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1628 if (!drv
->ops
->del_station
) {
1633 err
= drv
->ops
->del_station(&drv
->wiphy
, dev
, mac_addr
);
1636 cfg80211_put_dev(drv
);
1644 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1645 int flags
, struct net_device
*dev
,
1646 u8
*dst
, u8
*next_hop
,
1647 struct mpath_info
*pinfo
)
1650 struct nlattr
*pinfoattr
;
1652 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1656 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1657 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
1658 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
1660 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
1662 goto nla_put_failure
;
1663 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
1664 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
1666 if (pinfo
->filled
& MPATH_INFO_DSN
)
1667 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
1669 if (pinfo
->filled
& MPATH_INFO_METRIC
)
1670 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
1672 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
1673 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
1675 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
1676 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
1678 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
1679 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
1680 pinfo
->discovery_timeout
);
1681 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
1682 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
1683 pinfo
->discovery_retries
);
1685 nla_nest_end(msg
, pinfoattr
);
1687 return genlmsg_end(msg
, hdr
);
1690 genlmsg_cancel(msg
, hdr
);
1694 static int nl80211_dump_mpath(struct sk_buff
*skb
,
1695 struct netlink_callback
*cb
)
1697 struct mpath_info pinfo
;
1698 struct cfg80211_registered_device
*dev
;
1699 struct net_device
*netdev
;
1701 u8 next_hop
[ETH_ALEN
];
1702 int ifidx
= cb
->args
[0];
1703 int path_idx
= cb
->args
[1];
1707 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1708 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1713 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1716 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1723 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1729 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1735 if (!dev
->ops
->dump_mpath
) {
1740 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1746 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
1747 dst
, next_hop
, &pinfo
);
1753 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
1754 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1755 netdev
, dst
, next_hop
,
1764 cb
->args
[1] = path_idx
;
1767 cfg80211_put_dev(dev
);
1774 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1776 struct cfg80211_registered_device
*drv
;
1778 struct net_device
*dev
;
1779 struct mpath_info pinfo
;
1780 struct sk_buff
*msg
;
1782 u8 next_hop
[ETH_ALEN
];
1784 memset(&pinfo
, 0, sizeof(pinfo
));
1786 if (!info
->attrs
[NL80211_ATTR_MAC
])
1789 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1793 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1797 if (!drv
->ops
->get_mpath
) {
1802 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1807 err
= drv
->ops
->get_mpath(&drv
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
1811 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1815 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1816 dev
, dst
, next_hop
, &pinfo
) < 0)
1819 err
= genlmsg_unicast(msg
, info
->snd_pid
);
1825 cfg80211_put_dev(drv
);
1833 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1835 struct cfg80211_registered_device
*drv
;
1837 struct net_device
*dev
;
1839 u8
*next_hop
= NULL
;
1841 if (!info
->attrs
[NL80211_ATTR_MAC
])
1844 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
1847 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1848 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
1852 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1856 if (!drv
->ops
->change_mpath
) {
1861 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1866 if (!netif_running(dev
)) {
1871 err
= drv
->ops
->change_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
1874 cfg80211_put_dev(drv
);
1881 static int nl80211_new_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
->add_mpath
) {
1909 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
1914 if (!netif_running(dev
)) {
1919 err
= drv
->ops
->add_mpath(&drv
->wiphy
, dev
, dst
, next_hop
);
1922 cfg80211_put_dev(drv
);
1930 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
1932 struct cfg80211_registered_device
*drv
;
1934 struct net_device
*dev
;
1937 if (info
->attrs
[NL80211_ATTR_MAC
])
1938 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1942 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1946 if (!drv
->ops
->del_mpath
) {
1951 err
= drv
->ops
->del_mpath(&drv
->wiphy
, dev
, dst
);
1954 cfg80211_put_dev(drv
);
1962 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
1964 struct cfg80211_registered_device
*drv
;
1966 struct net_device
*dev
;
1967 struct bss_parameters params
;
1969 memset(¶ms
, 0, sizeof(params
));
1970 /* default to not changing parameters */
1971 params
.use_cts_prot
= -1;
1972 params
.use_short_preamble
= -1;
1973 params
.use_short_slot_time
= -1;
1975 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
1976 params
.use_cts_prot
=
1977 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
1978 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
1979 params
.use_short_preamble
=
1980 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
1981 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
1982 params
.use_short_slot_time
=
1983 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
1984 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
1985 params
.basic_rates
=
1986 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
1987 params
.basic_rates_len
=
1988 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
1993 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
1997 if (!drv
->ops
->change_bss
) {
2002 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2007 err
= drv
->ops
->change_bss(&drv
->wiphy
, dev
, ¶ms
);
2010 cfg80211_put_dev(drv
);
2018 static const struct nla_policy
2019 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2020 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2021 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2022 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2023 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2024 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2025 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2028 static int parse_reg_rule(struct nlattr
*tb
[],
2029 struct ieee80211_reg_rule
*reg_rule
)
2031 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2032 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2034 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2036 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2038 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2040 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2042 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2045 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2047 freq_range
->start_freq_khz
=
2048 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2049 freq_range
->end_freq_khz
=
2050 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2051 freq_range
->max_bandwidth_khz
=
2052 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2054 power_rule
->max_eirp
=
2055 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2057 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2058 power_rule
->max_antenna_gain
=
2059 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2064 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2070 * You should only get this when cfg80211 hasn't yet initialized
2071 * completely when built-in to the kernel right between the time
2072 * window between nl80211_init() and regulatory_init(), if that is
2075 mutex_lock(&cfg80211_mutex
);
2076 if (unlikely(!cfg80211_regdomain
)) {
2077 mutex_unlock(&cfg80211_mutex
);
2078 return -EINPROGRESS
;
2080 mutex_unlock(&cfg80211_mutex
);
2082 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2085 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2087 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2088 /* We ignore world regdom requests with the old regdom setup */
2089 if (is_world_regdom(data
))
2093 r
= regulatory_hint_user(data
);
2098 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2099 struct genl_info
*info
)
2101 struct cfg80211_registered_device
*drv
;
2102 struct mesh_config cur_params
;
2104 struct net_device
*dev
;
2106 struct nlattr
*pinfoattr
;
2107 struct sk_buff
*msg
;
2111 /* Look up our device */
2112 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2116 if (!drv
->ops
->get_mesh_params
) {
2121 /* Get the mesh params */
2122 err
= drv
->ops
->get_mesh_params(&drv
->wiphy
, dev
, &cur_params
);
2126 /* Draw up a netlink message to send back */
2127 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2132 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2133 NL80211_CMD_GET_MESH_PARAMS
);
2135 goto nla_put_failure
;
2136 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2138 goto nla_put_failure
;
2139 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2140 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2141 cur_params
.dot11MeshRetryTimeout
);
2142 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2143 cur_params
.dot11MeshConfirmTimeout
);
2144 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2145 cur_params
.dot11MeshHoldingTimeout
);
2146 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2147 cur_params
.dot11MeshMaxPeerLinks
);
2148 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2149 cur_params
.dot11MeshMaxRetries
);
2150 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2151 cur_params
.dot11MeshTTL
);
2152 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2153 cur_params
.auto_open_plinks
);
2154 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2155 cur_params
.dot11MeshHWMPmaxPREQretries
);
2156 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2157 cur_params
.path_refresh_time
);
2158 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2159 cur_params
.min_discovery_timeout
);
2160 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2161 cur_params
.dot11MeshHWMPactivePathTimeout
);
2162 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2163 cur_params
.dot11MeshHWMPpreqMinInterval
);
2164 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2165 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2166 nla_nest_end(msg
, pinfoattr
);
2167 genlmsg_end(msg
, hdr
);
2168 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2172 genlmsg_cancel(msg
, hdr
);
2176 cfg80211_put_dev(drv
);
2184 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2186 if (table[attr_num]) {\
2187 cfg.param = nla_fn(table[attr_num]); \
2188 mask |= (1 << (attr_num - 1)); \
2192 static struct nla_policy
2193 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2194 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2195 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2196 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2197 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2198 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2199 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2200 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2202 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2203 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2204 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2205 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2206 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2207 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2210 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2214 struct cfg80211_registered_device
*drv
;
2215 struct net_device
*dev
;
2216 struct mesh_config cfg
;
2217 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2218 struct nlattr
*parent_attr
;
2220 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2223 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2224 parent_attr
, nl80211_meshconf_params_policy
))
2229 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2233 if (!drv
->ops
->set_mesh_params
) {
2238 /* This makes sure that there aren't more than 32 mesh config
2239 * parameters (otherwise our bitfield scheme would not work.) */
2240 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2242 /* Fill in the params struct */
2244 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2245 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2246 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2247 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2248 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2249 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2250 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2251 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2252 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2253 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2254 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2255 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2256 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2257 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2258 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2259 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2261 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2262 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2263 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2264 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2266 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2267 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2269 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2270 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2272 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2273 dot11MeshHWMPnetDiameterTraversalTime
,
2274 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2278 err
= drv
->ops
->set_mesh_params(&drv
->wiphy
, dev
, &cfg
, mask
);
2282 cfg80211_put_dev(drv
);
2290 #undef FILL_IN_MESH_PARAM_IF_SET
2292 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2294 struct sk_buff
*msg
;
2296 struct nlattr
*nl_reg_rules
;
2300 mutex_lock(&cfg80211_mutex
);
2302 if (!cfg80211_regdomain
)
2305 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
2311 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2312 NL80211_CMD_GET_REG
);
2314 goto nla_put_failure
;
2316 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2317 cfg80211_regdomain
->alpha2
);
2319 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2321 goto nla_put_failure
;
2323 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2324 struct nlattr
*nl_reg_rule
;
2325 const struct ieee80211_reg_rule
*reg_rule
;
2326 const struct ieee80211_freq_range
*freq_range
;
2327 const struct ieee80211_power_rule
*power_rule
;
2329 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2330 freq_range
= ®_rule
->freq_range
;
2331 power_rule
= ®_rule
->power_rule
;
2333 nl_reg_rule
= nla_nest_start(msg
, i
);
2335 goto nla_put_failure
;
2337 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2339 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2340 freq_range
->start_freq_khz
);
2341 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2342 freq_range
->end_freq_khz
);
2343 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2344 freq_range
->max_bandwidth_khz
);
2345 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2346 power_rule
->max_antenna_gain
);
2347 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2348 power_rule
->max_eirp
);
2350 nla_nest_end(msg
, nl_reg_rule
);
2353 nla_nest_end(msg
, nl_reg_rules
);
2355 genlmsg_end(msg
, hdr
);
2356 err
= genlmsg_unicast(msg
, info
->snd_pid
);
2360 genlmsg_cancel(msg
, hdr
);
2363 mutex_unlock(&cfg80211_mutex
);
2367 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2369 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2370 struct nlattr
*nl_reg_rule
;
2371 char *alpha2
= NULL
;
2372 int rem_reg_rules
= 0, r
= 0;
2373 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2374 struct ieee80211_regdomain
*rd
= NULL
;
2376 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2379 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2382 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2384 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2387 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2391 if (!reg_is_valid_request(alpha2
))
2394 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2395 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2397 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2401 rd
->n_reg_rules
= num_rules
;
2402 rd
->alpha2
[0] = alpha2
[0];
2403 rd
->alpha2
[1] = alpha2
[1];
2405 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2407 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2408 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2410 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2416 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
)
2420 BUG_ON(rule_idx
!= num_rules
);
2422 mutex_lock(&cfg80211_mutex
);
2424 mutex_unlock(&cfg80211_mutex
);
2432 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2434 struct cfg80211_registered_device
*drv
;
2435 struct net_device
*dev
;
2436 struct cfg80211_scan_request
*request
;
2437 struct cfg80211_ssid
*ssid
;
2438 struct ieee80211_channel
*channel
;
2439 struct nlattr
*attr
;
2440 struct wiphy
*wiphy
;
2441 int err
, tmp
, n_ssids
= 0, n_channels
= 0, i
;
2442 enum ieee80211_band band
;
2447 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2451 wiphy
= &drv
->wiphy
;
2453 if (!drv
->ops
->scan
) {
2458 if (!netif_running(dev
)) {
2463 if (drv
->scan_req
) {
2468 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2469 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
)
2476 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2477 if (wiphy
->bands
[band
])
2478 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2481 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2482 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2485 if (n_ssids
> wiphy
->max_scan_ssids
) {
2490 if (info
->attrs
[NL80211_ATTR_IE
])
2491 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2495 request
= kzalloc(sizeof(*request
)
2496 + sizeof(*ssid
) * n_ssids
2497 + sizeof(channel
) * n_channels
2498 + ie_len
, GFP_KERNEL
);
2504 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
2505 request
->n_channels
= n_channels
;
2507 request
->ssids
= (void *)(request
->channels
+ n_channels
);
2508 request
->n_ssids
= n_ssids
;
2511 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
2513 request
->ie
= (void *)(request
->channels
+ n_channels
);
2516 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2517 /* user specified, bail out if channel not found */
2518 request
->n_channels
= n_channels
;
2520 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
2521 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
2522 if (!request
->channels
[i
]) {
2531 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
2533 if (!wiphy
->bands
[band
])
2535 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
2536 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
2543 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
2544 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
2545 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2549 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
2550 request
->ssids
[i
].ssid_len
= nla_len(attr
);
2555 if (info
->attrs
[NL80211_ATTR_IE
]) {
2556 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2557 memcpy(request
->ie
, nla_data(info
->attrs
[NL80211_ATTR_IE
]),
2561 request
->ifidx
= dev
->ifindex
;
2562 request
->wiphy
= &drv
->wiphy
;
2564 drv
->scan_req
= request
;
2565 err
= drv
->ops
->scan(&drv
->wiphy
, dev
, request
);
2569 drv
->scan_req
= NULL
;
2573 cfg80211_put_dev(drv
);
2581 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
2582 struct cfg80211_registered_device
*rdev
,
2583 struct net_device
*dev
,
2584 struct cfg80211_bss
*res
)
2589 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
2590 NL80211_CMD_NEW_SCAN_RESULTS
);
2594 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
2595 rdev
->bss_generation
);
2596 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2598 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
2600 goto nla_put_failure
;
2601 if (!is_zero_ether_addr(res
->bssid
))
2602 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
2603 if (res
->information_elements
&& res
->len_information_elements
)
2604 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
2605 res
->len_information_elements
,
2606 res
->information_elements
);
2608 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
2609 if (res
->beacon_interval
)
2610 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
2611 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
2612 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
2614 switch (rdev
->wiphy
.signal_type
) {
2615 case CFG80211_SIGNAL_TYPE_MBM
:
2616 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
2618 case CFG80211_SIGNAL_TYPE_UNSPEC
:
2619 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
2625 nla_nest_end(msg
, bss
);
2627 return genlmsg_end(msg
, hdr
);
2630 genlmsg_cancel(msg
, hdr
);
2634 static int nl80211_dump_scan(struct sk_buff
*skb
,
2635 struct netlink_callback
*cb
)
2637 struct cfg80211_registered_device
*dev
;
2638 struct net_device
*netdev
;
2639 struct cfg80211_internal_bss
*scan
;
2640 int ifidx
= cb
->args
[0];
2641 int start
= cb
->args
[1], idx
= 0;
2645 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2646 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2651 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2654 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2657 cb
->args
[0] = ifidx
;
2660 netdev
= dev_get_by_index(&init_net
, ifidx
);
2664 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2667 goto out_put_netdev
;
2670 spin_lock_bh(&dev
->bss_lock
);
2671 cfg80211_bss_expire(dev
);
2673 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
2676 if (nl80211_send_bss(skb
,
2677 NETLINK_CB(cb
->skb
).pid
,
2678 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2679 dev
, netdev
, &scan
->pub
) < 0) {
2686 spin_unlock_bh(&dev
->bss_lock
);
2690 cfg80211_put_dev(dev
);
2697 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
2699 return auth_type
== NL80211_AUTHTYPE_OPEN_SYSTEM
||
2700 auth_type
== NL80211_AUTHTYPE_SHARED_KEY
||
2701 auth_type
== NL80211_AUTHTYPE_FT
||
2702 auth_type
== NL80211_AUTHTYPE_NETWORK_EAP
;
2705 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2707 struct cfg80211_registered_device
*drv
;
2708 struct net_device
*dev
;
2709 struct cfg80211_auth_request req
;
2710 struct wiphy
*wiphy
;
2715 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2719 if (!drv
->ops
->auth
) {
2724 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2729 if (!netif_running(dev
)) {
2734 if (!info
->attrs
[NL80211_ATTR_MAC
]) {
2739 wiphy
= &drv
->wiphy
;
2740 memset(&req
, 0, sizeof(req
));
2742 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2744 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2745 req
.chan
= ieee80211_get_channel(
2747 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2754 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2755 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2756 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2759 if (info
->attrs
[NL80211_ATTR_IE
]) {
2760 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2761 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2764 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2766 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2767 if (!nl80211_valid_auth_type(req
.auth_type
)) {
2773 err
= drv
->ops
->auth(&drv
->wiphy
, dev
, &req
);
2776 cfg80211_put_dev(drv
);
2783 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
2785 struct cfg80211_registered_device
*drv
;
2786 struct net_device
*dev
;
2787 struct cfg80211_assoc_request req
;
2788 struct wiphy
*wiphy
;
2793 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2797 if (!drv
->ops
->assoc
) {
2802 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2807 if (!netif_running(dev
)) {
2812 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
2813 !info
->attrs
[NL80211_ATTR_SSID
]) {
2818 wiphy
= &drv
->wiphy
;
2819 memset(&req
, 0, sizeof(req
));
2821 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2823 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
2824 req
.chan
= ieee80211_get_channel(
2826 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
2833 req
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2834 req
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2836 if (info
->attrs
[NL80211_ATTR_IE
]) {
2837 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2838 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2841 err
= drv
->ops
->assoc(&drv
->wiphy
, dev
, &req
);
2844 cfg80211_put_dev(drv
);
2851 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
2853 struct cfg80211_registered_device
*drv
;
2854 struct net_device
*dev
;
2855 struct cfg80211_deauth_request req
;
2856 struct wiphy
*wiphy
;
2861 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2865 if (!drv
->ops
->deauth
) {
2870 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2875 if (!netif_running(dev
)) {
2880 if (!info
->attrs
[NL80211_ATTR_MAC
]) {
2885 wiphy
= &drv
->wiphy
;
2886 memset(&req
, 0, sizeof(req
));
2888 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2890 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
2892 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
2893 if (req
.reason_code
== 0) {
2894 /* Reason Code 0 is reserved */
2900 if (info
->attrs
[NL80211_ATTR_IE
]) {
2901 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2902 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2905 err
= drv
->ops
->deauth(&drv
->wiphy
, dev
, &req
);
2908 cfg80211_put_dev(drv
);
2915 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
2917 struct cfg80211_registered_device
*drv
;
2918 struct net_device
*dev
;
2919 struct cfg80211_disassoc_request req
;
2920 struct wiphy
*wiphy
;
2925 err
= get_drv_dev_by_info_ifindex(info
->attrs
, &drv
, &dev
);
2929 if (!drv
->ops
->disassoc
) {
2934 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
2939 if (!netif_running(dev
)) {
2944 if (!info
->attrs
[NL80211_ATTR_MAC
]) {
2949 wiphy
= &drv
->wiphy
;
2950 memset(&req
, 0, sizeof(req
));
2952 req
.peer_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2954 if (info
->attrs
[NL80211_ATTR_REASON_CODE
]) {
2956 nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
2957 if (req
.reason_code
== 0) {
2958 /* Reason Code 0 is reserved */
2964 if (info
->attrs
[NL80211_ATTR_IE
]) {
2965 req
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2966 req
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2969 err
= drv
->ops
->disassoc(&drv
->wiphy
, dev
, &req
);
2972 cfg80211_put_dev(drv
);
2979 static struct genl_ops nl80211_ops
[] = {
2981 .cmd
= NL80211_CMD_GET_WIPHY
,
2982 .doit
= nl80211_get_wiphy
,
2983 .dumpit
= nl80211_dump_wiphy
,
2984 .policy
= nl80211_policy
,
2985 /* can be retrieved by unprivileged users */
2988 .cmd
= NL80211_CMD_SET_WIPHY
,
2989 .doit
= nl80211_set_wiphy
,
2990 .policy
= nl80211_policy
,
2991 .flags
= GENL_ADMIN_PERM
,
2994 .cmd
= NL80211_CMD_GET_INTERFACE
,
2995 .doit
= nl80211_get_interface
,
2996 .dumpit
= nl80211_dump_interface
,
2997 .policy
= nl80211_policy
,
2998 /* can be retrieved by unprivileged users */
3001 .cmd
= NL80211_CMD_SET_INTERFACE
,
3002 .doit
= nl80211_set_interface
,
3003 .policy
= nl80211_policy
,
3004 .flags
= GENL_ADMIN_PERM
,
3007 .cmd
= NL80211_CMD_NEW_INTERFACE
,
3008 .doit
= nl80211_new_interface
,
3009 .policy
= nl80211_policy
,
3010 .flags
= GENL_ADMIN_PERM
,
3013 .cmd
= NL80211_CMD_DEL_INTERFACE
,
3014 .doit
= nl80211_del_interface
,
3015 .policy
= nl80211_policy
,
3016 .flags
= GENL_ADMIN_PERM
,
3019 .cmd
= NL80211_CMD_GET_KEY
,
3020 .doit
= nl80211_get_key
,
3021 .policy
= nl80211_policy
,
3022 .flags
= GENL_ADMIN_PERM
,
3025 .cmd
= NL80211_CMD_SET_KEY
,
3026 .doit
= nl80211_set_key
,
3027 .policy
= nl80211_policy
,
3028 .flags
= GENL_ADMIN_PERM
,
3031 .cmd
= NL80211_CMD_NEW_KEY
,
3032 .doit
= nl80211_new_key
,
3033 .policy
= nl80211_policy
,
3034 .flags
= GENL_ADMIN_PERM
,
3037 .cmd
= NL80211_CMD_DEL_KEY
,
3038 .doit
= nl80211_del_key
,
3039 .policy
= nl80211_policy
,
3040 .flags
= GENL_ADMIN_PERM
,
3043 .cmd
= NL80211_CMD_SET_BEACON
,
3044 .policy
= nl80211_policy
,
3045 .flags
= GENL_ADMIN_PERM
,
3046 .doit
= nl80211_addset_beacon
,
3049 .cmd
= NL80211_CMD_NEW_BEACON
,
3050 .policy
= nl80211_policy
,
3051 .flags
= GENL_ADMIN_PERM
,
3052 .doit
= nl80211_addset_beacon
,
3055 .cmd
= NL80211_CMD_DEL_BEACON
,
3056 .policy
= nl80211_policy
,
3057 .flags
= GENL_ADMIN_PERM
,
3058 .doit
= nl80211_del_beacon
,
3061 .cmd
= NL80211_CMD_GET_STATION
,
3062 .doit
= nl80211_get_station
,
3063 .dumpit
= nl80211_dump_station
,
3064 .policy
= nl80211_policy
,
3067 .cmd
= NL80211_CMD_SET_STATION
,
3068 .doit
= nl80211_set_station
,
3069 .policy
= nl80211_policy
,
3070 .flags
= GENL_ADMIN_PERM
,
3073 .cmd
= NL80211_CMD_NEW_STATION
,
3074 .doit
= nl80211_new_station
,
3075 .policy
= nl80211_policy
,
3076 .flags
= GENL_ADMIN_PERM
,
3079 .cmd
= NL80211_CMD_DEL_STATION
,
3080 .doit
= nl80211_del_station
,
3081 .policy
= nl80211_policy
,
3082 .flags
= GENL_ADMIN_PERM
,
3085 .cmd
= NL80211_CMD_GET_MPATH
,
3086 .doit
= nl80211_get_mpath
,
3087 .dumpit
= nl80211_dump_mpath
,
3088 .policy
= nl80211_policy
,
3089 .flags
= GENL_ADMIN_PERM
,
3092 .cmd
= NL80211_CMD_SET_MPATH
,
3093 .doit
= nl80211_set_mpath
,
3094 .policy
= nl80211_policy
,
3095 .flags
= GENL_ADMIN_PERM
,
3098 .cmd
= NL80211_CMD_NEW_MPATH
,
3099 .doit
= nl80211_new_mpath
,
3100 .policy
= nl80211_policy
,
3101 .flags
= GENL_ADMIN_PERM
,
3104 .cmd
= NL80211_CMD_DEL_MPATH
,
3105 .doit
= nl80211_del_mpath
,
3106 .policy
= nl80211_policy
,
3107 .flags
= GENL_ADMIN_PERM
,
3110 .cmd
= NL80211_CMD_SET_BSS
,
3111 .doit
= nl80211_set_bss
,
3112 .policy
= nl80211_policy
,
3113 .flags
= GENL_ADMIN_PERM
,
3116 .cmd
= NL80211_CMD_GET_REG
,
3117 .doit
= nl80211_get_reg
,
3118 .policy
= nl80211_policy
,
3119 /* can be retrieved by unprivileged users */
3122 .cmd
= NL80211_CMD_SET_REG
,
3123 .doit
= nl80211_set_reg
,
3124 .policy
= nl80211_policy
,
3125 .flags
= GENL_ADMIN_PERM
,
3128 .cmd
= NL80211_CMD_REQ_SET_REG
,
3129 .doit
= nl80211_req_set_reg
,
3130 .policy
= nl80211_policy
,
3131 .flags
= GENL_ADMIN_PERM
,
3134 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
3135 .doit
= nl80211_get_mesh_params
,
3136 .policy
= nl80211_policy
,
3137 /* can be retrieved by unprivileged users */
3140 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
3141 .doit
= nl80211_set_mesh_params
,
3142 .policy
= nl80211_policy
,
3143 .flags
= GENL_ADMIN_PERM
,
3146 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
3147 .doit
= nl80211_trigger_scan
,
3148 .policy
= nl80211_policy
,
3149 .flags
= GENL_ADMIN_PERM
,
3152 .cmd
= NL80211_CMD_GET_SCAN
,
3153 .policy
= nl80211_policy
,
3154 .dumpit
= nl80211_dump_scan
,
3157 .cmd
= NL80211_CMD_AUTHENTICATE
,
3158 .doit
= nl80211_authenticate
,
3159 .policy
= nl80211_policy
,
3160 .flags
= GENL_ADMIN_PERM
,
3163 .cmd
= NL80211_CMD_ASSOCIATE
,
3164 .doit
= nl80211_associate
,
3165 .policy
= nl80211_policy
,
3166 .flags
= GENL_ADMIN_PERM
,
3169 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
3170 .doit
= nl80211_deauthenticate
,
3171 .policy
= nl80211_policy
,
3172 .flags
= GENL_ADMIN_PERM
,
3175 .cmd
= NL80211_CMD_DISASSOCIATE
,
3176 .doit
= nl80211_disassociate
,
3177 .policy
= nl80211_policy
,
3178 .flags
= GENL_ADMIN_PERM
,
3181 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
3185 /* multicast groups */
3186 static struct genl_multicast_group nl80211_config_mcgrp
= {
3189 static struct genl_multicast_group nl80211_scan_mcgrp
= {
3192 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
3193 .name
= "regulatory",
3196 /* notification functions */
3198 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
3200 struct sk_buff
*msg
;
3202 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3206 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
3211 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
3214 static int nl80211_send_scan_donemsg(struct sk_buff
*msg
,
3215 struct cfg80211_registered_device
*rdev
,
3216 struct net_device
*netdev
,
3217 u32 pid
, u32 seq
, int flags
,
3222 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
3226 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3227 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3229 /* XXX: we should probably bounce back the request? */
3231 return genlmsg_end(msg
, hdr
);
3234 genlmsg_cancel(msg
, hdr
);
3238 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
3239 struct net_device
*netdev
)
3241 struct sk_buff
*msg
;
3243 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3247 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3248 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
3253 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3256 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
3257 struct net_device
*netdev
)
3259 struct sk_buff
*msg
;
3261 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3265 if (nl80211_send_scan_donemsg(msg
, rdev
, netdev
, 0, 0, 0,
3266 NL80211_CMD_SCAN_ABORTED
) < 0) {
3271 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
3275 * This can happen on global regulatory changes or device specific settings
3276 * based on custom world regulatory domains.
3278 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
3280 struct sk_buff
*msg
;
3283 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3287 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
3293 /* Userspace can always count this one always being set */
3294 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
3296 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
3297 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3298 NL80211_REGDOM_TYPE_WORLD
);
3299 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
3300 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3301 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
3302 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
3304 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3305 NL80211_REGDOM_TYPE_INTERSECTION
);
3307 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
3308 NL80211_REGDOM_TYPE_COUNTRY
);
3309 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
3312 if (wiphy_idx_valid(request
->wiphy_idx
))
3313 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
3315 if (genlmsg_end(msg
, hdr
) < 0) {
3320 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
3325 genlmsg_cancel(msg
, hdr
);
3329 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
3330 struct net_device
*netdev
,
3331 const u8
*buf
, size_t len
,
3332 enum nl80211_commands cmd
)
3334 struct sk_buff
*msg
;
3337 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
3341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
3347 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3348 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
3349 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
3351 if (genlmsg_end(msg
, hdr
) < 0) {
3356 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
3360 genlmsg_cancel(msg
, hdr
);
3364 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
3365 struct net_device
*netdev
, const u8
*buf
, size_t len
)
3367 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3368 NL80211_CMD_AUTHENTICATE
);
3371 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
3372 struct net_device
*netdev
, const u8
*buf
,
3375 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
, NL80211_CMD_ASSOCIATE
);
3378 void nl80211_send_rx_deauth(struct cfg80211_registered_device
*rdev
,
3379 struct net_device
*netdev
, const u8
*buf
,
3382 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3383 NL80211_CMD_DEAUTHENTICATE
);
3386 void nl80211_send_rx_disassoc(struct cfg80211_registered_device
*rdev
,
3387 struct net_device
*netdev
, const u8
*buf
,
3390 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
3391 NL80211_CMD_DISASSOCIATE
);
3394 /* initialisation/exit functions */
3396 int nl80211_init(void)
3400 err
= genl_register_family(&nl80211_fam
);
3404 for (i
= 0; i
< ARRAY_SIZE(nl80211_ops
); i
++) {
3405 err
= genl_register_ops(&nl80211_fam
, &nl80211_ops
[i
]);
3410 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
3414 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
3418 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
3422 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
3428 genl_unregister_family(&nl80211_fam
);
3432 void nl80211_exit(void)
3434 genl_unregister_family(&nl80211_fam
);