2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/if_ether.h>
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/netlink.h>
16 #include <linux/etherdevice.h>
17 #include <net/net_namespace.h>
18 #include <net/genetlink.h>
19 #include <net/cfg80211.h>
25 /* the netlink family */
26 static struct genl_family nl80211_fam
= {
27 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
28 .name
= "nl80211", /* have users key off the name instead */
29 .hdrsize
= 0, /* no private header */
30 .version
= 1, /* no particular meaning now */
31 .maxattr
= NL80211_ATTR_MAX
,
35 /* internal helper: get rdev and dev */
36 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
37 struct cfg80211_registered_device
**rdev
,
38 struct net_device
**dev
)
40 struct nlattr
**attrs
= info
->attrs
;
43 if (!attrs
[NL80211_ATTR_IFINDEX
])
46 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
47 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
51 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
54 return PTR_ERR(*rdev
);
60 /* policy for the attributes */
61 static struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] __read_mostly
= {
62 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
63 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
65 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
66 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
67 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
68 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
69 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
70 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
73 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
74 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
77 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
78 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
80 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
81 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
82 .len
= WLAN_MAX_KEY_LEN
},
83 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
84 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
86 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
88 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
89 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
91 .len
= IEEE80211_MAX_DATA_LEN
},
92 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
93 .len
= IEEE80211_MAX_DATA_LEN
},
94 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
95 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
96 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
97 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
98 .len
= NL80211_MAX_SUPP_RATES
},
99 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
100 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
101 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
102 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
103 .len
= IEEE80211_MAX_MESH_ID_LEN
},
104 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
106 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
107 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
109 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
111 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
112 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
113 .len
= NL80211_MAX_SUPP_RATES
},
115 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
117 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
118 .len
= NL80211_HT_CAPABILITY_LEN
},
120 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
121 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
122 .len
= IEEE80211_MAX_DATA_LEN
},
123 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
124 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
126 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
127 .len
= IEEE80211_MAX_SSID_LEN
},
128 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
129 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
130 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
131 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
132 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
133 [NL80211_ATTR_STA_FLAGS2
] = {
134 .len
= sizeof(struct nl80211_sta_flag_update
),
136 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
137 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
138 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
139 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
140 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
143 /* policy for the attributes */
144 static struct nla_policy
145 nl80211_key_policy
[NL80211_KEY_MAX
+ 1] __read_mostly
= {
146 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
147 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
148 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
149 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
150 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
151 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
155 static bool is_valid_ie_attr(const struct nlattr
*attr
)
163 pos
= nla_data(attr
);
184 /* message building helper */
185 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
188 /* since there is no private header just add the generic one */
189 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
192 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
193 struct ieee80211_channel
*chan
)
195 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
198 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
199 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
200 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
201 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
202 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
203 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
204 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
205 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
207 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
208 DBM_TO_MBM(chan
->max_power
));
216 /* netlink command implementations */
224 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
226 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
227 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
232 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
233 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
235 if (tb
[NL80211_KEY_IDX
])
236 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
238 if (tb
[NL80211_KEY_DATA
]) {
239 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
240 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
243 if (tb
[NL80211_KEY_SEQ
]) {
244 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
245 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
248 if (tb
[NL80211_KEY_CIPHER
])
249 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
254 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
256 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
257 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
258 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
261 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
262 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
263 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
266 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
267 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
269 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
270 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
272 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
273 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
278 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
282 memset(k
, 0, sizeof(*k
));
285 if (info
->attrs
[NL80211_ATTR_KEY
])
286 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
288 err
= nl80211_parse_key_old(info
, k
);
293 if (k
->def
&& k
->defmgmt
)
298 if (k
->idx
< 4 || k
->idx
> 5)
301 if (k
->idx
< 0 || k
->idx
> 3)
304 if (k
->idx
< 0 || k
->idx
> 5)
312 static struct cfg80211_cached_keys
*
313 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
316 struct key_parse parse
;
318 struct cfg80211_cached_keys
*result
;
319 int rem
, err
, def
= 0;
321 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
323 return ERR_PTR(-ENOMEM
);
326 result
->defmgmt
= -1;
328 nla_for_each_nested(key
, keys
, rem
) {
329 memset(&parse
, 0, sizeof(parse
));
332 err
= nl80211_parse_key_new(key
, &parse
);
338 if (parse
.idx
< 0 || parse
.idx
> 4)
344 result
->def
= parse
.idx
;
345 } else if (parse
.defmgmt
)
347 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
351 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
352 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
353 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
354 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
363 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
365 ASSERT_WDEV_LOCK(wdev
);
367 if (!netif_running(wdev
->netdev
))
370 switch (wdev
->iftype
) {
371 case NL80211_IFTYPE_AP
:
372 case NL80211_IFTYPE_AP_VLAN
:
374 case NL80211_IFTYPE_ADHOC
:
375 if (!wdev
->current_bss
)
378 case NL80211_IFTYPE_STATION
:
379 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
389 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
390 struct cfg80211_registered_device
*dev
)
393 struct nlattr
*nl_bands
, *nl_band
;
394 struct nlattr
*nl_freqs
, *nl_freq
;
395 struct nlattr
*nl_rates
, *nl_rate
;
396 struct nlattr
*nl_modes
;
397 struct nlattr
*nl_cmds
;
398 enum ieee80211_band band
;
399 struct ieee80211_channel
*chan
;
400 struct ieee80211_rate
*rate
;
402 u16 ifmodes
= dev
->wiphy
.interface_modes
;
404 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
408 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
409 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
411 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
412 dev
->wiphy
.retry_short
);
413 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
414 dev
->wiphy
.retry_long
);
415 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
416 dev
->wiphy
.frag_threshold
);
417 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
418 dev
->wiphy
.rts_threshold
);
420 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
421 dev
->wiphy
.max_scan_ssids
);
422 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
423 dev
->wiphy
.max_scan_ie_len
);
425 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
426 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
427 dev
->wiphy
.cipher_suites
);
429 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
431 goto nla_put_failure
;
436 NLA_PUT_FLAG(msg
, i
);
441 nla_nest_end(msg
, nl_modes
);
443 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
445 goto nla_put_failure
;
447 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
448 if (!dev
->wiphy
.bands
[band
])
451 nl_band
= nla_nest_start(msg
, band
);
453 goto nla_put_failure
;
456 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
457 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
458 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
459 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
460 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
461 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
462 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
463 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
464 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
465 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
468 /* add frequencies */
469 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
471 goto nla_put_failure
;
473 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
474 nl_freq
= nla_nest_start(msg
, i
);
476 goto nla_put_failure
;
478 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
480 if (nl80211_msg_put_channel(msg
, chan
))
481 goto nla_put_failure
;
483 nla_nest_end(msg
, nl_freq
);
486 nla_nest_end(msg
, nl_freqs
);
489 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
491 goto nla_put_failure
;
493 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
494 nl_rate
= nla_nest_start(msg
, i
);
496 goto nla_put_failure
;
498 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
499 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
501 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
503 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
505 nla_nest_end(msg
, nl_rate
);
508 nla_nest_end(msg
, nl_rates
);
510 nla_nest_end(msg
, nl_band
);
512 nla_nest_end(msg
, nl_bands
);
514 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
516 goto nla_put_failure
;
521 if (dev->ops->op) { \
523 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
527 CMD(add_virtual_intf
, NEW_INTERFACE
);
528 CMD(change_virtual_intf
, SET_INTERFACE
);
529 CMD(add_key
, NEW_KEY
);
530 CMD(add_beacon
, NEW_BEACON
);
531 CMD(add_station
, NEW_STATION
);
532 CMD(add_mpath
, NEW_MPATH
);
533 CMD(set_mesh_params
, SET_MESH_PARAMS
);
534 CMD(change_bss
, SET_BSS
);
535 CMD(auth
, AUTHENTICATE
);
536 CMD(assoc
, ASSOCIATE
);
537 CMD(deauth
, DEAUTHENTICATE
);
538 CMD(disassoc
, DISASSOCIATE
);
539 CMD(join_ibss
, JOIN_IBSS
);
540 if (dev
->wiphy
.netnsok
) {
542 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
547 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
549 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
552 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
554 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
557 nla_nest_end(msg
, nl_cmds
);
559 return genlmsg_end(msg
, hdr
);
562 genlmsg_cancel(msg
, hdr
);
566 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
569 int start
= cb
->args
[0];
570 struct cfg80211_registered_device
*dev
;
572 mutex_lock(&cfg80211_mutex
);
573 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
574 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
578 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
579 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
585 mutex_unlock(&cfg80211_mutex
);
592 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
595 struct cfg80211_registered_device
*dev
;
597 dev
= cfg80211_get_dev_from_info(info
);
601 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
605 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
608 cfg80211_unlock_rdev(dev
);
610 return genlmsg_reply(msg
, info
);
615 cfg80211_unlock_rdev(dev
);
619 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
620 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
621 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
622 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
623 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
624 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
627 static int parse_txq_params(struct nlattr
*tb
[],
628 struct ieee80211_txq_params
*txq_params
)
630 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
631 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
632 !tb
[NL80211_TXQ_ATTR_AIFS
])
635 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
636 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
637 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
638 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
639 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
644 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
646 struct cfg80211_registered_device
*rdev
;
647 int result
= 0, rem_txq_params
= 0;
648 struct nlattr
*nl_txq_params
;
650 u8 retry_short
= 0, retry_long
= 0;
651 u32 frag_threshold
= 0, rts_threshold
= 0;
655 mutex_lock(&cfg80211_mutex
);
657 rdev
= __cfg80211_rdev_from_info(info
);
659 mutex_unlock(&cfg80211_mutex
);
660 result
= PTR_ERR(rdev
);
664 mutex_lock(&rdev
->mtx
);
666 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
667 result
= cfg80211_dev_rename(
668 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
670 mutex_unlock(&cfg80211_mutex
);
675 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
676 struct ieee80211_txq_params txq_params
;
677 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
679 if (!rdev
->ops
->set_txq_params
) {
680 result
= -EOPNOTSUPP
;
684 nla_for_each_nested(nl_txq_params
,
685 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
687 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
688 nla_data(nl_txq_params
),
689 nla_len(nl_txq_params
),
691 result
= parse_txq_params(tb
, &txq_params
);
695 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
702 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
703 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
704 struct ieee80211_channel
*chan
;
705 struct ieee80211_sta_ht_cap
*ht_cap
;
708 if (!rdev
->ops
->set_channel
) {
709 result
= -EOPNOTSUPP
;
715 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
716 channel_type
= nla_get_u32(info
->attrs
[
717 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
718 if (channel_type
!= NL80211_CHAN_NO_HT
&&
719 channel_type
!= NL80211_CHAN_HT20
&&
720 channel_type
!= NL80211_CHAN_HT40PLUS
&&
721 channel_type
!= NL80211_CHAN_HT40MINUS
)
725 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
726 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
728 /* Primary channel not allowed */
729 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
732 if (channel_type
== NL80211_CHAN_HT40MINUS
&&
733 (chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
))
735 else if (channel_type
== NL80211_CHAN_HT40PLUS
&&
736 (chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
))
740 * At this point we know if that if HT40 was requested
741 * we are allowed to use it and the extension channel
745 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
747 /* no HT capabilities or intolerant */
748 if (channel_type
!= NL80211_CHAN_NO_HT
) {
749 if (!ht_cap
->ht_supported
)
751 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
752 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
756 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
761 rdev
->channel
= chan
;
766 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
767 retry_short
= nla_get_u8(
768 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
769 if (retry_short
== 0) {
773 changed
|= WIPHY_PARAM_RETRY_SHORT
;
776 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
777 retry_long
= nla_get_u8(
778 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
779 if (retry_long
== 0) {
783 changed
|= WIPHY_PARAM_RETRY_LONG
;
786 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
787 frag_threshold
= nla_get_u32(
788 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
789 if (frag_threshold
< 256) {
793 if (frag_threshold
!= (u32
) -1) {
795 * Fragments (apart from the last one) are required to
796 * have even length. Make the fragmentation code
797 * simpler by stripping LSB should someone try to use
798 * odd threshold value.
800 frag_threshold
&= ~0x1;
802 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
805 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
806 rts_threshold
= nla_get_u32(
807 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
808 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
812 u8 old_retry_short
, old_retry_long
;
813 u32 old_frag_threshold
, old_rts_threshold
;
815 if (!rdev
->ops
->set_wiphy_params
) {
816 result
= -EOPNOTSUPP
;
820 old_retry_short
= rdev
->wiphy
.retry_short
;
821 old_retry_long
= rdev
->wiphy
.retry_long
;
822 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
823 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
825 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
826 rdev
->wiphy
.retry_short
= retry_short
;
827 if (changed
& WIPHY_PARAM_RETRY_LONG
)
828 rdev
->wiphy
.retry_long
= retry_long
;
829 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
830 rdev
->wiphy
.frag_threshold
= frag_threshold
;
831 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
832 rdev
->wiphy
.rts_threshold
= rts_threshold
;
834 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
836 rdev
->wiphy
.retry_short
= old_retry_short
;
837 rdev
->wiphy
.retry_long
= old_retry_long
;
838 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
839 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
844 mutex_unlock(&rdev
->mtx
);
851 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
852 struct cfg80211_registered_device
*rdev
,
853 struct net_device
*dev
)
857 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
861 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
862 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
863 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
864 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
865 return genlmsg_end(msg
, hdr
);
868 genlmsg_cancel(msg
, hdr
);
872 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
876 int wp_start
= cb
->args
[0];
877 int if_start
= cb
->args
[1];
878 struct cfg80211_registered_device
*dev
;
879 struct wireless_dev
*wdev
;
881 mutex_lock(&cfg80211_mutex
);
882 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
883 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
885 if (wp_idx
< wp_start
) {
891 mutex_lock(&dev
->devlist_mtx
);
892 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
893 if (if_idx
< if_start
) {
897 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
898 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
899 dev
, wdev
->netdev
) < 0) {
900 mutex_unlock(&dev
->devlist_mtx
);
905 mutex_unlock(&dev
->devlist_mtx
);
910 mutex_unlock(&cfg80211_mutex
);
912 cb
->args
[0] = wp_idx
;
913 cb
->args
[1] = if_idx
;
918 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
921 struct cfg80211_registered_device
*dev
;
922 struct net_device
*netdev
;
925 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
929 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
933 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
938 cfg80211_unlock_rdev(dev
);
940 return genlmsg_reply(msg
, info
);
946 cfg80211_unlock_rdev(dev
);
950 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
951 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
952 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
953 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
954 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
955 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
958 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
960 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
968 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
969 nla
, mntr_flags_policy
))
972 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
974 *mntrflags
|= (1<<flag
);
979 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
981 struct cfg80211_registered_device
*rdev
;
982 struct vif_params params
;
984 enum nl80211_iftype otype
, ntype
;
985 struct net_device
*dev
;
986 u32 _flags
, *flags
= NULL
;
989 memset(¶ms
, 0, sizeof(params
));
993 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
997 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
999 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1000 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1003 if (ntype
> NL80211_IFTYPE_MAX
) {
1009 if (!rdev
->ops
->change_virtual_intf
||
1010 !(rdev
->wiphy
.interface_modes
& (1 << ntype
))) {
1015 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1016 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1020 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1021 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1025 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1026 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1030 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1040 err
= rdev
->ops
->change_virtual_intf(&rdev
->wiphy
, dev
,
1041 ntype
, flags
, ¶ms
);
1045 WARN_ON(!err
&& dev
->ieee80211_ptr
->iftype
!= ntype
);
1047 if (!err
&& (ntype
!= otype
)) {
1048 if (otype
== NL80211_IFTYPE_ADHOC
)
1049 cfg80211_clear_ibss(dev
, false);
1054 cfg80211_unlock_rdev(rdev
);
1060 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1062 struct cfg80211_registered_device
*rdev
;
1063 struct vif_params params
;
1065 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1068 memset(¶ms
, 0, sizeof(params
));
1070 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1073 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1074 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1075 if (type
> NL80211_IFTYPE_MAX
)
1081 rdev
= cfg80211_get_dev_from_info(info
);
1083 err
= PTR_ERR(rdev
);
1087 if (!rdev
->ops
->add_virtual_intf
||
1088 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1093 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1094 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1095 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1096 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1099 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1100 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1102 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1103 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1104 type
, err
? NULL
: &flags
, ¶ms
);
1107 cfg80211_unlock_rdev(rdev
);
1113 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1115 struct cfg80211_registered_device
*rdev
;
1117 struct net_device
*dev
;
1121 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1125 if (!rdev
->ops
->del_virtual_intf
) {
1130 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1133 cfg80211_unlock_rdev(rdev
);
1140 struct get_key_cookie
{
1141 struct sk_buff
*msg
;
1146 static void get_key_callback(void *c
, struct key_params
*params
)
1149 struct get_key_cookie
*cookie
= c
;
1152 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1153 params
->key_len
, params
->key
);
1156 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1157 params
->seq_len
, params
->seq
);
1160 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1163 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1165 goto nla_put_failure
;
1168 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1169 params
->key_len
, params
->key
);
1172 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1173 params
->seq_len
, params
->seq
);
1176 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1179 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1181 nla_nest_end(cookie
->msg
, key
);
1188 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1190 struct cfg80211_registered_device
*rdev
;
1192 struct net_device
*dev
;
1194 u8
*mac_addr
= NULL
;
1195 struct get_key_cookie cookie
= {
1199 struct sk_buff
*msg
;
1201 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1202 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1207 if (info
->attrs
[NL80211_ATTR_MAC
])
1208 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1212 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1216 if (!rdev
->ops
->get_key
) {
1221 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1227 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1228 NL80211_CMD_NEW_KEY
);
1236 cookie
.idx
= key_idx
;
1238 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1239 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1241 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1243 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1244 &cookie
, get_key_callback
);
1250 goto nla_put_failure
;
1252 genlmsg_end(msg
, hdr
);
1253 err
= genlmsg_reply(msg
, info
);
1261 cfg80211_unlock_rdev(rdev
);
1269 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1271 struct cfg80211_registered_device
*rdev
;
1272 struct key_parse key
;
1274 struct net_device
*dev
;
1275 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1278 err
= nl80211_parse_key(info
, &key
);
1285 /* only support setting default key */
1286 if (!key
.def
&& !key
.defmgmt
)
1291 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1296 func
= rdev
->ops
->set_default_key
;
1298 func
= rdev
->ops
->set_default_mgmt_key
;
1305 wdev_lock(dev
->ieee80211_ptr
);
1306 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1308 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1310 #ifdef CONFIG_WIRELESS_EXT
1312 if (func
== rdev
->ops
->set_default_key
)
1313 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1315 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1318 wdev_unlock(dev
->ieee80211_ptr
);
1321 cfg80211_unlock_rdev(rdev
);
1330 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1332 struct cfg80211_registered_device
*rdev
;
1334 struct net_device
*dev
;
1335 struct key_parse key
;
1336 u8
*mac_addr
= NULL
;
1338 err
= nl80211_parse_key(info
, &key
);
1345 if (info
->attrs
[NL80211_ATTR_MAC
])
1346 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1350 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1354 if (!rdev
->ops
->add_key
) {
1359 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1364 wdev_lock(dev
->ieee80211_ptr
);
1365 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1367 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1369 wdev_unlock(dev
->ieee80211_ptr
);
1372 cfg80211_unlock_rdev(rdev
);
1380 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1382 struct cfg80211_registered_device
*rdev
;
1384 struct net_device
*dev
;
1385 u8
*mac_addr
= NULL
;
1386 struct key_parse key
;
1388 err
= nl80211_parse_key(info
, &key
);
1392 if (info
->attrs
[NL80211_ATTR_MAC
])
1393 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1397 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1401 if (!rdev
->ops
->del_key
) {
1406 wdev_lock(dev
->ieee80211_ptr
);
1407 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1409 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1411 #ifdef CONFIG_WIRELESS_EXT
1413 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1414 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1415 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1416 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1419 wdev_unlock(dev
->ieee80211_ptr
);
1422 cfg80211_unlock_rdev(rdev
);
1431 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1433 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1434 struct beacon_parameters
*info
);
1435 struct cfg80211_registered_device
*rdev
;
1437 struct net_device
*dev
;
1438 struct beacon_parameters params
;
1441 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1446 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1450 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1455 switch (info
->genlhdr
->cmd
) {
1456 case NL80211_CMD_NEW_BEACON
:
1457 /* these are required for NEW_BEACON */
1458 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1459 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1460 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1465 call
= rdev
->ops
->add_beacon
;
1467 case NL80211_CMD_SET_BEACON
:
1468 call
= rdev
->ops
->set_beacon
;
1481 memset(¶ms
, 0, sizeof(params
));
1483 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1485 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1489 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1490 params
.dtim_period
=
1491 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1495 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1496 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1498 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1502 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1503 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1505 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1514 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1517 cfg80211_unlock_rdev(rdev
);
1525 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1527 struct cfg80211_registered_device
*rdev
;
1529 struct net_device
*dev
;
1533 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1537 if (!rdev
->ops
->del_beacon
) {
1542 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1546 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1549 cfg80211_unlock_rdev(rdev
);
1557 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1558 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1559 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1560 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1561 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1564 static int parse_station_flags(struct genl_info
*info
,
1565 struct station_parameters
*params
)
1567 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1572 * Try parsing the new attribute first so userspace
1573 * can specify both for older kernels.
1575 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1577 struct nl80211_sta_flag_update
*sta_flags
;
1579 sta_flags
= nla_data(nla
);
1580 params
->sta_flags_mask
= sta_flags
->mask
;
1581 params
->sta_flags_set
= sta_flags
->set
;
1582 if ((params
->sta_flags_mask
|
1583 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1588 /* if present, parse the old attribute */
1590 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1594 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1595 nla
, sta_flags_policy
))
1598 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1599 params
->sta_flags_mask
&= ~1;
1601 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1603 params
->sta_flags_set
|= (1<<flag
);
1608 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1610 int modulation
, streams
, bitrate
;
1612 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1613 return rate
->legacy
;
1615 /* the formula below does only work for MCS values smaller than 32 */
1616 if (rate
->mcs
>= 32)
1619 modulation
= rate
->mcs
& 7;
1620 streams
= (rate
->mcs
>> 3) + 1;
1622 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1626 bitrate
*= (modulation
+ 1);
1627 else if (modulation
== 4)
1628 bitrate
*= (modulation
+ 2);
1630 bitrate
*= (modulation
+ 3);
1634 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1635 bitrate
= (bitrate
/ 9) * 10;
1637 /* do NOT round down here */
1638 return (bitrate
+ 50000) / 100000;
1641 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1642 int flags
, struct net_device
*dev
,
1643 u8
*mac_addr
, struct station_info
*sinfo
)
1646 struct nlattr
*sinfoattr
, *txrate
;
1649 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1653 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1654 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1656 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1658 goto nla_put_failure
;
1659 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1660 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1661 sinfo
->inactive_time
);
1662 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1663 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1665 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1666 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1668 if (sinfo
->filled
& STATION_INFO_LLID
)
1669 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1671 if (sinfo
->filled
& STATION_INFO_PLID
)
1672 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1674 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1675 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1676 sinfo
->plink_state
);
1677 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1678 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1680 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1681 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1683 goto nla_put_failure
;
1685 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1686 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1688 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1690 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1691 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1693 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1694 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1695 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1696 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1698 nla_nest_end(msg
, txrate
);
1700 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1701 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1703 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1704 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1706 nla_nest_end(msg
, sinfoattr
);
1708 return genlmsg_end(msg
, hdr
);
1711 genlmsg_cancel(msg
, hdr
);
1715 static int nl80211_dump_station(struct sk_buff
*skb
,
1716 struct netlink_callback
*cb
)
1718 struct station_info sinfo
;
1719 struct cfg80211_registered_device
*dev
;
1720 struct net_device
*netdev
;
1721 u8 mac_addr
[ETH_ALEN
];
1722 int ifidx
= cb
->args
[0];
1723 int sta_idx
= cb
->args
[1];
1727 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1728 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1733 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1736 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1743 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1749 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1755 if (!dev
->ops
->dump_station
) {
1761 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1768 if (nl80211_send_station(skb
,
1769 NETLINK_CB(cb
->skb
).pid
,
1770 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1780 cb
->args
[1] = sta_idx
;
1783 cfg80211_unlock_rdev(dev
);
1790 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1792 struct cfg80211_registered_device
*rdev
;
1794 struct net_device
*dev
;
1795 struct station_info sinfo
;
1796 struct sk_buff
*msg
;
1797 u8
*mac_addr
= NULL
;
1799 memset(&sinfo
, 0, sizeof(sinfo
));
1801 if (!info
->attrs
[NL80211_ATTR_MAC
])
1804 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1808 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1812 if (!rdev
->ops
->get_station
) {
1817 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1821 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1825 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1826 dev
, mac_addr
, &sinfo
) < 0)
1829 err
= genlmsg_reply(msg
, info
);
1835 cfg80211_unlock_rdev(rdev
);
1844 * Get vlan interface making sure it is on the right wiphy.
1846 static int get_vlan(struct genl_info
*info
,
1847 struct cfg80211_registered_device
*rdev
,
1848 struct net_device
**vlan
)
1850 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1854 *vlan
= dev_get_by_index(genl_info_net(info
),
1855 nla_get_u32(vlanattr
));
1858 if (!(*vlan
)->ieee80211_ptr
)
1860 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1866 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1868 struct cfg80211_registered_device
*rdev
;
1870 struct net_device
*dev
;
1871 struct station_parameters params
;
1872 u8
*mac_addr
= NULL
;
1874 memset(¶ms
, 0, sizeof(params
));
1876 params
.listen_interval
= -1;
1878 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1881 if (!info
->attrs
[NL80211_ATTR_MAC
])
1884 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1886 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1887 params
.supported_rates
=
1888 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1889 params
.supported_rates_len
=
1890 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1893 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1894 params
.listen_interval
=
1895 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1897 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1899 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1901 if (parse_station_flags(info
, ¶ms
))
1904 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1905 params
.plink_action
=
1906 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1910 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1914 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
1918 /* validate settings */
1921 switch (dev
->ieee80211_ptr
->iftype
) {
1922 case NL80211_IFTYPE_AP
:
1923 case NL80211_IFTYPE_AP_VLAN
:
1924 /* disallow mesh-specific things */
1925 if (params
.plink_action
)
1928 case NL80211_IFTYPE_STATION
:
1929 /* disallow everything but AUTHORIZED flag */
1930 if (params
.plink_action
)
1934 if (params
.supported_rates
)
1938 if (params
.listen_interval
>= 0)
1940 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1943 case NL80211_IFTYPE_MESH_POINT
:
1944 /* disallow things mesh doesn't support */
1949 if (params
.listen_interval
>= 0)
1951 if (params
.supported_rates
)
1953 if (params
.sta_flags_mask
)
1963 if (!rdev
->ops
->change_station
) {
1968 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
1972 dev_put(params
.vlan
);
1973 cfg80211_unlock_rdev(rdev
);
1981 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1983 struct cfg80211_registered_device
*rdev
;
1985 struct net_device
*dev
;
1986 struct station_parameters params
;
1987 u8
*mac_addr
= NULL
;
1989 memset(¶ms
, 0, sizeof(params
));
1991 if (!info
->attrs
[NL80211_ATTR_MAC
])
1994 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1997 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2000 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2001 params
.supported_rates
=
2002 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2003 params
.supported_rates_len
=
2004 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2005 params
.listen_interval
=
2006 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2008 if (info
->attrs
[NL80211_ATTR_STA_AID
]) {
2009 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2010 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2014 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2016 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2018 if (parse_station_flags(info
, ¶ms
))
2023 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2027 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2031 /* validate settings */
2034 switch (dev
->ieee80211_ptr
->iftype
) {
2035 case NL80211_IFTYPE_AP
:
2036 case NL80211_IFTYPE_AP_VLAN
:
2037 /* all ok but must have AID */
2041 case NL80211_IFTYPE_MESH_POINT
:
2042 /* disallow things mesh doesn't support */
2049 if (params
.listen_interval
>= 0)
2051 if (params
.supported_rates
)
2053 if (params
.sta_flags_mask
)
2063 if (!rdev
->ops
->add_station
) {
2068 if (!netif_running(dev
)) {
2073 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2077 dev_put(params
.vlan
);
2078 cfg80211_unlock_rdev(rdev
);
2086 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2088 struct cfg80211_registered_device
*rdev
;
2090 struct net_device
*dev
;
2091 u8
*mac_addr
= NULL
;
2093 if (info
->attrs
[NL80211_ATTR_MAC
])
2094 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2098 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2102 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2103 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2104 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2109 if (!rdev
->ops
->del_station
) {
2114 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2117 cfg80211_unlock_rdev(rdev
);
2125 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2126 int flags
, struct net_device
*dev
,
2127 u8
*dst
, u8
*next_hop
,
2128 struct mpath_info
*pinfo
)
2131 struct nlattr
*pinfoattr
;
2133 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2137 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2138 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2139 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2141 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2143 goto nla_put_failure
;
2144 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2145 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2147 if (pinfo
->filled
& MPATH_INFO_DSN
)
2148 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
2150 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2151 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2153 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2154 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2156 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2157 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2159 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2160 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2161 pinfo
->discovery_timeout
);
2162 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2163 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2164 pinfo
->discovery_retries
);
2166 nla_nest_end(msg
, pinfoattr
);
2168 return genlmsg_end(msg
, hdr
);
2171 genlmsg_cancel(msg
, hdr
);
2175 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2176 struct netlink_callback
*cb
)
2178 struct mpath_info pinfo
;
2179 struct cfg80211_registered_device
*dev
;
2180 struct net_device
*netdev
;
2182 u8 next_hop
[ETH_ALEN
];
2183 int ifidx
= cb
->args
[0];
2184 int path_idx
= cb
->args
[1];
2188 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2189 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2194 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2197 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2204 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2210 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2216 if (!dev
->ops
->dump_mpath
) {
2221 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2227 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2228 dst
, next_hop
, &pinfo
);
2234 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2235 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2236 netdev
, dst
, next_hop
,
2245 cb
->args
[1] = path_idx
;
2248 cfg80211_unlock_rdev(dev
);
2255 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2257 struct cfg80211_registered_device
*rdev
;
2259 struct net_device
*dev
;
2260 struct mpath_info pinfo
;
2261 struct sk_buff
*msg
;
2263 u8 next_hop
[ETH_ALEN
];
2265 memset(&pinfo
, 0, sizeof(pinfo
));
2267 if (!info
->attrs
[NL80211_ATTR_MAC
])
2270 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2274 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2278 if (!rdev
->ops
->get_mpath
) {
2283 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2288 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2292 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2296 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2297 dev
, dst
, next_hop
, &pinfo
) < 0)
2300 err
= genlmsg_reply(msg
, info
);
2306 cfg80211_unlock_rdev(rdev
);
2314 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2316 struct cfg80211_registered_device
*rdev
;
2318 struct net_device
*dev
;
2320 u8
*next_hop
= NULL
;
2322 if (!info
->attrs
[NL80211_ATTR_MAC
])
2325 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2328 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2329 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2333 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2337 if (!rdev
->ops
->change_mpath
) {
2342 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2347 if (!netif_running(dev
)) {
2352 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2355 cfg80211_unlock_rdev(rdev
);
2362 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2364 struct cfg80211_registered_device
*rdev
;
2366 struct net_device
*dev
;
2368 u8
*next_hop
= NULL
;
2370 if (!info
->attrs
[NL80211_ATTR_MAC
])
2373 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2376 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2377 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2381 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2385 if (!rdev
->ops
->add_mpath
) {
2390 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2395 if (!netif_running(dev
)) {
2400 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2403 cfg80211_unlock_rdev(rdev
);
2411 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2413 struct cfg80211_registered_device
*rdev
;
2415 struct net_device
*dev
;
2418 if (info
->attrs
[NL80211_ATTR_MAC
])
2419 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2423 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2427 if (!rdev
->ops
->del_mpath
) {
2432 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2435 cfg80211_unlock_rdev(rdev
);
2443 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2445 struct cfg80211_registered_device
*rdev
;
2447 struct net_device
*dev
;
2448 struct bss_parameters params
;
2450 memset(¶ms
, 0, sizeof(params
));
2451 /* default to not changing parameters */
2452 params
.use_cts_prot
= -1;
2453 params
.use_short_preamble
= -1;
2454 params
.use_short_slot_time
= -1;
2456 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2457 params
.use_cts_prot
=
2458 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2459 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2460 params
.use_short_preamble
=
2461 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2462 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2463 params
.use_short_slot_time
=
2464 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2465 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2466 params
.basic_rates
=
2467 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2468 params
.basic_rates_len
=
2469 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2474 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2478 if (!rdev
->ops
->change_bss
) {
2483 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2488 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2491 cfg80211_unlock_rdev(rdev
);
2499 static const struct nla_policy
2500 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2501 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2502 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2503 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2504 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2505 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2506 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2509 static int parse_reg_rule(struct nlattr
*tb
[],
2510 struct ieee80211_reg_rule
*reg_rule
)
2512 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2513 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2515 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2517 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2519 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2521 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2523 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2526 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2528 freq_range
->start_freq_khz
=
2529 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2530 freq_range
->end_freq_khz
=
2531 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2532 freq_range
->max_bandwidth_khz
=
2533 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2535 power_rule
->max_eirp
=
2536 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2538 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2539 power_rule
->max_antenna_gain
=
2540 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2545 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2551 * You should only get this when cfg80211 hasn't yet initialized
2552 * completely when built-in to the kernel right between the time
2553 * window between nl80211_init() and regulatory_init(), if that is
2556 mutex_lock(&cfg80211_mutex
);
2557 if (unlikely(!cfg80211_regdomain
)) {
2558 mutex_unlock(&cfg80211_mutex
);
2559 return -EINPROGRESS
;
2561 mutex_unlock(&cfg80211_mutex
);
2563 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2566 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2568 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2569 /* We ignore world regdom requests with the old regdom setup */
2570 if (is_world_regdom(data
))
2574 r
= regulatory_hint_user(data
);
2579 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2580 struct genl_info
*info
)
2582 struct cfg80211_registered_device
*rdev
;
2583 struct mesh_config cur_params
;
2585 struct net_device
*dev
;
2587 struct nlattr
*pinfoattr
;
2588 struct sk_buff
*msg
;
2592 /* Look up our device */
2593 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2597 if (!rdev
->ops
->get_mesh_params
) {
2602 /* Get the mesh params */
2603 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2607 /* Draw up a netlink message to send back */
2608 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2613 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2614 NL80211_CMD_GET_MESH_PARAMS
);
2616 goto nla_put_failure
;
2617 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2619 goto nla_put_failure
;
2620 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2621 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2622 cur_params
.dot11MeshRetryTimeout
);
2623 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2624 cur_params
.dot11MeshConfirmTimeout
);
2625 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2626 cur_params
.dot11MeshHoldingTimeout
);
2627 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2628 cur_params
.dot11MeshMaxPeerLinks
);
2629 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2630 cur_params
.dot11MeshMaxRetries
);
2631 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2632 cur_params
.dot11MeshTTL
);
2633 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2634 cur_params
.auto_open_plinks
);
2635 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2636 cur_params
.dot11MeshHWMPmaxPREQretries
);
2637 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2638 cur_params
.path_refresh_time
);
2639 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2640 cur_params
.min_discovery_timeout
);
2641 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2642 cur_params
.dot11MeshHWMPactivePathTimeout
);
2643 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2644 cur_params
.dot11MeshHWMPpreqMinInterval
);
2645 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2646 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2647 nla_nest_end(msg
, pinfoattr
);
2648 genlmsg_end(msg
, hdr
);
2649 err
= genlmsg_reply(msg
, info
);
2653 genlmsg_cancel(msg
, hdr
);
2657 cfg80211_unlock_rdev(rdev
);
2665 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2667 if (table[attr_num]) {\
2668 cfg.param = nla_fn(table[attr_num]); \
2669 mask |= (1 << (attr_num - 1)); \
2673 static struct nla_policy
2674 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2675 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2676 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2677 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2678 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2679 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2680 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2681 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2683 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2684 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2685 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2686 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2687 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2688 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2691 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2695 struct cfg80211_registered_device
*rdev
;
2696 struct net_device
*dev
;
2697 struct mesh_config cfg
;
2698 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2699 struct nlattr
*parent_attr
;
2701 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2704 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2705 parent_attr
, nl80211_meshconf_params_policy
))
2710 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2714 if (!rdev
->ops
->set_mesh_params
) {
2719 /* This makes sure that there aren't more than 32 mesh config
2720 * parameters (otherwise our bitfield scheme would not work.) */
2721 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2723 /* Fill in the params struct */
2725 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2726 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2728 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2729 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2730 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2731 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2732 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2733 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2734 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2735 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2736 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2738 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2739 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2740 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2742 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2743 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2744 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2745 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2748 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2750 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2751 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2753 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2754 dot11MeshHWMPnetDiameterTraversalTime
,
2755 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2759 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2763 cfg80211_unlock_rdev(rdev
);
2771 #undef FILL_IN_MESH_PARAM_IF_SET
2773 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2775 struct sk_buff
*msg
;
2777 struct nlattr
*nl_reg_rules
;
2781 mutex_lock(&cfg80211_mutex
);
2783 if (!cfg80211_regdomain
)
2786 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2792 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2793 NL80211_CMD_GET_REG
);
2795 goto nla_put_failure
;
2797 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2798 cfg80211_regdomain
->alpha2
);
2800 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2802 goto nla_put_failure
;
2804 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2805 struct nlattr
*nl_reg_rule
;
2806 const struct ieee80211_reg_rule
*reg_rule
;
2807 const struct ieee80211_freq_range
*freq_range
;
2808 const struct ieee80211_power_rule
*power_rule
;
2810 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2811 freq_range
= ®_rule
->freq_range
;
2812 power_rule
= ®_rule
->power_rule
;
2814 nl_reg_rule
= nla_nest_start(msg
, i
);
2816 goto nla_put_failure
;
2818 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2820 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2821 freq_range
->start_freq_khz
);
2822 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2823 freq_range
->end_freq_khz
);
2824 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2825 freq_range
->max_bandwidth_khz
);
2826 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2827 power_rule
->max_antenna_gain
);
2828 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2829 power_rule
->max_eirp
);
2831 nla_nest_end(msg
, nl_reg_rule
);
2834 nla_nest_end(msg
, nl_reg_rules
);
2836 genlmsg_end(msg
, hdr
);
2837 err
= genlmsg_reply(msg
, info
);
2841 genlmsg_cancel(msg
, hdr
);
2844 mutex_unlock(&cfg80211_mutex
);
2848 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2850 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2851 struct nlattr
*nl_reg_rule
;
2852 char *alpha2
= NULL
;
2853 int rem_reg_rules
= 0, r
= 0;
2854 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2855 struct ieee80211_regdomain
*rd
= NULL
;
2857 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2860 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2863 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2865 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2868 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2872 mutex_lock(&cfg80211_mutex
);
2874 if (!reg_is_valid_request(alpha2
)) {
2879 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2880 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2882 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2888 rd
->n_reg_rules
= num_rules
;
2889 rd
->alpha2
[0] = alpha2
[0];
2890 rd
->alpha2
[1] = alpha2
[1];
2892 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2894 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2895 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2897 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2903 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2909 BUG_ON(rule_idx
!= num_rules
);
2913 mutex_unlock(&cfg80211_mutex
);
2918 mutex_unlock(&cfg80211_mutex
);
2923 static int validate_scan_freqs(struct nlattr
*freqs
)
2925 struct nlattr
*attr1
, *attr2
;
2926 int n_channels
= 0, tmp1
, tmp2
;
2928 nla_for_each_nested(attr1
, freqs
, tmp1
) {
2931 * Some hardware has a limited channel list for
2932 * scanning, and it is pretty much nonsensical
2933 * to scan for a channel twice, so disallow that
2934 * and don't require drivers to check that the
2935 * channel list they get isn't longer than what
2936 * they can scan, as long as they can scan all
2937 * the channels they registered at once.
2939 nla_for_each_nested(attr2
, freqs
, tmp2
)
2940 if (attr1
!= attr2
&&
2941 nla_get_u32(attr1
) == nla_get_u32(attr2
))
2948 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2950 struct cfg80211_registered_device
*rdev
;
2951 struct net_device
*dev
;
2952 struct cfg80211_scan_request
*request
;
2953 struct cfg80211_ssid
*ssid
;
2954 struct ieee80211_channel
*channel
;
2955 struct nlattr
*attr
;
2956 struct wiphy
*wiphy
;
2957 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
2958 enum ieee80211_band band
;
2961 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2966 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2970 wiphy
= &rdev
->wiphy
;
2972 if (!rdev
->ops
->scan
) {
2977 if (!netif_running(dev
)) {
2982 if (rdev
->scan_req
) {
2987 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2988 n_channels
= validate_scan_freqs(
2989 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
2997 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2998 if (wiphy
->bands
[band
])
2999 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3002 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3003 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3006 if (n_ssids
> wiphy
->max_scan_ssids
) {
3011 if (info
->attrs
[NL80211_ATTR_IE
])
3012 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3016 if (ie_len
> wiphy
->max_scan_ie_len
) {
3021 request
= kzalloc(sizeof(*request
)
3022 + sizeof(*ssid
) * n_ssids
3023 + sizeof(channel
) * n_channels
3024 + ie_len
, GFP_KERNEL
);
3030 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
3031 request
->n_channels
= n_channels
;
3033 request
->ssids
= (void *)(request
->channels
+ n_channels
);
3034 request
->n_ssids
= n_ssids
;
3037 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3039 request
->ie
= (void *)(request
->channels
+ n_channels
);
3042 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3043 /* user specified, bail out if channel not found */
3044 request
->n_channels
= n_channels
;
3046 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3047 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3048 if (!request
->channels
[i
]) {
3057 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3059 if (!wiphy
->bands
[band
])
3061 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3062 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
3069 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3070 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3071 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3075 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3076 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3081 if (info
->attrs
[NL80211_ATTR_IE
]) {
3082 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3083 memcpy((void *)request
->ie
,
3084 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3089 request
->wiphy
= &rdev
->wiphy
;
3091 rdev
->scan_req
= request
;
3092 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3095 nl80211_send_scan_start(rdev
, dev
);
3101 rdev
->scan_req
= NULL
;
3105 cfg80211_unlock_rdev(rdev
);
3113 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3114 struct cfg80211_registered_device
*rdev
,
3115 struct wireless_dev
*wdev
,
3116 struct cfg80211_internal_bss
*intbss
)
3118 struct cfg80211_bss
*res
= &intbss
->pub
;
3123 ASSERT_WDEV_LOCK(wdev
);
3125 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3126 NL80211_CMD_NEW_SCAN_RESULTS
);
3130 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
3131 rdev
->bss_generation
);
3132 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3134 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3136 goto nla_put_failure
;
3137 if (!is_zero_ether_addr(res
->bssid
))
3138 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3139 if (res
->information_elements
&& res
->len_information_elements
)
3140 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3141 res
->len_information_elements
,
3142 res
->information_elements
);
3144 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3145 if (res
->beacon_interval
)
3146 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3147 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3148 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3150 switch (rdev
->wiphy
.signal_type
) {
3151 case CFG80211_SIGNAL_TYPE_MBM
:
3152 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3154 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3155 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3161 switch (wdev
->iftype
) {
3162 case NL80211_IFTYPE_STATION
:
3163 if (intbss
== wdev
->current_bss
)
3164 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3165 NL80211_BSS_STATUS_ASSOCIATED
);
3166 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3167 if (intbss
!= wdev
->auth_bsses
[i
])
3169 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3170 NL80211_BSS_STATUS_AUTHENTICATED
);
3174 case NL80211_IFTYPE_ADHOC
:
3175 if (intbss
== wdev
->current_bss
)
3176 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3177 NL80211_BSS_STATUS_IBSS_JOINED
);
3183 nla_nest_end(msg
, bss
);
3185 return genlmsg_end(msg
, hdr
);
3188 genlmsg_cancel(msg
, hdr
);
3192 static int nl80211_dump_scan(struct sk_buff
*skb
,
3193 struct netlink_callback
*cb
)
3195 struct cfg80211_registered_device
*rdev
;
3196 struct net_device
*dev
;
3197 struct cfg80211_internal_bss
*scan
;
3198 struct wireless_dev
*wdev
;
3199 int ifidx
= cb
->args
[0];
3200 int start
= cb
->args
[1], idx
= 0;
3204 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
3205 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
3210 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
3213 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
3216 cb
->args
[0] = ifidx
;
3219 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3223 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3225 err
= PTR_ERR(rdev
);
3226 goto out_put_netdev
;
3229 wdev
= dev
->ieee80211_ptr
;
3232 spin_lock_bh(&rdev
->bss_lock
);
3233 cfg80211_bss_expire(rdev
);
3235 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3238 if (nl80211_send_bss(skb
,
3239 NETLINK_CB(cb
->skb
).pid
,
3240 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3241 rdev
, wdev
, scan
) < 0) {
3248 spin_unlock_bh(&rdev
->bss_lock
);
3253 cfg80211_unlock_rdev(rdev
);
3260 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3262 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3265 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3267 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3268 NL80211_WPA_VERSION_2
));
3271 static bool nl80211_valid_akm_suite(u32 akm
)
3273 return akm
== WLAN_AKM_SUITE_8021X
||
3274 akm
== WLAN_AKM_SUITE_PSK
;
3277 static bool nl80211_valid_cipher_suite(u32 cipher
)
3279 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3280 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3281 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3282 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3283 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3287 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3289 struct cfg80211_registered_device
*rdev
;
3290 struct net_device
*dev
;
3291 struct ieee80211_channel
*chan
;
3292 const u8
*bssid
, *ssid
, *ie
= NULL
;
3293 int err
, ssid_len
, ie_len
= 0;
3294 enum nl80211_auth_type auth_type
;
3295 struct key_parse key
;
3297 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3300 if (!info
->attrs
[NL80211_ATTR_MAC
])
3303 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3306 if (!info
->attrs
[NL80211_ATTR_SSID
])
3309 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3312 err
= nl80211_parse_key(info
, &key
);
3317 if (!key
.p
.key
|| !key
.p
.key_len
)
3319 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3320 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3321 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3322 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3333 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3337 if (!rdev
->ops
->auth
) {
3342 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3347 if (!netif_running(dev
)) {
3352 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3353 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3354 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3355 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3360 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3361 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3363 if (info
->attrs
[NL80211_ATTR_IE
]) {
3364 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3365 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3368 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3369 if (!nl80211_valid_auth_type(auth_type
)) {
3374 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3375 ssid
, ssid_len
, ie
, ie_len
,
3376 key
.p
.key
, key
.p
.key_len
, key
.idx
);
3379 cfg80211_unlock_rdev(rdev
);
3386 static int nl80211_crypto_settings(struct genl_info
*info
,
3387 struct cfg80211_crypto_settings
*settings
,
3390 memset(settings
, 0, sizeof(*settings
));
3392 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3394 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3398 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3399 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3400 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3402 if (len
% sizeof(u32
))
3405 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3408 memcpy(settings
->ciphers_pairwise
, data
, len
);
3410 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3411 if (!nl80211_valid_cipher_suite(
3412 settings
->ciphers_pairwise
[i
]))
3416 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3417 settings
->cipher_group
=
3418 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3419 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3423 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3424 settings
->wpa_versions
=
3425 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3426 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3430 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3434 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3435 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3436 settings
->n_akm_suites
= len
/ sizeof(u32
);
3438 if (len
% sizeof(u32
))
3441 memcpy(settings
->akm_suites
, data
, len
);
3443 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3444 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3451 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3453 struct cfg80211_registered_device
*rdev
;
3454 struct net_device
*dev
;
3455 struct cfg80211_crypto_settings crypto
;
3456 struct ieee80211_channel
*chan
;
3457 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3458 int err
, ssid_len
, ie_len
= 0;
3459 bool use_mfp
= false;
3461 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3464 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3465 !info
->attrs
[NL80211_ATTR_SSID
] ||
3466 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3471 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3475 if (!rdev
->ops
->assoc
) {
3480 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3485 if (!netif_running(dev
)) {
3490 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3492 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3493 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3494 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3499 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3500 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3502 if (info
->attrs
[NL80211_ATTR_IE
]) {
3503 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3504 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3507 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3508 enum nl80211_mfp mfp
=
3509 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3510 if (mfp
== NL80211_MFP_REQUIRED
)
3512 else if (mfp
!= NL80211_MFP_NO
) {
3518 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3519 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3521 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3523 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3524 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3528 cfg80211_unlock_rdev(rdev
);
3535 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3537 struct cfg80211_registered_device
*rdev
;
3538 struct net_device
*dev
;
3539 const u8
*ie
= NULL
, *bssid
;
3540 int err
, ie_len
= 0;
3543 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3546 if (!info
->attrs
[NL80211_ATTR_MAC
])
3549 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3554 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3558 if (!rdev
->ops
->deauth
) {
3563 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3568 if (!netif_running(dev
)) {
3573 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3575 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3576 if (reason_code
== 0) {
3577 /* Reason Code 0 is reserved */
3582 if (info
->attrs
[NL80211_ATTR_IE
]) {
3583 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3584 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3587 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3590 cfg80211_unlock_rdev(rdev
);
3597 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3599 struct cfg80211_registered_device
*rdev
;
3600 struct net_device
*dev
;
3601 const u8
*ie
= NULL
, *bssid
;
3602 int err
, ie_len
= 0;
3605 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3608 if (!info
->attrs
[NL80211_ATTR_MAC
])
3611 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3616 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3620 if (!rdev
->ops
->disassoc
) {
3625 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3630 if (!netif_running(dev
)) {
3635 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3637 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3638 if (reason_code
== 0) {
3639 /* Reason Code 0 is reserved */
3644 if (info
->attrs
[NL80211_ATTR_IE
]) {
3645 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3646 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3649 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3652 cfg80211_unlock_rdev(rdev
);
3659 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3661 struct cfg80211_registered_device
*rdev
;
3662 struct net_device
*dev
;
3663 struct cfg80211_ibss_params ibss
;
3664 struct wiphy
*wiphy
;
3665 struct cfg80211_cached_keys
*connkeys
= NULL
;
3668 memset(&ibss
, 0, sizeof(ibss
));
3670 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3673 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3674 !info
->attrs
[NL80211_ATTR_SSID
] ||
3675 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3678 ibss
.beacon_interval
= 100;
3680 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3681 ibss
.beacon_interval
=
3682 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3683 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3689 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3693 if (!rdev
->ops
->join_ibss
) {
3698 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3703 if (!netif_running(dev
)) {
3708 wiphy
= &rdev
->wiphy
;
3710 if (info
->attrs
[NL80211_ATTR_MAC
])
3711 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3712 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3713 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3715 if (info
->attrs
[NL80211_ATTR_IE
]) {
3716 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3717 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3720 ibss
.channel
= ieee80211_get_channel(wiphy
,
3721 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3722 if (!ibss
.channel
||
3723 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3724 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3729 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3730 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3732 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3733 connkeys
= nl80211_parse_connkeys(rdev
,
3734 info
->attrs
[NL80211_ATTR_KEYS
]);
3735 if (IS_ERR(connkeys
)) {
3736 err
= PTR_ERR(connkeys
);
3742 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3745 cfg80211_unlock_rdev(rdev
);
3754 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3756 struct cfg80211_registered_device
*rdev
;
3757 struct net_device
*dev
;
3762 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3766 if (!rdev
->ops
->leave_ibss
) {
3771 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3776 if (!netif_running(dev
)) {
3781 err
= cfg80211_leave_ibss(rdev
, dev
, false);
3784 cfg80211_unlock_rdev(rdev
);
3791 #ifdef CONFIG_NL80211_TESTMODE
3792 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3796 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3798 struct cfg80211_registered_device
*rdev
;
3801 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3806 rdev
= cfg80211_get_dev_from_info(info
);
3808 err
= PTR_ERR(rdev
);
3813 if (rdev
->ops
->testmode_cmd
) {
3814 rdev
->testmode_info
= info
;
3815 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3816 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3817 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3818 rdev
->testmode_info
= NULL
;
3821 cfg80211_unlock_rdev(rdev
);
3828 static struct sk_buff
*
3829 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
3830 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
3832 struct sk_buff
*skb
;
3834 struct nlattr
*data
;
3836 skb
= nlmsg_new(approxlen
+ 100, gfp
);
3840 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
3846 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3847 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
3849 ((void **)skb
->cb
)[0] = rdev
;
3850 ((void **)skb
->cb
)[1] = hdr
;
3851 ((void **)skb
->cb
)[2] = data
;
3860 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
3863 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3865 if (WARN_ON(!rdev
->testmode_info
))
3868 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
3869 rdev
->testmode_info
->snd_pid
,
3870 rdev
->testmode_info
->snd_seq
,
3873 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
3875 int cfg80211_testmode_reply(struct sk_buff
*skb
)
3877 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
3878 void *hdr
= ((void **)skb
->cb
)[1];
3879 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3881 if (WARN_ON(!rdev
->testmode_info
)) {
3886 nla_nest_end(skb
, data
);
3887 genlmsg_end(skb
, hdr
);
3888 return genlmsg_reply(skb
, rdev
->testmode_info
);
3890 EXPORT_SYMBOL(cfg80211_testmode_reply
);
3892 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
3893 int approxlen
, gfp_t gfp
)
3895 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3897 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
3899 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
3901 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
3903 void *hdr
= ((void **)skb
->cb
)[1];
3904 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3906 nla_nest_end(skb
, data
);
3907 genlmsg_end(skb
, hdr
);
3908 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
3910 EXPORT_SYMBOL(cfg80211_testmode_event
);
3913 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
3915 struct cfg80211_registered_device
*rdev
;
3916 struct net_device
*dev
;
3917 struct cfg80211_connect_params connect
;
3918 struct wiphy
*wiphy
;
3919 struct cfg80211_cached_keys
*connkeys
= NULL
;
3922 memset(&connect
, 0, sizeof(connect
));
3924 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3927 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
3928 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3931 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3933 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3934 if (!nl80211_valid_auth_type(connect
.auth_type
))
3937 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3939 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
3941 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
3942 NL80211_MAX_NR_CIPHER_SUITES
);
3947 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3951 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3956 if (!netif_running(dev
)) {
3961 wiphy
= &rdev
->wiphy
;
3963 if (info
->attrs
[NL80211_ATTR_MAC
])
3964 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3965 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3966 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3968 if (info
->attrs
[NL80211_ATTR_IE
]) {
3969 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3970 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3973 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3975 ieee80211_get_channel(wiphy
,
3976 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3977 if (!connect
.channel
||
3978 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3984 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3985 connkeys
= nl80211_parse_connkeys(rdev
,
3986 info
->attrs
[NL80211_ATTR_KEYS
]);
3987 if (IS_ERR(connkeys
)) {
3988 err
= PTR_ERR(connkeys
);
3994 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
3997 cfg80211_unlock_rdev(rdev
);
4006 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4008 struct cfg80211_registered_device
*rdev
;
4009 struct net_device
*dev
;
4013 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4014 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4016 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4023 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4027 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4032 if (!netif_running(dev
)) {
4037 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4040 cfg80211_unlock_rdev(rdev
);
4047 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4049 struct cfg80211_registered_device
*rdev
;
4054 if (!info
->attrs
[NL80211_ATTR_PID
])
4057 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4061 rdev
= cfg80211_get_dev_from_info(info
);
4063 err
= PTR_ERR(rdev
);
4067 net
= get_net_ns_by_pid(pid
);
4075 /* check if anything to do */
4076 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4079 err
= cfg80211_switch_netns(rdev
, net
);
4083 cfg80211_unlock_rdev(rdev
);
4088 static struct genl_ops nl80211_ops
[] = {
4090 .cmd
= NL80211_CMD_GET_WIPHY
,
4091 .doit
= nl80211_get_wiphy
,
4092 .dumpit
= nl80211_dump_wiphy
,
4093 .policy
= nl80211_policy
,
4094 /* can be retrieved by unprivileged users */
4097 .cmd
= NL80211_CMD_SET_WIPHY
,
4098 .doit
= nl80211_set_wiphy
,
4099 .policy
= nl80211_policy
,
4100 .flags
= GENL_ADMIN_PERM
,
4103 .cmd
= NL80211_CMD_GET_INTERFACE
,
4104 .doit
= nl80211_get_interface
,
4105 .dumpit
= nl80211_dump_interface
,
4106 .policy
= nl80211_policy
,
4107 /* can be retrieved by unprivileged users */
4110 .cmd
= NL80211_CMD_SET_INTERFACE
,
4111 .doit
= nl80211_set_interface
,
4112 .policy
= nl80211_policy
,
4113 .flags
= GENL_ADMIN_PERM
,
4116 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4117 .doit
= nl80211_new_interface
,
4118 .policy
= nl80211_policy
,
4119 .flags
= GENL_ADMIN_PERM
,
4122 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4123 .doit
= nl80211_del_interface
,
4124 .policy
= nl80211_policy
,
4125 .flags
= GENL_ADMIN_PERM
,
4128 .cmd
= NL80211_CMD_GET_KEY
,
4129 .doit
= nl80211_get_key
,
4130 .policy
= nl80211_policy
,
4131 .flags
= GENL_ADMIN_PERM
,
4134 .cmd
= NL80211_CMD_SET_KEY
,
4135 .doit
= nl80211_set_key
,
4136 .policy
= nl80211_policy
,
4137 .flags
= GENL_ADMIN_PERM
,
4140 .cmd
= NL80211_CMD_NEW_KEY
,
4141 .doit
= nl80211_new_key
,
4142 .policy
= nl80211_policy
,
4143 .flags
= GENL_ADMIN_PERM
,
4146 .cmd
= NL80211_CMD_DEL_KEY
,
4147 .doit
= nl80211_del_key
,
4148 .policy
= nl80211_policy
,
4149 .flags
= GENL_ADMIN_PERM
,
4152 .cmd
= NL80211_CMD_SET_BEACON
,
4153 .policy
= nl80211_policy
,
4154 .flags
= GENL_ADMIN_PERM
,
4155 .doit
= nl80211_addset_beacon
,
4158 .cmd
= NL80211_CMD_NEW_BEACON
,
4159 .policy
= nl80211_policy
,
4160 .flags
= GENL_ADMIN_PERM
,
4161 .doit
= nl80211_addset_beacon
,
4164 .cmd
= NL80211_CMD_DEL_BEACON
,
4165 .policy
= nl80211_policy
,
4166 .flags
= GENL_ADMIN_PERM
,
4167 .doit
= nl80211_del_beacon
,
4170 .cmd
= NL80211_CMD_GET_STATION
,
4171 .doit
= nl80211_get_station
,
4172 .dumpit
= nl80211_dump_station
,
4173 .policy
= nl80211_policy
,
4176 .cmd
= NL80211_CMD_SET_STATION
,
4177 .doit
= nl80211_set_station
,
4178 .policy
= nl80211_policy
,
4179 .flags
= GENL_ADMIN_PERM
,
4182 .cmd
= NL80211_CMD_NEW_STATION
,
4183 .doit
= nl80211_new_station
,
4184 .policy
= nl80211_policy
,
4185 .flags
= GENL_ADMIN_PERM
,
4188 .cmd
= NL80211_CMD_DEL_STATION
,
4189 .doit
= nl80211_del_station
,
4190 .policy
= nl80211_policy
,
4191 .flags
= GENL_ADMIN_PERM
,
4194 .cmd
= NL80211_CMD_GET_MPATH
,
4195 .doit
= nl80211_get_mpath
,
4196 .dumpit
= nl80211_dump_mpath
,
4197 .policy
= nl80211_policy
,
4198 .flags
= GENL_ADMIN_PERM
,
4201 .cmd
= NL80211_CMD_SET_MPATH
,
4202 .doit
= nl80211_set_mpath
,
4203 .policy
= nl80211_policy
,
4204 .flags
= GENL_ADMIN_PERM
,
4207 .cmd
= NL80211_CMD_NEW_MPATH
,
4208 .doit
= nl80211_new_mpath
,
4209 .policy
= nl80211_policy
,
4210 .flags
= GENL_ADMIN_PERM
,
4213 .cmd
= NL80211_CMD_DEL_MPATH
,
4214 .doit
= nl80211_del_mpath
,
4215 .policy
= nl80211_policy
,
4216 .flags
= GENL_ADMIN_PERM
,
4219 .cmd
= NL80211_CMD_SET_BSS
,
4220 .doit
= nl80211_set_bss
,
4221 .policy
= nl80211_policy
,
4222 .flags
= GENL_ADMIN_PERM
,
4225 .cmd
= NL80211_CMD_GET_REG
,
4226 .doit
= nl80211_get_reg
,
4227 .policy
= nl80211_policy
,
4228 /* can be retrieved by unprivileged users */
4231 .cmd
= NL80211_CMD_SET_REG
,
4232 .doit
= nl80211_set_reg
,
4233 .policy
= nl80211_policy
,
4234 .flags
= GENL_ADMIN_PERM
,
4237 .cmd
= NL80211_CMD_REQ_SET_REG
,
4238 .doit
= nl80211_req_set_reg
,
4239 .policy
= nl80211_policy
,
4240 .flags
= GENL_ADMIN_PERM
,
4243 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
4244 .doit
= nl80211_get_mesh_params
,
4245 .policy
= nl80211_policy
,
4246 /* can be retrieved by unprivileged users */
4249 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
4250 .doit
= nl80211_set_mesh_params
,
4251 .policy
= nl80211_policy
,
4252 .flags
= GENL_ADMIN_PERM
,
4255 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
4256 .doit
= nl80211_trigger_scan
,
4257 .policy
= nl80211_policy
,
4258 .flags
= GENL_ADMIN_PERM
,
4261 .cmd
= NL80211_CMD_GET_SCAN
,
4262 .policy
= nl80211_policy
,
4263 .dumpit
= nl80211_dump_scan
,
4266 .cmd
= NL80211_CMD_AUTHENTICATE
,
4267 .doit
= nl80211_authenticate
,
4268 .policy
= nl80211_policy
,
4269 .flags
= GENL_ADMIN_PERM
,
4272 .cmd
= NL80211_CMD_ASSOCIATE
,
4273 .doit
= nl80211_associate
,
4274 .policy
= nl80211_policy
,
4275 .flags
= GENL_ADMIN_PERM
,
4278 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
4279 .doit
= nl80211_deauthenticate
,
4280 .policy
= nl80211_policy
,
4281 .flags
= GENL_ADMIN_PERM
,
4284 .cmd
= NL80211_CMD_DISASSOCIATE
,
4285 .doit
= nl80211_disassociate
,
4286 .policy
= nl80211_policy
,
4287 .flags
= GENL_ADMIN_PERM
,
4290 .cmd
= NL80211_CMD_JOIN_IBSS
,
4291 .doit
= nl80211_join_ibss
,
4292 .policy
= nl80211_policy
,
4293 .flags
= GENL_ADMIN_PERM
,
4296 .cmd
= NL80211_CMD_LEAVE_IBSS
,
4297 .doit
= nl80211_leave_ibss
,
4298 .policy
= nl80211_policy
,
4299 .flags
= GENL_ADMIN_PERM
,
4301 #ifdef CONFIG_NL80211_TESTMODE
4303 .cmd
= NL80211_CMD_TESTMODE
,
4304 .doit
= nl80211_testmode_do
,
4305 .policy
= nl80211_policy
,
4306 .flags
= GENL_ADMIN_PERM
,
4310 .cmd
= NL80211_CMD_CONNECT
,
4311 .doit
= nl80211_connect
,
4312 .policy
= nl80211_policy
,
4313 .flags
= GENL_ADMIN_PERM
,
4316 .cmd
= NL80211_CMD_DISCONNECT
,
4317 .doit
= nl80211_disconnect
,
4318 .policy
= nl80211_policy
,
4319 .flags
= GENL_ADMIN_PERM
,
4322 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
4323 .doit
= nl80211_wiphy_netns
,
4324 .policy
= nl80211_policy
,
4325 .flags
= GENL_ADMIN_PERM
,
4328 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
4332 /* multicast groups */
4333 static struct genl_multicast_group nl80211_config_mcgrp
= {
4336 static struct genl_multicast_group nl80211_scan_mcgrp
= {
4339 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
4340 .name
= "regulatory",
4343 /* notification functions */
4345 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
4347 struct sk_buff
*msg
;
4349 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4353 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
4358 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4359 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
4362 static int nl80211_add_scan_req(struct sk_buff
*msg
,
4363 struct cfg80211_registered_device
*rdev
)
4365 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
4366 struct nlattr
*nest
;
4369 ASSERT_RDEV_LOCK(rdev
);
4374 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
4376 goto nla_put_failure
;
4377 for (i
= 0; i
< req
->n_ssids
; i
++)
4378 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
4379 nla_nest_end(msg
, nest
);
4381 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
4383 goto nla_put_failure
;
4384 for (i
= 0; i
< req
->n_channels
; i
++)
4385 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
4386 nla_nest_end(msg
, nest
);
4389 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
4396 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
4397 struct cfg80211_registered_device
*rdev
,
4398 struct net_device
*netdev
,
4399 u32 pid
, u32 seq
, int flags
,
4404 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
4408 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4409 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4411 /* ignore errors and send incomplete event anyway */
4412 nl80211_add_scan_req(msg
, rdev
);
4414 return genlmsg_end(msg
, hdr
);
4417 genlmsg_cancel(msg
, hdr
);
4421 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
4422 struct net_device
*netdev
)
4424 struct sk_buff
*msg
;
4426 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
4430 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4431 NL80211_CMD_TRIGGER_SCAN
) < 0) {
4436 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4437 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4440 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
4441 struct net_device
*netdev
)
4443 struct sk_buff
*msg
;
4445 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4449 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4450 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
4455 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4456 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4459 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
4460 struct net_device
*netdev
)
4462 struct sk_buff
*msg
;
4464 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4468 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4469 NL80211_CMD_SCAN_ABORTED
) < 0) {
4474 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4475 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4479 * This can happen on global regulatory changes or device specific settings
4480 * based on custom world regulatory domains.
4482 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
4484 struct sk_buff
*msg
;
4487 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4491 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
4497 /* Userspace can always count this one always being set */
4498 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
4500 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
4501 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4502 NL80211_REGDOM_TYPE_WORLD
);
4503 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
4504 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4505 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
4506 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
4508 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4509 NL80211_REGDOM_TYPE_INTERSECTION
);
4511 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4512 NL80211_REGDOM_TYPE_COUNTRY
);
4513 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
4516 if (wiphy_idx_valid(request
->wiphy_idx
))
4517 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
4519 if (genlmsg_end(msg
, hdr
) < 0) {
4525 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
4532 genlmsg_cancel(msg
, hdr
);
4536 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
4537 struct net_device
*netdev
,
4538 const u8
*buf
, size_t len
,
4539 enum nl80211_commands cmd
, gfp_t gfp
)
4541 struct sk_buff
*msg
;
4544 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4548 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
4554 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4555 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4556 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
4558 if (genlmsg_end(msg
, hdr
) < 0) {
4563 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4564 nl80211_mlme_mcgrp
.id
, gfp
);
4568 genlmsg_cancel(msg
, hdr
);
4572 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
4573 struct net_device
*netdev
, const u8
*buf
,
4574 size_t len
, gfp_t gfp
)
4576 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4577 NL80211_CMD_AUTHENTICATE
, gfp
);
4580 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
4581 struct net_device
*netdev
, const u8
*buf
,
4582 size_t len
, gfp_t gfp
)
4584 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4585 NL80211_CMD_ASSOCIATE
, gfp
);
4588 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
4589 struct net_device
*netdev
, const u8
*buf
,
4590 size_t len
, gfp_t gfp
)
4592 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4593 NL80211_CMD_DEAUTHENTICATE
, gfp
);
4596 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
4597 struct net_device
*netdev
, const u8
*buf
,
4598 size_t len
, gfp_t gfp
)
4600 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4601 NL80211_CMD_DISASSOCIATE
, gfp
);
4604 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
4605 struct net_device
*netdev
, int cmd
,
4606 const u8
*addr
, gfp_t gfp
)
4608 struct sk_buff
*msg
;
4611 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4615 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
4621 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4622 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4623 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
4624 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4626 if (genlmsg_end(msg
, hdr
) < 0) {
4631 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4632 nl80211_mlme_mcgrp
.id
, gfp
);
4636 genlmsg_cancel(msg
, hdr
);
4640 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
4641 struct net_device
*netdev
, const u8
*addr
,
4644 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
4648 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
4649 struct net_device
*netdev
, const u8
*addr
,
4652 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
4656 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
4657 struct net_device
*netdev
, const u8
*bssid
,
4658 const u8
*req_ie
, size_t req_ie_len
,
4659 const u8
*resp_ie
, size_t resp_ie_len
,
4660 u16 status
, gfp_t gfp
)
4662 struct sk_buff
*msg
;
4665 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
4669 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
4675 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4676 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4678 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4679 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
4681 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
4683 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
4685 if (genlmsg_end(msg
, hdr
) < 0) {
4690 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4691 nl80211_mlme_mcgrp
.id
, gfp
);
4695 genlmsg_cancel(msg
, hdr
);
4700 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
4701 struct net_device
*netdev
, const u8
*bssid
,
4702 const u8
*req_ie
, size_t req_ie_len
,
4703 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
4705 struct sk_buff
*msg
;
4708 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
4712 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
4718 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4719 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4720 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4722 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
4724 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
4726 if (genlmsg_end(msg
, hdr
) < 0) {
4731 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4732 nl80211_mlme_mcgrp
.id
, gfp
);
4736 genlmsg_cancel(msg
, hdr
);
4741 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
4742 struct net_device
*netdev
, u16 reason
,
4743 const u8
*ie
, size_t ie_len
, bool from_ap
)
4745 struct sk_buff
*msg
;
4748 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
4752 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
4758 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4759 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4760 if (from_ap
&& reason
)
4761 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
4763 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
4765 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
4767 if (genlmsg_end(msg
, hdr
) < 0) {
4772 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4773 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
4777 genlmsg_cancel(msg
, hdr
);
4782 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
4783 struct net_device
*netdev
, const u8
*bssid
,
4786 struct sk_buff
*msg
;
4789 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4793 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
4799 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4800 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4801 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4803 if (genlmsg_end(msg
, hdr
) < 0) {
4808 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4809 nl80211_mlme_mcgrp
.id
, gfp
);
4813 genlmsg_cancel(msg
, hdr
);
4817 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
4818 struct net_device
*netdev
, const u8
*addr
,
4819 enum nl80211_key_type key_type
, int key_id
,
4820 const u8
*tsc
, gfp_t gfp
)
4822 struct sk_buff
*msg
;
4825 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4829 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
4835 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4836 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4838 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4839 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
4840 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
4842 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
4844 if (genlmsg_end(msg
, hdr
) < 0) {
4849 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4850 nl80211_mlme_mcgrp
.id
, gfp
);
4854 genlmsg_cancel(msg
, hdr
);
4858 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
4859 struct ieee80211_channel
*channel_before
,
4860 struct ieee80211_channel
*channel_after
)
4862 struct sk_buff
*msg
;
4864 struct nlattr
*nl_freq
;
4866 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
4870 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
4877 * Since we are applying the beacon hint to a wiphy we know its
4878 * wiphy_idx is valid
4880 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
4883 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
4885 goto nla_put_failure
;
4886 if (nl80211_msg_put_channel(msg
, channel_before
))
4887 goto nla_put_failure
;
4888 nla_nest_end(msg
, nl_freq
);
4891 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
4893 goto nla_put_failure
;
4894 if (nl80211_msg_put_channel(msg
, channel_after
))
4895 goto nla_put_failure
;
4896 nla_nest_end(msg
, nl_freq
);
4898 if (genlmsg_end(msg
, hdr
) < 0) {
4904 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
4911 genlmsg_cancel(msg
, hdr
);
4915 /* initialisation/exit functions */
4917 int nl80211_init(void)
4921 err
= genl_register_family_with_ops(&nl80211_fam
,
4922 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
4926 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
4930 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
4934 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
4938 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
4942 #ifdef CONFIG_NL80211_TESTMODE
4943 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
4950 genl_unregister_family(&nl80211_fam
);
4954 void nl80211_exit(void)
4956 genl_unregister_family(&nl80211_fam
);