2 * Driver interaction with Linux nl80211/cfg80211
3 * Copyright (c) 2002-2012, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2003-2004, Instant802 Networks, Inc.
5 * Copyright (c) 2005-2006, Devicescape Software, Inc.
6 * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
7 * Copyright (c) 2009-2010, Atheros Communications
9 * This software may be distributed under the terms of the BSD license.
10 * See README for more details.
14 #include <sys/ioctl.h>
15 #include <sys/types.h>
19 #include <netlink/genl/genl.h>
20 #include <netlink/genl/family.h>
21 #include <netlink/genl/ctrl.h>
22 #include <linux/rtnetlink.h>
23 #include <netpacket/packet.h>
24 #include <linux/filter.h>
25 #include <linux/errqueue.h>
26 #include "nl80211_copy.h"
30 #include "utils/list.h"
31 #include "common/ieee802_11_defs.h"
32 #include "common/ieee802_11_common.h"
33 #include "l2_packet/l2_packet.h"
35 #include "linux_ioctl.h"
37 #include "radiotap_iter.h"
41 #ifndef SO_WIFI_STATUS
42 # if defined(__sparc__)
43 # define SO_WIFI_STATUS 0x0025
44 # elif defined(__parisc__)
45 # define SO_WIFI_STATUS 0x4022
47 # define SO_WIFI_STATUS 41
50 # define SCM_WIFI_STATUS SO_WIFI_STATUS
53 #ifndef SO_EE_ORIGIN_TXSTATUS
54 #define SO_EE_ORIGIN_TXSTATUS 4
57 #ifndef PACKET_TX_TIMESTAMP
58 #define PACKET_TX_TIMESTAMP 16
62 #include "android_drv.h"
65 /* libnl 2.0 compatibility code */
66 #define nl_handle nl_sock
67 #define nl80211_handle_alloc nl_socket_alloc_cb
68 #define nl80211_handle_destroy nl_socket_free
71 * libnl 1.1 has a bug, it tries to allocate socket numbers densely
72 * but when you free a socket again it will mess up its bitmap and
73 * and use the wrong number the next time it needs a socket ID.
74 * Therefore, we wrap the handle alloc/destroy and add our own pid
77 static uint32_t port_bitmap
[32] = { 0 };
79 static struct nl_handle
*nl80211_handle_alloc(void *cb
)
81 struct nl_handle
*handle
;
82 uint32_t pid
= getpid() & 0x3FFFFF;
85 handle
= nl_handle_alloc_cb(cb
);
87 for (i
= 0; i
< 1024; i
++) {
88 if (port_bitmap
[i
/ 32] & (1 << (i
% 32)))
90 port_bitmap
[i
/ 32] |= 1 << (i
% 32);
95 nl_socket_set_local_port(handle
, pid
);
100 static void nl80211_handle_destroy(struct nl_handle
*handle
)
102 uint32_t port
= nl_socket_get_local_port(handle
);
105 port_bitmap
[port
/ 32] &= ~(1 << (port
% 32));
107 nl_handle_destroy(handle
);
109 #endif /* CONFIG_LIBNL20 */
112 static struct nl_handle
* nl_create_handle(struct nl_cb
*cb
, const char *dbg
)
114 struct nl_handle
*handle
;
116 handle
= nl80211_handle_alloc(cb
);
117 if (handle
== NULL
) {
118 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
119 "callbacks (%s)", dbg
);
123 if (genl_connect(handle
)) {
124 wpa_printf(MSG_ERROR
, "nl80211: Failed to connect to generic "
125 "netlink (%s)", dbg
);
126 nl80211_handle_destroy(handle
);
134 static void nl_destroy_handles(struct nl_handle
**handle
)
138 nl80211_handle_destroy(*handle
);
144 #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
146 #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
149 static void nl80211_register_eloop_read(struct nl_handle
**handle
,
150 eloop_sock_handler handler
,
153 nl_socket_set_nonblocking(*handle
);
154 eloop_register_read_sock(nl_socket_get_fd(*handle
), handler
,
155 eloop_data
, *handle
);
156 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
160 static void nl80211_destroy_eloop_handle(struct nl_handle
**handle
)
162 *handle
= (void *) (((intptr_t) *handle
) ^ ELOOP_SOCKET_INVALID
);
163 eloop_unregister_read_sock(nl_socket_get_fd(*handle
));
164 nl_destroy_handles(handle
);
169 #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */
172 #define IFF_DORMANT 0x20000 /* driver signals dormant */
175 #ifndef IF_OPER_DORMANT
176 #define IF_OPER_DORMANT 5
182 struct nl80211_global
{
183 struct dl_list interfaces
;
186 int if_add_wdevid_set
;
187 struct netlink_data
*netlink
;
189 struct nl_handle
*nl
;
191 int ioctl_sock
; /* socket for ioctl() use */
193 struct nl_handle
*nl_event
;
196 struct nl80211_wiphy_data
{
201 struct nl_handle
*nl_beacons
;
207 static void nl80211_global_deinit(void *priv
);
210 struct wpa_driver_nl80211_data
*drv
;
211 struct i802_bss
*next
;
214 char ifname
[IFNAMSIZ
+ 1];
215 char brname
[IFNAMSIZ
];
216 unsigned int beacon_set
:1;
217 unsigned int added_if_into_bridge
:1;
218 unsigned int added_bridge
:1;
219 unsigned int in_deinit
:1;
220 unsigned int wdev_id_set
:1;
228 struct nl_handle
*nl_preq
, *nl_mgmt
;
231 struct nl80211_wiphy_data
*wiphy_data
;
232 struct dl_list wiphy_list
;
235 struct wpa_driver_nl80211_data
{
236 struct nl80211_global
*global
;
238 struct dl_list wiphy_list
;
244 int ignore_if_down_event
;
245 struct rfkill_data
*rfkill
;
246 struct wpa_driver_capa capa
;
247 u8
*extended_capa
, *extended_capa_mask
;
248 unsigned int extended_capa_len
;
253 int scan_complete_events
;
255 NO_SCAN
, SCAN_REQUESTED
, SCAN_STARTED
, SCAN_COMPLETED
,
256 SCAN_ABORTED
, SCHED_SCAN_STARTED
, SCHED_SCAN_STOPPED
,
262 u8 auth_bssid
[ETH_ALEN
];
263 u8 auth_attempt_bssid
[ETH_ALEN
];
265 u8 prev_bssid
[ETH_ALEN
];
269 enum nl80211_iftype nlmode
;
270 enum nl80211_iftype ap_scan_as_station
;
271 unsigned int assoc_freq
;
275 int monitor_refcount
;
277 unsigned int disabled_11b_rates
:1;
278 unsigned int pending_remain_on_chan
:1;
279 unsigned int in_interface_list
:1;
280 unsigned int device_ap_sme
:1;
281 unsigned int poll_command_supported
:1;
282 unsigned int data_tx_status
:1;
283 unsigned int scan_for_auth
:1;
284 unsigned int retry_auth
:1;
285 unsigned int use_monitor
:1;
286 unsigned int ignore_next_local_disconnect
:1;
287 unsigned int allow_p2p_device
:1;
289 u64 remain_on_chan_cookie
;
290 u64 send_action_cookie
;
292 unsigned int last_mgmt_freq
;
294 struct wpa_driver_scan_filter
*filter_ssids
;
295 size_t num_filter_ssids
;
297 struct i802_bss first_bss
;
302 int eapol_sock
; /* socket for EAPOL frames */
304 int default_if_indices
[16];
312 /* From failed authentication command */
314 u8 auth_bssid_
[ETH_ALEN
];
316 size_t auth_ssid_len
;
320 u8 auth_wep_key
[4][16];
321 size_t auth_wep_key_len
[4];
322 int auth_wep_tx_keyidx
;
323 int auth_local_state_change
;
328 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
329 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
331 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
332 enum nl80211_iftype nlmode
);
334 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
335 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
336 const u8
*addr
, int cmd
, u16 reason_code
,
337 int local_state_change
);
338 static void nl80211_remove_monitor_interface(
339 struct wpa_driver_nl80211_data
*drv
);
340 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
341 unsigned int freq
, unsigned int wait
,
342 const u8
*buf
, size_t buf_len
, u64
*cookie
,
343 int no_cck
, int no_ack
, int offchanok
);
344 static int nl80211_register_frame(struct i802_bss
*bss
,
345 struct nl_handle
*hl_handle
,
346 u16 type
, const u8
*match
, size_t match_len
);
347 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
350 static int android_pno_start(struct i802_bss
*bss
,
351 struct wpa_driver_scan_params
*params
);
352 static int android_pno_stop(struct i802_bss
*bss
);
356 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
357 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
358 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
359 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
360 enum wpa_driver_if_type type
,
363 static inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
367 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
371 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
377 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
378 struct hostapd_freq_params
*freq
);
379 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
380 int ifindex
, int disabled
);
382 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
383 static int wpa_driver_nl80211_authenticate_retry(
384 struct wpa_driver_nl80211_data
*drv
);
386 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
);
389 static const char * nl80211_command_to_string(enum nl80211_commands cmd
)
391 #define C2S(x) case x: return #x;
393 C2S(NL80211_CMD_UNSPEC
)
394 C2S(NL80211_CMD_GET_WIPHY
)
395 C2S(NL80211_CMD_SET_WIPHY
)
396 C2S(NL80211_CMD_NEW_WIPHY
)
397 C2S(NL80211_CMD_DEL_WIPHY
)
398 C2S(NL80211_CMD_GET_INTERFACE
)
399 C2S(NL80211_CMD_SET_INTERFACE
)
400 C2S(NL80211_CMD_NEW_INTERFACE
)
401 C2S(NL80211_CMD_DEL_INTERFACE
)
402 C2S(NL80211_CMD_GET_KEY
)
403 C2S(NL80211_CMD_SET_KEY
)
404 C2S(NL80211_CMD_NEW_KEY
)
405 C2S(NL80211_CMD_DEL_KEY
)
406 C2S(NL80211_CMD_GET_BEACON
)
407 C2S(NL80211_CMD_SET_BEACON
)
408 C2S(NL80211_CMD_START_AP
)
409 C2S(NL80211_CMD_STOP_AP
)
410 C2S(NL80211_CMD_GET_STATION
)
411 C2S(NL80211_CMD_SET_STATION
)
412 C2S(NL80211_CMD_NEW_STATION
)
413 C2S(NL80211_CMD_DEL_STATION
)
414 C2S(NL80211_CMD_GET_MPATH
)
415 C2S(NL80211_CMD_SET_MPATH
)
416 C2S(NL80211_CMD_NEW_MPATH
)
417 C2S(NL80211_CMD_DEL_MPATH
)
418 C2S(NL80211_CMD_SET_BSS
)
419 C2S(NL80211_CMD_SET_REG
)
420 C2S(NL80211_CMD_REQ_SET_REG
)
421 C2S(NL80211_CMD_GET_MESH_CONFIG
)
422 C2S(NL80211_CMD_SET_MESH_CONFIG
)
423 C2S(NL80211_CMD_SET_MGMT_EXTRA_IE
)
424 C2S(NL80211_CMD_GET_REG
)
425 C2S(NL80211_CMD_GET_SCAN
)
426 C2S(NL80211_CMD_TRIGGER_SCAN
)
427 C2S(NL80211_CMD_NEW_SCAN_RESULTS
)
428 C2S(NL80211_CMD_SCAN_ABORTED
)
429 C2S(NL80211_CMD_REG_CHANGE
)
430 C2S(NL80211_CMD_AUTHENTICATE
)
431 C2S(NL80211_CMD_ASSOCIATE
)
432 C2S(NL80211_CMD_DEAUTHENTICATE
)
433 C2S(NL80211_CMD_DISASSOCIATE
)
434 C2S(NL80211_CMD_MICHAEL_MIC_FAILURE
)
435 C2S(NL80211_CMD_REG_BEACON_HINT
)
436 C2S(NL80211_CMD_JOIN_IBSS
)
437 C2S(NL80211_CMD_LEAVE_IBSS
)
438 C2S(NL80211_CMD_TESTMODE
)
439 C2S(NL80211_CMD_CONNECT
)
440 C2S(NL80211_CMD_ROAM
)
441 C2S(NL80211_CMD_DISCONNECT
)
442 C2S(NL80211_CMD_SET_WIPHY_NETNS
)
443 C2S(NL80211_CMD_GET_SURVEY
)
444 C2S(NL80211_CMD_NEW_SURVEY_RESULTS
)
445 C2S(NL80211_CMD_SET_PMKSA
)
446 C2S(NL80211_CMD_DEL_PMKSA
)
447 C2S(NL80211_CMD_FLUSH_PMKSA
)
448 C2S(NL80211_CMD_REMAIN_ON_CHANNEL
)
449 C2S(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
)
450 C2S(NL80211_CMD_SET_TX_BITRATE_MASK
)
451 C2S(NL80211_CMD_REGISTER_FRAME
)
452 C2S(NL80211_CMD_FRAME
)
453 C2S(NL80211_CMD_FRAME_TX_STATUS
)
454 C2S(NL80211_CMD_SET_POWER_SAVE
)
455 C2S(NL80211_CMD_GET_POWER_SAVE
)
456 C2S(NL80211_CMD_SET_CQM
)
457 C2S(NL80211_CMD_NOTIFY_CQM
)
458 C2S(NL80211_CMD_SET_CHANNEL
)
459 C2S(NL80211_CMD_SET_WDS_PEER
)
460 C2S(NL80211_CMD_FRAME_WAIT_CANCEL
)
461 C2S(NL80211_CMD_JOIN_MESH
)
462 C2S(NL80211_CMD_LEAVE_MESH
)
463 C2S(NL80211_CMD_UNPROT_DEAUTHENTICATE
)
464 C2S(NL80211_CMD_UNPROT_DISASSOCIATE
)
465 C2S(NL80211_CMD_NEW_PEER_CANDIDATE
)
466 C2S(NL80211_CMD_GET_WOWLAN
)
467 C2S(NL80211_CMD_SET_WOWLAN
)
468 C2S(NL80211_CMD_START_SCHED_SCAN
)
469 C2S(NL80211_CMD_STOP_SCHED_SCAN
)
470 C2S(NL80211_CMD_SCHED_SCAN_RESULTS
)
471 C2S(NL80211_CMD_SCHED_SCAN_STOPPED
)
472 C2S(NL80211_CMD_SET_REKEY_OFFLOAD
)
473 C2S(NL80211_CMD_PMKSA_CANDIDATE
)
474 C2S(NL80211_CMD_TDLS_OPER
)
475 C2S(NL80211_CMD_TDLS_MGMT
)
476 C2S(NL80211_CMD_UNEXPECTED_FRAME
)
477 C2S(NL80211_CMD_PROBE_CLIENT
)
478 C2S(NL80211_CMD_REGISTER_BEACONS
)
479 C2S(NL80211_CMD_UNEXPECTED_4ADDR_FRAME
)
480 C2S(NL80211_CMD_SET_NOACK_MAP
)
481 C2S(NL80211_CMD_CH_SWITCH_NOTIFY
)
482 C2S(NL80211_CMD_START_P2P_DEVICE
)
483 C2S(NL80211_CMD_STOP_P2P_DEVICE
)
484 C2S(NL80211_CMD_CONN_FAILED
)
485 C2S(NL80211_CMD_SET_MCAST_RATE
)
486 C2S(NL80211_CMD_SET_MAC_ACL
)
487 C2S(NL80211_CMD_RADAR_DETECT
)
488 C2S(NL80211_CMD_GET_PROTOCOL_FEATURES
)
489 C2S(NL80211_CMD_UPDATE_FT_IES
)
490 C2S(NL80211_CMD_FT_EVENT
)
491 C2S(NL80211_CMD_CRIT_PROTOCOL_START
)
492 C2S(NL80211_CMD_CRIT_PROTOCOL_STOP
)
494 return "NL80211_CMD_UNKNOWN";
500 static int is_ap_interface(enum nl80211_iftype nlmode
)
502 return (nlmode
== NL80211_IFTYPE_AP
||
503 nlmode
== NL80211_IFTYPE_P2P_GO
);
507 static int is_sta_interface(enum nl80211_iftype nlmode
)
509 return (nlmode
== NL80211_IFTYPE_STATION
||
510 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
514 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
516 return (nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
517 nlmode
== NL80211_IFTYPE_P2P_GO
);
521 static void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
524 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
526 os_memset(drv
->bssid
, 0, ETH_ALEN
);
530 struct nl80211_bss_info_arg
{
531 struct wpa_driver_nl80211_data
*drv
;
532 struct wpa_scan_results
*res
;
533 unsigned int assoc_freq
;
534 u8 assoc_bssid
[ETH_ALEN
];
537 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
541 static int ack_handler(struct nl_msg
*msg
, void *arg
)
548 static int finish_handler(struct nl_msg
*msg
, void *arg
)
555 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
564 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
570 static int send_and_recv(struct nl80211_global
*global
,
571 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
572 int (*valid_handler
)(struct nl_msg
*, void *),
578 cb
= nl_cb_clone(global
->nl_cb
);
582 err
= nl_send_auto_complete(nl_handle
, msg
);
588 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
589 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
590 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
593 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
594 valid_handler
, valid_data
);
597 int res
= nl_recvmsgs(nl_handle
, cb
);
600 "nl80211: %s->nl_recvmsgs failed: %d",
611 static int send_and_recv_msgs_global(struct nl80211_global
*global
,
613 int (*valid_handler
)(struct nl_msg
*, void *),
616 return send_and_recv(global
, global
->nl
, msg
, valid_handler
,
621 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
623 int (*valid_handler
)(struct nl_msg
*, void *),
626 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
627 valid_handler
, valid_data
);
637 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
639 if (bss
->wdev_id_set
)
640 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
642 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
650 static int family_handler(struct nl_msg
*msg
, void *arg
)
652 struct family_data
*res
= arg
;
653 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
654 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
655 struct nlattr
*mcgrp
;
658 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
659 genlmsg_attrlen(gnlh
, 0), NULL
);
660 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
663 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
664 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
665 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
666 nla_len(mcgrp
), NULL
);
667 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
668 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
669 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
671 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
673 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
681 static int nl_get_multicast_id(struct nl80211_global
*global
,
682 const char *family
, const char *group
)
686 struct family_data res
= { group
, -ENOENT
};
691 genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
692 0, 0, CTRL_CMD_GETFAMILY
, 0);
693 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
695 ret
= send_and_recv_msgs_global(global
, msg
, family_handler
, &res
);
706 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
707 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
709 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
714 struct wiphy_idx_data
{
716 enum nl80211_iftype nlmode
;
721 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
723 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
724 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
725 struct wiphy_idx_data
*info
= arg
;
727 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
728 genlmsg_attrlen(gnlh
, 0), NULL
);
730 if (tb
[NL80211_ATTR_WIPHY
])
731 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
733 if (tb
[NL80211_ATTR_IFTYPE
])
734 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
736 if (tb
[NL80211_ATTR_MAC
] && info
->macaddr
)
737 os_memcpy(info
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
744 static int nl80211_get_wiphy_index(struct i802_bss
*bss
)
747 struct wiphy_idx_data data
= {
754 return NL80211_IFTYPE_UNSPECIFIED
;
756 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
758 if (nl80211_set_iface_id(msg
, bss
) < 0)
759 goto nla_put_failure
;
761 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
762 return data
.wiphy_idx
;
770 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
773 struct wiphy_idx_data data
= {
774 .nlmode
= NL80211_IFTYPE_UNSPECIFIED
,
782 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
784 if (nl80211_set_iface_id(msg
, bss
) < 0)
785 goto nla_put_failure
;
787 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
792 return NL80211_IFTYPE_UNSPECIFIED
;
797 static int nl80211_get_macaddr(struct i802_bss
*bss
)
800 struct wiphy_idx_data data
= {
801 .macaddr
= bss
->addr
,
806 return NL80211_IFTYPE_UNSPECIFIED
;
808 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
809 if (nl80211_set_iface_id(msg
, bss
) < 0)
810 goto nla_put_failure
;
812 return send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
);
816 return NL80211_IFTYPE_UNSPECIFIED
;
821 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
822 struct nl80211_wiphy_data
*w
)
831 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
);
833 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
);
835 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
838 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
839 "failed: ret=%d (%s)",
840 ret
, strerror(-ret
));
841 goto nla_put_failure
;
850 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
852 struct nl80211_wiphy_data
*w
= eloop_ctx
;
855 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
857 res
= nl_recvmsgs(handle
, w
->nl_cb
);
859 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
865 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
867 struct nl80211_wiphy_data
*w
= arg
;
868 struct wpa_driver_nl80211_data
*drv
;
869 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
870 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
871 union wpa_event_data event
;
873 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
874 genlmsg_attrlen(gnlh
, 0), NULL
);
876 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
877 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
882 if (!tb
[NL80211_ATTR_FRAME
])
885 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
887 os_memset(&event
, 0, sizeof(event
));
888 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
889 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
890 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
897 static struct nl80211_wiphy_data
*
898 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
900 static DEFINE_DL_LIST(nl80211_wiphys
);
901 struct nl80211_wiphy_data
*w
;
902 int wiphy_idx
, found
= 0;
903 struct i802_bss
*tmp_bss
;
905 if (bss
->wiphy_data
!= NULL
)
906 return bss
->wiphy_data
;
908 wiphy_idx
= nl80211_get_wiphy_index(bss
);
910 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
911 if (w
->wiphy_idx
== wiphy_idx
)
916 w
= os_zalloc(sizeof(*w
));
919 w
->wiphy_idx
= wiphy_idx
;
920 dl_list_init(&w
->bsss
);
921 dl_list_init(&w
->drvs
);
923 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
928 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
929 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
932 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
934 if (w
->nl_beacons
== NULL
) {
939 if (nl80211_register_beacons(bss
->drv
, w
)) {
940 nl_destroy_handles(&w
->nl_beacons
);
945 nl80211_register_eloop_read(&w
->nl_beacons
, nl80211_recv_beacons
, w
);
947 dl_list_add(&nl80211_wiphys
, &w
->list
);
950 /* drv entry for this bss already there? */
951 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
952 if (tmp_bss
->drv
== bss
->drv
) {
959 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
961 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
967 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
969 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
970 struct i802_bss
*tmp_bss
;
975 bss
->wiphy_data
= NULL
;
976 dl_list_del(&bss
->wiphy_list
);
978 /* still any for this drv present? */
979 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
980 if (tmp_bss
->drv
== bss
->drv
) {
985 /* if not remove it */
987 dl_list_del(&bss
->drv
->wiphy_list
);
989 if (!dl_list_empty(&w
->bsss
))
992 nl80211_destroy_eloop_handle(&w
->nl_beacons
);
995 dl_list_del(&w
->list
);
1000 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
1002 struct i802_bss
*bss
= priv
;
1003 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1004 if (!drv
->associated
)
1006 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
1011 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
1013 struct i802_bss
*bss
= priv
;
1014 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1015 if (!drv
->associated
)
1017 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
1018 return drv
->ssid_len
;
1022 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
1023 char *buf
, size_t len
, int del
)
1025 union wpa_event_data event
;
1027 os_memset(&event
, 0, sizeof(event
));
1028 if (len
> sizeof(event
.interface_status
.ifname
))
1029 len
= sizeof(event
.interface_status
.ifname
) - 1;
1030 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
1031 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
1032 EVENT_INTERFACE_ADDED
;
1034 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
1035 del
? "DEL" : "NEW",
1036 event
.interface_status
.ifname
,
1037 del
? "removed" : "added");
1039 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
1041 if (drv
->if_removed
) {
1042 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
1043 "already set - ignore event");
1046 drv
->if_removed
= 1;
1048 if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
1049 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s "
1050 "does not exist - ignore "
1052 drv
->first_bss
.ifname
);
1055 if (!drv
->if_removed
) {
1056 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
1057 "already cleared - ignore event");
1060 drv
->if_removed
= 0;
1064 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
1068 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
1069 u8
*buf
, size_t len
)
1071 int attrlen
, rta_len
;
1072 struct rtattr
*attr
;
1075 attr
= (struct rtattr
*) buf
;
1077 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1078 while (RTA_OK(attr
, attrlen
)) {
1079 if (attr
->rta_type
== IFLA_IFNAME
) {
1080 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
1086 attr
= RTA_NEXT(attr
, attrlen
);
1093 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
1094 int ifindex
, u8
*buf
, size_t len
)
1096 if (drv
->ifindex
== ifindex
)
1099 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
1100 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
1102 wpa_driver_nl80211_finish_drv_init(drv
);
1110 static struct wpa_driver_nl80211_data
*
1111 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
1113 struct wpa_driver_nl80211_data
*drv
;
1114 dl_list_for_each(drv
, &global
->interfaces
,
1115 struct wpa_driver_nl80211_data
, list
) {
1116 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
1117 have_ifidx(drv
, idx
))
1124 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
1125 struct ifinfomsg
*ifi
,
1126 u8
*buf
, size_t len
)
1128 struct nl80211_global
*global
= ctx
;
1129 struct wpa_driver_nl80211_data
*drv
;
1130 int attrlen
, rta_len
;
1131 struct rtattr
*attr
;
1133 char namebuf
[IFNAMSIZ
];
1135 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1137 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
1138 "ifindex %d", ifi
->ifi_index
);
1142 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
1144 drv
->operstate
, ifi
->ifi_flags
,
1145 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1146 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1147 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1148 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1150 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
1151 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1152 linux_iface_up(drv
->global
->ioctl_sock
,
1153 drv
->first_bss
.ifname
) > 0) {
1154 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1155 "event since interface %s is up", namebuf
);
1158 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
1159 if (drv
->ignore_if_down_event
) {
1160 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1161 "event generated by mode change");
1162 drv
->ignore_if_down_event
= 0;
1164 drv
->if_disabled
= 1;
1165 wpa_supplicant_event(drv
->ctx
,
1166 EVENT_INTERFACE_DISABLED
, NULL
);
1170 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
1171 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1172 linux_iface_up(drv
->global
->ioctl_sock
,
1173 drv
->first_bss
.ifname
) == 0) {
1174 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1175 "event since interface %s is down",
1177 } else if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
1178 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1179 "event since interface %s does not exist",
1180 drv
->first_bss
.ifname
);
1181 } else if (drv
->if_removed
) {
1182 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1183 "event since interface %s is marked "
1184 "removed", drv
->first_bss
.ifname
);
1186 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1187 drv
->if_disabled
= 0;
1188 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1194 * Some drivers send the association event before the operup event--in
1195 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1196 * fails. This will hit us when wpa_supplicant does not need to do
1197 * IEEE 802.1X authentication
1199 if (drv
->operstate
== 1 &&
1200 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1201 !(ifi
->ifi_flags
& IFF_RUNNING
))
1202 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1206 attr
= (struct rtattr
*) buf
;
1207 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1208 while (RTA_OK(attr
, attrlen
)) {
1209 if (attr
->rta_type
== IFLA_IFNAME
) {
1210 wpa_driver_nl80211_event_link(
1212 ((char *) attr
) + rta_len
,
1213 attr
->rta_len
- rta_len
, 0);
1214 } else if (attr
->rta_type
== IFLA_MASTER
)
1215 brid
= nla_get_u32((struct nlattr
*) attr
);
1216 attr
= RTA_NEXT(attr
, attrlen
);
1219 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1220 /* device has been added to bridge */
1221 if_indextoname(brid
, namebuf
);
1222 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1224 add_ifidx(drv
, brid
);
1229 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1230 struct ifinfomsg
*ifi
,
1231 u8
*buf
, size_t len
)
1233 struct nl80211_global
*global
= ctx
;
1234 struct wpa_driver_nl80211_data
*drv
;
1235 int attrlen
, rta_len
;
1236 struct rtattr
*attr
;
1239 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1241 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
1242 "foreign ifindex %d", ifi
->ifi_index
);
1247 attr
= (struct rtattr
*) buf
;
1249 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1250 while (RTA_OK(attr
, attrlen
)) {
1251 if (attr
->rta_type
== IFLA_IFNAME
) {
1252 wpa_driver_nl80211_event_link(
1254 ((char *) attr
) + rta_len
,
1255 attr
->rta_len
- rta_len
, 1);
1256 } else if (attr
->rta_type
== IFLA_MASTER
)
1257 brid
= nla_get_u32((struct nlattr
*) attr
);
1258 attr
= RTA_NEXT(attr
, attrlen
);
1261 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1262 /* device has been removed from bridge */
1263 char namebuf
[IFNAMSIZ
];
1264 if_indextoname(brid
, namebuf
);
1265 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
1266 "%s", brid
, namebuf
);
1267 del_ifidx(drv
, brid
);
1272 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
1273 const u8
*frame
, size_t len
)
1275 const struct ieee80211_mgmt
*mgmt
;
1276 union wpa_event_data event
;
1278 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate event");
1279 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1280 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
1281 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1286 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
1287 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
1288 os_memset(&event
, 0, sizeof(event
));
1289 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
1290 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1291 event
.auth
.auth_transaction
=
1292 le_to_host16(mgmt
->u
.auth
.auth_transaction
);
1293 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1294 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
1295 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
1296 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
1299 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
1303 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1307 struct nl80211_bss_info_arg arg
;
1309 os_memset(&arg
, 0, sizeof(arg
));
1310 msg
= nlmsg_alloc();
1312 goto nla_put_failure
;
1314 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1315 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1318 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1321 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1322 "associated BSS from scan results: %u MHz",
1325 drv
->assoc_freq
= arg
.assoc_freq
;
1326 return drv
->assoc_freq
;
1328 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1329 "(%s)", ret
, strerror(-ret
));
1332 return drv
->assoc_freq
;
1336 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
1337 const u8
*frame
, size_t len
)
1339 const struct ieee80211_mgmt
*mgmt
;
1340 union wpa_event_data event
;
1343 wpa_printf(MSG_DEBUG
, "nl80211: Associate event");
1344 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1345 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1346 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1351 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1352 if (status
!= WLAN_STATUS_SUCCESS
) {
1353 os_memset(&event
, 0, sizeof(event
));
1354 event
.assoc_reject
.bssid
= mgmt
->bssid
;
1355 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1356 event
.assoc_reject
.resp_ies
=
1357 (u8
*) mgmt
->u
.assoc_resp
.variable
;
1358 event
.assoc_reject
.resp_ies_len
=
1359 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1361 event
.assoc_reject
.status_code
= status
;
1363 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1367 drv
->associated
= 1;
1368 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
1369 os_memcpy(drv
->prev_bssid
, mgmt
->sa
, ETH_ALEN
);
1371 os_memset(&event
, 0, sizeof(event
));
1372 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1373 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
1374 event
.assoc_info
.resp_ies_len
=
1375 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1378 event
.assoc_info
.freq
= drv
->assoc_freq
;
1380 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1384 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
1385 enum nl80211_commands cmd
, struct nlattr
*status
,
1386 struct nlattr
*addr
, struct nlattr
*req_ie
,
1387 struct nlattr
*resp_ie
)
1389 union wpa_event_data event
;
1391 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1393 * Avoid reporting two association events that would confuse
1396 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
1397 "when using userspace SME", cmd
);
1401 if (cmd
== NL80211_CMD_CONNECT
)
1402 wpa_printf(MSG_DEBUG
, "nl80211: Connect event");
1403 else if (cmd
== NL80211_CMD_ROAM
)
1404 wpa_printf(MSG_DEBUG
, "nl80211: Roam event");
1406 os_memset(&event
, 0, sizeof(event
));
1407 if (cmd
== NL80211_CMD_CONNECT
&&
1408 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
1410 event
.assoc_reject
.bssid
= nla_data(addr
);
1412 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
1413 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
1415 event
.assoc_reject
.status_code
= nla_get_u16(status
);
1416 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1420 drv
->associated
= 1;
1422 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
1423 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
1427 event
.assoc_info
.req_ies
= nla_data(req_ie
);
1428 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
1431 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
1432 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
1435 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
1437 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1441 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
1442 struct nlattr
*reason
, struct nlattr
*addr
,
1443 struct nlattr
*by_ap
)
1445 union wpa_event_data data
;
1446 unsigned int locally_generated
= by_ap
== NULL
;
1448 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1450 * Avoid reporting two disassociation events that could
1451 * confuse the core code.
1453 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1454 "event when using userspace SME");
1458 if (drv
->ignore_next_local_disconnect
) {
1459 drv
->ignore_next_local_disconnect
= 0;
1460 if (locally_generated
) {
1461 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1462 "event triggered during reassociation");
1465 wpa_printf(MSG_WARNING
, "nl80211: Was expecting local "
1466 "disconnect but got another disconnect "
1470 wpa_printf(MSG_DEBUG
, "nl80211: Disconnect event");
1471 nl80211_mark_disconnected(drv
);
1472 os_memset(&data
, 0, sizeof(data
));
1474 data
.deauth_info
.reason_code
= nla_get_u16(reason
);
1475 data
.deauth_info
.locally_generated
= by_ap
== NULL
;
1476 wpa_supplicant_event(drv
->ctx
, EVENT_DEAUTH
, &data
);
1480 static void mlme_event_ch_switch(struct wpa_driver_nl80211_data
*drv
,
1481 struct nlattr
*freq
, struct nlattr
*type
)
1483 union wpa_event_data data
;
1485 int chan_offset
= 0;
1487 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch event");
1492 switch (nla_get_u32(type
)) {
1493 case NL80211_CHAN_NO_HT
:
1496 case NL80211_CHAN_HT20
:
1498 case NL80211_CHAN_HT40PLUS
:
1501 case NL80211_CHAN_HT40MINUS
:
1506 data
.ch_switch
.freq
= nla_get_u32(freq
);
1507 data
.ch_switch
.ht_enabled
= ht_enabled
;
1508 data
.ch_switch
.ch_offset
= chan_offset
;
1510 wpa_supplicant_event(drv
->ctx
, EVENT_CH_SWITCH
, &data
);
1514 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
1515 enum nl80211_commands cmd
, struct nlattr
*addr
)
1517 union wpa_event_data event
;
1518 enum wpa_event_type ev
;
1520 if (nla_len(addr
) != ETH_ALEN
)
1523 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
1524 cmd
, MAC2STR((u8
*) nla_data(addr
)));
1526 if (cmd
== NL80211_CMD_AUTHENTICATE
)
1527 ev
= EVENT_AUTH_TIMED_OUT
;
1528 else if (cmd
== NL80211_CMD_ASSOCIATE
)
1529 ev
= EVENT_ASSOC_TIMED_OUT
;
1533 os_memset(&event
, 0, sizeof(event
));
1534 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
1535 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
1539 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
1540 struct nlattr
*freq
, struct nlattr
*sig
,
1541 const u8
*frame
, size_t len
)
1543 const struct ieee80211_mgmt
*mgmt
;
1544 union wpa_event_data event
;
1549 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame event");
1550 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1552 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
1556 fc
= le_to_host16(mgmt
->frame_control
);
1557 stype
= WLAN_FC_GET_STYPE(fc
);
1560 ssi_signal
= (s32
) nla_get_u32(sig
);
1562 os_memset(&event
, 0, sizeof(event
));
1564 event
.rx_action
.freq
= nla_get_u32(freq
);
1565 rx_freq
= drv
->last_mgmt_freq
= event
.rx_action
.freq
;
1567 wpa_printf(MSG_DEBUG
,
1568 "nl80211: RX frame freq=%d ssi_signal=%d stype=%u len=%u",
1569 rx_freq
, ssi_signal
, stype
, (unsigned int) len
);
1570 if (stype
== WLAN_FC_STYPE_ACTION
) {
1571 event
.rx_action
.da
= mgmt
->da
;
1572 event
.rx_action
.sa
= mgmt
->sa
;
1573 event
.rx_action
.bssid
= mgmt
->bssid
;
1574 event
.rx_action
.category
= mgmt
->u
.action
.category
;
1575 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
1576 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
1577 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
1579 event
.rx_mgmt
.frame
= frame
;
1580 event
.rx_mgmt
.frame_len
= len
;
1581 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1582 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
1587 static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data
*drv
,
1588 struct nlattr
*cookie
, const u8
*frame
,
1589 size_t len
, struct nlattr
*ack
)
1591 union wpa_event_data event
;
1592 const struct ieee80211_hdr
*hdr
;
1595 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX status event");
1596 if (!is_ap_interface(drv
->nlmode
)) {
1602 cookie_val
= nla_get_u64(cookie
);
1603 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status:"
1604 " cookie=0%llx%s (ack=%d)",
1605 (long long unsigned int) cookie_val
,
1606 cookie_val
== drv
->send_action_cookie
?
1607 " (match)" : " (unknown)", ack
!= NULL
);
1608 if (cookie_val
!= drv
->send_action_cookie
)
1612 hdr
= (const struct ieee80211_hdr
*) frame
;
1613 fc
= le_to_host16(hdr
->frame_control
);
1615 os_memset(&event
, 0, sizeof(event
));
1616 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
1617 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
1618 event
.tx_status
.dst
= hdr
->addr1
;
1619 event
.tx_status
.data
= frame
;
1620 event
.tx_status
.data_len
= len
;
1621 event
.tx_status
.ack
= ack
!= NULL
;
1622 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
1626 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
1627 enum wpa_event_type type
,
1628 const u8
*frame
, size_t len
)
1630 const struct ieee80211_mgmt
*mgmt
;
1631 union wpa_event_data event
;
1632 const u8
*bssid
= NULL
;
1633 u16 reason_code
= 0;
1635 if (type
== EVENT_DEAUTH
)
1636 wpa_printf(MSG_DEBUG
, "nl80211: Deauthenticate event");
1638 wpa_printf(MSG_DEBUG
, "nl80211: Disassociate event");
1640 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1642 bssid
= mgmt
->bssid
;
1644 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) &&
1646 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0 &&
1647 os_memcmp(bssid
, drv
->auth_attempt_bssid
, ETH_ALEN
) != 0 &&
1648 os_memcmp(bssid
, drv
->prev_bssid
, ETH_ALEN
) == 0) {
1650 * Avoid issues with some roaming cases where
1651 * disconnection event for the old AP may show up after
1652 * we have started connection with the new AP.
1654 wpa_printf(MSG_DEBUG
, "nl80211: Ignore deauth/disassoc event from old AP " MACSTR
" when already authenticating with " MACSTR
,
1656 MAC2STR(drv
->auth_attempt_bssid
));
1660 if (drv
->associated
!= 0 &&
1661 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
1662 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
1664 * We have presumably received this deauth as a
1665 * response to a clear_state_mismatch() outgoing
1666 * deauth. Don't let it take us offline!
1668 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
1669 "from Unknown BSSID " MACSTR
" -- ignoring",
1675 nl80211_mark_disconnected(drv
);
1676 os_memset(&event
, 0, sizeof(event
));
1678 /* Note: Same offset for Reason Code in both frame subtypes */
1679 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1680 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1682 if (type
== EVENT_DISASSOC
) {
1683 event
.disassoc_info
.locally_generated
=
1684 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1685 event
.disassoc_info
.addr
= bssid
;
1686 event
.disassoc_info
.reason_code
= reason_code
;
1687 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1688 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1689 event
.disassoc_info
.ie_len
= frame
+ len
-
1690 mgmt
->u
.disassoc
.variable
;
1693 event
.deauth_info
.locally_generated
=
1694 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1695 event
.deauth_info
.addr
= bssid
;
1696 event
.deauth_info
.reason_code
= reason_code
;
1697 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1698 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1699 event
.deauth_info
.ie_len
= frame
+ len
-
1700 mgmt
->u
.deauth
.variable
;
1704 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1708 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1709 enum wpa_event_type type
,
1710 const u8
*frame
, size_t len
)
1712 const struct ieee80211_mgmt
*mgmt
;
1713 union wpa_event_data event
;
1714 u16 reason_code
= 0;
1716 if (type
== EVENT_UNPROT_DEAUTH
)
1717 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Deauthenticate event");
1719 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Disassociate event");
1724 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1726 os_memset(&event
, 0, sizeof(event
));
1727 /* Note: Same offset for Reason Code in both frame subtypes */
1728 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1729 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1731 if (type
== EVENT_UNPROT_DISASSOC
) {
1732 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1733 event
.unprot_disassoc
.da
= mgmt
->da
;
1734 event
.unprot_disassoc
.reason_code
= reason_code
;
1736 event
.unprot_deauth
.sa
= mgmt
->sa
;
1737 event
.unprot_deauth
.da
= mgmt
->da
;
1738 event
.unprot_deauth
.reason_code
= reason_code
;
1741 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1745 static void mlme_event(struct i802_bss
*bss
,
1746 enum nl80211_commands cmd
, struct nlattr
*frame
,
1747 struct nlattr
*addr
, struct nlattr
*timed_out
,
1748 struct nlattr
*freq
, struct nlattr
*ack
,
1749 struct nlattr
*cookie
, struct nlattr
*sig
)
1751 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1755 if (timed_out
&& addr
) {
1756 mlme_timeout_event(drv
, cmd
, addr
);
1760 if (frame
== NULL
) {
1761 wpa_printf(MSG_DEBUG
,
1762 "nl80211: MLME event %d (%s) without frame data",
1763 cmd
, nl80211_command_to_string(cmd
));
1767 data
= nla_data(frame
);
1768 len
= nla_len(frame
);
1769 if (len
< 4 + 2 * ETH_ALEN
) {
1770 wpa_printf(MSG_MSGDUMP
, "nl80211: MLME event %d (%s) on %s("
1771 MACSTR
") - too short",
1772 cmd
, nl80211_command_to_string(cmd
), bss
->ifname
,
1773 MAC2STR(bss
->addr
));
1776 wpa_printf(MSG_MSGDUMP
, "nl80211: MLME event %d (%s) on %s(" MACSTR
1777 ") A1=" MACSTR
" A2=" MACSTR
, cmd
,
1778 nl80211_command_to_string(cmd
), bss
->ifname
,
1779 MAC2STR(bss
->addr
), MAC2STR(data
+ 4),
1780 MAC2STR(data
+ 4 + ETH_ALEN
));
1781 if (cmd
!= NL80211_CMD_FRAME_TX_STATUS
&& !(data
[4] & 0x01) &&
1782 os_memcmp(bss
->addr
, data
+ 4, ETH_ALEN
) != 0 &&
1783 os_memcmp(bss
->addr
, data
+ 4 + ETH_ALEN
, ETH_ALEN
) != 0) {
1784 wpa_printf(MSG_MSGDUMP
, "nl80211: %s: Ignore MLME frame event "
1785 "for foreign address", bss
->ifname
);
1788 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1789 nla_data(frame
), nla_len(frame
));
1792 case NL80211_CMD_AUTHENTICATE
:
1793 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1795 case NL80211_CMD_ASSOCIATE
:
1796 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1798 case NL80211_CMD_DEAUTHENTICATE
:
1799 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1800 nla_data(frame
), nla_len(frame
));
1802 case NL80211_CMD_DISASSOCIATE
:
1803 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1804 nla_data(frame
), nla_len(frame
));
1806 case NL80211_CMD_FRAME
:
1807 mlme_event_mgmt(drv
, freq
, sig
, nla_data(frame
),
1810 case NL80211_CMD_FRAME_TX_STATUS
:
1811 mlme_event_mgmt_tx_status(drv
, cookie
, nla_data(frame
),
1812 nla_len(frame
), ack
);
1814 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1815 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1816 nla_data(frame
), nla_len(frame
));
1818 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1819 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1820 nla_data(frame
), nla_len(frame
));
1828 static void mlme_event_michael_mic_failure(struct i802_bss
*bss
,
1829 struct nlattr
*tb
[])
1831 union wpa_event_data data
;
1833 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1834 os_memset(&data
, 0, sizeof(data
));
1835 if (tb
[NL80211_ATTR_MAC
]) {
1836 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1837 nla_data(tb
[NL80211_ATTR_MAC
]),
1838 nla_len(tb
[NL80211_ATTR_MAC
]));
1839 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1841 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1842 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1843 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1844 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1846 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1847 enum nl80211_key_type key_type
=
1848 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1849 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1850 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1851 data
.michael_mic_failure
.unicast
= 1;
1853 data
.michael_mic_failure
.unicast
= 1;
1855 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1856 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1857 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1860 wpa_supplicant_event(bss
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1864 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1865 struct nlattr
*tb
[])
1867 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1868 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1872 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1874 drv
->associated
= 1;
1875 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1876 MAC2STR(drv
->bssid
));
1878 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1882 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1883 int cancel_event
, struct nlattr
*tb
[])
1885 unsigned int freq
, chan_type
, duration
;
1886 union wpa_event_data data
;
1889 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1890 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1894 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1895 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1899 if (tb
[NL80211_ATTR_DURATION
])
1900 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1904 if (tb
[NL80211_ATTR_COOKIE
])
1905 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1909 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1910 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1911 cancel_event
, freq
, chan_type
, duration
,
1912 (long long unsigned int) cookie
,
1913 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1915 if (cookie
!= drv
->remain_on_chan_cookie
)
1916 return; /* not for us */
1919 drv
->pending_remain_on_chan
= 0;
1921 os_memset(&data
, 0, sizeof(data
));
1922 data
.remain_on_channel
.freq
= freq
;
1923 data
.remain_on_channel
.duration
= duration
;
1924 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1925 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1926 EVENT_REMAIN_ON_CHANNEL
, &data
);
1930 static void mlme_event_ft_event(struct wpa_driver_nl80211_data
*drv
,
1931 struct nlattr
*tb
[])
1933 union wpa_event_data data
;
1935 os_memset(&data
, 0, sizeof(data
));
1937 if (tb
[NL80211_ATTR_IE
]) {
1938 data
.ft_ies
.ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1939 data
.ft_ies
.ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1942 if (tb
[NL80211_ATTR_IE_RIC
]) {
1943 data
.ft_ies
.ric_ies
= nla_data(tb
[NL80211_ATTR_IE_RIC
]);
1944 data
.ft_ies
.ric_ies_len
= nla_len(tb
[NL80211_ATTR_IE_RIC
]);
1947 if (tb
[NL80211_ATTR_MAC
])
1948 os_memcpy(data
.ft_ies
.target_ap
,
1949 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1951 wpa_printf(MSG_DEBUG
, "nl80211: FT event target_ap " MACSTR
,
1952 MAC2STR(data
.ft_ies
.target_ap
));
1954 wpa_supplicant_event(drv
->ctx
, EVENT_FT_RESPONSE
, &data
);
1958 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1959 struct nlattr
*tb
[])
1961 union wpa_event_data event
;
1964 struct scan_info
*info
;
1965 #define MAX_REPORT_FREQS 50
1966 int freqs
[MAX_REPORT_FREQS
];
1969 if (drv
->scan_for_auth
) {
1970 drv
->scan_for_auth
= 0;
1971 wpa_printf(MSG_DEBUG
, "nl80211: Scan results for missing "
1972 "cfg80211 BSS entry");
1973 wpa_driver_nl80211_authenticate_retry(drv
);
1977 os_memset(&event
, 0, sizeof(event
));
1978 info
= &event
.scan_info
;
1979 info
->aborted
= aborted
;
1981 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1982 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1983 struct wpa_driver_scan_ssid
*s
=
1984 &info
->ssids
[info
->num_ssids
];
1985 s
->ssid
= nla_data(nl
);
1986 s
->ssid_len
= nla_len(nl
);
1988 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1992 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1993 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1995 freqs
[num_freqs
] = nla_get_u32(nl
);
1997 if (num_freqs
== MAX_REPORT_FREQS
- 1)
2000 info
->freqs
= freqs
;
2001 info
->num_freqs
= num_freqs
;
2003 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
2007 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
2009 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2010 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2011 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
2012 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
2013 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
2014 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
2016 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
2017 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
2018 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
2019 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
2020 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
2021 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
2023 struct wpa_signal_info
*sig_change
= arg
;
2025 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2026 genlmsg_attrlen(gnlh
, 0), NULL
);
2027 if (!tb
[NL80211_ATTR_STA_INFO
] ||
2028 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
2029 tb
[NL80211_ATTR_STA_INFO
], policy
))
2031 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
2034 sig_change
->current_signal
=
2035 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
2037 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
2038 sig_change
->avg_signal
=
2039 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
2041 sig_change
->avg_signal
= 0;
2043 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
2044 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
2045 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
2047 sig_change
->current_txrate
= 0;
2049 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
2050 sig_change
->current_txrate
=
2052 NL80211_RATE_INFO_BITRATE
]) * 100;
2061 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
2062 struct wpa_signal_info
*sig
)
2066 sig
->current_signal
= -9999;
2067 sig
->current_txrate
= 0;
2069 msg
= nlmsg_alloc();
2073 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
2075 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2076 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
2078 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
2085 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
2087 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2088 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2089 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
2090 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
2091 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
2092 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
2094 struct wpa_signal_info
*sig_change
= arg
;
2096 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2097 genlmsg_attrlen(gnlh
, 0), NULL
);
2099 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
2100 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
2104 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
2105 tb
[NL80211_ATTR_SURVEY_INFO
],
2107 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
2112 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
2115 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
2116 sig_change
->frequency
)
2119 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
2122 sig_change
->current_noise
=
2123 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
2129 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
2130 struct wpa_signal_info
*sig_change
)
2134 sig_change
->current_noise
= 9999;
2135 sig_change
->frequency
= drv
->assoc_freq
;
2137 msg
= nlmsg_alloc();
2141 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
2143 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2145 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
2152 static int get_noise_for_scan_results(struct nl_msg
*msg
, void *arg
)
2154 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2155 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2156 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
2157 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
2158 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
2159 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
2161 struct wpa_scan_results
*scan_results
= arg
;
2162 struct wpa_scan_res
*scan_res
;
2165 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2166 genlmsg_attrlen(gnlh
, 0), NULL
);
2168 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
2169 wpa_printf(MSG_DEBUG
, "nl80211: Survey data missing");
2173 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
2174 tb
[NL80211_ATTR_SURVEY_INFO
],
2176 wpa_printf(MSG_DEBUG
, "nl80211: Failed to parse nested "
2181 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
2184 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
2187 for (i
= 0; i
< scan_results
->num
; ++i
) {
2188 scan_res
= scan_results
->res
[i
];
2191 if ((int) nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
2194 if (!(scan_res
->flags
& WPA_SCAN_NOISE_INVALID
))
2196 scan_res
->noise
= (s8
)
2197 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
2198 scan_res
->flags
&= ~WPA_SCAN_NOISE_INVALID
;
2205 static int nl80211_get_noise_for_scan_results(
2206 struct wpa_driver_nl80211_data
*drv
,
2207 struct wpa_scan_results
*scan_res
)
2211 msg
= nlmsg_alloc();
2215 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
2217 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2219 return send_and_recv_msgs(drv
, msg
, get_noise_for_scan_results
,
2227 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
2228 struct nlattr
*tb
[])
2230 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
2231 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
2232 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
2233 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
2234 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
2236 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
2237 enum nl80211_cqm_rssi_threshold_event event
;
2238 union wpa_event_data ed
;
2239 struct wpa_signal_info sig
;
2242 if (tb
[NL80211_ATTR_CQM
] == NULL
||
2243 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
2245 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
2249 os_memset(&ed
, 0, sizeof(ed
));
2251 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
2252 if (!tb
[NL80211_ATTR_MAC
])
2254 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
2256 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
2260 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
2262 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
2264 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
2265 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
2266 "event: RSSI high");
2267 ed
.signal_change
.above_threshold
= 1;
2268 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
2269 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
2271 ed
.signal_change
.above_threshold
= 0;
2275 res
= nl80211_get_link_signal(drv
, &sig
);
2277 ed
.signal_change
.current_signal
= sig
.current_signal
;
2278 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
2279 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
2280 sig
.current_signal
, sig
.current_txrate
);
2283 res
= nl80211_get_link_noise(drv
, &sig
);
2285 ed
.signal_change
.current_noise
= sig
.current_noise
;
2286 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
2290 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
2294 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
2298 union wpa_event_data data
;
2300 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2302 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2303 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
2305 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2308 if (tb
[NL80211_ATTR_IE
]) {
2309 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
2310 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
2312 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
2313 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
2317 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2320 os_memset(&data
, 0, sizeof(data
));
2321 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
2322 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
2326 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
2330 union wpa_event_data data
;
2332 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2334 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2335 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
2338 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2339 drv_event_disassoc(drv
->ctx
, addr
);
2343 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2346 os_memset(&data
, 0, sizeof(data
));
2347 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
2348 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
2352 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
2355 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
2356 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
2357 [NL80211_REKEY_DATA_KEK
] = {
2358 .minlen
= NL80211_KEK_LEN
,
2359 .maxlen
= NL80211_KEK_LEN
,
2361 [NL80211_REKEY_DATA_KCK
] = {
2362 .minlen
= NL80211_KCK_LEN
,
2363 .maxlen
= NL80211_KCK_LEN
,
2365 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
2366 .minlen
= NL80211_REPLAY_CTR_LEN
,
2367 .maxlen
= NL80211_REPLAY_CTR_LEN
,
2370 union wpa_event_data data
;
2372 if (!tb
[NL80211_ATTR_MAC
])
2374 if (!tb
[NL80211_ATTR_REKEY_DATA
])
2376 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
2377 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
2379 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
2382 os_memset(&data
, 0, sizeof(data
));
2383 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
2384 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
2385 MAC2STR(data
.driver_gtk_rekey
.bssid
));
2386 data
.driver_gtk_rekey
.replay_ctr
=
2387 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
2388 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
2389 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
2390 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
2394 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
2397 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
2398 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
2399 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
2400 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
2404 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
2406 union wpa_event_data data
;
2408 wpa_printf(MSG_DEBUG
, "nl80211: PMKSA candidate event");
2410 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
2412 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
2413 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
2415 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
2416 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
2419 os_memset(&data
, 0, sizeof(data
));
2420 os_memcpy(data
.pmkid_candidate
.bssid
,
2421 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
2422 data
.pmkid_candidate
.index
=
2423 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
2424 data
.pmkid_candidate
.preauth
=
2425 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
2426 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
2430 static void nl80211_client_probe_event(struct wpa_driver_nl80211_data
*drv
,
2433 union wpa_event_data data
;
2435 wpa_printf(MSG_DEBUG
, "nl80211: Probe client event");
2437 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_ACK
])
2440 os_memset(&data
, 0, sizeof(data
));
2441 os_memcpy(data
.client_poll
.addr
,
2442 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2444 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_CLIENT_POLL_OK
, &data
);
2448 static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data
*drv
,
2451 union wpa_event_data data
;
2453 wpa_printf(MSG_DEBUG
, "nl80211: TDLS operation event");
2455 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_TDLS_OPERATION
])
2458 os_memset(&data
, 0, sizeof(data
));
2459 os_memcpy(data
.tdls
.peer
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2460 switch (nla_get_u8(tb
[NL80211_ATTR_TDLS_OPERATION
])) {
2461 case NL80211_TDLS_SETUP
:
2462 wpa_printf(MSG_DEBUG
, "nl80211: TDLS setup request for peer "
2463 MACSTR
, MAC2STR(data
.tdls
.peer
));
2464 data
.tdls
.oper
= TDLS_REQUEST_SETUP
;
2466 case NL80211_TDLS_TEARDOWN
:
2467 wpa_printf(MSG_DEBUG
, "nl80211: TDLS teardown request for peer "
2468 MACSTR
, MAC2STR(data
.tdls
.peer
));
2469 data
.tdls
.oper
= TDLS_REQUEST_TEARDOWN
;
2472 wpa_printf(MSG_DEBUG
, "nl80211: Unsupported TDLS operatione "
2476 if (tb
[NL80211_ATTR_REASON_CODE
]) {
2477 data
.tdls
.reason_code
=
2478 nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]);
2481 wpa_supplicant_event(drv
->ctx
, EVENT_TDLS
, &data
);
2485 static void nl80211_stop_ap(struct wpa_driver_nl80211_data
*drv
,
2488 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_UNAVAILABLE
, NULL
);
2492 static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data
*drv
,
2495 union wpa_event_data data
;
2498 wpa_printf(MSG_DEBUG
, "nl80211: Connect failed event");
2500 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_CONN_FAILED_REASON
])
2503 os_memset(&data
, 0, sizeof(data
));
2504 os_memcpy(data
.connect_failed_reason
.addr
,
2505 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2507 reason
= nla_get_u32(tb
[NL80211_ATTR_CONN_FAILED_REASON
]);
2509 case NL80211_CONN_FAIL_MAX_CLIENTS
:
2510 wpa_printf(MSG_DEBUG
, "nl80211: Max client reached");
2511 data
.connect_failed_reason
.code
= MAX_CLIENT_REACHED
;
2513 case NL80211_CONN_FAIL_BLOCKED_CLIENT
:
2514 wpa_printf(MSG_DEBUG
, "nl80211: Blocked client " MACSTR
2515 " tried to connect",
2516 MAC2STR(data
.connect_failed_reason
.addr
));
2517 data
.connect_failed_reason
.code
= BLOCKED_CLIENT
;
2520 wpa_printf(MSG_DEBUG
, "nl8021l: Unknown connect failed reason "
2525 wpa_supplicant_event(drv
->ctx
, EVENT_CONNECT_FAILED_REASON
, &data
);
2529 static enum chan_width
convert2width(int width
);
2531 static void nl80211_radar_event(struct wpa_driver_nl80211_data
*drv
,
2534 union wpa_event_data data
;
2535 enum nl80211_radar_event event_type
;
2537 if (!tb
[NL80211_ATTR_WIPHY_FREQ
] || !tb
[NL80211_ATTR_RADAR_EVENT
])
2540 os_memset(&data
, 0, sizeof(data
));
2541 data
.dfs_event
.freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
2542 event_type
= nla_get_u32(tb
[NL80211_ATTR_RADAR_EVENT
]);
2544 /* Check HT params */
2545 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
2546 data
.dfs_event
.ht_enabled
= 1;
2547 data
.dfs_event
.chan_offset
= 0;
2549 switch (nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])) {
2550 case NL80211_CHAN_NO_HT
:
2551 data
.dfs_event
.ht_enabled
= 0;
2553 case NL80211_CHAN_HT20
:
2555 case NL80211_CHAN_HT40PLUS
:
2556 data
.dfs_event
.chan_offset
= 1;
2558 case NL80211_CHAN_HT40MINUS
:
2559 data
.dfs_event
.chan_offset
= -1;
2564 /* Get VHT params */
2565 data
.dfs_event
.chan_width
=
2566 convert2width(nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
2567 data
.dfs_event
.cf1
= nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
2568 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
2569 data
.dfs_event
.cf2
= nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
2571 wpa_printf(MSG_DEBUG
, "nl80211: DFS event on freq %d MHz, ht: %d, offset: %d, width: %d, cf1: %dMHz, cf2: %dMHz",
2572 data
.dfs_event
.freq
, data
.dfs_event
.ht_enabled
,
2573 data
.dfs_event
.chan_offset
, data
.dfs_event
.chan_width
,
2574 data
.dfs_event
.cf1
, data
.dfs_event
.cf2
);
2576 switch (event_type
) {
2577 case NL80211_RADAR_DETECTED
:
2578 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_RADAR_DETECTED
, &data
);
2580 case NL80211_RADAR_CAC_FINISHED
:
2581 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_CAC_FINISHED
, &data
);
2583 case NL80211_RADAR_CAC_ABORTED
:
2584 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_CAC_ABORTED
, &data
);
2586 case NL80211_RADAR_NOP_FINISHED
:
2587 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_NOP_FINISHED
, &data
);
2590 wpa_printf(MSG_DEBUG
, "nl80211: Unknown radar event %d "
2591 "received", event_type
);
2597 static void nl80211_spurious_frame(struct i802_bss
*bss
, struct nlattr
**tb
,
2600 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2601 union wpa_event_data event
;
2603 if (!tb
[NL80211_ATTR_MAC
])
2606 os_memset(&event
, 0, sizeof(event
));
2607 event
.rx_from_unknown
.bssid
= bss
->addr
;
2608 event
.rx_from_unknown
.addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2609 event
.rx_from_unknown
.wds
= wds
;
2611 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
2615 static void do_process_drv_event(struct i802_bss
*bss
, int cmd
,
2618 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2620 wpa_printf(MSG_DEBUG
, "nl80211: Drv Event %d (%s) received for %s",
2621 cmd
, nl80211_command_to_string(cmd
), bss
->ifname
);
2623 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
2624 (cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
2625 cmd
== NL80211_CMD_SCAN_ABORTED
)) {
2626 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2627 drv
->ap_scan_as_station
);
2628 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2632 case NL80211_CMD_TRIGGER_SCAN
:
2633 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Scan trigger");
2634 drv
->scan_state
= SCAN_STARTED
;
2636 case NL80211_CMD_START_SCHED_SCAN
:
2637 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Sched scan started");
2638 drv
->scan_state
= SCHED_SCAN_STARTED
;
2640 case NL80211_CMD_SCHED_SCAN_STOPPED
:
2641 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Sched scan stopped");
2642 drv
->scan_state
= SCHED_SCAN_STOPPED
;
2643 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
2645 case NL80211_CMD_NEW_SCAN_RESULTS
:
2646 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2647 "nl80211: New scan results available");
2648 drv
->scan_state
= SCAN_COMPLETED
;
2649 drv
->scan_complete_events
= 1;
2650 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2652 send_scan_event(drv
, 0, tb
);
2654 case NL80211_CMD_SCHED_SCAN_RESULTS
:
2655 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2656 "nl80211: New sched scan results available");
2657 drv
->scan_state
= SCHED_SCAN_RESULTS
;
2658 send_scan_event(drv
, 0, tb
);
2660 case NL80211_CMD_SCAN_ABORTED
:
2661 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Scan aborted");
2662 drv
->scan_state
= SCAN_ABORTED
;
2664 * Need to indicate that scan results are available in order
2665 * not to make wpa_supplicant stop its scanning.
2667 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2669 send_scan_event(drv
, 1, tb
);
2671 case NL80211_CMD_AUTHENTICATE
:
2672 case NL80211_CMD_ASSOCIATE
:
2673 case NL80211_CMD_DEAUTHENTICATE
:
2674 case NL80211_CMD_DISASSOCIATE
:
2675 case NL80211_CMD_FRAME_TX_STATUS
:
2676 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
2677 case NL80211_CMD_UNPROT_DISASSOCIATE
:
2678 mlme_event(bss
, cmd
, tb
[NL80211_ATTR_FRAME
],
2679 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2680 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2681 tb
[NL80211_ATTR_COOKIE
],
2682 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2684 case NL80211_CMD_CONNECT
:
2685 case NL80211_CMD_ROAM
:
2686 mlme_event_connect(drv
, cmd
,
2687 tb
[NL80211_ATTR_STATUS_CODE
],
2688 tb
[NL80211_ATTR_MAC
],
2689 tb
[NL80211_ATTR_REQ_IE
],
2690 tb
[NL80211_ATTR_RESP_IE
]);
2692 case NL80211_CMD_CH_SWITCH_NOTIFY
:
2693 mlme_event_ch_switch(drv
, tb
[NL80211_ATTR_WIPHY_FREQ
],
2694 tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2696 case NL80211_CMD_DISCONNECT
:
2697 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
2698 tb
[NL80211_ATTR_MAC
],
2699 tb
[NL80211_ATTR_DISCONNECTED_BY_AP
]);
2701 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
2702 mlme_event_michael_mic_failure(bss
, tb
);
2704 case NL80211_CMD_JOIN_IBSS
:
2705 mlme_event_join_ibss(drv
, tb
);
2707 case NL80211_CMD_REMAIN_ON_CHANNEL
:
2708 mlme_event_remain_on_channel(drv
, 0, tb
);
2710 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
2711 mlme_event_remain_on_channel(drv
, 1, tb
);
2713 case NL80211_CMD_NOTIFY_CQM
:
2714 nl80211_cqm_event(drv
, tb
);
2716 case NL80211_CMD_REG_CHANGE
:
2717 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
2718 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2721 case NL80211_CMD_REG_BEACON_HINT
:
2722 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
2723 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2726 case NL80211_CMD_NEW_STATION
:
2727 nl80211_new_station_event(drv
, tb
);
2729 case NL80211_CMD_DEL_STATION
:
2730 nl80211_del_station_event(drv
, tb
);
2732 case NL80211_CMD_SET_REKEY_OFFLOAD
:
2733 nl80211_rekey_offload_event(drv
, tb
);
2735 case NL80211_CMD_PMKSA_CANDIDATE
:
2736 nl80211_pmksa_candidate_event(drv
, tb
);
2738 case NL80211_CMD_PROBE_CLIENT
:
2739 nl80211_client_probe_event(drv
, tb
);
2741 case NL80211_CMD_TDLS_OPER
:
2742 nl80211_tdls_oper_event(drv
, tb
);
2744 case NL80211_CMD_CONN_FAILED
:
2745 nl80211_connect_failed_event(drv
, tb
);
2747 case NL80211_CMD_FT_EVENT
:
2748 mlme_event_ft_event(drv
, tb
);
2750 case NL80211_CMD_RADAR_DETECT
:
2751 nl80211_radar_event(drv
, tb
);
2753 case NL80211_CMD_STOP_AP
:
2754 nl80211_stop_ap(drv
, tb
);
2757 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Ignored unknown event "
2764 static int process_drv_event(struct nl_msg
*msg
, void *arg
)
2766 struct wpa_driver_nl80211_data
*drv
= arg
;
2767 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2768 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2769 struct i802_bss
*bss
;
2772 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2773 genlmsg_attrlen(gnlh
, 0), NULL
);
2775 if (tb
[NL80211_ATTR_IFINDEX
]) {
2776 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2778 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
)
2779 if (ifidx
== -1 || ifidx
== bss
->ifindex
) {
2780 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2783 wpa_printf(MSG_DEBUG
,
2784 "nl80211: Ignored event (cmd=%d) for foreign interface (ifindex %d)",
2786 } else if (tb
[NL80211_ATTR_WDEV
]) {
2787 u64 wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
2788 wpa_printf(MSG_DEBUG
, "nl80211: Process event on P2P device");
2789 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
) {
2790 if (bss
->wdev_id_set
&& wdev_id
== bss
->wdev_id
) {
2791 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2795 wpa_printf(MSG_DEBUG
,
2796 "nl80211: Ignored event (cmd=%d) for foreign interface (wdev 0x%llx)",
2797 gnlh
->cmd
, (long long unsigned int) wdev_id
);
2804 static int process_global_event(struct nl_msg
*msg
, void *arg
)
2806 struct nl80211_global
*global
= arg
;
2807 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2808 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2809 struct wpa_driver_nl80211_data
*drv
, *tmp
;
2811 struct i802_bss
*bss
;
2813 int wdev_id_set
= 0;
2815 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2816 genlmsg_attrlen(gnlh
, 0), NULL
);
2818 if (tb
[NL80211_ATTR_IFINDEX
])
2819 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2820 else if (tb
[NL80211_ATTR_WDEV
]) {
2821 wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
2825 dl_list_for_each_safe(drv
, tmp
, &global
->interfaces
,
2826 struct wpa_driver_nl80211_data
, list
) {
2827 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
) {
2828 if ((ifidx
== -1 && !wdev_id_set
) ||
2829 ifidx
== bss
->ifindex
||
2830 (wdev_id_set
&& bss
->wdev_id_set
&&
2831 wdev_id
== bss
->wdev_id
)) {
2832 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2842 static int process_bss_event(struct nl_msg
*msg
, void *arg
)
2844 struct i802_bss
*bss
= arg
;
2845 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2846 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2848 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2849 genlmsg_attrlen(gnlh
, 0), NULL
);
2851 wpa_printf(MSG_DEBUG
, "nl80211: BSS Event %d (%s) received for %s",
2852 gnlh
->cmd
, nl80211_command_to_string(gnlh
->cmd
),
2855 switch (gnlh
->cmd
) {
2856 case NL80211_CMD_FRAME
:
2857 case NL80211_CMD_FRAME_TX_STATUS
:
2858 mlme_event(bss
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
2859 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2860 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2861 tb
[NL80211_ATTR_COOKIE
],
2862 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2864 case NL80211_CMD_UNEXPECTED_FRAME
:
2865 nl80211_spurious_frame(bss
, tb
, 0);
2867 case NL80211_CMD_UNEXPECTED_4ADDR_FRAME
:
2868 nl80211_spurious_frame(bss
, tb
, 1);
2871 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2872 "(cmd=%d)", gnlh
->cmd
);
2880 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
2883 struct nl_cb
*cb
= eloop_ctx
;
2886 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
2888 res
= nl_recvmsgs(handle
, cb
);
2890 wpa_printf(MSG_INFO
, "nl80211: %s->nl_recvmsgs failed: %d",
2897 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
2898 * @priv: driver_nl80211 private data
2899 * @alpha2_arg: country to which to switch to
2900 * Returns: 0 on success, -1 on failure
2902 * This asks nl80211 to set the regulatory domain for given
2903 * country ISO / IEC alpha2.
2905 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
2907 struct i802_bss
*bss
= priv
;
2908 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2912 msg
= nlmsg_alloc();
2916 alpha2
[0] = alpha2_arg
[0];
2917 alpha2
[1] = alpha2_arg
[1];
2920 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
2922 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
2923 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
2932 static int protocol_feature_handler(struct nl_msg
*msg
, void *arg
)
2935 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
2936 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2938 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2939 genlmsg_attrlen(gnlh
, 0), NULL
);
2941 if (tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
])
2942 *feat
= nla_get_u32(tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
]);
2948 static u32
get_nl80211_protocol_features(struct wpa_driver_nl80211_data
*drv
)
2953 msg
= nlmsg_alloc();
2955 goto nla_put_failure
;
2957 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_PROTOCOL_FEATURES
);
2958 if (send_and_recv_msgs(drv
, msg
, protocol_feature_handler
, &feat
) == 0)
2968 struct wiphy_info_data
{
2969 struct wpa_driver_nl80211_data
*drv
;
2970 struct wpa_driver_capa
*capa
;
2972 unsigned int num_multichan_concurrent
;
2974 unsigned int error
:1;
2975 unsigned int device_ap_sme
:1;
2976 unsigned int poll_command_supported
:1;
2977 unsigned int data_tx_status
:1;
2978 unsigned int monitor_supported
:1;
2979 unsigned int auth_supported
:1;
2980 unsigned int connect_supported
:1;
2981 unsigned int p2p_go_supported
:1;
2982 unsigned int p2p_client_supported
:1;
2983 unsigned int p2p_concurrent
:1;
2987 static unsigned int probe_resp_offload_support(int supp_protocols
)
2989 unsigned int prot
= 0;
2991 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
2992 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
2993 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
2994 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
2995 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
2996 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
2997 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
2998 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
3004 static void wiphy_info_supported_iftypes(struct wiphy_info_data
*info
,
3007 struct nlattr
*nl_mode
;
3013 nla_for_each_nested(nl_mode
, tb
, i
) {
3014 switch (nla_type(nl_mode
)) {
3015 case NL80211_IFTYPE_AP
:
3016 info
->capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
3018 case NL80211_IFTYPE_ADHOC
:
3019 info
->capa
->flags
|= WPA_DRIVER_FLAGS_IBSS
;
3021 case NL80211_IFTYPE_P2P_DEVICE
:
3022 info
->capa
->flags
|=
3023 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
;
3025 case NL80211_IFTYPE_P2P_GO
:
3026 info
->p2p_go_supported
= 1;
3028 case NL80211_IFTYPE_P2P_CLIENT
:
3029 info
->p2p_client_supported
= 1;
3031 case NL80211_IFTYPE_MONITOR
:
3032 info
->monitor_supported
= 1;
3039 static int wiphy_info_iface_comb_process(struct wiphy_info_data
*info
,
3040 struct nlattr
*nl_combi
)
3042 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
3043 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
3044 struct nlattr
*nl_limit
, *nl_mode
;
3045 int err
, rem_limit
, rem_mode
;
3046 int combination_has_p2p
= 0, combination_has_mgd
= 0;
3047 static struct nla_policy
3048 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
3049 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
3050 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
3051 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
3052 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
3053 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
] = { .type
= NLA_U32
},
3055 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
3056 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
3057 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
3060 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
3061 nl_combi
, iface_combination_policy
);
3062 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
3063 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
3064 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
3065 return 0; /* broken combination */
3067 if (tb_comb
[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
])
3068 info
->capa
->flags
|= WPA_DRIVER_FLAGS_RADAR
;
3070 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
],
3072 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
3073 nl_limit
, iface_limit_policy
);
3074 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
3075 return 0; /* broken combination */
3077 nla_for_each_nested(nl_mode
,
3078 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
3080 int ift
= nla_type(nl_mode
);
3081 if (ift
== NL80211_IFTYPE_P2P_GO
||
3082 ift
== NL80211_IFTYPE_P2P_CLIENT
)
3083 combination_has_p2p
= 1;
3084 if (ift
== NL80211_IFTYPE_STATION
)
3085 combination_has_mgd
= 1;
3087 if (combination_has_p2p
&& combination_has_mgd
)
3091 if (combination_has_p2p
&& combination_has_mgd
) {
3092 info
->p2p_concurrent
= 1;
3093 info
->num_multichan_concurrent
=
3094 nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]);
3102 static void wiphy_info_iface_comb(struct wiphy_info_data
*info
,
3105 struct nlattr
*nl_combi
;
3111 nla_for_each_nested(nl_combi
, tb
, rem_combi
) {
3112 if (wiphy_info_iface_comb_process(info
, nl_combi
) > 0)
3118 static void wiphy_info_supp_cmds(struct wiphy_info_data
*info
,
3121 struct nlattr
*nl_cmd
;
3127 nla_for_each_nested(nl_cmd
, tb
, i
) {
3128 switch (nla_get_u32(nl_cmd
)) {
3129 case NL80211_CMD_AUTHENTICATE
:
3130 info
->auth_supported
= 1;
3132 case NL80211_CMD_CONNECT
:
3133 info
->connect_supported
= 1;
3135 case NL80211_CMD_START_SCHED_SCAN
:
3136 info
->capa
->sched_scan_supported
= 1;
3138 case NL80211_CMD_PROBE_CLIENT
:
3139 info
->poll_command_supported
= 1;
3146 static void wiphy_info_max_roc(struct wpa_driver_capa
*capa
,
3150 capa
->max_remain_on_chan
= nla_get_u32(tb
);
3154 static void wiphy_info_tdls(struct wpa_driver_capa
*capa
, struct nlattr
*tdls
,
3155 struct nlattr
*ext_setup
)
3160 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
3161 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
3164 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
3165 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
3170 static void wiphy_info_feature_flags(struct wiphy_info_data
*info
,
3174 struct wpa_driver_capa
*capa
= info
->capa
;
3179 flags
= nla_get_u32(tb
);
3181 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
3182 info
->data_tx_status
= 1;
3184 if (flags
& NL80211_FEATURE_INACTIVITY_TIMER
)
3185 capa
->flags
|= WPA_DRIVER_FLAGS_INACTIVITY_TIMER
;
3187 if (flags
& NL80211_FEATURE_SAE
)
3188 capa
->flags
|= WPA_DRIVER_FLAGS_SAE
;
3190 if (flags
& NL80211_FEATURE_NEED_OBSS_SCAN
)
3191 capa
->flags
|= WPA_DRIVER_FLAGS_OBSS_SCAN
;
3195 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa
*capa
,
3203 protocols
= nla_get_u32(tb
);
3204 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response offload in AP "
3206 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
3207 capa
->probe_resp_offloads
= probe_resp_offload_support(protocols
);
3211 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
3213 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
3214 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3215 struct wiphy_info_data
*info
= arg
;
3216 struct wpa_driver_capa
*capa
= info
->capa
;
3217 struct wpa_driver_nl80211_data
*drv
= info
->drv
;
3219 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3220 genlmsg_attrlen(gnlh
, 0), NULL
);
3222 if (tb
[NL80211_ATTR_WIPHY_NAME
])
3223 os_strlcpy(drv
->phyname
,
3224 nla_get_string(tb
[NL80211_ATTR_WIPHY_NAME
]),
3225 sizeof(drv
->phyname
));
3226 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
3227 capa
->max_scan_ssids
=
3228 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
3230 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
3231 capa
->max_sched_scan_ssids
=
3232 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
3234 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
3235 capa
->max_match_sets
=
3236 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
3238 if (tb
[NL80211_ATTR_MAC_ACL_MAX
])
3239 capa
->max_acl_mac_addrs
=
3240 nla_get_u8(tb
[NL80211_ATTR_MAC_ACL_MAX
]);
3242 wiphy_info_supported_iftypes(info
, tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]);
3243 wiphy_info_iface_comb(info
, tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]);
3244 wiphy_info_supp_cmds(info
, tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]);
3246 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
3247 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
3249 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
3252 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
3253 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
3254 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
3257 wiphy_info_max_roc(capa
,
3258 tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
3260 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
3261 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
3263 wiphy_info_tdls(capa
, tb
[NL80211_ATTR_TDLS_SUPPORT
],
3264 tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]);
3266 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
3267 info
->device_ap_sme
= 1;
3269 wiphy_info_feature_flags(info
, tb
[NL80211_ATTR_FEATURE_FLAGS
]);
3270 wiphy_info_probe_resp_offload(capa
,
3271 tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
3273 if (tb
[NL80211_ATTR_EXT_CAPA
] && tb
[NL80211_ATTR_EXT_CAPA_MASK
] &&
3274 drv
->extended_capa
== NULL
) {
3275 drv
->extended_capa
=
3276 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3277 if (drv
->extended_capa
) {
3278 os_memcpy(drv
->extended_capa
,
3279 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
3280 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3281 drv
->extended_capa_len
=
3282 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]);
3284 drv
->extended_capa_mask
=
3285 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3286 if (drv
->extended_capa_mask
) {
3287 os_memcpy(drv
->extended_capa_mask
,
3288 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
3289 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3291 os_free(drv
->extended_capa
);
3292 drv
->extended_capa
= NULL
;
3293 drv
->extended_capa_len
= 0;
3301 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
3302 struct wiphy_info_data
*info
)
3307 os_memset(info
, 0, sizeof(*info
));
3308 info
->capa
= &drv
->capa
;
3311 msg
= nlmsg_alloc();
3315 feat
= get_nl80211_protocol_features(drv
);
3316 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
3317 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
3319 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
3321 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
3322 if (nl80211_set_iface_id(msg
, &drv
->first_bss
) < 0)
3323 goto nla_put_failure
;
3325 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
))
3328 if (info
->auth_supported
)
3329 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SME
;
3330 else if (!info
->connect_supported
) {
3331 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
3332 "authentication/association or connect commands");
3336 if (info
->p2p_go_supported
&& info
->p2p_client_supported
)
3337 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
3338 if (info
->p2p_concurrent
) {
3339 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
3340 "interface (driver advertised support)");
3341 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
3342 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
3344 if (info
->num_multichan_concurrent
> 1) {
3345 wpa_printf(MSG_DEBUG
, "nl80211: Enable multi-channel "
3346 "concurrent (driver advertised support)");
3347 drv
->capa
.num_multichan_concurrent
=
3348 info
->num_multichan_concurrent
;
3351 /* default to 5000 since early versions of mac80211 don't set it */
3352 if (!drv
->capa
.max_remain_on_chan
)
3353 drv
->capa
.max_remain_on_chan
= 5000;
3362 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
3364 struct wiphy_info_data info
;
3365 if (wpa_driver_nl80211_get_info(drv
, &info
))
3371 drv
->has_capability
= 1;
3372 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
3373 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3374 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3375 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3376 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
3377 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
3378 WPA_DRIVER_CAPA_ENC_WEP104
|
3379 WPA_DRIVER_CAPA_ENC_TKIP
|
3380 WPA_DRIVER_CAPA_ENC_CCMP
;
3381 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
3382 WPA_DRIVER_AUTH_SHARED
|
3383 WPA_DRIVER_AUTH_LEAP
;
3385 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
3386 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
3387 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3389 if (!info
.device_ap_sme
) {
3390 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
3393 * No AP SME is currently assumed to also indicate no AP MLME
3394 * in the driver/firmware.
3396 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_MLME
;
3399 drv
->device_ap_sme
= info
.device_ap_sme
;
3400 drv
->poll_command_supported
= info
.poll_command_supported
;
3401 drv
->data_tx_status
= info
.data_tx_status
;
3404 * If poll command and tx status are supported, mac80211 is new enough
3405 * to have everything we need to not need monitor interfaces.
3407 drv
->use_monitor
= !info
.poll_command_supported
|| !info
.data_tx_status
;
3409 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
3411 * Non-mac80211 drivers may not support monitor interface.
3412 * Make sure we do not get stuck with incorrect capability here
3413 * by explicitly testing this.
3415 if (!info
.monitor_supported
) {
3416 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
3417 "with device_ap_sme since no monitor mode "
3418 "support detected");
3419 drv
->use_monitor
= 0;
3424 * If we aren't going to use monitor interfaces, but the
3425 * driver doesn't support data TX status, we won't get TX
3426 * status for EAPOL frames.
3428 if (!drv
->use_monitor
&& !info
.data_tx_status
)
3429 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3436 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
3440 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
3441 * need to work around that.
3443 struct nl_cache
*cache
= NULL
;
3444 struct genl_family
*nl80211
= NULL
;
3447 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
3448 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
3453 nl80211
= genl_ctrl_search_by_name(cache
, name
);
3454 if (nl80211
== NULL
)
3457 id
= genl_family_get_id(nl80211
);
3461 genl_family_put(nl80211
);
3463 nl_cache_free(cache
);
3467 #define genl_ctrl_resolve android_genl_ctrl_resolve
3468 #endif /* ANDROID */
3471 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
3475 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3476 if (global
->nl_cb
== NULL
) {
3477 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
3482 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
3483 if (global
->nl
== NULL
)
3486 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
3487 if (global
->nl80211_id
< 0) {
3488 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
3493 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
3494 if (global
->nl_event
== NULL
)
3497 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
3499 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3501 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3502 "membership for scan events: %d (%s)",
3503 ret
, strerror(-ret
));
3507 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
3509 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3511 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3512 "membership for mlme events: %d (%s)",
3513 ret
, strerror(-ret
));
3517 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
3519 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3521 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
3522 "membership for regulatory events: %d (%s)",
3523 ret
, strerror(-ret
));
3524 /* Continue without regulatory events */
3527 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3528 no_seq_check
, NULL
);
3529 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3530 process_global_event
, global
);
3532 nl80211_register_eloop_read(&global
->nl_event
,
3533 wpa_driver_nl80211_event_receive
,
3539 nl_destroy_handles(&global
->nl_event
);
3540 nl_destroy_handles(&global
->nl
);
3541 nl_cb_put(global
->nl_cb
);
3542 global
->nl_cb
= NULL
;
3547 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
3549 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3551 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
3555 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3556 no_seq_check
, NULL
);
3557 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3558 process_drv_event
, drv
);
3564 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
3566 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
3568 * This may be for any interface; use ifdown event to disable
3574 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
3576 struct wpa_driver_nl80211_data
*drv
= ctx
;
3577 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
3578 if (i802_set_iface_flags(&drv
->first_bss
, 1)) {
3579 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
3580 "after rfkill unblock");
3583 /* rtnetlink ifup handler will report interface as enabled */
3587 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
3591 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3596 struct cmsghdr
*cmsg
;
3597 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
3598 union wpa_event_data event
;
3600 memset(&msg
, 0, sizeof(msg
));
3601 msg
.msg_iov
= &entry
;
3603 entry
.iov_base
= data
;
3604 entry
.iov_len
= sizeof(data
);
3605 msg
.msg_control
= &control
;
3606 msg
.msg_controllen
= sizeof(control
);
3608 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
3609 /* if error or not fitting 802.3 header, return */
3613 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
3615 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
3616 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
3620 ack
= (void *)CMSG_DATA(cmsg
);
3624 if (cmsg
->cmsg_level
== SOL_PACKET
&&
3625 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
3626 struct sock_extended_err
*err
=
3627 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
3629 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
3634 if (!found_ee
|| !found_wifi
)
3637 memset(&event
, 0, sizeof(event
));
3638 event
.eapol_tx_status
.dst
= data
;
3639 event
.eapol_tx_status
.data
= data
+ 14;
3640 event
.eapol_tx_status
.data_len
= res
- 14;
3641 event
.eapol_tx_status
.ack
= acked
;
3642 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
3646 static int nl80211_init_bss(struct i802_bss
*bss
)
3648 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3652 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3653 no_seq_check
, NULL
);
3654 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3655 process_bss_event
, bss
);
3661 static void nl80211_destroy_bss(struct i802_bss
*bss
)
3663 nl_cb_put(bss
->nl_cb
);
3669 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
3670 * @ctx: context to be used when calling wpa_supplicant functions,
3671 * e.g., wpa_supplicant_event()
3672 * @ifname: interface name, e.g., wlan0
3673 * @global_priv: private driver global data from global_init()
3674 * Returns: Pointer to private data, %NULL on failure
3676 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
3679 struct wpa_driver_nl80211_data
*drv
;
3680 struct rfkill_config
*rcfg
;
3681 struct i802_bss
*bss
;
3683 if (global_priv
== NULL
)
3685 drv
= os_zalloc(sizeof(*drv
));
3688 drv
->global
= global_priv
;
3690 bss
= &drv
->first_bss
;
3694 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
3695 drv
->monitor_ifidx
= -1;
3696 drv
->monitor_sock
= -1;
3697 drv
->eapol_tx_sock
= -1;
3698 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3700 if (wpa_driver_nl80211_init_nl(drv
)) {
3705 if (nl80211_init_bss(bss
))
3708 rcfg
= os_zalloc(sizeof(*rcfg
));
3712 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
3713 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
3714 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
3715 drv
->rfkill
= rfkill_init(rcfg
);
3716 if (drv
->rfkill
== NULL
) {
3717 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
3721 if (wpa_driver_nl80211_finish_drv_init(drv
))
3724 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
3725 if (drv
->eapol_tx_sock
< 0)
3728 if (drv
->data_tx_status
) {
3731 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
3732 &enabled
, sizeof(enabled
)) < 0) {
3733 wpa_printf(MSG_DEBUG
,
3734 "nl80211: wifi status sockopt failed\n");
3735 drv
->data_tx_status
= 0;
3736 if (!drv
->use_monitor
)
3738 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3740 eloop_register_read_sock(drv
->eapol_tx_sock
,
3741 wpa_driver_nl80211_handle_eapol_tx_status
,
3747 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
3748 drv
->in_interface_list
= 1;
3754 wpa_driver_nl80211_deinit(bss
);
3759 static int nl80211_register_frame(struct i802_bss
*bss
,
3760 struct nl_handle
*nl_handle
,
3761 u16 type
, const u8
*match
, size_t match_len
)
3763 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3767 msg
= nlmsg_alloc();
3771 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
3773 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3776 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
3778 if (nl80211_set_iface_id(msg
, bss
) < 0)
3779 goto nla_put_failure
;
3781 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
3782 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
3784 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
3787 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
3788 "failed (type=%u): ret=%d (%s)",
3789 type
, ret
, strerror(-ret
));
3790 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3792 goto nla_put_failure
;
3801 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
3803 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3806 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
3807 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
3811 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
3812 if (bss
->nl_mgmt
== NULL
)
3819 static void nl80211_mgmt_handle_register_eloop(struct i802_bss
*bss
)
3821 nl80211_register_eloop_read(&bss
->nl_mgmt
,
3822 wpa_driver_nl80211_event_receive
,
3827 static int nl80211_register_action_frame(struct i802_bss
*bss
,
3828 const u8
*match
, size_t match_len
)
3830 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3831 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3832 type
, match
, match_len
);
3836 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3838 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3840 if (nl80211_alloc_mgmt_handle(bss
))
3842 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3843 "handle %p", bss
->nl_mgmt
);
3845 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
) {
3846 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_AUTH
<< 4);
3848 /* register for any AUTH message */
3849 nl80211_register_frame(bss
, bss
->nl_mgmt
, type
, NULL
, 0);
3852 #ifdef CONFIG_INTERWORKING
3853 /* QoS Map Configure */
3854 if (nl80211_register_action_frame(bss
, (u8
*) "\x01\x04", 2) < 0)
3856 #endif /* CONFIG_INTERWORKING */
3857 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3858 /* GAS Initial Request */
3859 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3861 /* GAS Initial Response */
3862 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3864 /* GAS Comeback Request */
3865 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3867 /* GAS Comeback Response */
3868 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3870 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3872 /* P2P Public Action */
3873 if (nl80211_register_action_frame(bss
,
3874 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3878 if (nl80211_register_action_frame(bss
,
3879 (u8
*) "\x7f\x50\x6f\x9a\x09",
3882 #endif /* CONFIG_P2P */
3883 #ifdef CONFIG_IEEE80211W
3884 /* SA Query Response */
3885 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3887 #endif /* CONFIG_IEEE80211W */
3889 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3890 /* TDLS Discovery Response */
3891 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3895 #endif /* CONFIG_TDLS */
3897 /* FT Action frames */
3898 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3901 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3902 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3904 /* WNM - BSS Transition Management Request */
3905 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3907 /* WNM-Sleep Mode Response */
3908 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
3911 nl80211_mgmt_handle_register_eloop(bss
);
3917 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3919 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3923 msg
= nlmsg_alloc();
3927 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3929 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3931 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3934 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3935 "failed: ret=%d (%s)",
3936 ret
, strerror(-ret
));
3937 goto nla_put_failure
;
3946 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
3948 static const int stypes
[] = {
3950 WLAN_FC_STYPE_ASSOC_REQ
,
3951 WLAN_FC_STYPE_REASSOC_REQ
,
3952 WLAN_FC_STYPE_DISASSOC
,
3953 WLAN_FC_STYPE_DEAUTH
,
3954 WLAN_FC_STYPE_ACTION
,
3955 WLAN_FC_STYPE_PROBE_REQ
,
3956 /* Beacon doesn't work as mac80211 doesn't currently allow
3957 * it, but it wouldn't really be the right thing anyway as
3958 * it isn't per interface ... maybe just dump the scan
3959 * results periodically for OLBC?
3961 // WLAN_FC_STYPE_BEACON,
3965 if (nl80211_alloc_mgmt_handle(bss
))
3967 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3968 "handle %p", bss
->nl_mgmt
);
3970 for (i
= 0; i
< ARRAY_SIZE(stypes
); i
++) {
3971 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3972 (WLAN_FC_TYPE_MGMT
<< 2) |
3979 if (nl80211_register_spurious_class3(bss
))
3982 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
3985 nl80211_mgmt_handle_register_eloop(bss
);
3989 nl_destroy_handles(&bss
->nl_mgmt
);
3994 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
3996 if (nl80211_alloc_mgmt_handle(bss
))
3998 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3999 "handle %p (device SME)", bss
->nl_mgmt
);
4001 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
4002 (WLAN_FC_TYPE_MGMT
<< 2) |
4003 (WLAN_FC_STYPE_ACTION
<< 4),
4007 nl80211_mgmt_handle_register_eloop(bss
);
4011 nl_destroy_handles(&bss
->nl_mgmt
);
4016 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
4018 if (bss
->nl_mgmt
== NULL
)
4020 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
4021 "(%s)", bss
->nl_mgmt
, reason
);
4022 nl80211_destroy_eloop_handle(&bss
->nl_mgmt
);
4024 nl80211_put_wiphy_data_ap(bss
);
4028 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
4030 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
4034 static void nl80211_del_p2pdev(struct i802_bss
*bss
)
4036 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4040 msg
= nlmsg_alloc();
4044 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
4045 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
4047 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4050 wpa_printf(MSG_DEBUG
, "nl80211: Delete P2P Device %s (0x%llx): %s",
4051 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
4059 static int nl80211_set_p2pdev(struct i802_bss
*bss
, int start
)
4061 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4065 msg
= nlmsg_alloc();
4070 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_START_P2P_DEVICE
);
4072 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_P2P_DEVICE
);
4074 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
4076 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4079 wpa_printf(MSG_DEBUG
, "nl80211: %s P2P Device %s (0x%llx): %s",
4080 start
? "Start" : "Stop",
4081 bss
->ifname
, (long long unsigned int) bss
->wdev_id
,
4090 static int i802_set_iface_flags(struct i802_bss
*bss
, int up
)
4092 enum nl80211_iftype nlmode
;
4094 nlmode
= nl80211_get_ifmode(bss
);
4095 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
4096 return linux_set_iface_flags(bss
->drv
->global
->ioctl_sock
,
4100 /* P2P Device has start/stop which is equivalent */
4101 return nl80211_set_p2pdev(bss
, up
);
4106 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
4109 enum nl80211_iftype nlmode
= NL80211_IFTYPE_STATION
;
4110 #endif /* HOSTAPD */
4111 struct i802_bss
*bss
= &drv
->first_bss
;
4112 int send_rfkill_event
= 0;
4114 drv
->ifindex
= if_nametoindex(bss
->ifname
);
4115 bss
->ifindex
= drv
->ifindex
;
4116 bss
->wdev_id
= drv
->global
->if_add_wdevid
;
4117 bss
->wdev_id_set
= drv
->global
->if_add_wdevid_set
;
4119 bss
->if_dynamic
= drv
->ifindex
== drv
->global
->if_add_ifindex
;
4120 bss
->if_dynamic
= bss
->if_dynamic
|| drv
->global
->if_add_wdevid_set
;
4121 drv
->global
->if_add_wdevid_set
= 0;
4123 if (wpa_driver_nl80211_capa(drv
))
4126 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
4127 bss
->ifname
, drv
->phyname
);
4130 if (bss
->if_dynamic
)
4131 nlmode
= nl80211_get_ifmode(bss
);
4134 * Make sure the interface starts up in station mode unless this is a
4135 * dynamically added interface (e.g., P2P) that was already configured
4136 * with proper iftype.
4138 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
4139 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to use managed mode");
4142 drv
->nlmode
= nlmode
;
4144 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
4145 int ret
= nl80211_set_p2pdev(bss
, 1);
4147 wpa_printf(MSG_ERROR
, "nl80211: Could not start P2P device");
4148 nl80211_get_macaddr(bss
);
4152 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
4153 if (rfkill_is_blocked(drv
->rfkill
)) {
4154 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
4155 "interface '%s' due to rfkill",
4157 drv
->if_disabled
= 1;
4158 send_rfkill_event
= 1;
4160 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
4161 "interface '%s' UP", bss
->ifname
);
4166 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
4167 1, IF_OPER_DORMANT
);
4168 #endif /* HOSTAPD */
4170 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
4174 if (send_rfkill_event
) {
4175 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
4183 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
4187 msg
= nlmsg_alloc();
4191 wpa_printf(MSG_DEBUG
, "nl80211: Remove beacon (ifindex=%d)",
4193 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
4194 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4196 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4204 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
4205 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
4207 * Shut down driver interface and processing of driver events. Free
4208 * private data buffer if one was allocated in wpa_driver_nl80211_init().
4210 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
4212 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4215 if (drv
->data_tx_status
)
4216 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
4217 if (drv
->eapol_tx_sock
>= 0)
4218 close(drv
->eapol_tx_sock
);
4221 wpa_driver_nl80211_probe_req_report(bss
, 0);
4222 if (bss
->added_if_into_bridge
) {
4223 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
4225 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
4226 "interface %s from bridge %s: %s",
4227 bss
->ifname
, bss
->brname
, strerror(errno
));
4229 if (bss
->added_bridge
) {
4230 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
4231 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
4233 bss
->brname
, strerror(errno
));
4236 nl80211_remove_monitor_interface(drv
);
4238 if (is_ap_interface(drv
->nlmode
))
4239 wpa_driver_nl80211_del_beacon(drv
);
4242 if (drv
->last_freq_ht
) {
4243 /* Clear HT flags from the driver */
4244 struct hostapd_freq_params freq
;
4245 os_memset(&freq
, 0, sizeof(freq
));
4246 freq
.freq
= drv
->last_freq
;
4247 wpa_driver_nl80211_set_freq(bss
, &freq
);
4250 if (drv
->eapol_sock
>= 0) {
4251 eloop_unregister_read_sock(drv
->eapol_sock
);
4252 close(drv
->eapol_sock
);
4255 if (drv
->if_indices
!= drv
->default_if_indices
)
4256 os_free(drv
->if_indices
);
4257 #endif /* HOSTAPD */
4259 if (drv
->disabled_11b_rates
)
4260 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
4262 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
4264 rfkill_deinit(drv
->rfkill
);
4266 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
4268 (void) i802_set_iface_flags(bss
, 0);
4269 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
) {
4270 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
4271 nl80211_mgmt_unsubscribe(bss
, "deinit");
4273 nl80211_mgmt_unsubscribe(bss
, "deinit");
4274 nl80211_del_p2pdev(bss
);
4276 nl_cb_put(drv
->nl_cb
);
4278 nl80211_destroy_bss(&drv
->first_bss
);
4280 os_free(drv
->filter_ssids
);
4282 os_free(drv
->auth_ie
);
4284 if (drv
->in_interface_list
)
4285 dl_list_del(&drv
->list
);
4287 os_free(drv
->extended_capa
);
4288 os_free(drv
->extended_capa_mask
);
4294 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
4295 * @eloop_ctx: Driver private data
4296 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
4298 * This function can be used as registered timeout when starting a scan to
4299 * generate a scan completed event if the driver does not report this.
4301 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
4303 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
4304 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
4305 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
4306 drv
->ap_scan_as_station
);
4307 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
4309 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
4310 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
4314 static struct nl_msg
*
4315 nl80211_scan_common(struct wpa_driver_nl80211_data
*drv
, u8 cmd
,
4316 struct wpa_driver_scan_params
*params
, u64
*wdev_id
)
4321 msg
= nlmsg_alloc();
4325 nl80211_cmd(drv
, msg
, 0, cmd
);
4328 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4330 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, *wdev_id
);
4332 if (params
->num_ssids
) {
4333 struct nlattr
*ssids
;
4335 ssids
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
4338 for (i
= 0; i
< params
->num_ssids
; i
++) {
4339 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
4340 params
->ssids
[i
].ssid
,
4341 params
->ssids
[i
].ssid_len
);
4342 if (nla_put(msg
, i
+ 1, params
->ssids
[i
].ssid_len
,
4343 params
->ssids
[i
].ssid
) < 0)
4346 nla_nest_end(msg
, ssids
);
4349 if (params
->extra_ies
) {
4350 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
4351 params
->extra_ies
, params
->extra_ies_len
);
4352 if (nla_put(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
4353 params
->extra_ies
) < 0)
4357 if (params
->freqs
) {
4358 struct nlattr
*freqs
;
4359 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
4362 for (i
= 0; params
->freqs
[i
]; i
++) {
4363 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
4364 "MHz", params
->freqs
[i
]);
4365 if (nla_put_u32(msg
, i
+ 1, params
->freqs
[i
]) < 0)
4368 nla_nest_end(msg
, freqs
);
4371 os_free(drv
->filter_ssids
);
4372 drv
->filter_ssids
= params
->filter_ssids
;
4373 params
->filter_ssids
= NULL
;
4374 drv
->num_filter_ssids
= params
->num_filter_ssids
;
4386 * wpa_driver_nl80211_scan - Request the driver to initiate scan
4387 * @bss: Pointer to private driver data from wpa_driver_nl80211_init()
4388 * @params: Scan parameters
4389 * Returns: 0 on success, -1 on failure
4391 static int wpa_driver_nl80211_scan(struct i802_bss
*bss
,
4392 struct wpa_driver_scan_params
*params
)
4394 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4395 int ret
= -1, timeout
;
4396 struct nl_msg
*msg
= NULL
;
4398 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: scan request");
4399 drv
->scan_for_auth
= 0;
4401 msg
= nl80211_scan_common(drv
, NL80211_CMD_TRIGGER_SCAN
, params
,
4402 bss
->wdev_id_set
? &bss
->wdev_id
: NULL
);
4406 if (params
->p2p_probe
) {
4407 struct nlattr
*rates
;
4409 wpa_printf(MSG_DEBUG
, "nl80211: P2P probe - mask SuppRates");
4411 rates
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SUPP_RATES
);
4413 goto nla_put_failure
;
4416 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
4417 * by masking out everything else apart from the OFDM rates 6,
4418 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
4419 * rates are left enabled.
4421 NLA_PUT(msg
, NL80211_BAND_2GHZ
, 8,
4422 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
4423 nla_nest_end(msg
, rates
);
4425 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
4428 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4431 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
4432 "(%s)", ret
, strerror(-ret
));
4434 if (is_ap_interface(drv
->nlmode
)) {
4436 * mac80211 does not allow scan requests in AP mode, so
4437 * try to do this in station mode.
4439 if (wpa_driver_nl80211_set_mode(
4440 bss
, NL80211_IFTYPE_STATION
))
4441 goto nla_put_failure
;
4443 if (wpa_driver_nl80211_scan(bss
, params
)) {
4444 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
4445 goto nla_put_failure
;
4448 /* Restore AP mode when processing scan results */
4449 drv
->ap_scan_as_station
= drv
->nlmode
;
4452 goto nla_put_failure
;
4454 goto nla_put_failure
;
4455 #endif /* HOSTAPD */
4458 drv
->scan_state
= SCAN_REQUESTED
;
4459 /* Not all drivers generate "scan completed" wireless event, so try to
4460 * read results after a timeout. */
4462 if (drv
->scan_complete_events
) {
4464 * The driver seems to deliver events to notify when scan is
4465 * complete, so use longer timeout to avoid race conditions
4466 * with scanning and following association request.
4470 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
4471 "seconds", ret
, timeout
);
4472 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
4473 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
4483 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
4484 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
4485 * @params: Scan parameters
4486 * @interval: Interval between scan cycles in milliseconds
4487 * Returns: 0 on success, -1 on failure or if not supported
4489 static int wpa_driver_nl80211_sched_scan(void *priv
,
4490 struct wpa_driver_scan_params
*params
,
4493 struct i802_bss
*bss
= priv
;
4494 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4499 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: sched_scan request");
4502 if (!drv
->capa
.sched_scan_supported
)
4503 return android_pno_start(bss
, params
);
4504 #endif /* ANDROID */
4506 msg
= nl80211_scan_common(drv
, NL80211_CMD_START_SCHED_SCAN
, params
,
4507 bss
->wdev_id_set
? &bss
->wdev_id
: NULL
);
4509 goto nla_put_failure
;
4511 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
4513 if ((drv
->num_filter_ssids
&&
4514 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) ||
4515 params
->filter_rssi
) {
4516 struct nlattr
*match_sets
;
4517 match_sets
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
4518 if (match_sets
== NULL
)
4519 goto nla_put_failure
;
4521 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4522 struct nlattr
*match_set_ssid
;
4523 wpa_hexdump_ascii(MSG_MSGDUMP
,
4524 "nl80211: Sched scan filter SSID",
4525 drv
->filter_ssids
[i
].ssid
,
4526 drv
->filter_ssids
[i
].ssid_len
);
4528 match_set_ssid
= nla_nest_start(msg
, i
+ 1);
4529 if (match_set_ssid
== NULL
)
4530 goto nla_put_failure
;
4531 NLA_PUT(msg
, NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
4532 drv
->filter_ssids
[i
].ssid_len
,
4533 drv
->filter_ssids
[i
].ssid
);
4535 nla_nest_end(msg
, match_set_ssid
);
4538 if (params
->filter_rssi
) {
4539 struct nlattr
*match_set_rssi
;
4540 match_set_rssi
= nla_nest_start(msg
, 0);
4541 if (match_set_rssi
== NULL
)
4542 goto nla_put_failure
;
4543 NLA_PUT_U32(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
,
4544 params
->filter_rssi
);
4545 wpa_printf(MSG_MSGDUMP
,
4546 "nl80211: Sched scan RSSI filter %d dBm",
4547 params
->filter_rssi
);
4548 nla_nest_end(msg
, match_set_rssi
);
4551 nla_nest_end(msg
, match_sets
);
4554 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4556 /* TODO: if we get an error here, we should fall back to normal scan */
4560 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
4561 "ret=%d (%s)", ret
, strerror(-ret
));
4562 goto nla_put_failure
;
4565 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
4566 "scan interval %d msec", ret
, interval
);
4575 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
4576 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
4577 * Returns: 0 on success, -1 on failure or if not supported
4579 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
4581 struct i802_bss
*bss
= priv
;
4582 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4587 if (!drv
->capa
.sched_scan_supported
)
4588 return android_pno_stop(bss
);
4589 #endif /* ANDROID */
4591 msg
= nlmsg_alloc();
4595 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
4597 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4599 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4602 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
4603 "ret=%d (%s)", ret
, strerror(-ret
));
4604 goto nla_put_failure
;
4607 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
4615 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
4617 const u8
*end
, *pos
;
4623 end
= ies
+ ies_len
;
4625 while (pos
+ 1 < end
) {
4626 if (pos
+ 2 + pos
[1] > end
)
4637 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
4638 const u8
*ie
, size_t ie_len
)
4643 if (drv
->filter_ssids
== NULL
)
4646 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
4650 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4651 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
4652 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
4661 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
4663 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
4664 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4665 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
4666 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
4667 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
4668 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
4669 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
4670 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
4671 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
4672 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
4673 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
4674 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
4675 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
4676 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
4677 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
4679 struct nl80211_bss_info_arg
*_arg
= arg
;
4680 struct wpa_scan_results
*res
= _arg
->res
;
4681 struct wpa_scan_res
**tmp
;
4682 struct wpa_scan_res
*r
;
4683 const u8
*ie
, *beacon_ie
;
4684 size_t ie_len
, beacon_ie_len
;
4688 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4689 genlmsg_attrlen(gnlh
, 0), NULL
);
4690 if (!tb
[NL80211_ATTR_BSS
])
4692 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
4695 if (bss
[NL80211_BSS_STATUS
]) {
4696 enum nl80211_bss_status status
;
4697 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4698 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4699 bss
[NL80211_BSS_FREQUENCY
]) {
4701 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4702 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
4705 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4706 bss
[NL80211_BSS_BSSID
]) {
4707 os_memcpy(_arg
->assoc_bssid
,
4708 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
4709 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
4710 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
4715 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
4716 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4717 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4722 if (bss
[NL80211_BSS_BEACON_IES
]) {
4723 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
4724 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
4730 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
4731 ie
? ie_len
: beacon_ie_len
))
4734 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
4737 if (bss
[NL80211_BSS_BSSID
])
4738 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
4740 if (bss
[NL80211_BSS_FREQUENCY
])
4741 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4742 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
4743 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
4744 if (bss
[NL80211_BSS_CAPABILITY
])
4745 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
4746 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
4747 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
4748 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
4749 r
->level
/= 100; /* mBm to dBm */
4750 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
4751 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
4752 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
4753 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
4755 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
4756 if (bss
[NL80211_BSS_TSF
])
4757 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
4758 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
4759 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
4761 pos
= (u8
*) (r
+ 1);
4763 os_memcpy(pos
, ie
, ie_len
);
4766 r
->beacon_ie_len
= beacon_ie_len
;
4768 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
4770 if (bss
[NL80211_BSS_STATUS
]) {
4771 enum nl80211_bss_status status
;
4772 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4774 case NL80211_BSS_STATUS_AUTHENTICATED
:
4775 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
4777 case NL80211_BSS_STATUS_ASSOCIATED
:
4778 r
->flags
|= WPA_SCAN_ASSOCIATED
;
4786 * cfg80211 maintains separate BSS table entries for APs if the same
4787 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
4788 * not use frequency as a separate key in the BSS table, so filter out
4789 * duplicated entries. Prefer associated BSS entry in such a case in
4790 * order to get the correct frequency into the BSS table.
4792 for (i
= 0; i
< res
->num
; i
++) {
4794 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
4797 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
4798 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
4799 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
4800 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
4801 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
4804 /* Same BSSID,SSID was already included in scan results */
4805 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
4806 "for " MACSTR
, MAC2STR(r
->bssid
));
4808 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
4809 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
4810 os_free(res
->res
[i
]);
4817 tmp
= os_realloc_array(res
->res
, res
->num
+ 1,
4818 sizeof(struct wpa_scan_res
*));
4823 tmp
[res
->num
++] = r
;
4830 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
4833 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
4834 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
4835 "mismatch (" MACSTR
")", MAC2STR(addr
));
4836 wpa_driver_nl80211_mlme(drv
, addr
,
4837 NL80211_CMD_DEAUTHENTICATE
,
4838 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
4843 static void wpa_driver_nl80211_check_bss_status(
4844 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
4848 for (i
= 0; i
< res
->num
; i
++) {
4849 struct wpa_scan_res
*r
= res
->res
[i
];
4850 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
4851 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4852 "indicates BSS status with " MACSTR
4853 " as authenticated",
4855 if (is_sta_interface(drv
->nlmode
) &&
4856 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
4857 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
4859 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
4860 " in local state (auth=" MACSTR
4861 " assoc=" MACSTR
")",
4862 MAC2STR(drv
->auth_bssid
),
4863 MAC2STR(drv
->bssid
));
4864 clear_state_mismatch(drv
, r
->bssid
);
4868 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
4869 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4870 "indicate BSS status with " MACSTR
4873 if (is_sta_interface(drv
->nlmode
) &&
4875 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4876 "(not associated) does not match "
4878 clear_state_mismatch(drv
, r
->bssid
);
4879 } else if (is_sta_interface(drv
->nlmode
) &&
4880 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
4882 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4883 "(associated with " MACSTR
") does "
4884 "not match with BSS state",
4885 MAC2STR(drv
->bssid
));
4886 clear_state_mismatch(drv
, r
->bssid
);
4887 clear_state_mismatch(drv
, drv
->bssid
);
4894 static struct wpa_scan_results
*
4895 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
4898 struct wpa_scan_results
*res
;
4900 struct nl80211_bss_info_arg arg
;
4902 res
= os_zalloc(sizeof(*res
));
4905 msg
= nlmsg_alloc();
4907 goto nla_put_failure
;
4909 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
4910 if (nl80211_set_iface_id(msg
, &drv
->first_bss
) < 0)
4911 goto nla_put_failure
;
4915 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
4918 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
4919 "BSSes)", (unsigned long) res
->num
);
4920 nl80211_get_noise_for_scan_results(drv
, res
);
4923 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
4924 "(%s)", ret
, strerror(-ret
));
4927 wpa_scan_results_free(res
);
4933 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
4934 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
4935 * Returns: Scan results on success, -1 on failure
4937 static struct wpa_scan_results
*
4938 wpa_driver_nl80211_get_scan_results(void *priv
)
4940 struct i802_bss
*bss
= priv
;
4941 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4942 struct wpa_scan_results
*res
;
4944 res
= nl80211_get_scan_results(drv
);
4946 wpa_driver_nl80211_check_bss_status(drv
, res
);
4951 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
4953 struct wpa_scan_results
*res
;
4956 res
= nl80211_get_scan_results(drv
);
4958 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
4962 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
4963 for (i
= 0; i
< res
->num
; i
++) {
4964 struct wpa_scan_res
*r
= res
->res
[i
];
4965 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
4966 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
4967 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
4968 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
4971 wpa_scan_results_free(res
);
4975 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
4976 enum wpa_alg alg
, const u8
*addr
,
4977 int key_idx
, int set_tx
,
4978 const u8
*seq
, size_t seq_len
,
4979 const u8
*key
, size_t key_len
)
4981 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4987 /* Ignore for P2P Device */
4988 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
4991 ifindex
= if_nametoindex(ifname
);
4992 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
4993 "set_tx=%d seq_len=%lu key_len=%lu",
4994 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
4995 (unsigned long) seq_len
, (unsigned long) key_len
);
4997 if (key_idx
== -1) {
5001 #endif /* CONFIG_TDLS */
5003 msg
= nlmsg_alloc();
5007 if (alg
== WPA_ALG_NONE
) {
5008 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
5010 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
5011 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
5015 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5016 WLAN_CIPHER_SUITE_WEP40
);
5018 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5019 WLAN_CIPHER_SUITE_WEP104
);
5022 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5023 WLAN_CIPHER_SUITE_TKIP
);
5026 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5027 WLAN_CIPHER_SUITE_CCMP
);
5030 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5031 WLAN_CIPHER_SUITE_GCMP
);
5034 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5035 WLAN_CIPHER_SUITE_AES_CMAC
);
5038 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5039 WLAN_CIPHER_SUITE_SMS4
);
5042 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
5043 WLAN_CIPHER_SUITE_KRK
);
5046 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
5047 "algorithm %d", __func__
, alg
);
5054 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
5056 if (addr
&& !is_broadcast_ether_addr(addr
)) {
5057 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
5058 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5060 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
5061 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
5062 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
5063 NL80211_KEYTYPE_GROUP
);
5065 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
5066 struct nlattr
*types
;
5068 wpa_printf(MSG_DEBUG
, " broadcast key");
5070 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
5072 goto nla_put_failure
;
5073 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
5074 nla_nest_end(msg
, types
);
5076 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
5077 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5079 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5080 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
5083 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
5084 ret
, strerror(-ret
));
5087 * If we failed or don't need to set the default TX key (below),
5090 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
|| tdls
)
5092 if (is_ap_interface(drv
->nlmode
) && addr
&&
5093 !is_broadcast_ether_addr(addr
))
5096 msg
= nlmsg_alloc();
5100 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
5101 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
5102 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
5103 if (alg
== WPA_ALG_IGTK
)
5104 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
5106 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
5107 if (addr
&& is_broadcast_ether_addr(addr
)) {
5108 struct nlattr
*types
;
5110 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
5112 goto nla_put_failure
;
5113 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
5114 nla_nest_end(msg
, types
);
5116 struct nlattr
*types
;
5118 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
5120 goto nla_put_failure
;
5121 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
5122 nla_nest_end(msg
, types
);
5125 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5129 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
5130 "err=%d %s)", ret
, strerror(-ret
));
5139 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
5140 int key_idx
, int defkey
,
5141 const u8
*seq
, size_t seq_len
,
5142 const u8
*key
, size_t key_len
)
5144 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
5148 if (defkey
&& alg
== WPA_ALG_IGTK
)
5149 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
5151 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
5153 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
5158 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5159 WLAN_CIPHER_SUITE_WEP40
);
5161 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5162 WLAN_CIPHER_SUITE_WEP104
);
5165 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
5168 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
5171 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_GCMP
);
5174 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5175 WLAN_CIPHER_SUITE_AES_CMAC
);
5178 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
5179 "algorithm %d", __func__
, alg
);
5184 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
5186 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
5188 nla_nest_end(msg
, key_attr
);
5196 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
5200 struct nlattr
*nl_keys
, *nl_key
;
5202 for (i
= 0; i
< 4; i
++) {
5203 if (!params
->wep_key
[i
])
5208 if (params
->wps
== WPS_MODE_PRIVACY
)
5210 if (params
->pairwise_suite
&&
5211 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
5217 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5219 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
5221 goto nla_put_failure
;
5223 for (i
= 0; i
< 4; i
++) {
5224 if (!params
->wep_key
[i
])
5227 nl_key
= nla_nest_start(msg
, i
);
5229 goto nla_put_failure
;
5231 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
5232 params
->wep_key
[i
]);
5233 if (params
->wep_key_len
[i
] == 5)
5234 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5235 WLAN_CIPHER_SUITE_WEP40
);
5237 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5238 WLAN_CIPHER_SUITE_WEP104
);
5240 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
5242 if (i
== params
->wep_tx_keyidx
)
5243 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
5245 nla_nest_end(msg
, nl_key
);
5247 nla_nest_end(msg
, nl_keys
);
5256 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
5257 const u8
*addr
, int cmd
, u16 reason_code
,
5258 int local_state_change
)
5263 msg
= nlmsg_alloc();
5267 nl80211_cmd(drv
, msg
, 0, cmd
);
5269 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5270 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
5272 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5273 if (local_state_change
)
5274 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
5276 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5279 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5280 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
5281 reason_code
, ret
, strerror(-ret
));
5282 goto nla_put_failure
;
5292 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
5297 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
5298 nl80211_mark_disconnected(drv
);
5299 /* Disconnect command doesn't need BSSID - it uses cached value */
5300 ret
= wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
5303 * For locally generated disconnect, supplicant already generates a
5304 * DEAUTH event, so ignore the event from NL80211.
5306 drv
->ignore_next_local_disconnect
= ret
== 0;
5312 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
5313 const u8
*addr
, int reason_code
)
5315 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5316 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
5317 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
5318 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
5319 __func__
, MAC2STR(addr
), reason_code
);
5320 nl80211_mark_disconnected(drv
);
5321 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
5322 return nl80211_leave_ibss(drv
);
5323 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
5328 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
5329 struct wpa_driver_auth_params
*params
)
5333 drv
->auth_freq
= params
->freq
;
5334 drv
->auth_alg
= params
->auth_alg
;
5335 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
5336 drv
->auth_local_state_change
= params
->local_state_change
;
5337 drv
->auth_p2p
= params
->p2p
;
5340 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
5342 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
5345 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
5346 drv
->auth_ssid_len
= params
->ssid_len
;
5348 drv
->auth_ssid_len
= 0;
5351 os_free(drv
->auth_ie
);
5352 drv
->auth_ie
= NULL
;
5353 drv
->auth_ie_len
= 0;
5355 drv
->auth_ie
= os_malloc(params
->ie_len
);
5357 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
5358 drv
->auth_ie_len
= params
->ie_len
;
5362 for (i
= 0; i
< 4; i
++) {
5363 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
5364 params
->wep_key_len
[i
] <= 16) {
5365 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
5366 params
->wep_key_len
[i
]);
5367 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
5369 drv
->auth_wep_key_len
[i
] = 0;
5374 static int wpa_driver_nl80211_authenticate(
5375 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
5377 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5380 enum nl80211_auth_type type
;
5381 enum nl80211_iftype nlmode
;
5385 is_retry
= drv
->retry_auth
;
5386 drv
->retry_auth
= 0;
5388 nl80211_mark_disconnected(drv
);
5389 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
5391 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
5393 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
5394 /* FIX: IBSS mode */
5395 nlmode
= params
->p2p
?
5396 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5397 if (drv
->nlmode
!= nlmode
&&
5398 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
5402 msg
= nlmsg_alloc();
5406 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
5409 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
5411 for (i
= 0; i
< 4; i
++) {
5412 if (!params
->wep_key
[i
])
5414 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
5416 i
== params
->wep_tx_keyidx
, NULL
, 0,
5418 params
->wep_key_len
[i
]);
5419 if (params
->wep_tx_keyidx
!= i
)
5421 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
5422 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
5428 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5429 if (params
->bssid
) {
5430 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5431 MAC2STR(params
->bssid
));
5432 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5435 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5436 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5439 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5440 params
->ssid
, params
->ssid_len
);
5441 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5444 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
5446 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
5447 if (params
->sae_data
) {
5448 wpa_hexdump(MSG_DEBUG
, " * SAE data", params
->sae_data
,
5449 params
->sae_data_len
);
5450 NLA_PUT(msg
, NL80211_ATTR_SAE_DATA
, params
->sae_data_len
,
5453 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5454 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
5455 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5456 type
= NL80211_AUTHTYPE_SHARED_KEY
;
5457 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5458 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
5459 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5460 type
= NL80211_AUTHTYPE_FT
;
5461 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
5462 type
= NL80211_AUTHTYPE_SAE
;
5464 goto nla_put_failure
;
5465 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5466 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
5467 if (params
->local_state_change
) {
5468 wpa_printf(MSG_DEBUG
, " * Local state change only");
5469 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
5472 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5475 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5476 "nl80211: MLME command failed (auth): ret=%d (%s)",
5477 ret
, strerror(-ret
));
5479 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
5480 !params
->local_state_change
) {
5482 * mac80211 does not currently accept new
5483 * authentication if we are already authenticated. As a
5484 * workaround, force deauthentication and try again.
5486 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
5487 "after forced deauthentication");
5488 wpa_driver_nl80211_deauthenticate(
5490 WLAN_REASON_PREV_AUTH_NOT_VALID
);
5495 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
5497 * cfg80211 has likely expired the BSS entry even
5498 * though it was previously available in our internal
5499 * BSS table. To recover quickly, start a single
5500 * channel scan on the specified channel.
5502 struct wpa_driver_scan_params scan
;
5505 os_memset(&scan
, 0, sizeof(scan
));
5508 scan
.ssids
[0].ssid
= params
->ssid
;
5509 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
5511 freqs
[0] = params
->freq
;
5514 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
5515 "channel scan to refresh cfg80211 BSS "
5517 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
5519 nl80211_copy_auth_params(drv
, params
);
5520 drv
->scan_for_auth
= 1;
5522 } else if (is_retry
) {
5524 * Need to indicate this with an event since the return
5525 * value from the retry is not delivered to core code.
5527 union wpa_event_data event
;
5528 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
5530 os_memset(&event
, 0, sizeof(event
));
5531 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
5533 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
5537 goto nla_put_failure
;
5540 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
5549 static int wpa_driver_nl80211_authenticate_retry(
5550 struct wpa_driver_nl80211_data
*drv
)
5552 struct wpa_driver_auth_params params
;
5553 struct i802_bss
*bss
= &drv
->first_bss
;
5556 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
5558 os_memset(¶ms
, 0, sizeof(params
));
5559 params
.freq
= drv
->auth_freq
;
5560 params
.auth_alg
= drv
->auth_alg
;
5561 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
5562 params
.local_state_change
= drv
->auth_local_state_change
;
5563 params
.p2p
= drv
->auth_p2p
;
5565 if (!is_zero_ether_addr(drv
->auth_bssid_
))
5566 params
.bssid
= drv
->auth_bssid_
;
5568 if (drv
->auth_ssid_len
) {
5569 params
.ssid
= drv
->auth_ssid
;
5570 params
.ssid_len
= drv
->auth_ssid_len
;
5573 params
.ie
= drv
->auth_ie
;
5574 params
.ie_len
= drv
->auth_ie_len
;
5576 for (i
= 0; i
< 4; i
++) {
5577 if (drv
->auth_wep_key_len
[i
]) {
5578 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
5579 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
5583 drv
->retry_auth
= 1;
5584 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
5588 struct phy_info_arg
{
5590 struct hostapd_hw_modes
*modes
;
5591 int last_mode
, last_chan_idx
;
5594 static void phy_info_ht_capa(struct hostapd_hw_modes
*mode
, struct nlattr
*capa
,
5595 struct nlattr
*ampdu_factor
,
5596 struct nlattr
*ampdu_density
,
5597 struct nlattr
*mcs_set
)
5600 mode
->ht_capab
= nla_get_u16(capa
);
5603 mode
->a_mpdu_params
|= nla_get_u8(ampdu_factor
) & 0x03;
5606 mode
->a_mpdu_params
|= nla_get_u8(ampdu_density
) << 2;
5608 if (mcs_set
&& nla_len(mcs_set
) >= 16) {
5610 mcs
= nla_data(mcs_set
);
5611 os_memcpy(mode
->mcs_set
, mcs
, 16);
5616 static void phy_info_vht_capa(struct hostapd_hw_modes
*mode
,
5617 struct nlattr
*capa
,
5618 struct nlattr
*mcs_set
)
5621 mode
->vht_capab
= nla_get_u32(capa
);
5623 if (mcs_set
&& nla_len(mcs_set
) >= 8) {
5625 mcs
= nla_data(mcs_set
);
5626 os_memcpy(mode
->vht_mcs_set
, mcs
, 8);
5631 static void phy_info_freq(struct hostapd_hw_modes
*mode
,
5632 struct hostapd_channel_data
*chan
,
5633 struct nlattr
*tb_freq
[])
5636 chan
->freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
5638 if (ieee80211_freq_to_chan(chan
->freq
, &channel
) != NUM_HOSTAPD_MODES
)
5639 chan
->chan
= channel
;
5641 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
5642 chan
->flag
|= HOSTAPD_CHAN_DISABLED
;
5643 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
5644 chan
->flag
|= HOSTAPD_CHAN_PASSIVE_SCAN
;
5645 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
5646 chan
->flag
|= HOSTAPD_CHAN_NO_IBSS
;
5647 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
5648 chan
->flag
|= HOSTAPD_CHAN_RADAR
;
5650 if (tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]) {
5651 enum nl80211_dfs_state state
=
5652 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]);
5655 case NL80211_DFS_USABLE
:
5656 chan
->flag
|= HOSTAPD_CHAN_DFS_USABLE
;
5658 case NL80211_DFS_AVAILABLE
:
5659 chan
->flag
|= HOSTAPD_CHAN_DFS_AVAILABLE
;
5661 case NL80211_DFS_UNAVAILABLE
:
5662 chan
->flag
|= HOSTAPD_CHAN_DFS_UNAVAILABLE
;
5669 static int phy_info_freqs(struct phy_info_arg
*phy_info
,
5670 struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5672 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5673 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
5674 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
5675 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
5676 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
5677 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
5678 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
5679 [NL80211_FREQUENCY_ATTR_DFS_STATE
] = { .type
= NLA_U32
},
5681 int new_channels
= 0;
5682 struct hostapd_channel_data
*channel
;
5683 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5684 struct nlattr
*nl_freq
;
5690 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5691 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5692 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5693 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5698 channel
= os_realloc_array(mode
->channels
,
5699 mode
->num_channels
+ new_channels
,
5700 sizeof(struct hostapd_channel_data
));
5704 mode
->channels
= channel
;
5705 mode
->num_channels
+= new_channels
;
5707 idx
= phy_info
->last_chan_idx
;
5709 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5710 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5711 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5712 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5714 phy_info_freq(mode
, &mode
->channels
[idx
], tb_freq
);
5717 phy_info
->last_chan_idx
= idx
;
5723 static int phy_info_rates(struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5725 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
5726 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
5727 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] =
5728 { .type
= NLA_FLAG
},
5730 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
5731 struct nlattr
*nl_rate
;
5737 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5738 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5739 nla_data(nl_rate
), nla_len(nl_rate
),
5741 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5746 mode
->rates
= os_calloc(mode
->num_rates
, sizeof(int));
5752 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5753 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5754 nla_data(nl_rate
), nla_len(nl_rate
),
5756 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5758 mode
->rates
[idx
] = nla_get_u32(
5759 tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
5767 static int phy_info_band(struct phy_info_arg
*phy_info
, struct nlattr
*nl_band
)
5769 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
5770 struct hostapd_hw_modes
*mode
;
5773 if (phy_info
->last_mode
!= nl_band
->nla_type
) {
5774 mode
= os_realloc_array(phy_info
->modes
,
5775 *phy_info
->num_modes
+ 1,
5779 phy_info
->modes
= mode
;
5781 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
5782 os_memset(mode
, 0, sizeof(*mode
));
5783 mode
->mode
= NUM_HOSTAPD_MODES
;
5784 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
|
5785 HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN
;
5788 * Unsupported VHT MCS stream is defined as value 3, so the VHT
5789 * MCS RX/TX map must be initialized with 0xffff to mark all 8
5790 * possible streams as unsupported. This will be overridden if
5791 * driver advertises VHT support.
5793 mode
->vht_mcs_set
[0] = 0xff;
5794 mode
->vht_mcs_set
[1] = 0xff;
5795 mode
->vht_mcs_set
[4] = 0xff;
5796 mode
->vht_mcs_set
[5] = 0xff;
5798 *(phy_info
->num_modes
) += 1;
5799 phy_info
->last_mode
= nl_band
->nla_type
;
5800 phy_info
->last_chan_idx
= 0;
5802 mode
= &phy_info
->modes
[*(phy_info
->num_modes
) - 1];
5804 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
5805 nla_len(nl_band
), NULL
);
5807 phy_info_ht_capa(mode
, tb_band
[NL80211_BAND_ATTR_HT_CAPA
],
5808 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
],
5809 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
],
5810 tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
5811 phy_info_vht_capa(mode
, tb_band
[NL80211_BAND_ATTR_VHT_CAPA
],
5812 tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
]);
5813 ret
= phy_info_freqs(phy_info
, mode
, tb_band
[NL80211_BAND_ATTR_FREQS
]);
5816 ret
= phy_info_rates(mode
, tb_band
[NL80211_BAND_ATTR_RATES
]);
5824 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
5826 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5827 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5828 struct phy_info_arg
*phy_info
= arg
;
5829 struct nlattr
*nl_band
;
5832 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5833 genlmsg_attrlen(gnlh
, 0), NULL
);
5835 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
5838 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
)
5840 int res
= phy_info_band(phy_info
, nl_band
);
5849 static struct hostapd_hw_modes
*
5850 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes
*modes
,
5854 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
5855 int i
, mode11g_idx
= -1;
5857 /* heuristic to set up modes */
5858 for (m
= 0; m
< *num_modes
; m
++) {
5859 if (!modes
[m
].num_channels
)
5861 if (modes
[m
].channels
[0].freq
< 4000) {
5862 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211B
;
5863 for (i
= 0; i
< modes
[m
].num_rates
; i
++) {
5864 if (modes
[m
].rates
[i
] > 200) {
5865 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211G
;
5869 } else if (modes
[m
].channels
[0].freq
> 50000)
5870 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211AD
;
5872 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211A
;
5875 /* If only 802.11g mode is included, use it to construct matching
5876 * 802.11b mode data. */
5878 for (m
= 0; m
< *num_modes
; m
++) {
5879 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
5880 return modes
; /* 802.11b already included */
5881 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
5885 if (mode11g_idx
< 0)
5886 return modes
; /* 2.4 GHz band not supported at all */
5888 nmodes
= os_realloc_array(modes
, *num_modes
+ 1, sizeof(*nmodes
));
5890 return modes
; /* Could not add 802.11b mode */
5892 mode
= &nmodes
[*num_modes
];
5893 os_memset(mode
, 0, sizeof(*mode
));
5897 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
5899 mode11g
= &modes
[mode11g_idx
];
5900 mode
->num_channels
= mode11g
->num_channels
;
5901 mode
->channels
= os_malloc(mode11g
->num_channels
*
5902 sizeof(struct hostapd_channel_data
));
5903 if (mode
->channels
== NULL
) {
5905 return modes
; /* Could not add 802.11b mode */
5907 os_memcpy(mode
->channels
, mode11g
->channels
,
5908 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
5910 mode
->num_rates
= 0;
5911 mode
->rates
= os_malloc(4 * sizeof(int));
5912 if (mode
->rates
== NULL
) {
5913 os_free(mode
->channels
);
5915 return modes
; /* Could not add 802.11b mode */
5918 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
5919 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
5920 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
5922 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
5924 if (mode
->num_rates
== 4)
5928 if (mode
->num_rates
== 0) {
5929 os_free(mode
->channels
);
5930 os_free(mode
->rates
);
5932 return modes
; /* No 802.11b rates */
5935 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
5942 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
5947 for (c
= 0; c
< mode
->num_channels
; c
++) {
5948 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5949 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
5950 chan
->flag
|= HOSTAPD_CHAN_HT40
;
5955 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
5960 for (c
= 0; c
< mode
->num_channels
; c
++) {
5961 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5962 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
5964 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
5965 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
5966 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
5967 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
5972 static void nl80211_reg_rule_max_eirp(struct nlattr
*tb
[],
5973 struct phy_info_arg
*results
)
5975 u32 start
, end
, max_eirp
;
5978 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5979 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5980 tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
] == NULL
)
5983 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5984 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5985 max_eirp
= nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]) / 100;
5987 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u mBm",
5988 start
, end
, max_eirp
);
5990 for (m
= 0; m
< *results
->num_modes
; m
++) {
5992 struct hostapd_hw_modes
*mode
= &results
->modes
[m
];
5994 for (c
= 0; c
< mode
->num_channels
; c
++) {
5995 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5996 if ((u32
) chan
->freq
- 10 >= start
&&
5997 (u32
) chan
->freq
+ 10 <= end
)
5998 chan
->max_tx_power
= max_eirp
;
6004 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
6005 struct phy_info_arg
*results
)
6007 u32 start
, end
, max_bw
;
6010 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6011 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6012 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
6015 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6016 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6017 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
6019 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
6020 start
, end
, max_bw
);
6024 for (m
= 0; m
< *results
->num_modes
; m
++) {
6025 if (!(results
->modes
[m
].ht_capab
&
6026 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
6028 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
6033 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
6034 struct phy_info_arg
*results
)
6036 u32 start
, end
, max_bw
;
6039 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6040 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6041 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
6044 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6045 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6046 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
6051 for (m
= 0; m
< *results
->num_modes
; m
++) {
6052 if (!(results
->modes
[m
].ht_capab
&
6053 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
6055 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
6060 static void nl80211_set_vht_mode(struct hostapd_hw_modes
*mode
, int start
,
6065 for (c
= 0; c
< mode
->num_channels
; c
++) {
6066 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
6067 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 70 <= end
)
6068 chan
->flag
|= HOSTAPD_CHAN_VHT_10_70
;
6070 if (chan
->freq
- 30 >= start
&& chan
->freq
+ 50 <= end
)
6071 chan
->flag
|= HOSTAPD_CHAN_VHT_30_50
;
6073 if (chan
->freq
- 50 >= start
&& chan
->freq
+ 30 <= end
)
6074 chan
->flag
|= HOSTAPD_CHAN_VHT_50_30
;
6076 if (chan
->freq
- 70 >= start
&& chan
->freq
+ 10 <= end
)
6077 chan
->flag
|= HOSTAPD_CHAN_VHT_70_10
;
6082 static void nl80211_reg_rule_vht(struct nlattr
*tb
[],
6083 struct phy_info_arg
*results
)
6085 u32 start
, end
, max_bw
;
6088 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
6089 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
6090 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
6093 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
6094 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
6095 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
6100 for (m
= 0; m
< *results
->num_modes
; m
++) {
6101 if (!(results
->modes
[m
].ht_capab
&
6102 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
6104 /* TODO: use a real VHT support indication */
6105 if (!results
->modes
[m
].vht_capab
)
6108 nl80211_set_vht_mode(&results
->modes
[m
], start
, end
);
6113 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
6115 struct phy_info_arg
*results
= arg
;
6116 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
6117 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
6118 struct nlattr
*nl_rule
;
6119 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
6121 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
6122 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
6123 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
6124 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
6125 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
6126 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
6127 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
6130 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
6131 genlmsg_attrlen(gnlh
, 0), NULL
);
6132 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
6133 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
6134 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
6139 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
6140 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
6142 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
6144 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
6145 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
6146 nl80211_reg_rule_ht40(tb_rule
, results
);
6147 nl80211_reg_rule_max_eirp(tb_rule
, results
);
6150 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
6152 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
6153 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
6154 nl80211_reg_rule_sec(tb_rule
, results
);
6157 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
6159 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
6160 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
6161 nl80211_reg_rule_vht(tb_rule
, results
);
6168 static int nl80211_set_regulatory_flags(struct wpa_driver_nl80211_data
*drv
,
6169 struct phy_info_arg
*results
)
6173 msg
= nlmsg_alloc();
6177 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
6178 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
6182 static struct hostapd_hw_modes
*
6183 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
6186 struct i802_bss
*bss
= priv
;
6187 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6189 struct phy_info_arg result
= {
6190 .num_modes
= num_modes
,
6198 msg
= nlmsg_alloc();
6202 feat
= get_nl80211_protocol_features(drv
);
6203 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
6204 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
6206 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
6208 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
6209 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6211 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
6212 nl80211_set_regulatory_flags(drv
, &result
);
6213 return wpa_driver_nl80211_postprocess_modes(result
.modes
,
6223 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
6224 const void *data
, size_t len
,
6225 int encrypt
, int noack
)
6228 0x00, 0x00, /* radiotap version */
6229 0x0e, 0x00, /* radiotap length */
6230 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
6231 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
6233 0x00, 0x00, /* RX and TX flags to indicate that */
6234 0x00, 0x00, /* this is the injected frame directly */
6236 struct iovec iov
[2] = {
6238 .iov_base
= &rtap_hdr
,
6239 .iov_len
= sizeof(rtap_hdr
),
6242 .iov_base
= (void *) data
,
6246 struct msghdr msg
= {
6251 .msg_control
= NULL
,
6252 .msg_controllen
= 0,
6259 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
6261 if (drv
->monitor_sock
< 0) {
6262 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
6263 "for %s", __func__
);
6268 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
6269 WPA_PUT_LE16(&rtap_hdr
[12], txflags
);
6271 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
6273 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
6280 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
6281 const void *data
, size_t len
,
6282 int encrypt
, int noack
,
6283 unsigned int freq
, int no_cck
,
6284 int offchanok
, unsigned int wait_time
)
6286 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6291 wpa_printf(MSG_DEBUG
, "nl80211: send_frame - Use bss->freq=%u",
6296 if (drv
->use_monitor
) {
6297 wpa_printf(MSG_DEBUG
, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_mntr",
6299 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
6303 wpa_printf(MSG_DEBUG
, "nl80211: send_frame -> send_frame_cmd");
6304 res
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
6305 &cookie
, no_cck
, noack
, offchanok
);
6306 if (res
== 0 && !noack
) {
6307 const struct ieee80211_mgmt
*mgmt
;
6310 mgmt
= (const struct ieee80211_mgmt
*) data
;
6311 fc
= le_to_host16(mgmt
->frame_control
);
6312 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6313 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_ACTION
) {
6314 wpa_printf(MSG_MSGDUMP
,
6315 "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
6316 (long long unsigned int)
6317 drv
->send_action_cookie
,
6318 (long long unsigned int) cookie
);
6319 drv
->send_action_cookie
= cookie
;
6327 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
6328 size_t data_len
, int noack
,
6329 unsigned int freq
, int no_cck
,
6331 unsigned int wait_time
)
6333 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6334 struct ieee80211_mgmt
*mgmt
;
6338 mgmt
= (struct ieee80211_mgmt
*) data
;
6339 fc
= le_to_host16(mgmt
->frame_control
);
6340 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme - noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x nlmode=%d",
6341 noack
, freq
, no_cck
, offchanok
, wait_time
, fc
, drv
->nlmode
);
6343 if ((is_sta_interface(drv
->nlmode
) ||
6344 drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
) &&
6345 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6346 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
6348 * The use of last_mgmt_freq is a bit of a hack,
6349 * but it works due to the single-threaded nature
6350 * of wpa_supplicant.
6353 wpa_printf(MSG_DEBUG
, "nl80211: Use last_mgmt_freq=%d",
6354 drv
->last_mgmt_freq
);
6355 freq
= drv
->last_mgmt_freq
;
6357 return nl80211_send_frame_cmd(bss
, freq
, 0,
6358 data
, data_len
, NULL
, 1, noack
,
6362 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
6364 wpa_printf(MSG_DEBUG
, "nl80211: Use bss->freq=%d",
6368 return nl80211_send_frame_cmd(bss
, freq
,
6369 (int) freq
== bss
->freq
? 0 :
6372 &drv
->send_action_cookie
,
6373 no_cck
, noack
, offchanok
);
6376 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6377 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
6379 * Only one of the authentication frame types is encrypted.
6380 * In order for static WEP encryption to work properly (i.e.,
6381 * to not encrypt the frame), we need to tell mac80211 about
6382 * the frames that must not be encrypted.
6384 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
6385 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
6386 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
6390 wpa_printf(MSG_DEBUG
, "nl80211: send_mlme -> send_frame");
6391 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
6392 noack
, freq
, no_cck
, offchanok
,
6397 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
6398 int slot
, int ht_opmode
, int ap_isolate
,
6401 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6404 msg
= nlmsg_alloc();
6408 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
6411 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
6413 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
6415 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
6417 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
6418 if (ap_isolate
>= 0)
6419 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
6422 u8 rates
[NL80211_MAX_SUPP_RATES
];
6426 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
6428 rates
[rates_len
++] = basic_rates
[i
] / 5;
6430 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
6433 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6435 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6442 static int wpa_driver_nl80211_set_acl(void *priv
,
6443 struct hostapd_acl_params
*params
)
6445 struct i802_bss
*bss
= priv
;
6446 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6452 if (!(drv
->capa
.max_acl_mac_addrs
))
6455 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
6458 msg
= nlmsg_alloc();
6462 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
6463 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
6465 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_MAC_ACL
);
6467 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6469 NLA_PUT_U32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
6470 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
6471 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
);
6473 acl
= nla_nest_start(msg
, NL80211_ATTR_MAC_ADDRS
);
6475 goto nla_put_failure
;
6477 for (i
= 0; i
< params
->num_mac_acl
; i
++)
6478 NLA_PUT(msg
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
);
6480 nla_nest_end(msg
, acl
);
6482 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6485 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
6486 ret
, strerror(-ret
));
6496 static int wpa_driver_nl80211_set_ap(void *priv
,
6497 struct wpa_driver_ap_params
*params
)
6499 struct i802_bss
*bss
= priv
;
6500 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6502 u8 cmd
= NL80211_CMD_NEW_BEACON
;
6505 int ifindex
= if_nametoindex(bss
->ifname
);
6510 beacon_set
= bss
->beacon_set
;
6512 msg
= nlmsg_alloc();
6516 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
6519 cmd
= NL80211_CMD_SET_BEACON
;
6521 nl80211_cmd(drv
, msg
, 0, cmd
);
6522 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
6523 params
->head
, params
->head_len
);
6524 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
6525 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
6526 params
->tail
, params
->tail_len
);
6527 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
6528 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", ifindex
);
6529 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6530 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
6531 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
6532 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
6533 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
6534 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
6535 params
->ssid
, params
->ssid_len
);
6536 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6538 if (params
->proberesp
&& params
->proberesp_len
) {
6539 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
6540 params
->proberesp
, params
->proberesp_len
);
6541 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
6544 switch (params
->hide_ssid
) {
6545 case NO_SSID_HIDING
:
6546 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
6547 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6548 NL80211_HIDDEN_SSID_NOT_IN_USE
);
6550 case HIDDEN_SSID_ZERO_LEN
:
6551 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
6552 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6553 NL80211_HIDDEN_SSID_ZERO_LEN
);
6555 case HIDDEN_SSID_ZERO_CONTENTS
:
6556 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
6557 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6558 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
6561 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
6562 if (params
->privacy
)
6563 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
6564 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
6565 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
6566 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
6567 /* Leave out the attribute */
6568 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
6569 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
6570 NL80211_AUTHTYPE_SHARED_KEY
);
6572 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
6573 NL80211_AUTHTYPE_OPEN_SYSTEM
);
6575 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
6577 if (params
->wpa_version
& WPA_PROTO_WPA
)
6578 ver
|= NL80211_WPA_VERSION_1
;
6579 if (params
->wpa_version
& WPA_PROTO_RSN
)
6580 ver
|= NL80211_WPA_VERSION_2
;
6582 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
6584 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
6585 params
->key_mgmt_suites
);
6587 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
6588 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
6589 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
6590 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
6592 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
6593 num_suites
* sizeof(u32
), suites
);
6596 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
6597 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
6598 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
6600 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
6601 params
->pairwise_ciphers
);
6603 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
6604 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
6605 if (params
->pairwise_ciphers
& WPA_CIPHER_GCMP
)
6606 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
6607 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
6608 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
6609 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
6610 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
6611 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
6612 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
6614 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
6615 num_suites
* sizeof(u32
), suites
);
6618 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
6619 params
->group_cipher
);
6620 switch (params
->group_cipher
) {
6621 case WPA_CIPHER_CCMP
:
6622 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6623 WLAN_CIPHER_SUITE_CCMP
);
6625 case WPA_CIPHER_GCMP
:
6626 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6627 WLAN_CIPHER_SUITE_GCMP
);
6629 case WPA_CIPHER_TKIP
:
6630 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6631 WLAN_CIPHER_SUITE_TKIP
);
6633 case WPA_CIPHER_WEP104
:
6634 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6635 WLAN_CIPHER_SUITE_WEP104
);
6637 case WPA_CIPHER_WEP40
:
6638 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6639 WLAN_CIPHER_SUITE_WEP40
);
6643 if (params
->beacon_ies
) {
6644 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
6645 params
->beacon_ies
);
6646 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
6647 wpabuf_head(params
->beacon_ies
));
6649 if (params
->proberesp_ies
) {
6650 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
6651 params
->proberesp_ies
);
6652 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
6653 wpabuf_len(params
->proberesp_ies
),
6654 wpabuf_head(params
->proberesp_ies
));
6656 if (params
->assocresp_ies
) {
6657 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
6658 params
->assocresp_ies
);
6659 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
6660 wpabuf_len(params
->assocresp_ies
),
6661 wpabuf_head(params
->assocresp_ies
));
6664 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
6665 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
6666 params
->ap_max_inactivity
);
6667 NLA_PUT_U16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
6668 params
->ap_max_inactivity
);
6671 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6673 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
6674 ret
, strerror(-ret
));
6676 bss
->beacon_set
= 1;
6677 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
6678 params
->short_slot_time
, params
->ht_opmode
,
6679 params
->isolate
, params
->basic_rates
);
6688 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
6689 struct hostapd_freq_params
*freq
)
6691 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6695 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d,"
6696 " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
6697 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
6698 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
6699 msg
= nlmsg_alloc();
6703 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
6705 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6706 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
);
6707 if (freq
->vht_enabled
) {
6708 switch (freq
->bandwidth
) {
6710 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6711 NL80211_CHAN_WIDTH_20
);
6714 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6715 NL80211_CHAN_WIDTH_40
);
6718 if (freq
->center_freq2
)
6719 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6720 NL80211_CHAN_WIDTH_80P80
);
6722 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6723 NL80211_CHAN_WIDTH_80
);
6726 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6727 NL80211_CHAN_WIDTH_160
);
6732 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
->center_freq1
);
6733 if (freq
->center_freq2
)
6734 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
,
6735 freq
->center_freq2
);
6736 } else if (freq
->ht_enabled
) {
6737 switch (freq
->sec_channel_offset
) {
6739 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6740 NL80211_CHAN_HT40MINUS
);
6743 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6744 NL80211_CHAN_HT40PLUS
);
6747 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6753 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6756 bss
->freq
= freq
->freq
;
6759 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
6760 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
6767 static u32
sta_flags_nl80211(int flags
)
6771 if (flags
& WPA_STA_AUTHORIZED
)
6772 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6773 if (flags
& WPA_STA_WMM
)
6774 f
|= BIT(NL80211_STA_FLAG_WME
);
6775 if (flags
& WPA_STA_SHORT_PREAMBLE
)
6776 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
6777 if (flags
& WPA_STA_MFP
)
6778 f
|= BIT(NL80211_STA_FLAG_MFP
);
6779 if (flags
& WPA_STA_TDLS_PEER
)
6780 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
6786 static int wpa_driver_nl80211_sta_add(void *priv
,
6787 struct hostapd_sta_add_params
*params
)
6789 struct i802_bss
*bss
= priv
;
6790 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6792 struct nl80211_sta_flag_update upd
;
6795 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
6796 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
6799 msg
= nlmsg_alloc();
6803 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
6804 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
6805 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
6806 NL80211_CMD_NEW_STATION
);
6808 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6809 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
6810 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
6811 params
->supp_rates
);
6812 wpa_hexdump(MSG_DEBUG
, " * supported rates", params
->supp_rates
,
6813 params
->supp_rates_len
);
6816 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
6817 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
6820 * cfg80211 validates that AID is non-zero, so we have
6821 * to make this a non-zero value for the TDLS case where
6822 * a dummy STA entry is used for now.
6824 wpa_printf(MSG_DEBUG
, " * aid=1 (TDLS workaround)");
6825 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, 1);
6827 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
6828 params
->listen_interval
);
6829 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
6830 params
->listen_interval
);
6831 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
6832 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
6833 NLA_PUT_U16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
);
6835 if (params
->ht_capabilities
) {
6836 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
6837 (u8
*) params
->ht_capabilities
,
6838 sizeof(*params
->ht_capabilities
));
6839 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
6840 sizeof(*params
->ht_capabilities
),
6841 params
->ht_capabilities
);
6844 if (params
->vht_capabilities
) {
6845 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
6846 (u8
*) params
->vht_capabilities
,
6847 sizeof(*params
->vht_capabilities
));
6848 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
,
6849 sizeof(*params
->vht_capabilities
),
6850 params
->vht_capabilities
);
6853 wpa_printf(MSG_DEBUG
, " * capability=0x%x", params
->capability
);
6854 NLA_PUT_U16(msg
, NL80211_ATTR_STA_CAPABILITY
, params
->capability
);
6856 if (params
->ext_capab
) {
6857 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
6858 params
->ext_capab
, params
->ext_capab_len
);
6859 NLA_PUT(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
6860 params
->ext_capab_len
, params
->ext_capab
);
6863 os_memset(&upd
, 0, sizeof(upd
));
6864 upd
.mask
= sta_flags_nl80211(params
->flags
);
6866 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
6868 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6870 if (params
->flags
& WPA_STA_WMM
) {
6871 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
6874 goto nla_put_failure
;
6876 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
6877 NLA_PUT_U8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
6878 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
6879 NLA_PUT_U8(msg
, NL80211_STA_WME_MAX_SP
,
6880 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
6881 WMM_QOSINFO_STA_SP_MASK
);
6882 nla_nest_end(msg
, wme
);
6885 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6888 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
6889 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
6899 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
)
6901 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6905 msg
= nlmsg_alloc();
6909 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
6911 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6912 if_nametoindex(bss
->ifname
));
6913 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6915 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6916 wpa_printf(MSG_DEBUG
, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
6918 bss
->ifname
, MAC2STR(addr
), ret
, strerror(-ret
));
6928 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
6933 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
6935 /* stop listening for EAPOL on this interface */
6936 del_ifidx(drv
, ifidx
);
6938 msg
= nlmsg_alloc();
6940 goto nla_put_failure
;
6942 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
6943 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
6945 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
6950 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
6954 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
6957 case NL80211_IFTYPE_ADHOC
:
6959 case NL80211_IFTYPE_STATION
:
6961 case NL80211_IFTYPE_AP
:
6963 case NL80211_IFTYPE_AP_VLAN
:
6965 case NL80211_IFTYPE_WDS
:
6967 case NL80211_IFTYPE_MONITOR
:
6969 case NL80211_IFTYPE_MESH_POINT
:
6970 return "MESH_POINT";
6971 case NL80211_IFTYPE_P2P_CLIENT
:
6972 return "P2P_CLIENT";
6973 case NL80211_IFTYPE_P2P_GO
:
6975 case NL80211_IFTYPE_P2P_DEVICE
:
6976 return "P2P_DEVICE";
6983 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
6985 enum nl80211_iftype iftype
,
6986 const u8
*addr
, int wds
,
6987 int (*handler
)(struct nl_msg
*, void *),
6994 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
6995 iftype
, nl80211_iftype_str(iftype
));
6997 msg
= nlmsg_alloc();
7001 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
7002 if (nl80211_set_iface_id(msg
, &drv
->first_bss
) < 0)
7003 goto nla_put_failure
;
7004 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
7005 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
7007 if (iftype
== NL80211_IFTYPE_MONITOR
) {
7008 struct nlattr
*flags
;
7010 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
7012 goto nla_put_failure
;
7014 NLA_PUT_FLAG(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
);
7016 nla_nest_end(msg
, flags
);
7018 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
7021 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
7026 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
7027 ifname
, ret
, strerror(-ret
));
7031 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
)
7034 ifidx
= if_nametoindex(ifname
);
7035 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
7041 /* start listening for EAPOL on this interface */
7042 add_ifidx(drv
, ifidx
);
7044 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
7045 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
7046 nl80211_remove_iface(drv
, ifidx
);
7054 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
7055 const char *ifname
, enum nl80211_iftype iftype
,
7056 const u8
*addr
, int wds
,
7057 int (*handler
)(struct nl_msg
*, void *),
7062 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
7065 /* if error occurred and interface exists already */
7066 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
7067 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
7069 /* Try to remove the interface that was already there. */
7070 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
7072 /* Try to create the interface again */
7073 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
7077 if (ret
>= 0 && is_p2p_net_interface(iftype
))
7078 nl80211_disable_11b_rates(drv
, ret
, 1);
7084 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
7086 struct ieee80211_hdr
*hdr
;
7088 union wpa_event_data event
;
7090 hdr
= (struct ieee80211_hdr
*) buf
;
7091 fc
= le_to_host16(hdr
->frame_control
);
7093 os_memset(&event
, 0, sizeof(event
));
7094 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
7095 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
7096 event
.tx_status
.dst
= hdr
->addr1
;
7097 event
.tx_status
.data
= buf
;
7098 event
.tx_status
.data_len
= len
;
7099 event
.tx_status
.ack
= ok
;
7100 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
7104 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
7105 u8
*buf
, size_t len
)
7107 struct ieee80211_hdr
*hdr
= (void *)buf
;
7109 union wpa_event_data event
;
7111 if (len
< sizeof(*hdr
))
7114 fc
= le_to_host16(hdr
->frame_control
);
7116 os_memset(&event
, 0, sizeof(event
));
7117 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
7118 event
.rx_from_unknown
.addr
= hdr
->addr2
;
7119 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
7120 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
7121 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
7125 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
7126 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
7128 struct ieee80211_hdr
*hdr
;
7130 union wpa_event_data event
;
7132 hdr
= (struct ieee80211_hdr
*) buf
;
7133 fc
= le_to_host16(hdr
->frame_control
);
7135 switch (WLAN_FC_GET_TYPE(fc
)) {
7136 case WLAN_FC_TYPE_MGMT
:
7137 os_memset(&event
, 0, sizeof(event
));
7138 event
.rx_mgmt
.frame
= buf
;
7139 event
.rx_mgmt
.frame_len
= len
;
7140 event
.rx_mgmt
.datarate
= datarate
;
7141 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
7142 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
7144 case WLAN_FC_TYPE_CTRL
:
7145 /* can only get here with PS-Poll frames */
7146 wpa_printf(MSG_DEBUG
, "CTRL");
7147 from_unknown_sta(drv
, buf
, len
);
7149 case WLAN_FC_TYPE_DATA
:
7150 from_unknown_sta(drv
, buf
, len
);
7156 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
7158 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
7160 unsigned char buf
[3000];
7161 struct ieee80211_radiotap_iterator iter
;
7163 int datarate
= 0, ssi_signal
= 0;
7164 int injected
= 0, failed
= 0, rxflags
= 0;
7166 len
= recv(sock
, buf
, sizeof(buf
), 0);
7168 wpa_printf(MSG_ERROR
, "nl80211: Monitor socket recv failed: %s",
7173 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
7174 wpa_printf(MSG_INFO
, "nl80211: received invalid radiotap frame");
7179 ret
= ieee80211_radiotap_iterator_next(&iter
);
7183 wpa_printf(MSG_INFO
, "nl80211: received invalid radiotap frame (%d)",
7187 switch (iter
.this_arg_index
) {
7188 case IEEE80211_RADIOTAP_FLAGS
:
7189 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
7192 case IEEE80211_RADIOTAP_RX_FLAGS
:
7195 case IEEE80211_RADIOTAP_TX_FLAGS
:
7197 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
7198 IEEE80211_RADIOTAP_F_TX_FAIL
;
7200 case IEEE80211_RADIOTAP_DATA_RETRIES
:
7202 case IEEE80211_RADIOTAP_CHANNEL
:
7203 /* TODO: convert from freq/flags to channel number */
7205 case IEEE80211_RADIOTAP_RATE
:
7206 datarate
= *iter
.this_arg
* 5;
7208 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
7209 ssi_signal
= (s8
) *iter
.this_arg
;
7214 if (rxflags
&& injected
)
7218 handle_frame(drv
, buf
+ iter
.max_length
,
7219 len
- iter
.max_length
, datarate
, ssi_signal
);
7221 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
7222 len
- iter
.max_length
, !failed
);
7227 * we post-process the filter code later and rewrite
7228 * this to the offset to the last instruction
7233 static struct sock_filter msock_filter_insns
[] = {
7235 * do a little-endian load of the radiotap length field
7237 /* load lower byte into A */
7238 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
7239 /* put it into X (== index register) */
7240 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
7241 /* load upper byte into A */
7242 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
7243 /* left-shift it by 8 */
7244 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
7246 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
7247 /* put result into X */
7248 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
7251 * Allow management frames through, this also gives us those
7252 * management frames that we sent ourselves with status
7254 /* load the lower byte of the IEEE 802.11 frame control field */
7255 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
7256 /* mask off frame type and version */
7257 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
7258 /* accept frame if it's both 0, fall through otherwise */
7259 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
7262 * TODO: add a bit to radiotap RX flags that indicates
7263 * that the sending station is not associated, then
7264 * add a filter here that filters on our DA and that flag
7265 * to allow us to deauth frames to that bad station.
7267 * For now allow all To DS data frames through.
7269 /* load the IEEE 802.11 frame control field */
7270 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
7271 /* mask off frame type, version and DS status */
7272 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
7273 /* accept frame if version 0, type 2 and To DS, fall through otherwise
7275 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
7279 * drop non-data frames
7281 /* load the lower byte of the frame control field */
7282 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
7283 /* mask off QoS bit */
7284 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
7285 /* drop non-data frames */
7286 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
7288 /* load the upper byte of the frame control field */
7289 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
7290 /* mask off toDS/fromDS */
7291 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
7292 /* accept WDS frames */
7293 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
7296 * add header length to index
7298 /* load the lower byte of the frame control field */
7299 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
7300 /* mask off QoS bit */
7301 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
7302 /* right shift it by 6 to give 0 or 2 */
7303 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
7304 /* add data frame header length */
7305 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
7306 /* add index, was start of 802.11 header */
7307 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
7308 /* move to index, now start of LL header */
7309 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
7312 * Accept empty data frames, we use those for
7315 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
7316 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
7319 * Accept EAPOL frames
7321 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
7322 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
7323 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
7324 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
7326 /* keep these last two statements or change the code below */
7327 /* return 0 == "DROP" */
7328 BPF_STMT(BPF_RET
| BPF_K
, 0),
7329 /* return ~0 == "keep all" */
7330 BPF_STMT(BPF_RET
| BPF_K
, ~0),
7333 static struct sock_fprog msock_filter
= {
7334 .len
= ARRAY_SIZE(msock_filter_insns
),
7335 .filter
= msock_filter_insns
,
7339 static int add_monitor_filter(int s
)
7343 /* rewrite all PASS/FAIL jump offsets */
7344 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
7345 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
7347 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
7348 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
7349 if (insn
->k
== PASS
)
7350 insn
->k
= msock_filter
.len
- idx
- 2;
7351 else if (insn
->k
== FAIL
)
7352 insn
->k
= msock_filter
.len
- idx
- 3;
7355 if (insn
->jt
== PASS
)
7356 insn
->jt
= msock_filter
.len
- idx
- 2;
7357 else if (insn
->jt
== FAIL
)
7358 insn
->jt
= msock_filter
.len
- idx
- 3;
7360 if (insn
->jf
== PASS
)
7361 insn
->jf
= msock_filter
.len
- idx
- 2;
7362 else if (insn
->jf
== FAIL
)
7363 insn
->jf
= msock_filter
.len
- idx
- 3;
7367 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
7368 &msock_filter
, sizeof(msock_filter
))) {
7369 wpa_printf(MSG_ERROR
, "nl80211: setsockopt(SO_ATTACH_FILTER) failed: %s",
7378 static void nl80211_remove_monitor_interface(
7379 struct wpa_driver_nl80211_data
*drv
)
7381 drv
->monitor_refcount
--;
7382 if (drv
->monitor_refcount
> 0)
7385 if (drv
->monitor_ifidx
>= 0) {
7386 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
7387 drv
->monitor_ifidx
= -1;
7389 if (drv
->monitor_sock
>= 0) {
7390 eloop_unregister_read_sock(drv
->monitor_sock
);
7391 close(drv
->monitor_sock
);
7392 drv
->monitor_sock
= -1;
7398 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
7401 struct sockaddr_ll ll
;
7405 if (drv
->monitor_ifidx
>= 0) {
7406 drv
->monitor_refcount
++;
7410 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
7412 * P2P interface name is of the format p2p-%s-%d. For monitor
7413 * interface name corresponding to P2P GO, replace "p2p-" with
7414 * "mon-" to retain the same interface name length and to
7415 * indicate that it is a monitor interface.
7417 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
7419 /* Non-P2P interface with AP functionality. */
7420 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
7423 buf
[IFNAMSIZ
- 1] = '\0';
7425 drv
->monitor_ifidx
=
7426 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
7429 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
7431 * This is backward compatibility for a few versions of
7432 * the kernel only that didn't advertise the right
7433 * attributes for the only driver that then supported
7434 * AP mode w/o monitor -- ath6kl.
7436 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
7437 "monitor interface type - try to run without it");
7438 drv
->device_ap_sme
= 1;
7441 if (drv
->monitor_ifidx
< 0)
7444 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
7447 memset(&ll
, 0, sizeof(ll
));
7448 ll
.sll_family
= AF_PACKET
;
7449 ll
.sll_ifindex
= drv
->monitor_ifidx
;
7450 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
7451 if (drv
->monitor_sock
< 0) {
7452 wpa_printf(MSG_ERROR
, "nl80211: socket[PF_PACKET,SOCK_RAW] failed: %s",
7457 if (add_monitor_filter(drv
->monitor_sock
)) {
7458 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
7459 "interface; do filtering in user space");
7460 /* This works, but will cost in performance. */
7463 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
7464 wpa_printf(MSG_ERROR
, "nl80211: monitor socket bind failed: %s",
7469 optlen
= sizeof(optval
);
7472 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
7473 wpa_printf(MSG_ERROR
, "nl80211: Failed to set socket priority: %s",
7478 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
7480 wpa_printf(MSG_INFO
, "nl80211: Could not register monitor read socket");
7486 nl80211_remove_monitor_interface(drv
);
7491 static int nl80211_setup_ap(struct i802_bss
*bss
)
7493 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7495 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP - device_ap_sme=%d "
7496 "use_monitor=%d", drv
->device_ap_sme
, drv
->use_monitor
);
7499 * Disable Probe Request reporting unless we need it in this way for
7500 * devices that include the AP SME, in the other case (unless using
7501 * monitor iface) we'll get it through the nl_mgmt socket instead.
7503 if (!drv
->device_ap_sme
)
7504 wpa_driver_nl80211_probe_req_report(bss
, 0);
7506 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
7507 if (nl80211_mgmt_subscribe_ap(bss
))
7510 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
7511 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
7514 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
7515 nl80211_create_monitor_interface(drv
) &&
7516 !drv
->device_ap_sme
)
7519 if (drv
->device_ap_sme
&&
7520 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
7521 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
7522 "Probe Request frame reporting in AP mode");
7523 /* Try to survive without this */
7530 static void nl80211_teardown_ap(struct i802_bss
*bss
)
7532 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7534 if (drv
->device_ap_sme
) {
7535 wpa_driver_nl80211_probe_req_report(bss
, 0);
7536 if (!drv
->use_monitor
)
7537 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
7538 } else if (drv
->use_monitor
)
7539 nl80211_remove_monitor_interface(drv
);
7541 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
7543 bss
->beacon_set
= 0;
7547 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
7548 const u8
*addr
, const u8
*data
,
7551 struct sockaddr_ll ll
;
7554 if (bss
->drv
->eapol_tx_sock
< 0) {
7555 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
7559 os_memset(&ll
, 0, sizeof(ll
));
7560 ll
.sll_family
= AF_PACKET
;
7561 ll
.sll_ifindex
= bss
->ifindex
;
7562 ll
.sll_protocol
= htons(ETH_P_PAE
);
7563 ll
.sll_halen
= ETH_ALEN
;
7564 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
7565 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
7566 (struct sockaddr
*) &ll
, sizeof(ll
));
7568 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
7575 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
7577 static int wpa_driver_nl80211_hapd_send_eapol(
7578 void *priv
, const u8
*addr
, const u8
*data
,
7579 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
7581 struct i802_bss
*bss
= priv
;
7582 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7583 struct ieee80211_hdr
*hdr
;
7587 int qos
= flags
& WPA_STA_WMM
;
7589 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
7590 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
7592 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
7594 hdr
= os_zalloc(len
);
7596 wpa_printf(MSG_INFO
, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
7597 (unsigned long) len
);
7601 hdr
->frame_control
=
7602 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
7603 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7605 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
7607 hdr
->frame_control
|=
7608 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
7611 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7612 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7613 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7614 pos
= (u8
*) (hdr
+ 1);
7617 /* Set highest priority in QoS header */
7623 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
7624 pos
+= sizeof(rfc1042_header
);
7625 WPA_PUT_BE16(pos
, ETH_P_PAE
);
7627 memcpy(pos
, data
, data_len
);
7629 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
7632 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
7634 (unsigned long) len
, errno
, strerror(errno
));
7642 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
7644 int flags_or
, int flags_and
)
7646 struct i802_bss
*bss
= priv
;
7647 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7649 struct nlattr
*flags
;
7650 struct nl80211_sta_flag_update upd
;
7652 msg
= nlmsg_alloc();
7656 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7658 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7659 if_nametoindex(bss
->ifname
));
7660 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7663 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
7664 * can be removed eventually.
7666 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
7668 goto nla_put_failure
;
7669 if (total_flags
& WPA_STA_AUTHORIZED
)
7670 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_AUTHORIZED
);
7672 if (total_flags
& WPA_STA_WMM
)
7673 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_WME
);
7675 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
7676 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
7678 if (total_flags
& WPA_STA_MFP
)
7679 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_MFP
);
7681 if (total_flags
& WPA_STA_TDLS_PEER
)
7682 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_TDLS_PEER
);
7684 nla_nest_end(msg
, flags
);
7686 os_memset(&upd
, 0, sizeof(upd
));
7687 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
7688 upd
.set
= sta_flags_nl80211(flags_or
);
7689 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
7691 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7698 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
7699 struct wpa_driver_associate_params
*params
)
7701 enum nl80211_iftype nlmode
, old_mode
;
7702 struct hostapd_freq_params freq
= {
7703 .freq
= params
->freq
,
7707 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
7709 nlmode
= NL80211_IFTYPE_P2P_GO
;
7711 nlmode
= NL80211_IFTYPE_AP
;
7713 old_mode
= drv
->nlmode
;
7714 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
)) {
7715 nl80211_remove_monitor_interface(drv
);
7719 if (wpa_driver_nl80211_set_freq(&drv
->first_bss
, &freq
)) {
7720 if (old_mode
!= nlmode
)
7721 wpa_driver_nl80211_set_mode(&drv
->first_bss
, old_mode
);
7722 nl80211_remove_monitor_interface(drv
);
7730 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
7735 msg
= nlmsg_alloc();
7739 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
7740 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7741 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7744 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
7745 "(%s)", ret
, strerror(-ret
));
7746 goto nla_put_failure
;
7750 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
7753 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
7754 NL80211_IFTYPE_STATION
)) {
7755 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
7764 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
7765 struct wpa_driver_associate_params
*params
)
7771 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
7773 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
7774 NL80211_IFTYPE_ADHOC
)) {
7775 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
7781 msg
= nlmsg_alloc();
7785 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
7786 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7788 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
7789 goto nla_put_failure
;
7791 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7792 params
->ssid
, params
->ssid_len
);
7793 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7795 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7796 drv
->ssid_len
= params
->ssid_len
;
7798 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7799 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7801 ret
= nl80211_set_conn_keys(params
, msg
);
7803 goto nla_put_failure
;
7805 if (params
->bssid
&& params
->fixed_bssid
) {
7806 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
7807 MAC2STR(params
->bssid
));
7808 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7811 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
7812 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
7813 params
->key_mgmt_suite
== KEY_MGMT_802_1X_SHA256
||
7814 params
->key_mgmt_suite
== KEY_MGMT_PSK_SHA256
) {
7815 wpa_printf(MSG_DEBUG
, " * control port");
7816 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
7819 if (params
->wpa_ie
) {
7820 wpa_hexdump(MSG_DEBUG
,
7821 " * Extra IEs for Beacon/Probe Response frames",
7822 params
->wpa_ie
, params
->wpa_ie_len
);
7823 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7827 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7830 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
7831 ret
, strerror(-ret
));
7833 if (ret
== -EALREADY
&& count
== 1) {
7834 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
7836 nl80211_leave_ibss(drv
);
7841 goto nla_put_failure
;
7844 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
7852 static int wpa_driver_nl80211_try_connect(
7853 struct wpa_driver_nl80211_data
*drv
,
7854 struct wpa_driver_associate_params
*params
)
7857 enum nl80211_auth_type type
;
7861 msg
= nlmsg_alloc();
7865 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
7866 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
7868 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7869 if (params
->bssid
) {
7870 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
7871 MAC2STR(params
->bssid
));
7872 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7875 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7876 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7877 drv
->assoc_freq
= params
->freq
;
7879 drv
->assoc_freq
= 0;
7880 if (params
->bg_scan_period
>= 0) {
7881 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
7882 params
->bg_scan_period
);
7883 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
7884 params
->bg_scan_period
);
7887 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7888 params
->ssid
, params
->ssid_len
);
7889 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7891 if (params
->ssid_len
> sizeof(drv
->ssid
))
7892 goto nla_put_failure
;
7893 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7894 drv
->ssid_len
= params
->ssid_len
;
7896 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
7898 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7902 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7904 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7906 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7909 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
7911 goto skip_auth_type
;
7914 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7915 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
7916 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7917 type
= NL80211_AUTHTYPE_SHARED_KEY
;
7918 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7919 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
7920 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
7921 type
= NL80211_AUTHTYPE_FT
;
7923 goto nla_put_failure
;
7925 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
7926 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
7929 if (params
->wpa_proto
) {
7930 enum nl80211_wpa_versions ver
= 0;
7932 if (params
->wpa_proto
& WPA_PROTO_WPA
)
7933 ver
|= NL80211_WPA_VERSION_1
;
7934 if (params
->wpa_proto
& WPA_PROTO_RSN
)
7935 ver
|= NL80211_WPA_VERSION_2
;
7937 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
7938 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
7941 if (params
->pairwise_suite
!= CIPHER_NONE
) {
7944 switch (params
->pairwise_suite
) {
7946 cipher
= WLAN_CIPHER_SUITE_SMS4
;
7949 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7952 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7955 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7958 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7962 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7965 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
7968 if (params
->group_suite
!= CIPHER_NONE
) {
7971 switch (params
->group_suite
) {
7973 cipher
= WLAN_CIPHER_SUITE_SMS4
;
7976 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7979 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7982 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7985 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7989 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7992 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
7995 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
7996 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
7997 params
->key_mgmt_suite
== KEY_MGMT_FT_802_1X
||
7998 params
->key_mgmt_suite
== KEY_MGMT_FT_PSK
||
7999 params
->key_mgmt_suite
== KEY_MGMT_CCKM
) {
8000 int mgmt
= WLAN_AKM_SUITE_PSK
;
8002 switch (params
->key_mgmt_suite
) {
8004 mgmt
= WLAN_AKM_SUITE_CCKM
;
8006 case KEY_MGMT_802_1X
:
8007 mgmt
= WLAN_AKM_SUITE_8021X
;
8009 case KEY_MGMT_FT_802_1X
:
8010 mgmt
= WLAN_AKM_SUITE_FT_8021X
;
8012 case KEY_MGMT_FT_PSK
:
8013 mgmt
= WLAN_AKM_SUITE_FT_PSK
;
8017 mgmt
= WLAN_AKM_SUITE_PSK
;
8020 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
8023 #ifdef CONFIG_IEEE80211W
8024 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
8025 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
8026 #endif /* CONFIG_IEEE80211W */
8028 if (params
->disable_ht
)
8029 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
8031 if (params
->htcaps
&& params
->htcaps_mask
) {
8032 int sz
= sizeof(struct ieee80211_ht_capabilities
);
8033 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
8034 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
8035 params
->htcaps_mask
);
8038 #ifdef CONFIG_VHT_OVERRIDES
8039 if (params
->disable_vht
) {
8040 wpa_printf(MSG_DEBUG
, " * VHT disabled");
8041 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
8044 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
8045 int sz
= sizeof(struct ieee80211_vht_capabilities
);
8046 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
8047 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
8048 params
->vhtcaps_mask
);
8050 #endif /* CONFIG_VHT_OVERRIDES */
8052 ret
= nl80211_set_conn_keys(params
, msg
);
8054 goto nla_put_failure
;
8056 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8059 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
8060 "(%s)", ret
, strerror(-ret
));
8061 goto nla_put_failure
;
8064 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
8073 static int wpa_driver_nl80211_connect(
8074 struct wpa_driver_nl80211_data
*drv
,
8075 struct wpa_driver_associate_params
*params
)
8077 int ret
= wpa_driver_nl80211_try_connect(drv
, params
);
8078 if (ret
== -EALREADY
) {
8080 * cfg80211 does not currently accept new connections if
8081 * we are already connected. As a workaround, force
8082 * disconnection and try again.
8084 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
8085 "disconnecting before reassociation "
8087 if (wpa_driver_nl80211_disconnect(
8088 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
8090 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
8096 static int wpa_driver_nl80211_associate(
8097 void *priv
, struct wpa_driver_associate_params
*params
)
8099 struct i802_bss
*bss
= priv
;
8100 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8104 if (params
->mode
== IEEE80211_MODE_AP
)
8105 return wpa_driver_nl80211_ap(drv
, params
);
8107 if (params
->mode
== IEEE80211_MODE_IBSS
)
8108 return wpa_driver_nl80211_ibss(drv
, params
);
8110 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
8111 enum nl80211_iftype nlmode
= params
->p2p
?
8112 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
8114 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
8116 return wpa_driver_nl80211_connect(drv
, params
);
8119 nl80211_mark_disconnected(drv
);
8121 msg
= nlmsg_alloc();
8125 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
8127 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
8129 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8130 if (params
->bssid
) {
8131 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
8132 MAC2STR(params
->bssid
));
8133 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
8136 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
8137 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
8138 drv
->assoc_freq
= params
->freq
;
8140 drv
->assoc_freq
= 0;
8141 if (params
->bg_scan_period
>= 0) {
8142 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
8143 params
->bg_scan_period
);
8144 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
8145 params
->bg_scan_period
);
8148 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
8149 params
->ssid
, params
->ssid_len
);
8150 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
8152 if (params
->ssid_len
> sizeof(drv
->ssid
))
8153 goto nla_put_failure
;
8154 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
8155 drv
->ssid_len
= params
->ssid_len
;
8157 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
8159 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
8162 if (params
->pairwise_suite
!= CIPHER_NONE
) {
8165 switch (params
->pairwise_suite
) {
8167 cipher
= WLAN_CIPHER_SUITE_WEP40
;
8170 cipher
= WLAN_CIPHER_SUITE_WEP104
;
8173 cipher
= WLAN_CIPHER_SUITE_CCMP
;
8176 cipher
= WLAN_CIPHER_SUITE_GCMP
;
8180 cipher
= WLAN_CIPHER_SUITE_TKIP
;
8183 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
8184 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
8187 if (params
->group_suite
!= CIPHER_NONE
) {
8190 switch (params
->group_suite
) {
8192 cipher
= WLAN_CIPHER_SUITE_WEP40
;
8195 cipher
= WLAN_CIPHER_SUITE_WEP104
;
8198 cipher
= WLAN_CIPHER_SUITE_CCMP
;
8201 cipher
= WLAN_CIPHER_SUITE_GCMP
;
8205 cipher
= WLAN_CIPHER_SUITE_TKIP
;
8208 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
8209 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
8212 #ifdef CONFIG_IEEE80211W
8213 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
8214 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
8215 #endif /* CONFIG_IEEE80211W */
8217 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
8219 if (params
->prev_bssid
) {
8220 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
8221 MAC2STR(params
->prev_bssid
));
8222 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
8223 params
->prev_bssid
);
8226 if (params
->disable_ht
)
8227 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
8229 if (params
->htcaps
&& params
->htcaps_mask
) {
8230 int sz
= sizeof(struct ieee80211_ht_capabilities
);
8231 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
8232 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
8233 params
->htcaps_mask
);
8236 #ifdef CONFIG_VHT_OVERRIDES
8237 if (params
->disable_vht
) {
8238 wpa_printf(MSG_DEBUG
, " * VHT disabled");
8239 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
8242 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
8243 int sz
= sizeof(struct ieee80211_vht_capabilities
);
8244 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
8245 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
8246 params
->vhtcaps_mask
);
8248 #endif /* CONFIG_VHT_OVERRIDES */
8251 wpa_printf(MSG_DEBUG
, " * P2P group");
8253 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8256 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
8257 "nl80211: MLME command failed (assoc): ret=%d (%s)",
8258 ret
, strerror(-ret
));
8259 nl80211_dump_scan(drv
);
8260 goto nla_put_failure
;
8263 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
8272 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
8273 int ifindex
, enum nl80211_iftype mode
)
8278 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
8279 ifindex
, mode
, nl80211_iftype_str(mode
));
8281 msg
= nlmsg_alloc();
8285 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
8286 if (nl80211_set_iface_id(msg
, &drv
->first_bss
) < 0)
8287 goto nla_put_failure
;
8288 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
8290 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8296 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
8297 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
8302 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
8303 enum nl80211_iftype nlmode
)
8305 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8308 int was_ap
= is_ap_interface(drv
->nlmode
);
8311 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
8312 if (res
&& nlmode
== nl80211_get_ifmode(bss
))
8316 drv
->nlmode
= nlmode
;
8324 if (nlmode
== drv
->nlmode
) {
8325 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
8326 "requested mode - ignore error");
8328 goto done
; /* Already in the requested mode */
8331 /* mac80211 doesn't allow mode changes while the device is up, so
8332 * take the device down, try to set the mode again, and bring the
8335 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
8337 for (i
= 0; i
< 10; i
++) {
8338 res
= i802_set_iface_flags(bss
, 0);
8339 if (res
== -EACCES
|| res
== -ENODEV
)
8342 /* Try to set the mode again while the interface is
8344 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
8347 res
= i802_set_iface_flags(bss
, 1);
8350 else if (ret
!= -EBUSY
)
8353 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
8355 os_sleep(0, 100000);
8359 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
8360 "interface is down");
8361 drv
->nlmode
= nlmode
;
8362 drv
->ignore_if_down_event
= 1;
8367 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
8368 "from %d failed", nlmode
, drv
->nlmode
);
8372 if (is_p2p_net_interface(nlmode
))
8373 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
8374 else if (drv
->disabled_11b_rates
)
8375 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
8377 if (is_ap_interface(nlmode
)) {
8378 nl80211_mgmt_unsubscribe(bss
, "start AP");
8379 /* Setup additional AP mode functionality if needed */
8380 if (nl80211_setup_ap(bss
))
8382 } else if (was_ap
) {
8383 /* Remove additional AP mode functionality */
8384 nl80211_teardown_ap(bss
);
8386 nl80211_mgmt_unsubscribe(bss
, "mode change");
8389 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
8390 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
8391 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
8392 "frame processing - ignore for now");
8398 static int wpa_driver_nl80211_get_capa(void *priv
,
8399 struct wpa_driver_capa
*capa
)
8401 struct i802_bss
*bss
= priv
;
8402 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8403 if (!drv
->has_capability
)
8405 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
8406 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
8407 capa
->extended_capa
= drv
->extended_capa
;
8408 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
8409 capa
->extended_capa_len
= drv
->extended_capa_len
;
8412 if ((capa
->flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
8413 !drv
->allow_p2p_device
) {
8414 wpa_printf(MSG_DEBUG
, "nl80211: Do not indicate P2P_DEVICE support (p2p_device=1 driver param not specified)");
8415 capa
->flags
&= ~WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
;
8422 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
8424 struct i802_bss
*bss
= priv
;
8425 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8427 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
8428 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
8429 drv
->operstate
= state
;
8430 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
8431 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
8435 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
8437 struct i802_bss
*bss
= priv
;
8438 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8440 struct nl80211_sta_flag_update upd
;
8442 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
8443 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
8445 msg
= nlmsg_alloc();
8449 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
8451 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8452 if_nametoindex(bss
->ifname
));
8453 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
8455 os_memset(&upd
, 0, sizeof(upd
));
8456 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
8458 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
8459 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
8461 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8468 /* Set kernel driver on given frequency (MHz) */
8469 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
8471 struct i802_bss
*bss
= priv
;
8472 return wpa_driver_nl80211_set_freq(bss
, freq
);
8476 #if defined(HOSTAPD) || defined(CONFIG_AP)
8478 static inline int min_int(int a
, int b
)
8486 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
8488 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8489 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8491 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8492 genlmsg_attrlen(gnlh
, 0), NULL
);
8495 * TODO: validate the key index and mac address!
8496 * Otherwise, there's a race condition as soon as
8497 * the kernel starts sending key notifications.
8500 if (tb
[NL80211_ATTR_KEY_SEQ
])
8501 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
8502 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
8507 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
8510 struct i802_bss
*bss
= priv
;
8511 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8514 msg
= nlmsg_alloc();
8518 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
8521 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8522 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
8523 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
8527 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
8534 static int i802_set_rts(void *priv
, int rts
)
8536 struct i802_bss
*bss
= priv
;
8537 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8542 msg
= nlmsg_alloc();
8551 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8552 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8553 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
8555 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8561 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
8562 "%d (%s)", rts
, ret
, strerror(-ret
));
8567 static int i802_set_frag(void *priv
, int frag
)
8569 struct i802_bss
*bss
= priv
;
8570 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8575 msg
= nlmsg_alloc();
8584 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8585 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8586 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
8588 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8594 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
8595 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
8600 static int i802_flush(void *priv
)
8602 struct i802_bss
*bss
= priv
;
8603 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8607 msg
= nlmsg_alloc();
8611 wpa_printf(MSG_DEBUG
, "nl80211: flush -> DEL_STATION %s (all)",
8613 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
8616 * XXX: FIX! this needs to flush all VLANs too
8618 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8619 if_nametoindex(bss
->ifname
));
8621 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8623 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
8624 "(%s)", res
, strerror(-res
));
8632 #endif /* HOSTAPD || CONFIG_AP */
8635 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
8637 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8638 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8639 struct hostap_sta_driver_data
*data
= arg
;
8640 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
8641 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
8642 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
8643 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
8644 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
8645 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
8646 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
8647 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
8650 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8651 genlmsg_attrlen(gnlh
, 0), NULL
);
8654 * TODO: validate the interface and mac address!
8655 * Otherwise, there's a race condition as soon as
8656 * the kernel starts sending station notifications.
8659 if (!tb
[NL80211_ATTR_STA_INFO
]) {
8660 wpa_printf(MSG_DEBUG
, "sta stats missing!");
8663 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
8664 tb
[NL80211_ATTR_STA_INFO
],
8666 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
8670 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
8671 data
->inactive_msec
=
8672 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
8673 if (stats
[NL80211_STA_INFO_RX_BYTES
])
8674 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
8675 if (stats
[NL80211_STA_INFO_TX_BYTES
])
8676 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
8677 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
8679 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
8680 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
8682 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
8683 if (stats
[NL80211_STA_INFO_TX_FAILED
])
8684 data
->tx_retry_failed
=
8685 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
8690 static int i802_read_sta_data(struct i802_bss
*bss
,
8691 struct hostap_sta_driver_data
*data
,
8694 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8697 os_memset(data
, 0, sizeof(*data
));
8698 msg
= nlmsg_alloc();
8702 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
8704 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8705 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8707 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
8714 #if defined(HOSTAPD) || defined(CONFIG_AP)
8716 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
8717 int cw_min
, int cw_max
, int burst_time
)
8719 struct i802_bss
*bss
= priv
;
8720 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8722 struct nlattr
*txq
, *params
;
8724 msg
= nlmsg_alloc();
8728 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8730 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8732 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
8734 goto nla_put_failure
;
8736 /* We are only sending parameters for a single TXQ at a time */
8737 params
= nla_nest_start(msg
, 1);
8739 goto nla_put_failure
;
8743 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
8746 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
8749 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
8752 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
8755 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
8756 * 32 usec, so need to convert the value here. */
8757 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
8758 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
8759 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
8760 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
8762 nla_nest_end(msg
, params
);
8764 nla_nest_end(msg
, txq
);
8766 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
8775 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
8776 const char *ifname
, int vlan_id
)
8778 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8782 msg
= nlmsg_alloc();
8786 wpa_printf(MSG_DEBUG
, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
8787 ", ifname=%s[%d], vlan_id=%d)",
8788 bss
->ifname
, if_nametoindex(bss
->ifname
),
8789 MAC2STR(addr
), ifname
, if_nametoindex(ifname
), vlan_id
);
8790 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
8792 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8793 if_nametoindex(bss
->ifname
));
8794 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8795 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
8796 if_nametoindex(ifname
));
8798 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8801 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
8802 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
8803 MAC2STR(addr
), ifname
, vlan_id
, ret
,
8812 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
8814 struct hostap_sta_driver_data data
;
8817 data
.inactive_msec
= (unsigned long) -1;
8818 ret
= i802_read_sta_data(priv
, &data
, addr
);
8819 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
8821 return data
.inactive_msec
/ 1000;
8825 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
8834 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
8837 struct i802_bss
*bss
= priv
;
8838 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8839 struct ieee80211_mgmt mgmt
;
8841 if (drv
->device_ap_sme
)
8842 return wpa_driver_nl80211_sta_remove(bss
, addr
);
8844 memset(&mgmt
, 0, sizeof(mgmt
));
8845 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
8846 WLAN_FC_STYPE_DEAUTH
);
8847 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
8848 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
8849 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
8850 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
8851 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
8853 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
8858 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
8861 struct i802_bss
*bss
= priv
;
8862 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8863 struct ieee80211_mgmt mgmt
;
8865 if (drv
->device_ap_sme
)
8866 return wpa_driver_nl80211_sta_remove(bss
, addr
);
8868 memset(&mgmt
, 0, sizeof(mgmt
));
8869 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
8870 WLAN_FC_STYPE_DISASSOC
);
8871 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
8872 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
8873 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
8874 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
8875 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
8877 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
8881 #endif /* HOSTAPD || CONFIG_AP */
8885 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8890 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
8892 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8893 if (drv
->if_indices
[i
] == 0) {
8894 drv
->if_indices
[i
] = ifidx
;
8899 if (drv
->if_indices
!= drv
->default_if_indices
)
8900 old
= drv
->if_indices
;
8904 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
8906 if (!drv
->if_indices
) {
8908 drv
->if_indices
= drv
->default_if_indices
;
8910 drv
->if_indices
= old
;
8911 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
8913 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
8916 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
8917 sizeof(drv
->default_if_indices
));
8918 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
8919 drv
->num_if_indices
++;
8923 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8927 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8928 if (drv
->if_indices
[i
] == ifidx
) {
8929 drv
->if_indices
[i
] = 0;
8936 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8940 for (i
= 0; i
< drv
->num_if_indices
; i
++)
8941 if (drv
->if_indices
[i
] == ifidx
)
8948 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
8949 const char *bridge_ifname
, char *ifname_wds
)
8951 struct i802_bss
*bss
= priv
;
8952 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8953 char name
[IFNAMSIZ
+ 1];
8955 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
8957 os_strlcpy(ifname_wds
, name
, IFNAMSIZ
+ 1);
8959 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
8960 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
8962 if (!if_nametoindex(name
)) {
8963 if (nl80211_create_iface(drv
, name
,
8964 NL80211_IFTYPE_AP_VLAN
,
8965 bss
->addr
, 1, NULL
, NULL
) < 0)
8967 if (bridge_ifname
&&
8968 linux_br_add_if(drv
->global
->ioctl_sock
,
8969 bridge_ifname
, name
) < 0)
8972 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
8973 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
8974 "interface %s up", name
);
8976 return i802_set_sta_vlan(priv
, addr
, name
, 0);
8979 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
8982 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
8983 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
8989 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
8991 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
8992 struct sockaddr_ll lladdr
;
8993 unsigned char buf
[3000];
8995 socklen_t fromlen
= sizeof(lladdr
);
8997 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
8998 (struct sockaddr
*)&lladdr
, &fromlen
);
9000 wpa_printf(MSG_ERROR
, "nl80211: EAPOL recv failed: %s",
9005 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
9006 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
9010 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
9011 struct i802_bss
*bss
,
9012 const char *brname
, const char *ifname
)
9015 char in_br
[IFNAMSIZ
];
9017 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
9018 ifindex
= if_nametoindex(brname
);
9021 * Bridge was configured, but the bridge device does
9022 * not exist. Try to add it now.
9024 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
9025 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
9026 "bridge interface %s: %s",
9027 brname
, strerror(errno
));
9030 bss
->added_bridge
= 1;
9031 add_ifidx(drv
, if_nametoindex(brname
));
9034 if (linux_br_get(in_br
, ifname
) == 0) {
9035 if (os_strcmp(in_br
, brname
) == 0)
9036 return 0; /* already in the bridge */
9038 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
9039 "bridge %s", ifname
, in_br
);
9040 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
9042 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
9043 "remove interface %s from bridge "
9045 ifname
, brname
, strerror(errno
));
9050 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
9052 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
9053 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
9054 "into bridge %s: %s",
9055 ifname
, brname
, strerror(errno
));
9058 bss
->added_if_into_bridge
= 1;
9064 static void *i802_init(struct hostapd_data
*hapd
,
9065 struct wpa_init_params
*params
)
9067 struct wpa_driver_nl80211_data
*drv
;
9068 struct i802_bss
*bss
;
9070 char brname
[IFNAMSIZ
];
9071 int ifindex
, br_ifindex
;
9074 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
9075 params
->global_priv
);
9080 drv
->nlmode
= NL80211_IFTYPE_AP
;
9081 drv
->eapol_sock
= -1;
9083 if (linux_br_get(brname
, params
->ifname
) == 0) {
9084 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
9085 params
->ifname
, brname
);
9086 br_ifindex
= if_nametoindex(brname
);
9092 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
9093 drv
->if_indices
= drv
->default_if_indices
;
9094 for (i
= 0; i
< params
->num_bridge
; i
++) {
9095 if (params
->bridge
[i
]) {
9096 ifindex
= if_nametoindex(params
->bridge
[i
]);
9098 add_ifidx(drv
, ifindex
);
9099 if (ifindex
== br_ifindex
)
9103 if (!br_added
&& br_ifindex
&&
9104 (params
->num_bridge
== 0 || !params
->bridge
[0]))
9105 add_ifidx(drv
, br_ifindex
);
9107 /* start listening for EAPOL on the default AP interface */
9108 add_ifidx(drv
, drv
->ifindex
);
9110 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
9113 if (params
->bssid
) {
9114 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
9119 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
9120 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
9121 "into AP mode", bss
->ifname
);
9125 if (params
->num_bridge
&& params
->bridge
[0] &&
9126 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
9129 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
9132 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
9133 if (drv
->eapol_sock
< 0) {
9134 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
9139 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
9141 wpa_printf(MSG_INFO
, "nl80211: Could not register read socket for eapol");
9145 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
9149 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
9154 wpa_driver_nl80211_deinit(bss
);
9159 static void i802_deinit(void *priv
)
9161 struct i802_bss
*bss
= priv
;
9162 wpa_driver_nl80211_deinit(bss
);
9165 #endif /* HOSTAPD */
9168 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
9169 enum wpa_driver_if_type type
)
9172 case WPA_IF_STATION
:
9173 return NL80211_IFTYPE_STATION
;
9174 case WPA_IF_P2P_CLIENT
:
9175 case WPA_IF_P2P_GROUP
:
9176 return NL80211_IFTYPE_P2P_CLIENT
;
9177 case WPA_IF_AP_VLAN
:
9178 return NL80211_IFTYPE_AP_VLAN
;
9180 return NL80211_IFTYPE_AP
;
9182 return NL80211_IFTYPE_P2P_GO
;
9183 case WPA_IF_P2P_DEVICE
:
9184 return NL80211_IFTYPE_P2P_DEVICE
;
9192 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
9194 struct wpa_driver_nl80211_data
*drv
;
9195 dl_list_for_each(drv
, &global
->interfaces
,
9196 struct wpa_driver_nl80211_data
, list
) {
9197 if (os_memcmp(addr
, drv
->first_bss
.addr
, ETH_ALEN
) == 0)
9204 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
9212 os_memcpy(new_addr
, drv
->first_bss
.addr
, ETH_ALEN
);
9213 for (idx
= 0; idx
< 64; idx
++) {
9214 new_addr
[0] = drv
->first_bss
.addr
[0] | 0x02;
9215 new_addr
[0] ^= idx
<< 2;
9216 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
9222 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
9223 MACSTR
, MAC2STR(new_addr
));
9228 #endif /* CONFIG_P2P */
9234 u8 macaddr
[ETH_ALEN
];
9237 static int nl80211_wdev_handler(struct nl_msg
*msg
, void *arg
)
9239 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9240 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9241 struct wdev_info
*wi
= arg
;
9243 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9244 genlmsg_attrlen(gnlh
, 0), NULL
);
9245 if (tb
[NL80211_ATTR_WDEV
]) {
9246 wi
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
9247 wi
->wdev_id_set
= 1;
9250 if (tb
[NL80211_ATTR_MAC
])
9251 os_memcpy(wi
->macaddr
, nla_data(tb
[NL80211_ATTR_MAC
]),
9258 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
9259 const char *ifname
, const u8
*addr
,
9260 void *bss_ctx
, void **drv_priv
,
9261 char *force_ifname
, u8
*if_addr
,
9264 enum nl80211_iftype nlmode
;
9265 struct i802_bss
*bss
= priv
;
9266 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9270 os_memcpy(if_addr
, addr
, ETH_ALEN
);
9271 nlmode
= wpa_driver_nl80211_if_type(type
);
9272 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
9273 struct wdev_info p2pdev_info
;
9275 os_memset(&p2pdev_info
, 0, sizeof(p2pdev_info
));
9276 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
9277 0, nl80211_wdev_handler
,
9279 if (!p2pdev_info
.wdev_id_set
|| ifidx
!= 0) {
9280 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
9285 drv
->global
->if_add_wdevid
= p2pdev_info
.wdev_id
;
9286 drv
->global
->if_add_wdevid_set
= p2pdev_info
.wdev_id_set
;
9287 if (!is_zero_ether_addr(p2pdev_info
.macaddr
))
9288 os_memcpy(if_addr
, p2pdev_info
.macaddr
, ETH_ALEN
);
9289 wpa_printf(MSG_DEBUG
, "nl80211: New P2P Device interface %s (0x%llx) created",
9291 (long long unsigned int) p2pdev_info
.wdev_id
);
9293 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
9301 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
9302 os_memcpy(if_addr
, bss
->addr
, ETH_ALEN
);
9303 else if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
,
9304 bss
->ifname
, if_addr
) < 0) {
9305 nl80211_remove_iface(drv
, ifidx
);
9312 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
9313 type
== WPA_IF_P2P_GO
)) {
9314 /* Enforce unique P2P Interface Address */
9315 u8 new_addr
[ETH_ALEN
];
9317 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
9319 nl80211_remove_iface(drv
, ifidx
);
9322 if (nl80211_addr_in_use(drv
->global
, new_addr
)) {
9323 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
9324 "for P2P group interface");
9325 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
9326 nl80211_remove_iface(drv
, ifidx
);
9329 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
9331 nl80211_remove_iface(drv
, ifidx
);
9335 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
9337 #endif /* CONFIG_P2P */
9340 if (type
== WPA_IF_AP_BSS
) {
9341 struct i802_bss
*new_bss
= os_zalloc(sizeof(*new_bss
));
9342 if (new_bss
== NULL
) {
9343 nl80211_remove_iface(drv
, ifidx
);
9348 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
9349 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
9350 "interface %s to a bridge %s",
9352 nl80211_remove_iface(drv
, ifidx
);
9357 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
9359 nl80211_remove_iface(drv
, ifidx
);
9363 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
9364 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
9365 new_bss
->ifindex
= ifidx
;
9367 new_bss
->next
= drv
->first_bss
.next
;
9368 new_bss
->freq
= drv
->first_bss
.freq
;
9369 new_bss
->ctx
= bss_ctx
;
9370 drv
->first_bss
.next
= new_bss
;
9372 *drv_priv
= new_bss
;
9373 nl80211_init_bss(new_bss
);
9375 /* Subscribe management frames for this WPA_IF_AP_BSS */
9376 if (nl80211_setup_ap(new_bss
))
9379 #endif /* HOSTAPD */
9382 drv
->global
->if_add_ifindex
= ifidx
;
9388 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
9389 enum wpa_driver_if_type type
,
9392 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9393 int ifindex
= if_nametoindex(ifname
);
9395 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
9396 __func__
, type
, ifname
, ifindex
);
9398 nl80211_remove_iface(drv
, ifindex
);
9401 if (type
!= WPA_IF_AP_BSS
)
9404 if (bss
->added_if_into_bridge
) {
9405 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
9407 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
9408 "interface %s from bridge %s: %s",
9409 bss
->ifname
, bss
->brname
, strerror(errno
));
9411 if (bss
->added_bridge
) {
9412 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
9413 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
9415 bss
->brname
, strerror(errno
));
9418 if (bss
!= &drv
->first_bss
) {
9419 struct i802_bss
*tbss
;
9421 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
9422 if (tbss
->next
== bss
) {
9423 tbss
->next
= bss
->next
;
9424 /* Unsubscribe management frames */
9425 nl80211_teardown_ap(bss
);
9426 nl80211_destroy_bss(bss
);
9433 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
9434 "BSS %p in the list", __func__
, bss
);
9436 #endif /* HOSTAPD */
9442 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
9444 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9445 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9447 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9448 genlmsg_attrlen(gnlh
, 0), NULL
);
9449 if (tb
[NL80211_ATTR_COOKIE
])
9450 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
9455 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
9456 unsigned int freq
, unsigned int wait
,
9457 const u8
*buf
, size_t buf_len
,
9458 u64
*cookie_out
, int no_cck
, int no_ack
,
9461 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9466 msg
= nlmsg_alloc();
9470 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
9471 "no_ack=%d offchanok=%d",
9472 freq
, wait
, no_cck
, no_ack
, offchanok
);
9473 wpa_hexdump(MSG_MSGDUMP
, "CMD_FRAME", buf
, buf_len
);
9474 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
9476 if (nl80211_set_iface_id(msg
, bss
) < 0)
9477 goto nla_put_failure
;
9479 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9481 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
9482 if (offchanok
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
))
9483 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
9485 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
9487 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
9489 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
9492 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
9495 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
9496 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
9498 goto nla_put_failure
;
9500 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
9501 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
9502 (long long unsigned int) cookie
);
9505 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
9513 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
9515 unsigned int wait_time
,
9516 const u8
*dst
, const u8
*src
,
9518 const u8
*data
, size_t data_len
,
9521 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9524 struct ieee80211_hdr
*hdr
;
9526 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
9527 "freq=%u MHz wait=%d ms no_cck=%d)",
9528 drv
->ifindex
, freq
, wait_time
, no_cck
);
9530 buf
= os_zalloc(24 + data_len
);
9533 os_memcpy(buf
+ 24, data
, data_len
);
9534 hdr
= (struct ieee80211_hdr
*) buf
;
9535 hdr
->frame_control
=
9536 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
9537 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
9538 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
9539 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
9541 if (is_ap_interface(drv
->nlmode
) &&
9542 (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
) ||
9543 (int) freq
== bss
->freq
|| drv
->device_ap_sme
||
9545 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
9549 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
9551 &drv
->send_action_cookie
,
9559 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
9561 struct i802_bss
*bss
= priv
;
9562 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9566 msg
= nlmsg_alloc();
9570 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
9571 (long long unsigned int) drv
->send_action_cookie
);
9572 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
9574 if (nl80211_set_iface_id(msg
, bss
) < 0)
9575 goto nla_put_failure
;
9576 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
9578 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9581 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
9582 "(%s)", ret
, strerror(-ret
));
9589 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
9590 unsigned int duration
)
9592 struct i802_bss
*bss
= priv
;
9593 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9598 msg
= nlmsg_alloc();
9602 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
9604 if (nl80211_set_iface_id(msg
, bss
) < 0)
9605 goto nla_put_failure
;
9607 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9608 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
9611 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
9614 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
9615 "0x%llx for freq=%u MHz duration=%u",
9616 (long long unsigned int) cookie
, freq
, duration
);
9617 drv
->remain_on_chan_cookie
= cookie
;
9618 drv
->pending_remain_on_chan
= 1;
9621 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
9622 "(freq=%d duration=%u): %d (%s)",
9623 freq
, duration
, ret
, strerror(-ret
));
9630 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
9632 struct i802_bss
*bss
= priv
;
9633 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9637 if (!drv
->pending_remain_on_chan
) {
9638 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
9643 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
9645 (long long unsigned int) drv
->remain_on_chan_cookie
);
9647 msg
= nlmsg_alloc();
9651 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
9653 if (nl80211_set_iface_id(msg
, bss
) < 0)
9654 goto nla_put_failure
;
9656 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
9658 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9662 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
9663 "%d (%s)", ret
, strerror(-ret
));
9670 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
9672 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9675 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
9676 is_ap_interface(drv
->nlmode
)) {
9678 * Do not disable Probe Request reporting that was
9679 * enabled in nl80211_setup_ap().
9681 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
9682 "Probe Request reporting nl_preq=%p while "
9683 "in AP mode", bss
->nl_preq
);
9684 } else if (bss
->nl_preq
) {
9685 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
9686 "reporting nl_preq=%p", bss
->nl_preq
);
9687 nl80211_destroy_eloop_handle(&bss
->nl_preq
);
9693 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
9694 "already on! nl_preq=%p", bss
->nl_preq
);
9698 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
9699 if (bss
->nl_preq
== NULL
)
9701 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
9702 "reporting nl_preq=%p", bss
->nl_preq
);
9704 if (nl80211_register_frame(bss
, bss
->nl_preq
,
9705 (WLAN_FC_TYPE_MGMT
<< 2) |
9706 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
9710 nl80211_register_eloop_read(&bss
->nl_preq
,
9711 wpa_driver_nl80211_event_receive
,
9717 nl_destroy_handles(&bss
->nl_preq
);
9722 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
9723 int ifindex
, int disabled
)
9726 struct nlattr
*bands
, *band
;
9729 msg
= nlmsg_alloc();
9733 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
9734 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
9736 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
9738 goto nla_put_failure
;
9741 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
9742 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
9743 * rates. All 5 GHz rates are left enabled.
9745 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
9747 goto nla_put_failure
;
9749 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
9750 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
9752 nla_nest_end(msg
, band
);
9754 nla_nest_end(msg
, bands
);
9756 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9759 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
9760 "(%s)", ret
, strerror(-ret
));
9762 drv
->disabled_11b_rates
= disabled
;
9772 static int wpa_driver_nl80211_deinit_ap(void *priv
)
9774 struct i802_bss
*bss
= priv
;
9775 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9776 if (!is_ap_interface(drv
->nlmode
))
9778 wpa_driver_nl80211_del_beacon(drv
);
9781 * If the P2P GO interface was dynamically added, then it is
9782 * possible that the interface change to station is not possible.
9784 if (drv
->nlmode
== NL80211_IFTYPE_P2P_GO
&& bss
->if_dynamic
)
9787 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
9791 static int wpa_driver_nl80211_stop_ap(void *priv
)
9793 struct i802_bss
*bss
= priv
;
9794 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9795 if (!is_ap_interface(drv
->nlmode
))
9797 wpa_driver_nl80211_del_beacon(drv
);
9798 bss
->beacon_set
= 0;
9803 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
9805 struct i802_bss
*bss
= priv
;
9806 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9807 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
9811 * If the P2P Client interface was dynamically added, then it is
9812 * possible that the interface change to station is not possible.
9814 if (bss
->if_dynamic
)
9817 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
9821 static void wpa_driver_nl80211_resume(void *priv
)
9823 struct i802_bss
*bss
= priv
;
9825 if (i802_set_iface_flags(bss
, 1))
9826 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on resume event");
9830 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
9831 const u8
*ies
, size_t ies_len
)
9833 struct i802_bss
*bss
= priv
;
9834 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9838 const u8
*own_addr
= bss
->addr
;
9841 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
9842 "action %d", action
);
9847 * Action frame payload:
9848 * Category[1] = 6 (Fast BSS Transition)
9849 * Action[1] = 1 (Fast BSS Transition Request)
9855 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
9856 data
= os_malloc(data_len
);
9860 *pos
++ = 0x06; /* FT Action category */
9862 os_memcpy(pos
, own_addr
, ETH_ALEN
);
9864 os_memcpy(pos
, target_ap
, ETH_ALEN
);
9866 os_memcpy(pos
, ies
, ies_len
);
9868 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
9869 drv
->bssid
, own_addr
, drv
->bssid
,
9877 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
9879 struct i802_bss
*bss
= priv
;
9880 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9885 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
9886 "hysteresis=%d", threshold
, hysteresis
);
9888 msg
= nlmsg_alloc();
9892 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
9894 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9896 cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9898 goto nla_put_failure
;
9900 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
9901 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
9902 nla_nest_end(msg
, cqm
);
9904 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9913 /* Converts nl80211_chan_width to a common format */
9914 static enum chan_width
convert2width(int width
)
9917 case NL80211_CHAN_WIDTH_20_NOHT
:
9918 return CHAN_WIDTH_20_NOHT
;
9919 case NL80211_CHAN_WIDTH_20
:
9920 return CHAN_WIDTH_20
;
9921 case NL80211_CHAN_WIDTH_40
:
9922 return CHAN_WIDTH_40
;
9923 case NL80211_CHAN_WIDTH_80
:
9924 return CHAN_WIDTH_80
;
9925 case NL80211_CHAN_WIDTH_80P80
:
9926 return CHAN_WIDTH_80P80
;
9927 case NL80211_CHAN_WIDTH_160
:
9928 return CHAN_WIDTH_160
;
9930 return CHAN_WIDTH_UNKNOWN
;
9934 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
9936 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9937 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9938 struct wpa_signal_info
*sig_change
= arg
;
9940 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9941 genlmsg_attrlen(gnlh
, 0), NULL
);
9943 sig_change
->center_frq1
= -1;
9944 sig_change
->center_frq2
= -1;
9945 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
9947 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
9948 sig_change
->chanwidth
= convert2width(
9949 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
9950 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
9951 sig_change
->center_frq1
=
9952 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
9953 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
9954 sig_change
->center_frq2
=
9955 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
9962 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
9963 struct wpa_signal_info
*sig
)
9967 msg
= nlmsg_alloc();
9971 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
9972 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9974 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
9982 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
9984 struct i802_bss
*bss
= priv
;
9985 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9988 os_memset(si
, 0, sizeof(*si
));
9989 res
= nl80211_get_link_signal(drv
, si
);
9993 res
= nl80211_get_channel_width(drv
, si
);
9997 return nl80211_get_link_noise(drv
, si
);
10001 static int wpa_driver_nl80211_shared_freq(void *priv
)
10003 struct i802_bss
*bss
= priv
;
10004 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10005 struct wpa_driver_nl80211_data
*driver
;
10009 * If the same PHY is in connected state with some other interface,
10010 * then retrieve the assoc freq.
10012 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
10015 dl_list_for_each(driver
, &drv
->global
->interfaces
,
10016 struct wpa_driver_nl80211_data
, list
) {
10017 if (drv
== driver
||
10018 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
10019 !driver
->associated
)
10022 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
10024 driver
->phyname
, driver
->first_bss
.ifname
,
10025 MAC2STR(driver
->first_bss
.addr
));
10026 if (is_ap_interface(driver
->nlmode
))
10027 freq
= driver
->first_bss
.freq
;
10029 freq
= nl80211_get_assoc_freq(driver
);
10030 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
10031 drv
->phyname
, freq
);
10035 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
10036 "PHY (%s) in associated state", drv
->phyname
);
10042 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
10045 struct i802_bss
*bss
= priv
;
10046 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
10051 static int nl80211_set_param(void *priv
, const char *param
)
10053 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
10058 if (os_strstr(param
, "use_p2p_group_interface=1")) {
10059 struct i802_bss
*bss
= priv
;
10060 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10062 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
10064 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
10065 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
10068 if (os_strstr(param
, "p2p_device=1")) {
10069 struct i802_bss
*bss
= priv
;
10070 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10071 drv
->allow_p2p_device
= 1;
10073 #endif /* CONFIG_P2P */
10079 static void * nl80211_global_init(void)
10081 struct nl80211_global
*global
;
10082 struct netlink_config
*cfg
;
10084 global
= os_zalloc(sizeof(*global
));
10085 if (global
== NULL
)
10087 global
->ioctl_sock
= -1;
10088 dl_list_init(&global
->interfaces
);
10089 global
->if_add_ifindex
= -1;
10091 cfg
= os_zalloc(sizeof(*cfg
));
10096 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
10097 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
10098 global
->netlink
= netlink_init(cfg
);
10099 if (global
->netlink
== NULL
) {
10104 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
10107 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
10108 if (global
->ioctl_sock
< 0) {
10109 wpa_printf(MSG_ERROR
, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
10117 nl80211_global_deinit(global
);
10122 static void nl80211_global_deinit(void *priv
)
10124 struct nl80211_global
*global
= priv
;
10125 if (global
== NULL
)
10127 if (!dl_list_empty(&global
->interfaces
)) {
10128 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
10129 "nl80211_global_deinit",
10130 dl_list_len(&global
->interfaces
));
10133 if (global
->netlink
)
10134 netlink_deinit(global
->netlink
);
10136 nl_destroy_handles(&global
->nl
);
10138 if (global
->nl_event
)
10139 nl80211_destroy_eloop_handle(&global
->nl_event
);
10141 nl_cb_put(global
->nl_cb
);
10143 if (global
->ioctl_sock
>= 0)
10144 close(global
->ioctl_sock
);
10150 static const char * nl80211_get_radio_name(void *priv
)
10152 struct i802_bss
*bss
= priv
;
10153 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10154 return drv
->phyname
;
10158 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
10161 struct nl_msg
*msg
;
10163 msg
= nlmsg_alloc();
10167 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
10169 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
10171 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
10173 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
10175 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
10182 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
10184 struct i802_bss
*bss
= priv
;
10185 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
10186 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
10190 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
10192 struct i802_bss
*bss
= priv
;
10193 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
10195 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
10199 static int nl80211_flush_pmkid(void *priv
)
10201 struct i802_bss
*bss
= priv
;
10202 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
10203 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
10207 static void clean_survey_results(struct survey_results
*survey_results
)
10209 struct freq_survey
*survey
, *tmp
;
10211 if (dl_list_empty(&survey_results
->survey_list
))
10214 dl_list_for_each_safe(survey
, tmp
, &survey_results
->survey_list
,
10215 struct freq_survey
, list
) {
10216 dl_list_del(&survey
->list
);
10222 static void add_survey(struct nlattr
**sinfo
, u32 ifidx
,
10223 struct dl_list
*survey_list
)
10225 struct freq_survey
*survey
;
10227 survey
= os_zalloc(sizeof(struct freq_survey
));
10231 survey
->ifidx
= ifidx
;
10232 survey
->freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
10233 survey
->filled
= 0;
10235 if (sinfo
[NL80211_SURVEY_INFO_NOISE
]) {
10236 survey
->nf
= (int8_t)
10237 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
10238 survey
->filled
|= SURVEY_HAS_NF
;
10241 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]) {
10242 survey
->channel_time
=
10243 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME
]);
10244 survey
->filled
|= SURVEY_HAS_CHAN_TIME
;
10247 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]) {
10248 survey
->channel_time_busy
=
10249 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
]);
10250 survey
->filled
|= SURVEY_HAS_CHAN_TIME_BUSY
;
10253 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]) {
10254 survey
->channel_time_rx
=
10255 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_RX
]);
10256 survey
->filled
|= SURVEY_HAS_CHAN_TIME_RX
;
10259 if (sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]) {
10260 survey
->channel_time_tx
=
10261 nla_get_u64(sinfo
[NL80211_SURVEY_INFO_CHANNEL_TIME_TX
]);
10262 survey
->filled
|= SURVEY_HAS_CHAN_TIME_TX
;
10265 wpa_printf(MSG_DEBUG
, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)",
10268 (unsigned long int) survey
->channel_time
,
10269 (unsigned long int) survey
->channel_time_busy
,
10270 (unsigned long int) survey
->channel_time_tx
,
10271 (unsigned long int) survey
->channel_time_rx
,
10274 dl_list_add_tail(survey_list
, &survey
->list
);
10278 static int check_survey_ok(struct nlattr
**sinfo
, u32 surveyed_freq
,
10279 unsigned int freq_filter
)
10284 return freq_filter
== surveyed_freq
;
10288 static int survey_handler(struct nl_msg
*msg
, void *arg
)
10290 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
10291 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
10292 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
10293 struct survey_results
*survey_results
;
10294 u32 surveyed_freq
= 0;
10297 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
10298 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
10299 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
10302 survey_results
= (struct survey_results
*) arg
;
10304 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
10305 genlmsg_attrlen(gnlh
, 0), NULL
);
10307 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
10309 if (!tb
[NL80211_ATTR_SURVEY_INFO
])
10312 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
10313 tb
[NL80211_ATTR_SURVEY_INFO
],
10317 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) {
10318 wpa_printf(MSG_ERROR
, "nl80211: Invalid survey data");
10322 surveyed_freq
= nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]);
10324 if (!check_survey_ok(sinfo
, surveyed_freq
,
10325 survey_results
->freq_filter
))
10328 if (survey_results
->freq_filter
&&
10329 survey_results
->freq_filter
!= surveyed_freq
) {
10330 wpa_printf(MSG_EXCESSIVE
, "nl80211: Ignoring survey data for freq %d MHz",
10335 add_survey(sinfo
, ifidx
, &survey_results
->survey_list
);
10341 static int wpa_driver_nl80211_get_survey(void *priv
, unsigned int freq
)
10343 struct i802_bss
*bss
= priv
;
10344 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10345 struct nl_msg
*msg
;
10346 int err
= -ENOBUFS
;
10347 union wpa_event_data data
;
10348 struct survey_results
*survey_results
;
10350 os_memset(&data
, 0, sizeof(data
));
10351 survey_results
= &data
.survey_results
;
10353 dl_list_init(&survey_results
->survey_list
);
10355 msg
= nlmsg_alloc();
10357 goto nla_put_failure
;
10359 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
10361 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10364 data
.survey_results
.freq_filter
= freq
;
10367 wpa_printf(MSG_DEBUG
, "nl80211: Fetch survey data");
10368 err
= send_and_recv_msgs(drv
, msg
, survey_handler
,
10373 wpa_printf(MSG_ERROR
, "nl80211: Failed to process survey data");
10377 wpa_supplicant_event(drv
->ctx
, EVENT_SURVEY
, &data
);
10380 clean_survey_results(survey_results
);
10386 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
10387 const u8
*replay_ctr
)
10389 struct i802_bss
*bss
= priv
;
10390 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10391 struct nlattr
*replay_nested
;
10392 struct nl_msg
*msg
;
10394 msg
= nlmsg_alloc();
10398 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
10400 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
10402 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
10403 if (!replay_nested
)
10404 goto nla_put_failure
;
10406 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
10407 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
10408 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
10411 nla_nest_end(msg
, replay_nested
);
10413 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10420 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
10421 const u8
*addr
, int qos
)
10423 /* send data frame to poll STA and check whether
10424 * this frame is ACKed */
10426 struct ieee80211_hdr hdr
;
10428 } STRUCT_PACKED nulldata
;
10431 /* Send data frame to poll STA and check whether this frame is ACKed */
10433 os_memset(&nulldata
, 0, sizeof(nulldata
));
10436 nulldata
.hdr
.frame_control
=
10437 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
10438 WLAN_FC_STYPE_QOS_NULL
);
10439 size
= sizeof(nulldata
);
10441 nulldata
.hdr
.frame_control
=
10442 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
10443 WLAN_FC_STYPE_NULLFUNC
);
10444 size
= sizeof(struct ieee80211_hdr
);
10447 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
10448 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
10449 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
10450 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
10452 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
10454 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
10455 "send poll frame");
10458 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
10461 struct i802_bss
*bss
= priv
;
10462 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10463 struct nl_msg
*msg
;
10465 if (!drv
->poll_command_supported
) {
10466 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
10470 msg
= nlmsg_alloc();
10474 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
10476 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
10477 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
10479 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10486 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
10488 struct nl_msg
*msg
;
10490 msg
= nlmsg_alloc();
10494 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
10495 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
10496 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
10497 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
10498 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
10505 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
10508 struct i802_bss
*bss
= priv
;
10510 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
10511 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
10513 if (opp_ps
!= -1 || ctwindow
!= -1)
10514 return -1; /* Not yet supported */
10516 if (legacy_ps
== -1)
10518 if (legacy_ps
!= 0 && legacy_ps
!= 1)
10519 return -1; /* Not yet supported */
10521 return nl80211_set_power_save(bss
, legacy_ps
);
10525 static int nl80211_start_radar_detection(void *priv
,
10526 struct hostapd_freq_params
*freq
)
10528 struct i802_bss
*bss
= priv
;
10529 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10530 struct nl_msg
*msg
;
10533 wpa_printf(MSG_DEBUG
, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
10534 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
10535 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
10537 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
10538 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
10543 msg
= nlmsg_alloc();
10547 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_RADAR_DETECT
);
10548 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10549 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
);
10551 if (freq
->vht_enabled
) {
10552 switch (freq
->bandwidth
) {
10554 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10555 NL80211_CHAN_WIDTH_20
);
10558 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10559 NL80211_CHAN_WIDTH_40
);
10562 if (freq
->center_freq2
)
10563 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10564 NL80211_CHAN_WIDTH_80P80
);
10566 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10567 NL80211_CHAN_WIDTH_80
);
10570 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
10571 NL80211_CHAN_WIDTH_160
);
10576 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
->center_freq1
);
10577 if (freq
->center_freq2
)
10578 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
,
10579 freq
->center_freq2
);
10580 } else if (freq
->ht_enabled
) {
10581 switch (freq
->sec_channel_offset
) {
10583 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10584 NL80211_CHAN_HT40MINUS
);
10587 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10588 NL80211_CHAN_HT40PLUS
);
10591 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
10592 NL80211_CHAN_HT20
);
10597 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10600 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
10601 "%d (%s)", ret
, strerror(-ret
));
10608 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
10609 u8 dialog_token
, u16 status_code
,
10610 const u8
*buf
, size_t len
)
10612 struct i802_bss
*bss
= priv
;
10613 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10614 struct nl_msg
*msg
;
10616 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
10617 return -EOPNOTSUPP
;
10622 msg
= nlmsg_alloc();
10626 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
10627 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10628 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
10629 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
10630 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
10631 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
10632 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
10634 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10642 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
10644 struct i802_bss
*bss
= priv
;
10645 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10646 struct nl_msg
*msg
;
10647 enum nl80211_tdls_operation nl80211_oper
;
10649 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
10650 return -EOPNOTSUPP
;
10653 case TDLS_DISCOVERY_REQ
:
10654 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
10657 nl80211_oper
= NL80211_TDLS_SETUP
;
10659 case TDLS_TEARDOWN
:
10660 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
10662 case TDLS_ENABLE_LINK
:
10663 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
10665 case TDLS_DISABLE_LINK
:
10666 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
10676 msg
= nlmsg_alloc();
10680 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
10681 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
10682 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10683 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
10685 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10692 #endif /* CONFIG TDLS */
10697 typedef struct android_wifi_priv_cmd
{
10701 } android_wifi_priv_cmd
;
10703 static int drv_errors
= 0;
10705 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
10708 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
10710 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
10715 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
10717 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10719 android_wifi_priv_cmd priv_cmd
;
10720 char buf
[MAX_DRV_CMD_SIZE
];
10723 os_memset(&ifr
, 0, sizeof(ifr
));
10724 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
10725 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
10727 os_memset(buf
, 0, sizeof(buf
));
10728 os_strlcpy(buf
, cmd
, sizeof(buf
));
10730 priv_cmd
.buf
= buf
;
10731 priv_cmd
.used_len
= sizeof(buf
);
10732 priv_cmd
.total_len
= sizeof(buf
);
10733 ifr
.ifr_data
= &priv_cmd
;
10735 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
10737 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
10739 wpa_driver_send_hang_msg(drv
);
10748 static int android_pno_start(struct i802_bss
*bss
,
10749 struct wpa_driver_scan_params
*params
)
10751 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10753 android_wifi_priv_cmd priv_cmd
;
10754 int ret
= 0, i
= 0, bp
;
10755 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
10757 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
10758 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
10759 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
10760 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
10761 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
10762 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
10764 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
10765 /* Check that there is enough space needed for 1 more SSID, the
10766 * other sections and null termination */
10767 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
10768 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
10770 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
10771 params
->ssids
[i
].ssid
,
10772 params
->ssids
[i
].ssid_len
);
10773 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
10774 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
10775 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
10776 params
->ssids
[i
].ssid_len
);
10777 bp
+= params
->ssids
[i
].ssid_len
;
10781 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
10782 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
10783 WEXT_PNO_SCAN_INTERVAL
);
10784 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
10786 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
10787 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
10789 bp
+= WEXT_PNO_REPEAT_LENGTH
;
10791 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
10792 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
10793 WEXT_PNO_MAX_REPEAT
);
10794 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
10796 memset(&ifr
, 0, sizeof(ifr
));
10797 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
10798 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
10800 priv_cmd
.buf
= buf
;
10801 priv_cmd
.used_len
= bp
;
10802 priv_cmd
.total_len
= bp
;
10803 ifr
.ifr_data
= &priv_cmd
;
10805 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
10808 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
10810 wpa_driver_send_hang_msg(drv
);
10816 return android_priv_cmd(bss
, "PNOFORCE 1");
10820 static int android_pno_stop(struct i802_bss
*bss
)
10822 return android_priv_cmd(bss
, "PNOFORCE 0");
10825 #endif /* ANDROID */
10828 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
10829 enum wpa_alg alg
, const u8
*addr
,
10830 int key_idx
, int set_tx
,
10831 const u8
*seq
, size_t seq_len
,
10832 const u8
*key
, size_t key_len
)
10834 struct i802_bss
*bss
= priv
;
10835 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
10836 set_tx
, seq
, seq_len
, key
, key_len
);
10840 static int driver_nl80211_scan2(void *priv
,
10841 struct wpa_driver_scan_params
*params
)
10843 struct i802_bss
*bss
= priv
;
10844 return wpa_driver_nl80211_scan(bss
, params
);
10848 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
10851 struct i802_bss
*bss
= priv
;
10852 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
10856 static int driver_nl80211_authenticate(void *priv
,
10857 struct wpa_driver_auth_params
*params
)
10859 struct i802_bss
*bss
= priv
;
10860 return wpa_driver_nl80211_authenticate(bss
, params
);
10864 static void driver_nl80211_deinit(void *priv
)
10866 struct i802_bss
*bss
= priv
;
10867 wpa_driver_nl80211_deinit(bss
);
10871 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
10872 const char *ifname
)
10874 struct i802_bss
*bss
= priv
;
10875 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
10879 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
10880 size_t data_len
, int noack
)
10882 struct i802_bss
*bss
= priv
;
10883 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
10888 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
10890 struct i802_bss
*bss
= priv
;
10891 return wpa_driver_nl80211_sta_remove(bss
, addr
);
10895 #if defined(HOSTAPD) || defined(CONFIG_AP)
10896 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
10897 const char *ifname
, int vlan_id
)
10899 struct i802_bss
*bss
= priv
;
10900 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
10902 #endif /* HOSTAPD || CONFIG_AP */
10905 static int driver_nl80211_read_sta_data(void *priv
,
10906 struct hostap_sta_driver_data
*data
,
10909 struct i802_bss
*bss
= priv
;
10910 return i802_read_sta_data(bss
, data
, addr
);
10914 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
10915 unsigned int wait_time
,
10916 const u8
*dst
, const u8
*src
,
10918 const u8
*data
, size_t data_len
,
10921 struct i802_bss
*bss
= priv
;
10922 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
10923 bssid
, data
, data_len
, no_cck
);
10927 static int driver_nl80211_probe_req_report(void *priv
, int report
)
10929 struct i802_bss
*bss
= priv
;
10930 return wpa_driver_nl80211_probe_req_report(bss
, report
);
10934 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
10935 const u8
*ies
, size_t ies_len
)
10938 struct nl_msg
*msg
;
10939 struct i802_bss
*bss
= priv
;
10940 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10941 u16 mdid
= WPA_GET_LE16(md
);
10943 msg
= nlmsg_alloc();
10947 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
10948 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UPDATE_FT_IES
);
10949 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10950 NLA_PUT(msg
, NL80211_ATTR_IE
, ies_len
, ies
);
10951 NLA_PUT_U16(msg
, NL80211_ATTR_MDID
, mdid
);
10953 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10955 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
10956 "err=%d (%s)", ret
, strerror(-ret
));
10967 const u8
* wpa_driver_nl80211_get_macaddr(void *priv
)
10969 struct i802_bss
*bss
= priv
;
10970 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10972 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
10979 static const char * scan_state_str(enum scan_states scan_state
)
10981 switch (scan_state
) {
10984 case SCAN_REQUESTED
:
10985 return "SCAN_REQUESTED";
10987 return "SCAN_STARTED";
10988 case SCAN_COMPLETED
:
10989 return "SCAN_COMPLETED";
10991 return "SCAN_ABORTED";
10992 case SCHED_SCAN_STARTED
:
10993 return "SCHED_SCAN_STARTED";
10994 case SCHED_SCAN_STOPPED
:
10995 return "SCHED_SCAN_STOPPED";
10996 case SCHED_SCAN_RESULTS
:
10997 return "SCHED_SCAN_RESULTS";
11004 static int wpa_driver_nl80211_status(void *priv
, char *buf
, size_t buflen
)
11006 struct i802_bss
*bss
= priv
;
11007 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
11012 end
= buf
+ buflen
;
11014 res
= os_snprintf(pos
, end
- pos
,
11018 "addr=" MACSTR
"\n"
11024 MAC2STR(bss
->addr
),
11026 bss
->beacon_set
? "beacon_set=1\n" : "",
11027 bss
->added_if_into_bridge
?
11028 "added_if_into_bridge=1\n" : "",
11029 bss
->added_bridge
? "added_bridge=1\n" : "",
11030 bss
->in_deinit
? "in_deinit=1\n" : "",
11031 bss
->if_dynamic
? "if_dynamic=1\n" : "");
11032 if (res
< 0 || res
>= end
- pos
)
11036 if (bss
->wdev_id_set
) {
11037 res
= os_snprintf(pos
, end
- pos
, "wdev_id=%llu\n",
11038 (unsigned long long) bss
->wdev_id
);
11039 if (res
< 0 || res
>= end
- pos
)
11044 res
= os_snprintf(pos
, end
- pos
,
11049 "auth_bssid=" MACSTR
"\n"
11050 "auth_attempt_bssid=" MACSTR
"\n"
11051 "bssid=" MACSTR
"\n"
11052 "prev_bssid=" MACSTR
"\n"
11055 "monitor_sock=%d\n"
11056 "monitor_ifidx=%d\n"
11057 "monitor_refcount=%d\n"
11058 "last_mgmt_freq=%u\n"
11059 "eapol_tx_sock=%d\n"
11060 "%s%s%s%s%s%s%s%s%s%s%s%s%s",
11064 scan_state_str(drv
->scan_state
),
11065 MAC2STR(drv
->auth_bssid
),
11066 MAC2STR(drv
->auth_attempt_bssid
),
11067 MAC2STR(drv
->bssid
),
11068 MAC2STR(drv
->prev_bssid
),
11072 drv
->monitor_ifidx
,
11073 drv
->monitor_refcount
,
11074 drv
->last_mgmt_freq
,
11075 drv
->eapol_tx_sock
,
11076 drv
->ignore_if_down_event
?
11077 "ignore_if_down_event=1\n" : "",
11078 drv
->scan_complete_events
?
11079 "scan_complete_events=1\n" : "",
11080 drv
->disabled_11b_rates
?
11081 "disabled_11b_rates=1\n" : "",
11082 drv
->pending_remain_on_chan
?
11083 "pending_remain_on_chan=1\n" : "",
11084 drv
->in_interface_list
? "in_interface_list=1\n" : "",
11085 drv
->device_ap_sme
? "device_ap_sme=1\n" : "",
11086 drv
->poll_command_supported
?
11087 "poll_command_supported=1\n" : "",
11088 drv
->data_tx_status
? "data_tx_status=1\n" : "",
11089 drv
->scan_for_auth
? "scan_for_auth=1\n" : "",
11090 drv
->retry_auth
? "retry_auth=1\n" : "",
11091 drv
->use_monitor
? "use_monitor=1\n" : "",
11092 drv
->ignore_next_local_disconnect
?
11093 "ignore_next_local_disconnect=1\n" : "",
11094 drv
->allow_p2p_device
? "allow_p2p_device=1\n" : "");
11095 if (res
< 0 || res
>= end
- pos
)
11099 if (drv
->has_capability
) {
11100 res
= os_snprintf(pos
, end
- pos
,
11101 "capa.key_mgmt=0x%x\n"
11104 "capa.flags=0x%x\n"
11105 "capa.max_scan_ssids=%d\n"
11106 "capa.max_sched_scan_ssids=%d\n"
11107 "capa.sched_scan_supported=%d\n"
11108 "capa.max_match_sets=%d\n"
11109 "capa.max_remain_on_chan=%u\n"
11110 "capa.max_stations=%u\n"
11111 "capa.probe_resp_offloads=0x%x\n"
11112 "capa.max_acl_mac_addrs=%u\n"
11113 "capa.num_multichan_concurrent=%u\n",
11114 drv
->capa
.key_mgmt
,
11118 drv
->capa
.max_scan_ssids
,
11119 drv
->capa
.max_sched_scan_ssids
,
11120 drv
->capa
.sched_scan_supported
,
11121 drv
->capa
.max_match_sets
,
11122 drv
->capa
.max_remain_on_chan
,
11123 drv
->capa
.max_stations
,
11124 drv
->capa
.probe_resp_offloads
,
11125 drv
->capa
.max_acl_mac_addrs
,
11126 drv
->capa
.num_multichan_concurrent
);
11127 if (res
< 0 || res
>= end
- pos
)
11136 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
11138 .desc
= "Linux nl80211/cfg80211",
11139 .get_bssid
= wpa_driver_nl80211_get_bssid
,
11140 .get_ssid
= wpa_driver_nl80211_get_ssid
,
11141 .set_key
= driver_nl80211_set_key
,
11142 .scan2
= driver_nl80211_scan2
,
11143 .sched_scan
= wpa_driver_nl80211_sched_scan
,
11144 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
11145 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
11146 .deauthenticate
= driver_nl80211_deauthenticate
,
11147 .authenticate
= driver_nl80211_authenticate
,
11148 .associate
= wpa_driver_nl80211_associate
,
11149 .global_init
= nl80211_global_init
,
11150 .global_deinit
= nl80211_global_deinit
,
11151 .init2
= wpa_driver_nl80211_init
,
11152 .deinit
= driver_nl80211_deinit
,
11153 .get_capa
= wpa_driver_nl80211_get_capa
,
11154 .set_operstate
= wpa_driver_nl80211_set_operstate
,
11155 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
11156 .set_country
= wpa_driver_nl80211_set_country
,
11157 .set_ap
= wpa_driver_nl80211_set_ap
,
11158 .set_acl
= wpa_driver_nl80211_set_acl
,
11159 .if_add
= wpa_driver_nl80211_if_add
,
11160 .if_remove
= driver_nl80211_if_remove
,
11161 .send_mlme
= driver_nl80211_send_mlme
,
11162 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
11163 .sta_add
= wpa_driver_nl80211_sta_add
,
11164 .sta_remove
= driver_nl80211_sta_remove
,
11165 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
11166 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
11168 .hapd_init
= i802_init
,
11169 .hapd_deinit
= i802_deinit
,
11170 .set_wds_sta
= i802_set_wds_sta
,
11171 #endif /* HOSTAPD */
11172 #if defined(HOSTAPD) || defined(CONFIG_AP)
11173 .get_seqnum
= i802_get_seqnum
,
11174 .flush
= i802_flush
,
11175 .get_inact_sec
= i802_get_inact_sec
,
11176 .sta_clear_stats
= i802_sta_clear_stats
,
11177 .set_rts
= i802_set_rts
,
11178 .set_frag
= i802_set_frag
,
11179 .set_tx_queue_params
= i802_set_tx_queue_params
,
11180 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
11181 .sta_deauth
= i802_sta_deauth
,
11182 .sta_disassoc
= i802_sta_disassoc
,
11183 #endif /* HOSTAPD || CONFIG_AP */
11184 .read_sta_data
= driver_nl80211_read_sta_data
,
11185 .set_freq
= i802_set_freq
,
11186 .send_action
= driver_nl80211_send_action
,
11187 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
11188 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
11189 .cancel_remain_on_channel
=
11190 wpa_driver_nl80211_cancel_remain_on_channel
,
11191 .probe_req_report
= driver_nl80211_probe_req_report
,
11192 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
11193 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
11194 .resume
= wpa_driver_nl80211_resume
,
11195 .send_ft_action
= nl80211_send_ft_action
,
11196 .signal_monitor
= nl80211_signal_monitor
,
11197 .signal_poll
= nl80211_signal_poll
,
11198 .send_frame
= nl80211_send_frame
,
11199 .shared_freq
= wpa_driver_nl80211_shared_freq
,
11200 .set_param
= nl80211_set_param
,
11201 .get_radio_name
= nl80211_get_radio_name
,
11202 .add_pmkid
= nl80211_add_pmkid
,
11203 .remove_pmkid
= nl80211_remove_pmkid
,
11204 .flush_pmkid
= nl80211_flush_pmkid
,
11205 .set_rekey_info
= nl80211_set_rekey_info
,
11206 .poll_client
= nl80211_poll_client
,
11207 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
11208 .start_dfs_cac
= nl80211_start_radar_detection
,
11209 .stop_ap
= wpa_driver_nl80211_stop_ap
,
11211 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
11212 .tdls_oper
= nl80211_tdls_oper
,
11213 #endif /* CONFIG_TDLS */
11214 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,
11215 .get_mac_addr
= wpa_driver_nl80211_get_macaddr
,
11216 .get_survey
= wpa_driver_nl80211_get_survey
,
11217 .status
= wpa_driver_nl80211_status
,