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 IFF_LOWER_UP 0x10000 /* driver signals L1 up */
147 #define IFF_DORMANT 0x20000 /* driver signals dormant */
150 #ifndef IF_OPER_DORMANT
151 #define IF_OPER_DORMANT 5
157 struct nl80211_global
{
158 struct dl_list interfaces
;
160 struct netlink_data
*netlink
;
162 struct nl_handle
*nl
;
164 int ioctl_sock
; /* socket for ioctl() use */
166 struct nl_handle
*nl_event
;
169 struct nl80211_wiphy_data
{
174 struct nl_handle
*nl_beacons
;
180 static void nl80211_global_deinit(void *priv
);
183 struct wpa_driver_nl80211_data
*drv
;
184 struct i802_bss
*next
;
187 char ifname
[IFNAMSIZ
+ 1];
188 char brname
[IFNAMSIZ
];
189 unsigned int beacon_set
:1;
190 unsigned int added_if_into_bridge
:1;
191 unsigned int added_bridge
:1;
192 unsigned int in_deinit
:1;
193 unsigned int wdev_id_set
:1;
200 struct nl_handle
*nl_preq
, *nl_mgmt
;
203 struct nl80211_wiphy_data
*wiphy_data
;
204 struct dl_list wiphy_list
;
207 struct wpa_driver_nl80211_data
{
208 struct nl80211_global
*global
;
210 struct dl_list wiphy_list
;
216 int ignore_if_down_event
;
217 struct rfkill_data
*rfkill
;
218 struct wpa_driver_capa capa
;
219 u8
*extended_capa
, *extended_capa_mask
;
220 unsigned int extended_capa_len
;
225 int scan_complete_events
;
229 u8 auth_bssid
[ETH_ALEN
];
230 u8 auth_attempt_bssid
[ETH_ALEN
];
232 u8 prev_bssid
[ETH_ALEN
];
236 enum nl80211_iftype nlmode
;
237 enum nl80211_iftype ap_scan_as_station
;
238 unsigned int assoc_freq
;
242 int monitor_refcount
;
244 unsigned int disabled_11b_rates
:1;
245 unsigned int pending_remain_on_chan
:1;
246 unsigned int in_interface_list
:1;
247 unsigned int device_ap_sme
:1;
248 unsigned int poll_command_supported
:1;
249 unsigned int data_tx_status
:1;
250 unsigned int scan_for_auth
:1;
251 unsigned int retry_auth
:1;
252 unsigned int use_monitor
:1;
253 unsigned int ignore_next_local_disconnect
:1;
255 u64 remain_on_chan_cookie
;
256 u64 send_action_cookie
;
258 unsigned int last_mgmt_freq
;
260 struct wpa_driver_scan_filter
*filter_ssids
;
261 size_t num_filter_ssids
;
263 struct i802_bss first_bss
;
268 int eapol_sock
; /* socket for EAPOL frames */
270 int default_if_indices
[16];
278 /* From failed authentication command */
280 u8 auth_bssid_
[ETH_ALEN
];
282 size_t auth_ssid_len
;
286 u8 auth_wep_key
[4][16];
287 size_t auth_wep_key_len
[4];
288 int auth_wep_tx_keyidx
;
289 int auth_local_state_change
;
294 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
);
295 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
,
297 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
298 enum nl80211_iftype nlmode
);
300 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
);
301 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
302 const u8
*addr
, int cmd
, u16 reason_code
,
303 int local_state_change
);
304 static void nl80211_remove_monitor_interface(
305 struct wpa_driver_nl80211_data
*drv
);
306 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
307 unsigned int freq
, unsigned int wait
,
308 const u8
*buf
, size_t buf_len
, u64
*cookie
,
309 int no_cck
, int no_ack
, int offchanok
);
310 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
,
313 static int android_pno_start(struct i802_bss
*bss
,
314 struct wpa_driver_scan_params
*params
);
315 static int android_pno_stop(struct i802_bss
*bss
);
319 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
320 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
321 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
);
322 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
323 enum wpa_driver_if_type type
,
326 static inline void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
330 static inline void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
334 static inline int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
340 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
341 struct hostapd_freq_params
*freq
);
342 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
343 int ifindex
, int disabled
);
345 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
);
346 static int wpa_driver_nl80211_authenticate_retry(
347 struct wpa_driver_nl80211_data
*drv
);
350 static const char * nl80211_command_to_string(enum nl80211_commands cmd
)
352 #define C2S(x) case x: return #x;
354 C2S(NL80211_CMD_UNSPEC
)
355 C2S(NL80211_CMD_GET_WIPHY
)
356 C2S(NL80211_CMD_SET_WIPHY
)
357 C2S(NL80211_CMD_NEW_WIPHY
)
358 C2S(NL80211_CMD_DEL_WIPHY
)
359 C2S(NL80211_CMD_GET_INTERFACE
)
360 C2S(NL80211_CMD_SET_INTERFACE
)
361 C2S(NL80211_CMD_NEW_INTERFACE
)
362 C2S(NL80211_CMD_DEL_INTERFACE
)
363 C2S(NL80211_CMD_GET_KEY
)
364 C2S(NL80211_CMD_SET_KEY
)
365 C2S(NL80211_CMD_NEW_KEY
)
366 C2S(NL80211_CMD_DEL_KEY
)
367 C2S(NL80211_CMD_GET_BEACON
)
368 C2S(NL80211_CMD_SET_BEACON
)
369 C2S(NL80211_CMD_START_AP
)
370 C2S(NL80211_CMD_STOP_AP
)
371 C2S(NL80211_CMD_GET_STATION
)
372 C2S(NL80211_CMD_SET_STATION
)
373 C2S(NL80211_CMD_NEW_STATION
)
374 C2S(NL80211_CMD_DEL_STATION
)
375 C2S(NL80211_CMD_GET_MPATH
)
376 C2S(NL80211_CMD_SET_MPATH
)
377 C2S(NL80211_CMD_NEW_MPATH
)
378 C2S(NL80211_CMD_DEL_MPATH
)
379 C2S(NL80211_CMD_SET_BSS
)
380 C2S(NL80211_CMD_SET_REG
)
381 C2S(NL80211_CMD_REQ_SET_REG
)
382 C2S(NL80211_CMD_GET_MESH_CONFIG
)
383 C2S(NL80211_CMD_SET_MESH_CONFIG
)
384 C2S(NL80211_CMD_SET_MGMT_EXTRA_IE
)
385 C2S(NL80211_CMD_GET_REG
)
386 C2S(NL80211_CMD_GET_SCAN
)
387 C2S(NL80211_CMD_TRIGGER_SCAN
)
388 C2S(NL80211_CMD_NEW_SCAN_RESULTS
)
389 C2S(NL80211_CMD_SCAN_ABORTED
)
390 C2S(NL80211_CMD_REG_CHANGE
)
391 C2S(NL80211_CMD_AUTHENTICATE
)
392 C2S(NL80211_CMD_ASSOCIATE
)
393 C2S(NL80211_CMD_DEAUTHENTICATE
)
394 C2S(NL80211_CMD_DISASSOCIATE
)
395 C2S(NL80211_CMD_MICHAEL_MIC_FAILURE
)
396 C2S(NL80211_CMD_REG_BEACON_HINT
)
397 C2S(NL80211_CMD_JOIN_IBSS
)
398 C2S(NL80211_CMD_LEAVE_IBSS
)
399 C2S(NL80211_CMD_TESTMODE
)
400 C2S(NL80211_CMD_CONNECT
)
401 C2S(NL80211_CMD_ROAM
)
402 C2S(NL80211_CMD_DISCONNECT
)
403 C2S(NL80211_CMD_SET_WIPHY_NETNS
)
404 C2S(NL80211_CMD_GET_SURVEY
)
405 C2S(NL80211_CMD_NEW_SURVEY_RESULTS
)
406 C2S(NL80211_CMD_SET_PMKSA
)
407 C2S(NL80211_CMD_DEL_PMKSA
)
408 C2S(NL80211_CMD_FLUSH_PMKSA
)
409 C2S(NL80211_CMD_REMAIN_ON_CHANNEL
)
410 C2S(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
)
411 C2S(NL80211_CMD_SET_TX_BITRATE_MASK
)
412 C2S(NL80211_CMD_REGISTER_FRAME
)
413 C2S(NL80211_CMD_FRAME
)
414 C2S(NL80211_CMD_FRAME_TX_STATUS
)
415 C2S(NL80211_CMD_SET_POWER_SAVE
)
416 C2S(NL80211_CMD_GET_POWER_SAVE
)
417 C2S(NL80211_CMD_SET_CQM
)
418 C2S(NL80211_CMD_NOTIFY_CQM
)
419 C2S(NL80211_CMD_SET_CHANNEL
)
420 C2S(NL80211_CMD_SET_WDS_PEER
)
421 C2S(NL80211_CMD_FRAME_WAIT_CANCEL
)
422 C2S(NL80211_CMD_JOIN_MESH
)
423 C2S(NL80211_CMD_LEAVE_MESH
)
424 C2S(NL80211_CMD_UNPROT_DEAUTHENTICATE
)
425 C2S(NL80211_CMD_UNPROT_DISASSOCIATE
)
426 C2S(NL80211_CMD_NEW_PEER_CANDIDATE
)
427 C2S(NL80211_CMD_GET_WOWLAN
)
428 C2S(NL80211_CMD_SET_WOWLAN
)
429 C2S(NL80211_CMD_START_SCHED_SCAN
)
430 C2S(NL80211_CMD_STOP_SCHED_SCAN
)
431 C2S(NL80211_CMD_SCHED_SCAN_RESULTS
)
432 C2S(NL80211_CMD_SCHED_SCAN_STOPPED
)
433 C2S(NL80211_CMD_SET_REKEY_OFFLOAD
)
434 C2S(NL80211_CMD_PMKSA_CANDIDATE
)
435 C2S(NL80211_CMD_TDLS_OPER
)
436 C2S(NL80211_CMD_TDLS_MGMT
)
437 C2S(NL80211_CMD_UNEXPECTED_FRAME
)
438 C2S(NL80211_CMD_PROBE_CLIENT
)
439 C2S(NL80211_CMD_REGISTER_BEACONS
)
440 C2S(NL80211_CMD_UNEXPECTED_4ADDR_FRAME
)
441 C2S(NL80211_CMD_SET_NOACK_MAP
)
442 C2S(NL80211_CMD_CH_SWITCH_NOTIFY
)
443 C2S(NL80211_CMD_START_P2P_DEVICE
)
444 C2S(NL80211_CMD_STOP_P2P_DEVICE
)
445 C2S(NL80211_CMD_CONN_FAILED
)
446 C2S(NL80211_CMD_SET_MCAST_RATE
)
447 C2S(NL80211_CMD_SET_MAC_ACL
)
448 C2S(NL80211_CMD_RADAR_DETECT
)
449 C2S(NL80211_CMD_GET_PROTOCOL_FEATURES
)
450 C2S(NL80211_CMD_UPDATE_FT_IES
)
451 C2S(NL80211_CMD_FT_EVENT
)
452 C2S(NL80211_CMD_CRIT_PROTOCOL_START
)
453 C2S(NL80211_CMD_CRIT_PROTOCOL_STOP
)
455 return "NL80211_CMD_UNKNOWN";
461 static int is_ap_interface(enum nl80211_iftype nlmode
)
463 return (nlmode
== NL80211_IFTYPE_AP
||
464 nlmode
== NL80211_IFTYPE_P2P_GO
);
468 static int is_sta_interface(enum nl80211_iftype nlmode
)
470 return (nlmode
== NL80211_IFTYPE_STATION
||
471 nlmode
== NL80211_IFTYPE_P2P_CLIENT
);
475 static int is_p2p_net_interface(enum nl80211_iftype nlmode
)
477 return (nlmode
== NL80211_IFTYPE_P2P_CLIENT
||
478 nlmode
== NL80211_IFTYPE_P2P_GO
);
482 static void nl80211_mark_disconnected(struct wpa_driver_nl80211_data
*drv
)
485 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
487 os_memset(drv
->bssid
, 0, ETH_ALEN
);
491 struct nl80211_bss_info_arg
{
492 struct wpa_driver_nl80211_data
*drv
;
493 struct wpa_scan_results
*res
;
494 unsigned int assoc_freq
;
495 u8 assoc_bssid
[ETH_ALEN
];
498 static int bss_info_handler(struct nl_msg
*msg
, void *arg
);
502 static int ack_handler(struct nl_msg
*msg
, void *arg
)
509 static int finish_handler(struct nl_msg
*msg
, void *arg
)
516 static int error_handler(struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
525 static int no_seq_check(struct nl_msg
*msg
, void *arg
)
531 static int send_and_recv(struct nl80211_global
*global
,
532 struct nl_handle
*nl_handle
, struct nl_msg
*msg
,
533 int (*valid_handler
)(struct nl_msg
*, void *),
539 cb
= nl_cb_clone(global
->nl_cb
);
543 err
= nl_send_auto_complete(nl_handle
, msg
);
549 nl_cb_err(cb
, NL_CB_CUSTOM
, error_handler
, &err
);
550 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, finish_handler
, &err
);
551 nl_cb_set(cb
, NL_CB_ACK
, NL_CB_CUSTOM
, ack_handler
, &err
);
554 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
555 valid_handler
, valid_data
);
558 nl_recvmsgs(nl_handle
, cb
);
566 static int send_and_recv_msgs_global(struct nl80211_global
*global
,
568 int (*valid_handler
)(struct nl_msg
*, void *),
571 return send_and_recv(global
, global
->nl
, msg
, valid_handler
,
576 static int send_and_recv_msgs(struct wpa_driver_nl80211_data
*drv
,
578 int (*valid_handler
)(struct nl_msg
*, void *),
581 return send_and_recv(drv
->global
, drv
->global
->nl
, msg
,
582 valid_handler
, valid_data
);
592 static int nl80211_set_iface_id(struct nl_msg
*msg
, struct i802_bss
*bss
)
594 if (bss
->wdev_id_set
)
595 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, bss
->wdev_id
);
597 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
605 static int family_handler(struct nl_msg
*msg
, void *arg
)
607 struct family_data
*res
= arg
;
608 struct nlattr
*tb
[CTRL_ATTR_MAX
+ 1];
609 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
610 struct nlattr
*mcgrp
;
613 nla_parse(tb
, CTRL_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
614 genlmsg_attrlen(gnlh
, 0), NULL
);
615 if (!tb
[CTRL_ATTR_MCAST_GROUPS
])
618 nla_for_each_nested(mcgrp
, tb
[CTRL_ATTR_MCAST_GROUPS
], i
) {
619 struct nlattr
*tb2
[CTRL_ATTR_MCAST_GRP_MAX
+ 1];
620 nla_parse(tb2
, CTRL_ATTR_MCAST_GRP_MAX
, nla_data(mcgrp
),
621 nla_len(mcgrp
), NULL
);
622 if (!tb2
[CTRL_ATTR_MCAST_GRP_NAME
] ||
623 !tb2
[CTRL_ATTR_MCAST_GRP_ID
] ||
624 os_strncmp(nla_data(tb2
[CTRL_ATTR_MCAST_GRP_NAME
]),
626 nla_len(tb2
[CTRL_ATTR_MCAST_GRP_NAME
])) != 0)
628 res
->id
= nla_get_u32(tb2
[CTRL_ATTR_MCAST_GRP_ID
]);
636 static int nl_get_multicast_id(struct nl80211_global
*global
,
637 const char *family
, const char *group
)
641 struct family_data res
= { group
, -ENOENT
};
646 genlmsg_put(msg
, 0, 0, genl_ctrl_resolve(global
->nl
, "nlctrl"),
647 0, 0, CTRL_CMD_GETFAMILY
, 0);
648 NLA_PUT_STRING(msg
, CTRL_ATTR_FAMILY_NAME
, family
);
650 ret
= send_and_recv_msgs_global(global
, msg
, family_handler
, &res
);
661 static void * nl80211_cmd(struct wpa_driver_nl80211_data
*drv
,
662 struct nl_msg
*msg
, int flags
, uint8_t cmd
)
664 return genlmsg_put(msg
, 0, 0, drv
->global
->nl80211_id
,
669 struct wiphy_idx_data
{
671 enum nl80211_iftype nlmode
;
675 static int netdev_info_handler(struct nl_msg
*msg
, void *arg
)
677 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
678 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
679 struct wiphy_idx_data
*info
= arg
;
681 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
682 genlmsg_attrlen(gnlh
, 0), NULL
);
684 if (tb
[NL80211_ATTR_WIPHY
])
685 info
->wiphy_idx
= nla_get_u32(tb
[NL80211_ATTR_WIPHY
]);
687 if (tb
[NL80211_ATTR_IFTYPE
])
688 info
->nlmode
= nla_get_u32(tb
[NL80211_ATTR_IFTYPE
]);
694 static int nl80211_get_wiphy_index(struct i802_bss
*bss
)
697 struct wiphy_idx_data data
= {
705 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
707 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
709 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
710 return data
.wiphy_idx
;
719 static enum nl80211_iftype
nl80211_get_ifmode(struct i802_bss
*bss
)
722 struct wiphy_idx_data data
= {
730 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
732 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
734 if (send_and_recv_msgs(bss
->drv
, msg
, netdev_info_handler
, &data
) == 0)
739 return NL80211_IFTYPE_UNSPECIFIED
;
744 static int nl80211_register_beacons(struct wpa_driver_nl80211_data
*drv
,
745 struct nl80211_wiphy_data
*w
)
754 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_BEACONS
);
756 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, w
->wiphy_idx
);
758 ret
= send_and_recv(drv
->global
, w
->nl_beacons
, msg
, NULL
, NULL
);
761 wpa_printf(MSG_DEBUG
, "nl80211: Register beacons command "
762 "failed: ret=%d (%s)",
763 ret
, strerror(-ret
));
764 goto nla_put_failure
;
773 static void nl80211_recv_beacons(int sock
, void *eloop_ctx
, void *handle
)
775 struct nl80211_wiphy_data
*w
= eloop_ctx
;
777 wpa_printf(MSG_EXCESSIVE
, "nl80211: Beacon event message available");
779 nl_recvmsgs(handle
, w
->nl_cb
);
783 static int process_beacon_event(struct nl_msg
*msg
, void *arg
)
785 struct nl80211_wiphy_data
*w
= arg
;
786 struct wpa_driver_nl80211_data
*drv
;
787 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
788 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
789 union wpa_event_data event
;
791 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
792 genlmsg_attrlen(gnlh
, 0), NULL
);
794 if (gnlh
->cmd
!= NL80211_CMD_FRAME
) {
795 wpa_printf(MSG_DEBUG
, "nl80211: Unexpected beacon event? (%d)",
800 if (!tb
[NL80211_ATTR_FRAME
])
803 dl_list_for_each(drv
, &w
->drvs
, struct wpa_driver_nl80211_data
,
805 os_memset(&event
, 0, sizeof(event
));
806 event
.rx_mgmt
.frame
= nla_data(tb
[NL80211_ATTR_FRAME
]);
807 event
.rx_mgmt
.frame_len
= nla_len(tb
[NL80211_ATTR_FRAME
]);
808 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
815 static struct nl80211_wiphy_data
*
816 nl80211_get_wiphy_data_ap(struct i802_bss
*bss
)
818 static DEFINE_DL_LIST(nl80211_wiphys
);
819 struct nl80211_wiphy_data
*w
;
820 int wiphy_idx
, found
= 0;
821 struct i802_bss
*tmp_bss
;
823 if (bss
->wiphy_data
!= NULL
)
824 return bss
->wiphy_data
;
826 wiphy_idx
= nl80211_get_wiphy_index(bss
);
828 dl_list_for_each(w
, &nl80211_wiphys
, struct nl80211_wiphy_data
, list
) {
829 if (w
->wiphy_idx
== wiphy_idx
)
834 w
= os_zalloc(sizeof(*w
));
837 w
->wiphy_idx
= wiphy_idx
;
838 dl_list_init(&w
->bsss
);
839 dl_list_init(&w
->drvs
);
841 w
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
846 nl_cb_set(w
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
, no_seq_check
, NULL
);
847 nl_cb_set(w
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
, process_beacon_event
,
850 w
->nl_beacons
= nl_create_handle(bss
->drv
->global
->nl_cb
,
852 if (w
->nl_beacons
== NULL
) {
857 if (nl80211_register_beacons(bss
->drv
, w
)) {
858 nl_destroy_handles(&w
->nl_beacons
);
863 eloop_register_read_sock(nl_socket_get_fd(w
->nl_beacons
),
864 nl80211_recv_beacons
, w
, w
->nl_beacons
);
866 dl_list_add(&nl80211_wiphys
, &w
->list
);
869 /* drv entry for this bss already there? */
870 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
871 if (tmp_bss
->drv
== bss
->drv
) {
878 dl_list_add(&w
->drvs
, &bss
->drv
->wiphy_list
);
880 dl_list_add(&w
->bsss
, &bss
->wiphy_list
);
886 static void nl80211_put_wiphy_data_ap(struct i802_bss
*bss
)
888 struct nl80211_wiphy_data
*w
= bss
->wiphy_data
;
889 struct i802_bss
*tmp_bss
;
894 bss
->wiphy_data
= NULL
;
895 dl_list_del(&bss
->wiphy_list
);
897 /* still any for this drv present? */
898 dl_list_for_each(tmp_bss
, &w
->bsss
, struct i802_bss
, wiphy_list
) {
899 if (tmp_bss
->drv
== bss
->drv
) {
904 /* if not remove it */
906 dl_list_del(&bss
->drv
->wiphy_list
);
908 if (!dl_list_empty(&w
->bsss
))
911 eloop_unregister_read_sock(nl_socket_get_fd(w
->nl_beacons
));
914 nl_destroy_handles(&w
->nl_beacons
);
915 dl_list_del(&w
->list
);
920 static int wpa_driver_nl80211_get_bssid(void *priv
, u8
*bssid
)
922 struct i802_bss
*bss
= priv
;
923 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
924 if (!drv
->associated
)
926 os_memcpy(bssid
, drv
->bssid
, ETH_ALEN
);
931 static int wpa_driver_nl80211_get_ssid(void *priv
, u8
*ssid
)
933 struct i802_bss
*bss
= priv
;
934 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
935 if (!drv
->associated
)
937 os_memcpy(ssid
, drv
->ssid
, drv
->ssid_len
);
938 return drv
->ssid_len
;
942 static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data
*drv
,
943 char *buf
, size_t len
, int del
)
945 union wpa_event_data event
;
947 os_memset(&event
, 0, sizeof(event
));
948 if (len
> sizeof(event
.interface_status
.ifname
))
949 len
= sizeof(event
.interface_status
.ifname
) - 1;
950 os_memcpy(event
.interface_status
.ifname
, buf
, len
);
951 event
.interface_status
.ievent
= del
? EVENT_INTERFACE_REMOVED
:
952 EVENT_INTERFACE_ADDED
;
954 wpa_printf(MSG_DEBUG
, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
956 event
.interface_status
.ifname
,
957 del
? "removed" : "added");
959 if (os_strcmp(drv
->first_bss
.ifname
, event
.interface_status
.ifname
) == 0) {
961 if (drv
->if_removed
) {
962 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
963 "already set - ignore event");
968 if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
969 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s "
970 "does not exist - ignore "
972 drv
->first_bss
.ifname
);
975 if (!drv
->if_removed
) {
976 wpa_printf(MSG_DEBUG
, "nl80211: if_removed "
977 "already cleared - ignore event");
984 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_STATUS
, &event
);
988 static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data
*drv
,
991 int attrlen
, rta_len
;
995 attr
= (struct rtattr
*) buf
;
997 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
998 while (RTA_OK(attr
, attrlen
)) {
999 if (attr
->rta_type
== IFLA_IFNAME
) {
1000 if (os_strcmp(((char *) attr
) + rta_len
, drv
->first_bss
.ifname
)
1006 attr
= RTA_NEXT(attr
, attrlen
);
1013 static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data
*drv
,
1014 int ifindex
, u8
*buf
, size_t len
)
1016 if (drv
->ifindex
== ifindex
)
1019 if (drv
->if_removed
&& wpa_driver_nl80211_own_ifname(drv
, buf
, len
)) {
1020 drv
->first_bss
.ifindex
= if_nametoindex(drv
->first_bss
.ifname
);
1021 wpa_printf(MSG_DEBUG
, "nl80211: Update ifindex for a removed "
1023 wpa_driver_nl80211_finish_drv_init(drv
);
1031 static struct wpa_driver_nl80211_data
*
1032 nl80211_find_drv(struct nl80211_global
*global
, int idx
, u8
*buf
, size_t len
)
1034 struct wpa_driver_nl80211_data
*drv
;
1035 dl_list_for_each(drv
, &global
->interfaces
,
1036 struct wpa_driver_nl80211_data
, list
) {
1037 if (wpa_driver_nl80211_own_ifindex(drv
, idx
, buf
, len
) ||
1038 have_ifidx(drv
, idx
))
1045 static void wpa_driver_nl80211_event_rtm_newlink(void *ctx
,
1046 struct ifinfomsg
*ifi
,
1047 u8
*buf
, size_t len
)
1049 struct nl80211_global
*global
= ctx
;
1050 struct wpa_driver_nl80211_data
*drv
;
1051 int attrlen
, rta_len
;
1052 struct rtattr
*attr
;
1054 char namebuf
[IFNAMSIZ
];
1056 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1058 wpa_printf(MSG_DEBUG
, "nl80211: Ignore event for foreign "
1059 "ifindex %d", ifi
->ifi_index
);
1063 wpa_printf(MSG_DEBUG
, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
1065 drv
->operstate
, ifi
->ifi_flags
,
1066 (ifi
->ifi_flags
& IFF_UP
) ? "[UP]" : "",
1067 (ifi
->ifi_flags
& IFF_RUNNING
) ? "[RUNNING]" : "",
1068 (ifi
->ifi_flags
& IFF_LOWER_UP
) ? "[LOWER_UP]" : "",
1069 (ifi
->ifi_flags
& IFF_DORMANT
) ? "[DORMANT]" : "");
1071 if (!drv
->if_disabled
&& !(ifi
->ifi_flags
& IFF_UP
)) {
1072 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1073 linux_iface_up(drv
->global
->ioctl_sock
,
1074 drv
->first_bss
.ifname
) > 0) {
1075 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1076 "event since interface %s is up", namebuf
);
1079 wpa_printf(MSG_DEBUG
, "nl80211: Interface down");
1080 if (drv
->ignore_if_down_event
) {
1081 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface down "
1082 "event generated by mode change");
1083 drv
->ignore_if_down_event
= 0;
1085 drv
->if_disabled
= 1;
1086 wpa_supplicant_event(drv
->ctx
,
1087 EVENT_INTERFACE_DISABLED
, NULL
);
1091 if (drv
->if_disabled
&& (ifi
->ifi_flags
& IFF_UP
)) {
1092 if (if_indextoname(ifi
->ifi_index
, namebuf
) &&
1093 linux_iface_up(drv
->global
->ioctl_sock
,
1094 drv
->first_bss
.ifname
) == 0) {
1095 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1096 "event since interface %s is down",
1098 } else if (if_nametoindex(drv
->first_bss
.ifname
) == 0) {
1099 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1100 "event since interface %s does not exist",
1101 drv
->first_bss
.ifname
);
1102 } else if (drv
->if_removed
) {
1103 wpa_printf(MSG_DEBUG
, "nl80211: Ignore interface up "
1104 "event since interface %s is marked "
1105 "removed", drv
->first_bss
.ifname
);
1107 wpa_printf(MSG_DEBUG
, "nl80211: Interface up");
1108 drv
->if_disabled
= 0;
1109 wpa_supplicant_event(drv
->ctx
, EVENT_INTERFACE_ENABLED
,
1115 * Some drivers send the association event before the operup event--in
1116 * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
1117 * fails. This will hit us when wpa_supplicant does not need to do
1118 * IEEE 802.1X authentication
1120 if (drv
->operstate
== 1 &&
1121 (ifi
->ifi_flags
& (IFF_LOWER_UP
| IFF_DORMANT
)) == IFF_LOWER_UP
&&
1122 !(ifi
->ifi_flags
& IFF_RUNNING
))
1123 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
1127 attr
= (struct rtattr
*) buf
;
1128 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1129 while (RTA_OK(attr
, attrlen
)) {
1130 if (attr
->rta_type
== IFLA_IFNAME
) {
1131 wpa_driver_nl80211_event_link(
1133 ((char *) attr
) + rta_len
,
1134 attr
->rta_len
- rta_len
, 0);
1135 } else if (attr
->rta_type
== IFLA_MASTER
)
1136 brid
= nla_get_u32((struct nlattr
*) attr
);
1137 attr
= RTA_NEXT(attr
, attrlen
);
1140 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1141 /* device has been added to bridge */
1142 if_indextoname(brid
, namebuf
);
1143 wpa_printf(MSG_DEBUG
, "nl80211: Add ifindex %u for bridge %s",
1145 add_ifidx(drv
, brid
);
1150 static void wpa_driver_nl80211_event_rtm_dellink(void *ctx
,
1151 struct ifinfomsg
*ifi
,
1152 u8
*buf
, size_t len
)
1154 struct nl80211_global
*global
= ctx
;
1155 struct wpa_driver_nl80211_data
*drv
;
1156 int attrlen
, rta_len
;
1157 struct rtattr
*attr
;
1160 drv
= nl80211_find_drv(global
, ifi
->ifi_index
, buf
, len
);
1162 wpa_printf(MSG_DEBUG
, "nl80211: Ignore dellink event for "
1163 "foreign ifindex %d", ifi
->ifi_index
);
1168 attr
= (struct rtattr
*) buf
;
1170 rta_len
= RTA_ALIGN(sizeof(struct rtattr
));
1171 while (RTA_OK(attr
, attrlen
)) {
1172 if (attr
->rta_type
== IFLA_IFNAME
) {
1173 wpa_driver_nl80211_event_link(
1175 ((char *) attr
) + rta_len
,
1176 attr
->rta_len
- rta_len
, 1);
1177 } else if (attr
->rta_type
== IFLA_MASTER
)
1178 brid
= nla_get_u32((struct nlattr
*) attr
);
1179 attr
= RTA_NEXT(attr
, attrlen
);
1182 if (ifi
->ifi_family
== AF_BRIDGE
&& brid
) {
1183 /* device has been removed from bridge */
1184 char namebuf
[IFNAMSIZ
];
1185 if_indextoname(brid
, namebuf
);
1186 wpa_printf(MSG_DEBUG
, "nl80211: Remove ifindex %u for bridge "
1187 "%s", brid
, namebuf
);
1188 del_ifidx(drv
, brid
);
1193 static void mlme_event_auth(struct wpa_driver_nl80211_data
*drv
,
1194 const u8
*frame
, size_t len
)
1196 const struct ieee80211_mgmt
*mgmt
;
1197 union wpa_event_data event
;
1199 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate event");
1200 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1201 if (len
< 24 + sizeof(mgmt
->u
.auth
)) {
1202 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1207 os_memcpy(drv
->auth_bssid
, mgmt
->sa
, ETH_ALEN
);
1208 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
1209 os_memset(&event
, 0, sizeof(event
));
1210 os_memcpy(event
.auth
.peer
, mgmt
->sa
, ETH_ALEN
);
1211 event
.auth
.auth_type
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
1212 event
.auth
.auth_transaction
=
1213 le_to_host16(mgmt
->u
.auth
.auth_transaction
);
1214 event
.auth
.status_code
= le_to_host16(mgmt
->u
.auth
.status_code
);
1215 if (len
> 24 + sizeof(mgmt
->u
.auth
)) {
1216 event
.auth
.ies
= mgmt
->u
.auth
.variable
;
1217 event
.auth
.ies_len
= len
- 24 - sizeof(mgmt
->u
.auth
);
1220 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH
, &event
);
1224 static unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data
*drv
)
1228 struct nl80211_bss_info_arg arg
;
1230 os_memset(&arg
, 0, sizeof(arg
));
1231 msg
= nlmsg_alloc();
1233 goto nla_put_failure
;
1235 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
1236 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1239 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
1242 wpa_printf(MSG_DEBUG
, "nl80211: Operating frequency for the "
1243 "associated BSS from scan results: %u MHz",
1245 return arg
.assoc_freq
? arg
.assoc_freq
: drv
->assoc_freq
;
1247 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
1248 "(%s)", ret
, strerror(-ret
));
1251 return drv
->assoc_freq
;
1255 static void mlme_event_assoc(struct wpa_driver_nl80211_data
*drv
,
1256 const u8
*frame
, size_t len
)
1258 const struct ieee80211_mgmt
*mgmt
;
1259 union wpa_event_data event
;
1262 wpa_printf(MSG_DEBUG
, "nl80211: Associate event");
1263 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1264 if (len
< 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1265 wpa_printf(MSG_DEBUG
, "nl80211: Too short association event "
1270 status
= le_to_host16(mgmt
->u
.assoc_resp
.status_code
);
1271 if (status
!= WLAN_STATUS_SUCCESS
) {
1272 os_memset(&event
, 0, sizeof(event
));
1273 event
.assoc_reject
.bssid
= mgmt
->bssid
;
1274 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1275 event
.assoc_reject
.resp_ies
=
1276 (u8
*) mgmt
->u
.assoc_resp
.variable
;
1277 event
.assoc_reject
.resp_ies_len
=
1278 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1280 event
.assoc_reject
.status_code
= status
;
1282 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1286 drv
->associated
= 1;
1287 os_memcpy(drv
->bssid
, mgmt
->sa
, ETH_ALEN
);
1288 os_memcpy(drv
->prev_bssid
, mgmt
->sa
, ETH_ALEN
);
1290 os_memset(&event
, 0, sizeof(event
));
1291 if (len
> 24 + sizeof(mgmt
->u
.assoc_resp
)) {
1292 event
.assoc_info
.resp_ies
= (u8
*) mgmt
->u
.assoc_resp
.variable
;
1293 event
.assoc_info
.resp_ies_len
=
1294 len
- 24 - sizeof(mgmt
->u
.assoc_resp
);
1297 event
.assoc_info
.freq
= drv
->assoc_freq
;
1299 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1303 static void mlme_event_connect(struct wpa_driver_nl80211_data
*drv
,
1304 enum nl80211_commands cmd
, struct nlattr
*status
,
1305 struct nlattr
*addr
, struct nlattr
*req_ie
,
1306 struct nlattr
*resp_ie
)
1308 union wpa_event_data event
;
1310 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1312 * Avoid reporting two association events that would confuse
1315 wpa_printf(MSG_DEBUG
, "nl80211: Ignore connect event (cmd=%d) "
1316 "when using userspace SME", cmd
);
1320 if (cmd
== NL80211_CMD_CONNECT
)
1321 wpa_printf(MSG_DEBUG
, "nl80211: Connect event");
1322 else if (cmd
== NL80211_CMD_ROAM
)
1323 wpa_printf(MSG_DEBUG
, "nl80211: Roam event");
1325 os_memset(&event
, 0, sizeof(event
));
1326 if (cmd
== NL80211_CMD_CONNECT
&&
1327 nla_get_u16(status
) != WLAN_STATUS_SUCCESS
) {
1329 event
.assoc_reject
.bssid
= nla_data(addr
);
1331 event
.assoc_reject
.resp_ies
= nla_data(resp_ie
);
1332 event
.assoc_reject
.resp_ies_len
= nla_len(resp_ie
);
1334 event
.assoc_reject
.status_code
= nla_get_u16(status
);
1335 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC_REJECT
, &event
);
1339 drv
->associated
= 1;
1341 os_memcpy(drv
->bssid
, nla_data(addr
), ETH_ALEN
);
1342 os_memcpy(drv
->prev_bssid
, drv
->bssid
, ETH_ALEN
);
1346 event
.assoc_info
.req_ies
= nla_data(req_ie
);
1347 event
.assoc_info
.req_ies_len
= nla_len(req_ie
);
1350 event
.assoc_info
.resp_ies
= nla_data(resp_ie
);
1351 event
.assoc_info
.resp_ies_len
= nla_len(resp_ie
);
1354 event
.assoc_info
.freq
= nl80211_get_assoc_freq(drv
);
1356 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, &event
);
1360 static void mlme_event_disconnect(struct wpa_driver_nl80211_data
*drv
,
1361 struct nlattr
*reason
, struct nlattr
*addr
,
1362 struct nlattr
*by_ap
)
1364 union wpa_event_data data
;
1365 unsigned int locally_generated
= by_ap
== NULL
;
1367 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
1369 * Avoid reporting two disassociation events that could
1370 * confuse the core code.
1372 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1373 "event when using userspace SME");
1377 if (drv
->ignore_next_local_disconnect
) {
1378 drv
->ignore_next_local_disconnect
= 0;
1379 if (locally_generated
) {
1380 wpa_printf(MSG_DEBUG
, "nl80211: Ignore disconnect "
1381 "event triggered during reassociation");
1384 wpa_printf(MSG_WARNING
, "nl80211: Was expecting local "
1385 "disconnect but got another disconnect "
1389 wpa_printf(MSG_DEBUG
, "nl80211: Disconnect event");
1390 nl80211_mark_disconnected(drv
);
1391 os_memset(&data
, 0, sizeof(data
));
1393 data
.deauth_info
.reason_code
= nla_get_u16(reason
);
1394 data
.deauth_info
.locally_generated
= by_ap
== NULL
;
1395 wpa_supplicant_event(drv
->ctx
, EVENT_DEAUTH
, &data
);
1399 static void mlme_event_ch_switch(struct wpa_driver_nl80211_data
*drv
,
1400 struct nlattr
*freq
, struct nlattr
*type
)
1402 union wpa_event_data data
;
1404 int chan_offset
= 0;
1406 wpa_printf(MSG_DEBUG
, "nl80211: Channel switch event");
1411 switch (nla_get_u32(type
)) {
1412 case NL80211_CHAN_NO_HT
:
1415 case NL80211_CHAN_HT20
:
1417 case NL80211_CHAN_HT40PLUS
:
1420 case NL80211_CHAN_HT40MINUS
:
1425 data
.ch_switch
.freq
= nla_get_u32(freq
);
1426 data
.ch_switch
.ht_enabled
= ht_enabled
;
1427 data
.ch_switch
.ch_offset
= chan_offset
;
1429 wpa_supplicant_event(drv
->ctx
, EVENT_CH_SWITCH
, &data
);
1433 static void mlme_timeout_event(struct wpa_driver_nl80211_data
*drv
,
1434 enum nl80211_commands cmd
, struct nlattr
*addr
)
1436 union wpa_event_data event
;
1437 enum wpa_event_type ev
;
1439 if (nla_len(addr
) != ETH_ALEN
)
1442 wpa_printf(MSG_DEBUG
, "nl80211: MLME event %d; timeout with " MACSTR
,
1443 cmd
, MAC2STR((u8
*) nla_data(addr
)));
1445 if (cmd
== NL80211_CMD_AUTHENTICATE
)
1446 ev
= EVENT_AUTH_TIMED_OUT
;
1447 else if (cmd
== NL80211_CMD_ASSOCIATE
)
1448 ev
= EVENT_ASSOC_TIMED_OUT
;
1452 os_memset(&event
, 0, sizeof(event
));
1453 os_memcpy(event
.timeout_event
.addr
, nla_data(addr
), ETH_ALEN
);
1454 wpa_supplicant_event(drv
->ctx
, ev
, &event
);
1458 static void mlme_event_mgmt(struct wpa_driver_nl80211_data
*drv
,
1459 struct nlattr
*freq
, struct nlattr
*sig
,
1460 const u8
*frame
, size_t len
)
1462 const struct ieee80211_mgmt
*mgmt
;
1463 union wpa_event_data event
;
1467 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame event");
1468 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1470 wpa_printf(MSG_DEBUG
, "nl80211: Too short action frame");
1474 fc
= le_to_host16(mgmt
->frame_control
);
1475 stype
= WLAN_FC_GET_STYPE(fc
);
1478 ssi_signal
= (s32
) nla_get_u32(sig
);
1480 os_memset(&event
, 0, sizeof(event
));
1482 event
.rx_action
.freq
= nla_get_u32(freq
);
1483 drv
->last_mgmt_freq
= event
.rx_action
.freq
;
1485 if (stype
== WLAN_FC_STYPE_ACTION
) {
1486 event
.rx_action
.da
= mgmt
->da
;
1487 event
.rx_action
.sa
= mgmt
->sa
;
1488 event
.rx_action
.bssid
= mgmt
->bssid
;
1489 event
.rx_action
.category
= mgmt
->u
.action
.category
;
1490 event
.rx_action
.data
= &mgmt
->u
.action
.category
+ 1;
1491 event
.rx_action
.len
= frame
+ len
- event
.rx_action
.data
;
1492 wpa_supplicant_event(drv
->ctx
, EVENT_RX_ACTION
, &event
);
1494 event
.rx_mgmt
.frame
= frame
;
1495 event
.rx_mgmt
.frame_len
= len
;
1496 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
1497 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
1502 static void mlme_event_mgmt_tx_status(struct wpa_driver_nl80211_data
*drv
,
1503 struct nlattr
*cookie
, const u8
*frame
,
1504 size_t len
, struct nlattr
*ack
)
1506 union wpa_event_data event
;
1507 const struct ieee80211_hdr
*hdr
;
1510 wpa_printf(MSG_DEBUG
, "nl80211: Frame TX status event");
1511 if (!is_ap_interface(drv
->nlmode
)) {
1517 cookie_val
= nla_get_u64(cookie
);
1518 wpa_printf(MSG_DEBUG
, "nl80211: Action TX status:"
1519 " cookie=0%llx%s (ack=%d)",
1520 (long long unsigned int) cookie_val
,
1521 cookie_val
== drv
->send_action_cookie
?
1522 " (match)" : " (unknown)", ack
!= NULL
);
1523 if (cookie_val
!= drv
->send_action_cookie
)
1527 hdr
= (const struct ieee80211_hdr
*) frame
;
1528 fc
= le_to_host16(hdr
->frame_control
);
1530 os_memset(&event
, 0, sizeof(event
));
1531 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
1532 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
1533 event
.tx_status
.dst
= hdr
->addr1
;
1534 event
.tx_status
.data
= frame
;
1535 event
.tx_status
.data_len
= len
;
1536 event
.tx_status
.ack
= ack
!= NULL
;
1537 wpa_supplicant_event(drv
->ctx
, EVENT_TX_STATUS
, &event
);
1541 static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data
*drv
,
1542 enum wpa_event_type type
,
1543 const u8
*frame
, size_t len
)
1545 const struct ieee80211_mgmt
*mgmt
;
1546 union wpa_event_data event
;
1547 const u8
*bssid
= NULL
;
1548 u16 reason_code
= 0;
1550 if (type
== EVENT_DEAUTH
)
1551 wpa_printf(MSG_DEBUG
, "nl80211: Deauthenticate event");
1553 wpa_printf(MSG_DEBUG
, "nl80211: Disassociate event");
1555 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1557 bssid
= mgmt
->bssid
;
1559 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) &&
1561 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0 &&
1562 os_memcmp(bssid
, drv
->auth_attempt_bssid
, ETH_ALEN
) != 0 &&
1563 os_memcmp(bssid
, drv
->prev_bssid
, ETH_ALEN
) == 0) {
1565 * Avoid issues with some roaming cases where
1566 * disconnection event for the old AP may show up after
1567 * we have started connection with the new AP.
1569 wpa_printf(MSG_DEBUG
, "nl80211: Ignore deauth/disassoc event from old AP " MACSTR
" when already authenticating with " MACSTR
,
1571 MAC2STR(drv
->auth_attempt_bssid
));
1575 if (drv
->associated
!= 0 &&
1576 os_memcmp(bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
1577 os_memcmp(bssid
, drv
->auth_bssid
, ETH_ALEN
) != 0) {
1579 * We have presumably received this deauth as a
1580 * response to a clear_state_mismatch() outgoing
1581 * deauth. Don't let it take us offline!
1583 wpa_printf(MSG_DEBUG
, "nl80211: Deauth received "
1584 "from Unknown BSSID " MACSTR
" -- ignoring",
1590 nl80211_mark_disconnected(drv
);
1591 os_memset(&event
, 0, sizeof(event
));
1593 /* Note: Same offset for Reason Code in both frame subtypes */
1594 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1595 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1597 if (type
== EVENT_DISASSOC
) {
1598 event
.disassoc_info
.locally_generated
=
1599 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1600 event
.disassoc_info
.addr
= bssid
;
1601 event
.disassoc_info
.reason_code
= reason_code
;
1602 if (frame
+ len
> mgmt
->u
.disassoc
.variable
) {
1603 event
.disassoc_info
.ie
= mgmt
->u
.disassoc
.variable
;
1604 event
.disassoc_info
.ie_len
= frame
+ len
-
1605 mgmt
->u
.disassoc
.variable
;
1608 event
.deauth_info
.locally_generated
=
1609 !os_memcmp(mgmt
->sa
, drv
->first_bss
.addr
, ETH_ALEN
);
1610 event
.deauth_info
.addr
= bssid
;
1611 event
.deauth_info
.reason_code
= reason_code
;
1612 if (frame
+ len
> mgmt
->u
.deauth
.variable
) {
1613 event
.deauth_info
.ie
= mgmt
->u
.deauth
.variable
;
1614 event
.deauth_info
.ie_len
= frame
+ len
-
1615 mgmt
->u
.deauth
.variable
;
1619 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1623 static void mlme_event_unprot_disconnect(struct wpa_driver_nl80211_data
*drv
,
1624 enum wpa_event_type type
,
1625 const u8
*frame
, size_t len
)
1627 const struct ieee80211_mgmt
*mgmt
;
1628 union wpa_event_data event
;
1629 u16 reason_code
= 0;
1631 if (type
== EVENT_UNPROT_DEAUTH
)
1632 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Deauthenticate event");
1634 wpa_printf(MSG_DEBUG
, "nl80211: Unprot Disassociate event");
1639 mgmt
= (const struct ieee80211_mgmt
*) frame
;
1641 os_memset(&event
, 0, sizeof(event
));
1642 /* Note: Same offset for Reason Code in both frame subtypes */
1643 if (len
>= 24 + sizeof(mgmt
->u
.deauth
))
1644 reason_code
= le_to_host16(mgmt
->u
.deauth
.reason_code
);
1646 if (type
== EVENT_UNPROT_DISASSOC
) {
1647 event
.unprot_disassoc
.sa
= mgmt
->sa
;
1648 event
.unprot_disassoc
.da
= mgmt
->da
;
1649 event
.unprot_disassoc
.reason_code
= reason_code
;
1651 event
.unprot_deauth
.sa
= mgmt
->sa
;
1652 event
.unprot_deauth
.da
= mgmt
->da
;
1653 event
.unprot_deauth
.reason_code
= reason_code
;
1656 wpa_supplicant_event(drv
->ctx
, type
, &event
);
1660 static void mlme_event(struct i802_bss
*bss
,
1661 enum nl80211_commands cmd
, struct nlattr
*frame
,
1662 struct nlattr
*addr
, struct nlattr
*timed_out
,
1663 struct nlattr
*freq
, struct nlattr
*ack
,
1664 struct nlattr
*cookie
, struct nlattr
*sig
)
1666 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
1670 if (timed_out
&& addr
) {
1671 mlme_timeout_event(drv
, cmd
, addr
);
1675 if (frame
== NULL
) {
1676 wpa_printf(MSG_DEBUG
,
1677 "nl80211: MLME event %d (%s) without frame data",
1678 cmd
, nl80211_command_to_string(cmd
));
1682 data
= nla_data(frame
);
1683 len
= nla_len(frame
);
1684 if (len
< 4 + 2 * ETH_ALEN
) {
1685 wpa_printf(MSG_MSGDUMP
, "nl80211: MLME event %d (%s) on %s("
1686 MACSTR
") - too short",
1687 cmd
, nl80211_command_to_string(cmd
), bss
->ifname
,
1688 MAC2STR(bss
->addr
));
1691 wpa_printf(MSG_MSGDUMP
, "nl80211: MLME event %d (%s) on %s(" MACSTR
1692 ") A1=" MACSTR
" A2=" MACSTR
, cmd
,
1693 nl80211_command_to_string(cmd
), bss
->ifname
,
1694 MAC2STR(bss
->addr
), MAC2STR(data
+ 4),
1695 MAC2STR(data
+ 4 + ETH_ALEN
));
1696 if (cmd
!= NL80211_CMD_FRAME_TX_STATUS
&& !(data
[4] & 0x01) &&
1697 os_memcmp(bss
->addr
, data
+ 4, ETH_ALEN
) != 0 &&
1698 os_memcmp(bss
->addr
, data
+ 4 + ETH_ALEN
, ETH_ALEN
) != 0) {
1699 wpa_printf(MSG_MSGDUMP
, "nl80211: %s: Ignore MLME frame event "
1700 "for foreign address", bss
->ifname
);
1703 wpa_hexdump(MSG_MSGDUMP
, "nl80211: MLME event frame",
1704 nla_data(frame
), nla_len(frame
));
1707 case NL80211_CMD_AUTHENTICATE
:
1708 mlme_event_auth(drv
, nla_data(frame
), nla_len(frame
));
1710 case NL80211_CMD_ASSOCIATE
:
1711 mlme_event_assoc(drv
, nla_data(frame
), nla_len(frame
));
1713 case NL80211_CMD_DEAUTHENTICATE
:
1714 mlme_event_deauth_disassoc(drv
, EVENT_DEAUTH
,
1715 nla_data(frame
), nla_len(frame
));
1717 case NL80211_CMD_DISASSOCIATE
:
1718 mlme_event_deauth_disassoc(drv
, EVENT_DISASSOC
,
1719 nla_data(frame
), nla_len(frame
));
1721 case NL80211_CMD_FRAME
:
1722 mlme_event_mgmt(drv
, freq
, sig
, nla_data(frame
),
1725 case NL80211_CMD_FRAME_TX_STATUS
:
1726 mlme_event_mgmt_tx_status(drv
, cookie
, nla_data(frame
),
1727 nla_len(frame
), ack
);
1729 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
1730 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DEAUTH
,
1731 nla_data(frame
), nla_len(frame
));
1733 case NL80211_CMD_UNPROT_DISASSOCIATE
:
1734 mlme_event_unprot_disconnect(drv
, EVENT_UNPROT_DISASSOC
,
1735 nla_data(frame
), nla_len(frame
));
1743 static void mlme_event_michael_mic_failure(struct i802_bss
*bss
,
1744 struct nlattr
*tb
[])
1746 union wpa_event_data data
;
1748 wpa_printf(MSG_DEBUG
, "nl80211: MLME event Michael MIC failure");
1749 os_memset(&data
, 0, sizeof(data
));
1750 if (tb
[NL80211_ATTR_MAC
]) {
1751 wpa_hexdump(MSG_DEBUG
, "nl80211: Source MAC address",
1752 nla_data(tb
[NL80211_ATTR_MAC
]),
1753 nla_len(tb
[NL80211_ATTR_MAC
]));
1754 data
.michael_mic_failure
.src
= nla_data(tb
[NL80211_ATTR_MAC
]);
1756 if (tb
[NL80211_ATTR_KEY_SEQ
]) {
1757 wpa_hexdump(MSG_DEBUG
, "nl80211: TSC",
1758 nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
1759 nla_len(tb
[NL80211_ATTR_KEY_SEQ
]));
1761 if (tb
[NL80211_ATTR_KEY_TYPE
]) {
1762 enum nl80211_key_type key_type
=
1763 nla_get_u32(tb
[NL80211_ATTR_KEY_TYPE
]);
1764 wpa_printf(MSG_DEBUG
, "nl80211: Key Type %d", key_type
);
1765 if (key_type
== NL80211_KEYTYPE_PAIRWISE
)
1766 data
.michael_mic_failure
.unicast
= 1;
1768 data
.michael_mic_failure
.unicast
= 1;
1770 if (tb
[NL80211_ATTR_KEY_IDX
]) {
1771 u8 key_id
= nla_get_u8(tb
[NL80211_ATTR_KEY_IDX
]);
1772 wpa_printf(MSG_DEBUG
, "nl80211: Key Id %d", key_id
);
1775 wpa_supplicant_event(bss
->ctx
, EVENT_MICHAEL_MIC_FAILURE
, &data
);
1779 static void mlme_event_join_ibss(struct wpa_driver_nl80211_data
*drv
,
1780 struct nlattr
*tb
[])
1782 if (tb
[NL80211_ATTR_MAC
] == NULL
) {
1783 wpa_printf(MSG_DEBUG
, "nl80211: No address in IBSS joined "
1787 os_memcpy(drv
->bssid
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1788 drv
->associated
= 1;
1789 wpa_printf(MSG_DEBUG
, "nl80211: IBSS " MACSTR
" joined",
1790 MAC2STR(drv
->bssid
));
1792 wpa_supplicant_event(drv
->ctx
, EVENT_ASSOC
, NULL
);
1796 static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data
*drv
,
1797 int cancel_event
, struct nlattr
*tb
[])
1799 unsigned int freq
, chan_type
, duration
;
1800 union wpa_event_data data
;
1803 if (tb
[NL80211_ATTR_WIPHY_FREQ
])
1804 freq
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_FREQ
]);
1808 if (tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
])
1809 chan_type
= nla_get_u32(tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1813 if (tb
[NL80211_ATTR_DURATION
])
1814 duration
= nla_get_u32(tb
[NL80211_ATTR_DURATION
]);
1818 if (tb
[NL80211_ATTR_COOKIE
])
1819 cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
1823 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel event (cancel=%d "
1824 "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
1825 cancel_event
, freq
, chan_type
, duration
,
1826 (long long unsigned int) cookie
,
1827 cookie
== drv
->remain_on_chan_cookie
? "match" : "unknown");
1829 if (cookie
!= drv
->remain_on_chan_cookie
)
1830 return; /* not for us */
1833 drv
->pending_remain_on_chan
= 0;
1835 os_memset(&data
, 0, sizeof(data
));
1836 data
.remain_on_channel
.freq
= freq
;
1837 data
.remain_on_channel
.duration
= duration
;
1838 wpa_supplicant_event(drv
->ctx
, cancel_event
?
1839 EVENT_CANCEL_REMAIN_ON_CHANNEL
:
1840 EVENT_REMAIN_ON_CHANNEL
, &data
);
1844 static void mlme_event_ft_event(struct wpa_driver_nl80211_data
*drv
,
1845 struct nlattr
*tb
[])
1847 union wpa_event_data data
;
1849 os_memset(&data
, 0, sizeof(data
));
1851 if (tb
[NL80211_ATTR_IE
]) {
1852 data
.ft_ies
.ies
= nla_data(tb
[NL80211_ATTR_IE
]);
1853 data
.ft_ies
.ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
1856 if (tb
[NL80211_ATTR_IE_RIC
]) {
1857 data
.ft_ies
.ric_ies
= nla_data(tb
[NL80211_ATTR_IE_RIC
]);
1858 data
.ft_ies
.ric_ies_len
= nla_len(tb
[NL80211_ATTR_IE_RIC
]);
1861 if (tb
[NL80211_ATTR_MAC
])
1862 os_memcpy(data
.ft_ies
.target_ap
,
1863 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
1865 wpa_printf(MSG_DEBUG
, "nl80211: FT event target_ap " MACSTR
,
1866 MAC2STR(data
.ft_ies
.target_ap
));
1868 wpa_supplicant_event(drv
->ctx
, EVENT_FT_RESPONSE
, &data
);
1872 static void send_scan_event(struct wpa_driver_nl80211_data
*drv
, int aborted
,
1873 struct nlattr
*tb
[])
1875 union wpa_event_data event
;
1878 struct scan_info
*info
;
1879 #define MAX_REPORT_FREQS 50
1880 int freqs
[MAX_REPORT_FREQS
];
1883 if (drv
->scan_for_auth
) {
1884 drv
->scan_for_auth
= 0;
1885 wpa_printf(MSG_DEBUG
, "nl80211: Scan results for missing "
1886 "cfg80211 BSS entry");
1887 wpa_driver_nl80211_authenticate_retry(drv
);
1891 os_memset(&event
, 0, sizeof(event
));
1892 info
= &event
.scan_info
;
1893 info
->aborted
= aborted
;
1895 if (tb
[NL80211_ATTR_SCAN_SSIDS
]) {
1896 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_SSIDS
], rem
) {
1897 struct wpa_driver_scan_ssid
*s
=
1898 &info
->ssids
[info
->num_ssids
];
1899 s
->ssid
= nla_data(nl
);
1900 s
->ssid_len
= nla_len(nl
);
1902 if (info
->num_ssids
== WPAS_MAX_SCAN_SSIDS
)
1906 if (tb
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
1907 nla_for_each_nested(nl
, tb
[NL80211_ATTR_SCAN_FREQUENCIES
], rem
)
1909 freqs
[num_freqs
] = nla_get_u32(nl
);
1911 if (num_freqs
== MAX_REPORT_FREQS
- 1)
1914 info
->freqs
= freqs
;
1915 info
->num_freqs
= num_freqs
;
1917 wpa_supplicant_event(drv
->ctx
, EVENT_SCAN_RESULTS
, &event
);
1921 static int get_link_signal(struct nl_msg
*msg
, void *arg
)
1923 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
1924 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
1925 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
1926 static struct nla_policy policy
[NL80211_STA_INFO_MAX
+ 1] = {
1927 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
1928 [NL80211_STA_INFO_SIGNAL_AVG
] = { .type
= NLA_U8
},
1930 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
1931 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
1932 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
1933 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
1934 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
1935 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
1937 struct wpa_signal_info
*sig_change
= arg
;
1939 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
1940 genlmsg_attrlen(gnlh
, 0), NULL
);
1941 if (!tb
[NL80211_ATTR_STA_INFO
] ||
1942 nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
1943 tb
[NL80211_ATTR_STA_INFO
], policy
))
1945 if (!sinfo
[NL80211_STA_INFO_SIGNAL
])
1948 sig_change
->current_signal
=
1949 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]);
1951 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
1952 sig_change
->avg_signal
=
1953 (s8
) nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]);
1955 sig_change
->avg_signal
= 0;
1957 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
1958 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
1959 sinfo
[NL80211_STA_INFO_TX_BITRATE
],
1961 sig_change
->current_txrate
= 0;
1963 if (rinfo
[NL80211_RATE_INFO_BITRATE
]) {
1964 sig_change
->current_txrate
=
1966 NL80211_RATE_INFO_BITRATE
]) * 100;
1975 static int nl80211_get_link_signal(struct wpa_driver_nl80211_data
*drv
,
1976 struct wpa_signal_info
*sig
)
1980 sig
->current_signal
= -9999;
1981 sig
->current_txrate
= 0;
1983 msg
= nlmsg_alloc();
1987 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
1989 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
1990 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
1992 return send_and_recv_msgs(drv
, msg
, get_link_signal
, sig
);
1999 static int get_link_noise(struct nl_msg
*msg
, void *arg
)
2001 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2002 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2003 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
2004 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
2005 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
2006 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
2008 struct wpa_signal_info
*sig_change
= arg
;
2010 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2011 genlmsg_attrlen(gnlh
, 0), NULL
);
2013 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
2014 wpa_printf(MSG_DEBUG
, "nl80211: survey data missing!");
2018 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
2019 tb
[NL80211_ATTR_SURVEY_INFO
],
2021 wpa_printf(MSG_DEBUG
, "nl80211: failed to parse nested "
2026 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
2029 if (nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
2030 sig_change
->frequency
)
2033 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
2036 sig_change
->current_noise
=
2037 (s8
) nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
2043 static int nl80211_get_link_noise(struct wpa_driver_nl80211_data
*drv
,
2044 struct wpa_signal_info
*sig_change
)
2048 sig_change
->current_noise
= 9999;
2049 sig_change
->frequency
= drv
->assoc_freq
;
2051 msg
= nlmsg_alloc();
2055 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
2057 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2059 return send_and_recv_msgs(drv
, msg
, get_link_noise
, sig_change
);
2066 static int get_noise_for_scan_results(struct nl_msg
*msg
, void *arg
)
2068 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2069 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2070 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
2071 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
2072 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
2073 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
2075 struct wpa_scan_results
*scan_results
= arg
;
2076 struct wpa_scan_res
*scan_res
;
2079 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2080 genlmsg_attrlen(gnlh
, 0), NULL
);
2082 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
2083 wpa_printf(MSG_DEBUG
, "nl80211: Survey data missing");
2087 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
2088 tb
[NL80211_ATTR_SURVEY_INFO
],
2090 wpa_printf(MSG_DEBUG
, "nl80211: Failed to parse nested "
2095 if (!sinfo
[NL80211_SURVEY_INFO_NOISE
])
2098 if (!sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
2101 for (i
= 0; i
< scan_results
->num
; ++i
) {
2102 scan_res
= scan_results
->res
[i
];
2105 if ((int) nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]) !=
2108 if (!(scan_res
->flags
& WPA_SCAN_NOISE_INVALID
))
2110 scan_res
->noise
= (s8
)
2111 nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]);
2112 scan_res
->flags
&= ~WPA_SCAN_NOISE_INVALID
;
2119 static int nl80211_get_noise_for_scan_results(
2120 struct wpa_driver_nl80211_data
*drv
,
2121 struct wpa_scan_results
*scan_res
)
2125 msg
= nlmsg_alloc();
2129 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SURVEY
);
2131 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
2133 return send_and_recv_msgs(drv
, msg
, get_noise_for_scan_results
,
2141 static void nl80211_cqm_event(struct wpa_driver_nl80211_data
*drv
,
2142 struct nlattr
*tb
[])
2144 static struct nla_policy cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] = {
2145 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
2146 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U8
},
2147 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
2148 [NL80211_ATTR_CQM_PKT_LOSS_EVENT
] = { .type
= NLA_U32
},
2150 struct nlattr
*cqm
[NL80211_ATTR_CQM_MAX
+ 1];
2151 enum nl80211_cqm_rssi_threshold_event event
;
2152 union wpa_event_data ed
;
2153 struct wpa_signal_info sig
;
2156 if (tb
[NL80211_ATTR_CQM
] == NULL
||
2157 nla_parse_nested(cqm
, NL80211_ATTR_CQM_MAX
, tb
[NL80211_ATTR_CQM
],
2159 wpa_printf(MSG_DEBUG
, "nl80211: Ignore invalid CQM event");
2163 os_memset(&ed
, 0, sizeof(ed
));
2165 if (cqm
[NL80211_ATTR_CQM_PKT_LOSS_EVENT
]) {
2166 if (!tb
[NL80211_ATTR_MAC
])
2168 os_memcpy(ed
.low_ack
.addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
2170 wpa_supplicant_event(drv
->ctx
, EVENT_STATION_LOW_ACK
, &ed
);
2174 if (cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] == NULL
)
2176 event
= nla_get_u32(cqm
[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
]);
2178 if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH
) {
2179 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
2180 "event: RSSI high");
2181 ed
.signal_change
.above_threshold
= 1;
2182 } else if (event
== NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW
) {
2183 wpa_printf(MSG_DEBUG
, "nl80211: Connection quality monitor "
2185 ed
.signal_change
.above_threshold
= 0;
2189 res
= nl80211_get_link_signal(drv
, &sig
);
2191 ed
.signal_change
.current_signal
= sig
.current_signal
;
2192 ed
.signal_change
.current_txrate
= sig
.current_txrate
;
2193 wpa_printf(MSG_DEBUG
, "nl80211: Signal: %d dBm txrate: %d",
2194 sig
.current_signal
, sig
.current_txrate
);
2197 res
= nl80211_get_link_noise(drv
, &sig
);
2199 ed
.signal_change
.current_noise
= sig
.current_noise
;
2200 wpa_printf(MSG_DEBUG
, "nl80211: Noise: %d dBm",
2204 wpa_supplicant_event(drv
->ctx
, EVENT_SIGNAL_CHANGE
, &ed
);
2208 static void nl80211_new_station_event(struct wpa_driver_nl80211_data
*drv
,
2212 union wpa_event_data data
;
2214 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2216 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2217 wpa_printf(MSG_DEBUG
, "nl80211: New station " MACSTR
, MAC2STR(addr
));
2219 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2222 if (tb
[NL80211_ATTR_IE
]) {
2223 ies
= nla_data(tb
[NL80211_ATTR_IE
]);
2224 ies_len
= nla_len(tb
[NL80211_ATTR_IE
]);
2226 wpa_hexdump(MSG_DEBUG
, "nl80211: Assoc Req IEs", ies
, ies_len
);
2227 drv_event_assoc(drv
->ctx
, addr
, ies
, ies_len
, 0);
2231 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2234 os_memset(&data
, 0, sizeof(data
));
2235 os_memcpy(data
.ibss_rsn_start
.peer
, addr
, ETH_ALEN
);
2236 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_RSN_START
, &data
);
2240 static void nl80211_del_station_event(struct wpa_driver_nl80211_data
*drv
,
2244 union wpa_event_data data
;
2246 if (tb
[NL80211_ATTR_MAC
] == NULL
)
2248 addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2249 wpa_printf(MSG_DEBUG
, "nl80211: Delete station " MACSTR
,
2252 if (is_ap_interface(drv
->nlmode
) && drv
->device_ap_sme
) {
2253 drv_event_disassoc(drv
->ctx
, addr
);
2257 if (drv
->nlmode
!= NL80211_IFTYPE_ADHOC
)
2260 os_memset(&data
, 0, sizeof(data
));
2261 os_memcpy(data
.ibss_peer_lost
.peer
, addr
, ETH_ALEN
);
2262 wpa_supplicant_event(drv
->ctx
, EVENT_IBSS_PEER_LOST
, &data
);
2266 static void nl80211_rekey_offload_event(struct wpa_driver_nl80211_data
*drv
,
2269 struct nlattr
*rekey_info
[NUM_NL80211_REKEY_DATA
];
2270 static struct nla_policy rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
2271 [NL80211_REKEY_DATA_KEK
] = {
2272 .minlen
= NL80211_KEK_LEN
,
2273 .maxlen
= NL80211_KEK_LEN
,
2275 [NL80211_REKEY_DATA_KCK
] = {
2276 .minlen
= NL80211_KCK_LEN
,
2277 .maxlen
= NL80211_KCK_LEN
,
2279 [NL80211_REKEY_DATA_REPLAY_CTR
] = {
2280 .minlen
= NL80211_REPLAY_CTR_LEN
,
2281 .maxlen
= NL80211_REPLAY_CTR_LEN
,
2284 union wpa_event_data data
;
2286 if (!tb
[NL80211_ATTR_MAC
])
2288 if (!tb
[NL80211_ATTR_REKEY_DATA
])
2290 if (nla_parse_nested(rekey_info
, MAX_NL80211_REKEY_DATA
,
2291 tb
[NL80211_ATTR_REKEY_DATA
], rekey_policy
))
2293 if (!rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
])
2296 os_memset(&data
, 0, sizeof(data
));
2297 data
.driver_gtk_rekey
.bssid
= nla_data(tb
[NL80211_ATTR_MAC
]);
2298 wpa_printf(MSG_DEBUG
, "nl80211: Rekey offload event for BSSID " MACSTR
,
2299 MAC2STR(data
.driver_gtk_rekey
.bssid
));
2300 data
.driver_gtk_rekey
.replay_ctr
=
2301 nla_data(rekey_info
[NL80211_REKEY_DATA_REPLAY_CTR
]);
2302 wpa_hexdump(MSG_DEBUG
, "nl80211: Rekey offload - Replay Counter",
2303 data
.driver_gtk_rekey
.replay_ctr
, NL80211_REPLAY_CTR_LEN
);
2304 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_GTK_REKEY
, &data
);
2308 static void nl80211_pmksa_candidate_event(struct wpa_driver_nl80211_data
*drv
,
2311 struct nlattr
*cand
[NUM_NL80211_PMKSA_CANDIDATE
];
2312 static struct nla_policy cand_policy
[NUM_NL80211_PMKSA_CANDIDATE
] = {
2313 [NL80211_PMKSA_CANDIDATE_INDEX
] = { .type
= NLA_U32
},
2314 [NL80211_PMKSA_CANDIDATE_BSSID
] = {
2318 [NL80211_PMKSA_CANDIDATE_PREAUTH
] = { .type
= NLA_FLAG
},
2320 union wpa_event_data data
;
2322 wpa_printf(MSG_DEBUG
, "nl80211: PMKSA candidate event");
2324 if (!tb
[NL80211_ATTR_PMKSA_CANDIDATE
])
2326 if (nla_parse_nested(cand
, MAX_NL80211_PMKSA_CANDIDATE
,
2327 tb
[NL80211_ATTR_PMKSA_CANDIDATE
], cand_policy
))
2329 if (!cand
[NL80211_PMKSA_CANDIDATE_INDEX
] ||
2330 !cand
[NL80211_PMKSA_CANDIDATE_BSSID
])
2333 os_memset(&data
, 0, sizeof(data
));
2334 os_memcpy(data
.pmkid_candidate
.bssid
,
2335 nla_data(cand
[NL80211_PMKSA_CANDIDATE_BSSID
]), ETH_ALEN
);
2336 data
.pmkid_candidate
.index
=
2337 nla_get_u32(cand
[NL80211_PMKSA_CANDIDATE_INDEX
]);
2338 data
.pmkid_candidate
.preauth
=
2339 cand
[NL80211_PMKSA_CANDIDATE_PREAUTH
] != NULL
;
2340 wpa_supplicant_event(drv
->ctx
, EVENT_PMKID_CANDIDATE
, &data
);
2344 static void nl80211_client_probe_event(struct wpa_driver_nl80211_data
*drv
,
2347 union wpa_event_data data
;
2349 wpa_printf(MSG_DEBUG
, "nl80211: Probe client event");
2351 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_ACK
])
2354 os_memset(&data
, 0, sizeof(data
));
2355 os_memcpy(data
.client_poll
.addr
,
2356 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2358 wpa_supplicant_event(drv
->ctx
, EVENT_DRIVER_CLIENT_POLL_OK
, &data
);
2362 static void nl80211_tdls_oper_event(struct wpa_driver_nl80211_data
*drv
,
2365 union wpa_event_data data
;
2367 wpa_printf(MSG_DEBUG
, "nl80211: TDLS operation event");
2369 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_TDLS_OPERATION
])
2372 os_memset(&data
, 0, sizeof(data
));
2373 os_memcpy(data
.tdls
.peer
, nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2374 switch (nla_get_u8(tb
[NL80211_ATTR_TDLS_OPERATION
])) {
2375 case NL80211_TDLS_SETUP
:
2376 wpa_printf(MSG_DEBUG
, "nl80211: TDLS setup request for peer "
2377 MACSTR
, MAC2STR(data
.tdls
.peer
));
2378 data
.tdls
.oper
= TDLS_REQUEST_SETUP
;
2380 case NL80211_TDLS_TEARDOWN
:
2381 wpa_printf(MSG_DEBUG
, "nl80211: TDLS teardown request for peer "
2382 MACSTR
, MAC2STR(data
.tdls
.peer
));
2383 data
.tdls
.oper
= TDLS_REQUEST_TEARDOWN
;
2386 wpa_printf(MSG_DEBUG
, "nl80211: Unsupported TDLS operatione "
2390 if (tb
[NL80211_ATTR_REASON_CODE
]) {
2391 data
.tdls
.reason_code
=
2392 nla_get_u16(tb
[NL80211_ATTR_REASON_CODE
]);
2395 wpa_supplicant_event(drv
->ctx
, EVENT_TDLS
, &data
);
2399 static void nl80211_connect_failed_event(struct wpa_driver_nl80211_data
*drv
,
2402 union wpa_event_data data
;
2405 wpa_printf(MSG_DEBUG
, "nl80211: Connect failed event");
2407 if (!tb
[NL80211_ATTR_MAC
] || !tb
[NL80211_ATTR_CONN_FAILED_REASON
])
2410 os_memset(&data
, 0, sizeof(data
));
2411 os_memcpy(data
.connect_failed_reason
.addr
,
2412 nla_data(tb
[NL80211_ATTR_MAC
]), ETH_ALEN
);
2414 reason
= nla_get_u32(tb
[NL80211_ATTR_CONN_FAILED_REASON
]);
2416 case NL80211_CONN_FAIL_MAX_CLIENTS
:
2417 wpa_printf(MSG_DEBUG
, "nl80211: Max client reached");
2418 data
.connect_failed_reason
.code
= MAX_CLIENT_REACHED
;
2420 case NL80211_CONN_FAIL_BLOCKED_CLIENT
:
2421 wpa_printf(MSG_DEBUG
, "nl80211: Blocked client " MACSTR
2422 " tried to connect",
2423 MAC2STR(data
.connect_failed_reason
.addr
));
2424 data
.connect_failed_reason
.code
= BLOCKED_CLIENT
;
2427 wpa_printf(MSG_DEBUG
, "nl8021l: Unknown connect failed reason "
2432 wpa_supplicant_event(drv
->ctx
, EVENT_CONNECT_FAILED_REASON
, &data
);
2436 static void nl80211_radar_event(struct wpa_driver_nl80211_data
*drv
,
2439 union wpa_event_data data
;
2440 enum nl80211_radar_event event_type
;
2442 if (!tb
[NL80211_ATTR_WIPHY_FREQ
] || !tb
[NL80211_ATTR_RADAR_EVENT
])
2445 os_memset(&data
, 0, sizeof(data
));
2446 data
.dfs_event
.freq
= nla_get_u16(tb
[NL80211_ATTR_WIPHY_FREQ
]);
2447 event_type
= nla_get_u8(tb
[NL80211_ATTR_RADAR_EVENT
]);
2449 wpa_printf(MSG_DEBUG
, "nl80211: DFS event on freq %d MHz",
2450 data
.dfs_event
.freq
);
2452 switch (event_type
) {
2453 case NL80211_RADAR_DETECTED
:
2454 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_RADAR_DETECTED
, &data
);
2456 case NL80211_RADAR_CAC_FINISHED
:
2457 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_CAC_FINISHED
, &data
);
2459 case NL80211_RADAR_CAC_ABORTED
:
2460 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_CAC_ABORTED
, &data
);
2462 case NL80211_RADAR_NOP_FINISHED
:
2463 wpa_supplicant_event(drv
->ctx
, EVENT_DFS_NOP_FINISHED
, &data
);
2466 wpa_printf(MSG_DEBUG
, "nl80211: Unknown radar event %d "
2467 "received", event_type
);
2473 static void nl80211_spurious_frame(struct i802_bss
*bss
, struct nlattr
**tb
,
2476 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2477 union wpa_event_data event
;
2479 if (!tb
[NL80211_ATTR_MAC
])
2482 os_memset(&event
, 0, sizeof(event
));
2483 event
.rx_from_unknown
.bssid
= bss
->addr
;
2484 event
.rx_from_unknown
.addr
= nla_data(tb
[NL80211_ATTR_MAC
]);
2485 event
.rx_from_unknown
.wds
= wds
;
2487 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
2491 static void do_process_drv_event(struct i802_bss
*bss
, int cmd
,
2494 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2496 wpa_printf(MSG_DEBUG
, "nl80211: Drv Event %d (%s) received for %s",
2497 cmd
, nl80211_command_to_string(cmd
), bss
->ifname
);
2499 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
&&
2500 (cmd
== NL80211_CMD_NEW_SCAN_RESULTS
||
2501 cmd
== NL80211_CMD_SCAN_ABORTED
)) {
2502 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
2503 drv
->ap_scan_as_station
);
2504 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
2508 case NL80211_CMD_TRIGGER_SCAN
:
2509 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Scan trigger");
2511 case NL80211_CMD_START_SCHED_SCAN
:
2512 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Sched scan started");
2514 case NL80211_CMD_SCHED_SCAN_STOPPED
:
2515 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Sched scan stopped");
2516 wpa_supplicant_event(drv
->ctx
, EVENT_SCHED_SCAN_STOPPED
, NULL
);
2518 case NL80211_CMD_NEW_SCAN_RESULTS
:
2519 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2520 "nl80211: New scan results available");
2521 drv
->scan_complete_events
= 1;
2522 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2524 send_scan_event(drv
, 0, tb
);
2526 case NL80211_CMD_SCHED_SCAN_RESULTS
:
2527 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
2528 "nl80211: New sched scan results available");
2529 send_scan_event(drv
, 0, tb
);
2531 case NL80211_CMD_SCAN_ABORTED
:
2532 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Scan aborted");
2534 * Need to indicate that scan results are available in order
2535 * not to make wpa_supplicant stop its scanning.
2537 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
,
2539 send_scan_event(drv
, 1, tb
);
2541 case NL80211_CMD_AUTHENTICATE
:
2542 case NL80211_CMD_ASSOCIATE
:
2543 case NL80211_CMD_DEAUTHENTICATE
:
2544 case NL80211_CMD_DISASSOCIATE
:
2545 case NL80211_CMD_FRAME_TX_STATUS
:
2546 case NL80211_CMD_UNPROT_DEAUTHENTICATE
:
2547 case NL80211_CMD_UNPROT_DISASSOCIATE
:
2548 mlme_event(bss
, cmd
, tb
[NL80211_ATTR_FRAME
],
2549 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2550 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2551 tb
[NL80211_ATTR_COOKIE
],
2552 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2554 case NL80211_CMD_CONNECT
:
2555 case NL80211_CMD_ROAM
:
2556 mlme_event_connect(drv
, cmd
,
2557 tb
[NL80211_ATTR_STATUS_CODE
],
2558 tb
[NL80211_ATTR_MAC
],
2559 tb
[NL80211_ATTR_REQ_IE
],
2560 tb
[NL80211_ATTR_RESP_IE
]);
2562 case NL80211_CMD_CH_SWITCH_NOTIFY
:
2563 mlme_event_ch_switch(drv
, tb
[NL80211_ATTR_WIPHY_FREQ
],
2564 tb
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
2566 case NL80211_CMD_DISCONNECT
:
2567 mlme_event_disconnect(drv
, tb
[NL80211_ATTR_REASON_CODE
],
2568 tb
[NL80211_ATTR_MAC
],
2569 tb
[NL80211_ATTR_DISCONNECTED_BY_AP
]);
2571 case NL80211_CMD_MICHAEL_MIC_FAILURE
:
2572 mlme_event_michael_mic_failure(bss
, tb
);
2574 case NL80211_CMD_JOIN_IBSS
:
2575 mlme_event_join_ibss(drv
, tb
);
2577 case NL80211_CMD_REMAIN_ON_CHANNEL
:
2578 mlme_event_remain_on_channel(drv
, 0, tb
);
2580 case NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
:
2581 mlme_event_remain_on_channel(drv
, 1, tb
);
2583 case NL80211_CMD_NOTIFY_CQM
:
2584 nl80211_cqm_event(drv
, tb
);
2586 case NL80211_CMD_REG_CHANGE
:
2587 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory domain change");
2588 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2591 case NL80211_CMD_REG_BEACON_HINT
:
2592 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory beacon hint");
2593 wpa_supplicant_event(drv
->ctx
, EVENT_CHANNEL_LIST_CHANGED
,
2596 case NL80211_CMD_NEW_STATION
:
2597 nl80211_new_station_event(drv
, tb
);
2599 case NL80211_CMD_DEL_STATION
:
2600 nl80211_del_station_event(drv
, tb
);
2602 case NL80211_CMD_SET_REKEY_OFFLOAD
:
2603 nl80211_rekey_offload_event(drv
, tb
);
2605 case NL80211_CMD_PMKSA_CANDIDATE
:
2606 nl80211_pmksa_candidate_event(drv
, tb
);
2608 case NL80211_CMD_PROBE_CLIENT
:
2609 nl80211_client_probe_event(drv
, tb
);
2611 case NL80211_CMD_TDLS_OPER
:
2612 nl80211_tdls_oper_event(drv
, tb
);
2614 case NL80211_CMD_CONN_FAILED
:
2615 nl80211_connect_failed_event(drv
, tb
);
2617 case NL80211_CMD_FT_EVENT
:
2618 mlme_event_ft_event(drv
, tb
);
2620 case NL80211_CMD_RADAR_DETECT
:
2621 nl80211_radar_event(drv
, tb
);
2624 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: Ignored unknown event "
2631 static int process_drv_event(struct nl_msg
*msg
, void *arg
)
2633 struct wpa_driver_nl80211_data
*drv
= arg
;
2634 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2635 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2636 struct i802_bss
*bss
;
2639 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2640 genlmsg_attrlen(gnlh
, 0), NULL
);
2642 if (tb
[NL80211_ATTR_IFINDEX
]) {
2643 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2645 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
)
2646 if (ifidx
== -1 || ifidx
== bss
->ifindex
) {
2647 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2650 wpa_printf(MSG_DEBUG
,
2651 "nl80211: Ignored event (cmd=%d) for foreign interface (ifindex %d)",
2653 } else if (tb
[NL80211_ATTR_WDEV
]) {
2654 u64 wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
2655 wpa_printf(MSG_DEBUG
, "nl80211: Process event on P2P device");
2656 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
) {
2657 if (bss
->wdev_id_set
&& wdev_id
== bss
->wdev_id
) {
2658 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2662 wpa_printf(MSG_DEBUG
,
2663 "nl80211: Ignored event (cmd=%d) for foreign interface (wdev 0x%llx)",
2664 gnlh
->cmd
, (long long unsigned int) wdev_id
);
2671 static int process_global_event(struct nl_msg
*msg
, void *arg
)
2673 struct nl80211_global
*global
= arg
;
2674 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2675 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2676 struct wpa_driver_nl80211_data
*drv
, *tmp
;
2678 struct i802_bss
*bss
;
2680 int wdev_id_set
= 0;
2682 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2683 genlmsg_attrlen(gnlh
, 0), NULL
);
2685 if (tb
[NL80211_ATTR_IFINDEX
])
2686 ifidx
= nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]);
2687 else if (tb
[NL80211_ATTR_WDEV
]) {
2688 wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
2692 dl_list_for_each_safe(drv
, tmp
, &global
->interfaces
,
2693 struct wpa_driver_nl80211_data
, list
) {
2694 for (bss
= &drv
->first_bss
; bss
; bss
= bss
->next
) {
2695 if ((ifidx
== -1 && !wdev_id_set
) ||
2696 ifidx
== bss
->ifindex
||
2697 (wdev_id_set
&& bss
->wdev_id_set
&&
2698 wdev_id
== bss
->wdev_id
)) {
2699 do_process_drv_event(bss
, gnlh
->cmd
, tb
);
2709 static int process_bss_event(struct nl_msg
*msg
, void *arg
)
2711 struct i802_bss
*bss
= arg
;
2712 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2713 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
2715 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2716 genlmsg_attrlen(gnlh
, 0), NULL
);
2718 wpa_printf(MSG_DEBUG
, "nl80211: BSS Event %d (%s) received for %s",
2719 gnlh
->cmd
, nl80211_command_to_string(gnlh
->cmd
),
2722 switch (gnlh
->cmd
) {
2723 case NL80211_CMD_FRAME
:
2724 case NL80211_CMD_FRAME_TX_STATUS
:
2725 mlme_event(bss
, gnlh
->cmd
, tb
[NL80211_ATTR_FRAME
],
2726 tb
[NL80211_ATTR_MAC
], tb
[NL80211_ATTR_TIMED_OUT
],
2727 tb
[NL80211_ATTR_WIPHY_FREQ
], tb
[NL80211_ATTR_ACK
],
2728 tb
[NL80211_ATTR_COOKIE
],
2729 tb
[NL80211_ATTR_RX_SIGNAL_DBM
]);
2731 case NL80211_CMD_UNEXPECTED_FRAME
:
2732 nl80211_spurious_frame(bss
, tb
, 0);
2734 case NL80211_CMD_UNEXPECTED_4ADDR_FRAME
:
2735 nl80211_spurious_frame(bss
, tb
, 1);
2738 wpa_printf(MSG_DEBUG
, "nl80211: Ignored unknown event "
2739 "(cmd=%d)", gnlh
->cmd
);
2747 static void wpa_driver_nl80211_event_receive(int sock
, void *eloop_ctx
,
2750 struct nl_cb
*cb
= eloop_ctx
;
2752 wpa_printf(MSG_MSGDUMP
, "nl80211: Event message available");
2754 nl_recvmsgs(handle
, cb
);
2759 * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
2760 * @priv: driver_nl80211 private data
2761 * @alpha2_arg: country to which to switch to
2762 * Returns: 0 on success, -1 on failure
2764 * This asks nl80211 to set the regulatory domain for given
2765 * country ISO / IEC alpha2.
2767 static int wpa_driver_nl80211_set_country(void *priv
, const char *alpha2_arg
)
2769 struct i802_bss
*bss
= priv
;
2770 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
2774 msg
= nlmsg_alloc();
2778 alpha2
[0] = alpha2_arg
[0];
2779 alpha2
[1] = alpha2_arg
[1];
2782 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REQ_SET_REG
);
2784 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, alpha2
);
2785 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
))
2794 static int protocol_feature_handler(struct nl_msg
*msg
, void *arg
)
2797 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
2798 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
2800 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
2801 genlmsg_attrlen(gnlh
, 0), NULL
);
2803 if (tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
])
2804 *feat
= nla_get_u32(tb_msg
[NL80211_ATTR_PROTOCOL_FEATURES
]);
2810 static u32
get_nl80211_protocol_features(struct wpa_driver_nl80211_data
*drv
)
2815 msg
= nlmsg_alloc();
2817 goto nla_put_failure
;
2819 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_PROTOCOL_FEATURES
);
2820 if (send_and_recv_msgs(drv
, msg
, protocol_feature_handler
, &feat
) == 0)
2830 struct wiphy_info_data
{
2831 struct wpa_driver_nl80211_data
*drv
;
2832 struct wpa_driver_capa
*capa
;
2834 unsigned int error
:1;
2835 unsigned int device_ap_sme
:1;
2836 unsigned int poll_command_supported
:1;
2837 unsigned int data_tx_status
:1;
2838 unsigned int monitor_supported
:1;
2839 unsigned int auth_supported
:1;
2840 unsigned int connect_supported
:1;
2841 unsigned int p2p_go_supported
:1;
2842 unsigned int p2p_client_supported
:1;
2843 unsigned int p2p_concurrent
:1;
2844 unsigned int p2p_multichan_concurrent
:1;
2848 static unsigned int probe_resp_offload_support(int supp_protocols
)
2850 unsigned int prot
= 0;
2852 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
)
2853 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS
;
2854 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
)
2855 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2
;
2856 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
)
2857 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P
;
2858 if (supp_protocols
& NL80211_PROBE_RESP_OFFLOAD_SUPPORT_80211U
)
2859 prot
|= WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING
;
2865 static void wiphy_info_supported_iftypes(struct wiphy_info_data
*info
,
2868 struct nlattr
*nl_mode
;
2874 nla_for_each_nested(nl_mode
, tb
, i
) {
2875 switch (nla_type(nl_mode
)) {
2876 case NL80211_IFTYPE_AP
:
2877 info
->capa
->flags
|= WPA_DRIVER_FLAGS_AP
;
2879 case NL80211_IFTYPE_ADHOC
:
2880 info
->capa
->flags
|= WPA_DRIVER_FLAGS_IBSS
;
2882 case NL80211_IFTYPE_P2P_DEVICE
:
2883 info
->capa
->flags
|=
2884 WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
;
2886 case NL80211_IFTYPE_P2P_GO
:
2887 info
->p2p_go_supported
= 1;
2889 case NL80211_IFTYPE_P2P_CLIENT
:
2890 info
->p2p_client_supported
= 1;
2892 case NL80211_IFTYPE_MONITOR
:
2893 info
->monitor_supported
= 1;
2900 static int wiphy_info_iface_comb_process(struct wiphy_info_data
*info
,
2901 struct nlattr
*nl_combi
)
2903 struct nlattr
*tb_comb
[NUM_NL80211_IFACE_COMB
];
2904 struct nlattr
*tb_limit
[NUM_NL80211_IFACE_LIMIT
];
2905 struct nlattr
*nl_limit
, *nl_mode
;
2906 int err
, rem_limit
, rem_mode
;
2907 int combination_has_p2p
= 0, combination_has_mgd
= 0;
2908 static struct nla_policy
2909 iface_combination_policy
[NUM_NL80211_IFACE_COMB
] = {
2910 [NL80211_IFACE_COMB_LIMITS
] = { .type
= NLA_NESTED
},
2911 [NL80211_IFACE_COMB_MAXNUM
] = { .type
= NLA_U32
},
2912 [NL80211_IFACE_COMB_STA_AP_BI_MATCH
] = { .type
= NLA_FLAG
},
2913 [NL80211_IFACE_COMB_NUM_CHANNELS
] = { .type
= NLA_U32
},
2914 [NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
] = { .type
= NLA_U32
},
2916 iface_limit_policy
[NUM_NL80211_IFACE_LIMIT
] = {
2917 [NL80211_IFACE_LIMIT_TYPES
] = { .type
= NLA_NESTED
},
2918 [NL80211_IFACE_LIMIT_MAX
] = { .type
= NLA_U32
},
2921 err
= nla_parse_nested(tb_comb
, MAX_NL80211_IFACE_COMB
,
2922 nl_combi
, iface_combination_policy
);
2923 if (err
|| !tb_comb
[NL80211_IFACE_COMB_LIMITS
] ||
2924 !tb_comb
[NL80211_IFACE_COMB_MAXNUM
] ||
2925 !tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
])
2926 return 0; /* broken combination */
2928 if (tb_comb
[NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS
])
2929 info
->capa
->flags
|= WPA_DRIVER_FLAGS_RADAR
;
2931 nla_for_each_nested(nl_limit
, tb_comb
[NL80211_IFACE_COMB_LIMITS
],
2933 err
= nla_parse_nested(tb_limit
, MAX_NL80211_IFACE_LIMIT
,
2934 nl_limit
, iface_limit_policy
);
2935 if (err
|| !tb_limit
[NL80211_IFACE_LIMIT_TYPES
])
2936 return 0; /* broken combination */
2938 nla_for_each_nested(nl_mode
,
2939 tb_limit
[NL80211_IFACE_LIMIT_TYPES
],
2941 int ift
= nla_type(nl_mode
);
2942 if (ift
== NL80211_IFTYPE_P2P_GO
||
2943 ift
== NL80211_IFTYPE_P2P_CLIENT
)
2944 combination_has_p2p
= 1;
2945 if (ift
== NL80211_IFTYPE_STATION
)
2946 combination_has_mgd
= 1;
2948 if (combination_has_p2p
&& combination_has_mgd
)
2952 if (combination_has_p2p
&& combination_has_mgd
) {
2953 info
->p2p_concurrent
= 1;
2954 if (nla_get_u32(tb_comb
[NL80211_IFACE_COMB_NUM_CHANNELS
]) > 1)
2955 info
->p2p_multichan_concurrent
= 1;
2963 static void wiphy_info_iface_comb(struct wiphy_info_data
*info
,
2966 struct nlattr
*nl_combi
;
2972 nla_for_each_nested(nl_combi
, tb
, rem_combi
) {
2973 if (wiphy_info_iface_comb_process(info
, nl_combi
) > 0)
2979 static void wiphy_info_supp_cmds(struct wiphy_info_data
*info
,
2982 struct nlattr
*nl_cmd
;
2988 nla_for_each_nested(nl_cmd
, tb
, i
) {
2989 switch (nla_get_u32(nl_cmd
)) {
2990 case NL80211_CMD_AUTHENTICATE
:
2991 info
->auth_supported
= 1;
2993 case NL80211_CMD_CONNECT
:
2994 info
->connect_supported
= 1;
2996 case NL80211_CMD_START_SCHED_SCAN
:
2997 info
->capa
->sched_scan_supported
= 1;
2999 case NL80211_CMD_PROBE_CLIENT
:
3000 info
->poll_command_supported
= 1;
3007 static void wiphy_info_max_roc(struct wpa_driver_capa
*capa
,
3011 capa
->max_remain_on_chan
= nla_get_u32(tb
);
3015 static void wiphy_info_tdls(struct wpa_driver_capa
*capa
, struct nlattr
*tdls
,
3016 struct nlattr
*ext_setup
)
3021 wpa_printf(MSG_DEBUG
, "nl80211: TDLS supported");
3022 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_SUPPORT
;
3025 wpa_printf(MSG_DEBUG
, "nl80211: TDLS external setup");
3026 capa
->flags
|= WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
;
3031 static void wiphy_info_feature_flags(struct wiphy_info_data
*info
,
3035 struct wpa_driver_capa
*capa
= info
->capa
;
3040 flags
= nla_get_u32(tb
);
3042 if (flags
& NL80211_FEATURE_SK_TX_STATUS
)
3043 info
->data_tx_status
= 1;
3045 if (flags
& NL80211_FEATURE_INACTIVITY_TIMER
)
3046 capa
->flags
|= WPA_DRIVER_FLAGS_INACTIVITY_TIMER
;
3048 if (flags
& NL80211_FEATURE_SAE
)
3049 capa
->flags
|= WPA_DRIVER_FLAGS_SAE
;
3051 if (flags
& NL80211_FEATURE_NEED_OBSS_SCAN
)
3052 capa
->flags
|= WPA_DRIVER_FLAGS_OBSS_SCAN
;
3056 static void wiphy_info_probe_resp_offload(struct wpa_driver_capa
*capa
,
3064 protocols
= nla_get_u32(tb
);
3065 wpa_printf(MSG_DEBUG
, "nl80211: Supports Probe Response offload in AP "
3067 capa
->flags
|= WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD
;
3068 capa
->probe_resp_offloads
= probe_resp_offload_support(protocols
);
3072 static int wiphy_info_handler(struct nl_msg
*msg
, void *arg
)
3074 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
3075 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
3076 struct wiphy_info_data
*info
= arg
;
3077 struct wpa_driver_capa
*capa
= info
->capa
;
3078 struct wpa_driver_nl80211_data
*drv
= info
->drv
;
3080 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
3081 genlmsg_attrlen(gnlh
, 0), NULL
);
3083 if (tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
])
3084 capa
->max_scan_ssids
=
3085 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCAN_SSIDS
]);
3087 if (tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
])
3088 capa
->max_sched_scan_ssids
=
3089 nla_get_u8(tb
[NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
]);
3091 if (tb
[NL80211_ATTR_MAX_MATCH_SETS
])
3092 capa
->max_match_sets
=
3093 nla_get_u8(tb
[NL80211_ATTR_MAX_MATCH_SETS
]);
3095 if (tb
[NL80211_ATTR_MAC_ACL_MAX
])
3096 capa
->max_acl_mac_addrs
=
3097 nla_get_u8(tb
[NL80211_ATTR_MAC_ACL_MAX
]);
3099 wiphy_info_supported_iftypes(info
, tb
[NL80211_ATTR_SUPPORTED_IFTYPES
]);
3100 wiphy_info_iface_comb(info
, tb
[NL80211_ATTR_INTERFACE_COMBINATIONS
]);
3101 wiphy_info_supp_cmds(info
, tb
[NL80211_ATTR_SUPPORTED_COMMANDS
]);
3103 if (tb
[NL80211_ATTR_OFFCHANNEL_TX_OK
]) {
3104 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based "
3106 capa
->flags
|= WPA_DRIVER_FLAGS_OFFCHANNEL_TX
;
3109 if (tb
[NL80211_ATTR_ROAM_SUPPORT
]) {
3110 wpa_printf(MSG_DEBUG
, "nl80211: Using driver-based roaming");
3111 capa
->flags
|= WPA_DRIVER_FLAGS_BSS_SELECTION
;
3114 wiphy_info_max_roc(capa
,
3115 tb
[NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
]);
3117 if (tb
[NL80211_ATTR_SUPPORT_AP_UAPSD
])
3118 capa
->flags
|= WPA_DRIVER_FLAGS_AP_UAPSD
;
3120 wiphy_info_tdls(capa
, tb
[NL80211_ATTR_TDLS_SUPPORT
],
3121 tb
[NL80211_ATTR_TDLS_EXTERNAL_SETUP
]);
3123 if (tb
[NL80211_ATTR_DEVICE_AP_SME
])
3124 info
->device_ap_sme
= 1;
3126 wiphy_info_feature_flags(info
, tb
[NL80211_ATTR_FEATURE_FLAGS
]);
3127 wiphy_info_probe_resp_offload(capa
,
3128 tb
[NL80211_ATTR_PROBE_RESP_OFFLOAD
]);
3130 if (tb
[NL80211_ATTR_EXT_CAPA
] && tb
[NL80211_ATTR_EXT_CAPA_MASK
] &&
3131 drv
->extended_capa
== NULL
) {
3132 drv
->extended_capa
=
3133 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3134 if (drv
->extended_capa
) {
3135 os_memcpy(drv
->extended_capa
,
3136 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
3137 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3138 drv
->extended_capa_len
=
3139 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]);
3141 drv
->extended_capa_mask
=
3142 os_malloc(nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3143 if (drv
->extended_capa_mask
) {
3144 os_memcpy(drv
->extended_capa_mask
,
3145 nla_data(tb
[NL80211_ATTR_EXT_CAPA
]),
3146 nla_len(tb
[NL80211_ATTR_EXT_CAPA
]));
3148 os_free(drv
->extended_capa
);
3149 drv
->extended_capa
= NULL
;
3150 drv
->extended_capa_len
= 0;
3158 static int wpa_driver_nl80211_get_info(struct wpa_driver_nl80211_data
*drv
,
3159 struct wiphy_info_data
*info
)
3164 os_memset(info
, 0, sizeof(*info
));
3165 info
->capa
= &drv
->capa
;
3168 msg
= nlmsg_alloc();
3172 feat
= get_nl80211_protocol_features(drv
);
3173 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
3174 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
3176 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
3178 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
3179 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->first_bss
.ifindex
);
3181 if (send_and_recv_msgs(drv
, msg
, wiphy_info_handler
, info
))
3184 if (info
->auth_supported
)
3185 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SME
;
3186 else if (!info
->connect_supported
) {
3187 wpa_printf(MSG_INFO
, "nl80211: Driver does not support "
3188 "authentication/association or connect commands");
3192 if (info
->p2p_go_supported
&& info
->p2p_client_supported
)
3193 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CAPABLE
;
3194 if (info
->p2p_concurrent
) {
3195 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
3196 "interface (driver advertised support)");
3197 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
3198 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
3200 if (info
->p2p_multichan_concurrent
) {
3201 wpa_printf(MSG_DEBUG
, "nl80211: Enable multi-channel "
3202 "concurrent (driver advertised support)");
3203 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
;
3206 /* default to 5000 since early versions of mac80211 don't set it */
3207 if (!drv
->capa
.max_remain_on_chan
)
3208 drv
->capa
.max_remain_on_chan
= 5000;
3217 static int wpa_driver_nl80211_capa(struct wpa_driver_nl80211_data
*drv
)
3219 struct wiphy_info_data info
;
3220 if (wpa_driver_nl80211_get_info(drv
, &info
))
3226 drv
->has_capability
= 1;
3227 /* For now, assume TKIP, CCMP, WPA, WPA2 are supported */
3228 drv
->capa
.key_mgmt
= WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3229 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3230 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3231 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
;
3232 drv
->capa
.enc
= WPA_DRIVER_CAPA_ENC_WEP40
|
3233 WPA_DRIVER_CAPA_ENC_WEP104
|
3234 WPA_DRIVER_CAPA_ENC_TKIP
|
3235 WPA_DRIVER_CAPA_ENC_CCMP
;
3236 drv
->capa
.auth
= WPA_DRIVER_AUTH_OPEN
|
3237 WPA_DRIVER_AUTH_SHARED
|
3238 WPA_DRIVER_AUTH_LEAP
;
3240 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SANE_ERROR_CODES
;
3241 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE
;
3242 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3244 if (!info
.device_ap_sme
) {
3245 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_DEAUTH_TX_STATUS
;
3248 * No AP SME is currently assumed to also indicate no AP MLME
3249 * in the driver/firmware.
3251 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_AP_MLME
;
3254 drv
->device_ap_sme
= info
.device_ap_sme
;
3255 drv
->poll_command_supported
= info
.poll_command_supported
;
3256 drv
->data_tx_status
= info
.data_tx_status
;
3259 * If poll command and tx status are supported, mac80211 is new enough
3260 * to have everything we need to not need monitor interfaces.
3262 drv
->use_monitor
= !info
.poll_command_supported
|| !info
.data_tx_status
;
3264 if (drv
->device_ap_sme
&& drv
->use_monitor
) {
3266 * Non-mac80211 drivers may not support monitor interface.
3267 * Make sure we do not get stuck with incorrect capability here
3268 * by explicitly testing this.
3270 if (!info
.monitor_supported
) {
3271 wpa_printf(MSG_DEBUG
, "nl80211: Disable use_monitor "
3272 "with device_ap_sme since no monitor mode "
3273 "support detected");
3274 drv
->use_monitor
= 0;
3279 * If we aren't going to use monitor interfaces, but the
3280 * driver doesn't support data TX status, we won't get TX
3281 * status for EAPOL frames.
3283 if (!drv
->use_monitor
&& !info
.data_tx_status
)
3284 drv
->capa
.flags
&= ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3291 static int android_genl_ctrl_resolve(struct nl_handle
*handle
,
3295 * Android ICS has very minimal genl_ctrl_resolve() implementation, so
3296 * need to work around that.
3298 struct nl_cache
*cache
= NULL
;
3299 struct genl_family
*nl80211
= NULL
;
3302 if (genl_ctrl_alloc_cache(handle
, &cache
) < 0) {
3303 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate generic "
3308 nl80211
= genl_ctrl_search_by_name(cache
, name
);
3309 if (nl80211
== NULL
)
3312 id
= genl_family_get_id(nl80211
);
3316 genl_family_put(nl80211
);
3318 nl_cache_free(cache
);
3322 #define genl_ctrl_resolve android_genl_ctrl_resolve
3323 #endif /* ANDROID */
3326 static int wpa_driver_nl80211_init_nl_global(struct nl80211_global
*global
)
3330 global
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3331 if (global
->nl_cb
== NULL
) {
3332 wpa_printf(MSG_ERROR
, "nl80211: Failed to allocate netlink "
3337 global
->nl
= nl_create_handle(global
->nl_cb
, "nl");
3338 if (global
->nl
== NULL
)
3341 global
->nl80211_id
= genl_ctrl_resolve(global
->nl
, "nl80211");
3342 if (global
->nl80211_id
< 0) {
3343 wpa_printf(MSG_ERROR
, "nl80211: 'nl80211' generic netlink not "
3348 global
->nl_event
= nl_create_handle(global
->nl_cb
, "event");
3349 if (global
->nl_event
== NULL
)
3352 ret
= nl_get_multicast_id(global
, "nl80211", "scan");
3354 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3356 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3357 "membership for scan events: %d (%s)",
3358 ret
, strerror(-ret
));
3362 ret
= nl_get_multicast_id(global
, "nl80211", "mlme");
3364 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3366 wpa_printf(MSG_ERROR
, "nl80211: Could not add multicast "
3367 "membership for mlme events: %d (%s)",
3368 ret
, strerror(-ret
));
3372 ret
= nl_get_multicast_id(global
, "nl80211", "regulatory");
3374 ret
= nl_socket_add_membership(global
->nl_event
, ret
);
3376 wpa_printf(MSG_DEBUG
, "nl80211: Could not add multicast "
3377 "membership for regulatory events: %d (%s)",
3378 ret
, strerror(-ret
));
3379 /* Continue without regulatory events */
3382 nl_cb_set(global
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3383 no_seq_check
, NULL
);
3384 nl_cb_set(global
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3385 process_global_event
, global
);
3387 eloop_register_read_sock(nl_socket_get_fd(global
->nl_event
),
3388 wpa_driver_nl80211_event_receive
,
3389 global
->nl_cb
, global
->nl_event
);
3394 nl_destroy_handles(&global
->nl_event
);
3395 nl_destroy_handles(&global
->nl
);
3396 nl_cb_put(global
->nl_cb
);
3397 global
->nl_cb
= NULL
;
3402 static int wpa_driver_nl80211_init_nl(struct wpa_driver_nl80211_data
*drv
)
3404 drv
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3406 wpa_printf(MSG_ERROR
, "nl80211: Failed to alloc cb struct");
3410 nl_cb_set(drv
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3411 no_seq_check
, NULL
);
3412 nl_cb_set(drv
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3413 process_drv_event
, drv
);
3419 static void wpa_driver_nl80211_rfkill_blocked(void *ctx
)
3421 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL blocked");
3423 * This may be for any interface; use ifdown event to disable
3429 static void wpa_driver_nl80211_rfkill_unblocked(void *ctx
)
3431 struct wpa_driver_nl80211_data
*drv
= ctx
;
3432 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL unblocked");
3433 if (linux_set_iface_flags(drv
->global
->ioctl_sock
,
3434 drv
->first_bss
.ifname
, 1)) {
3435 wpa_printf(MSG_DEBUG
, "nl80211: Could not set interface UP "
3436 "after rfkill unblock");
3439 /* rtnetlink ifup handler will report interface as enabled */
3443 static void nl80211_get_phy_name(struct wpa_driver_nl80211_data
*drv
)
3445 /* Find phy (radio) to which this interface belongs */
3449 drv
->phyname
[0] = '\0';
3450 snprintf(buf
, sizeof(buf
) - 1, "/sys/class/net/%s/phy80211/name",
3451 drv
->first_bss
.ifname
);
3452 f
= open(buf
, O_RDONLY
);
3454 wpa_printf(MSG_DEBUG
, "Could not open file %s: %s",
3455 buf
, strerror(errno
));
3459 rv
= read(f
, drv
->phyname
, sizeof(drv
->phyname
) - 1);
3462 wpa_printf(MSG_DEBUG
, "Could not read file %s: %s",
3463 buf
, strerror(errno
));
3467 drv
->phyname
[rv
] = '\0';
3468 pos
= os_strchr(drv
->phyname
, '\n');
3471 wpa_printf(MSG_DEBUG
, "nl80211: interface %s in phy %s",
3472 drv
->first_bss
.ifname
, drv
->phyname
);
3476 static void wpa_driver_nl80211_handle_eapol_tx_status(int sock
,
3480 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
3485 struct cmsghdr
*cmsg
;
3486 int res
, found_ee
= 0, found_wifi
= 0, acked
= 0;
3487 union wpa_event_data event
;
3489 memset(&msg
, 0, sizeof(msg
));
3490 msg
.msg_iov
= &entry
;
3492 entry
.iov_base
= data
;
3493 entry
.iov_len
= sizeof(data
);
3494 msg
.msg_control
= &control
;
3495 msg
.msg_controllen
= sizeof(control
);
3497 res
= recvmsg(sock
, &msg
, MSG_ERRQUEUE
);
3498 /* if error or not fitting 802.3 header, return */
3502 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
; cmsg
= CMSG_NXTHDR(&msg
, cmsg
))
3504 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
3505 cmsg
->cmsg_type
== SCM_WIFI_STATUS
) {
3509 ack
= (void *)CMSG_DATA(cmsg
);
3513 if (cmsg
->cmsg_level
== SOL_PACKET
&&
3514 cmsg
->cmsg_type
== PACKET_TX_TIMESTAMP
) {
3515 struct sock_extended_err
*err
=
3516 (struct sock_extended_err
*)CMSG_DATA(cmsg
);
3518 if (err
->ee_origin
== SO_EE_ORIGIN_TXSTATUS
)
3523 if (!found_ee
|| !found_wifi
)
3526 memset(&event
, 0, sizeof(event
));
3527 event
.eapol_tx_status
.dst
= data
;
3528 event
.eapol_tx_status
.data
= data
+ 14;
3529 event
.eapol_tx_status
.data_len
= res
- 14;
3530 event
.eapol_tx_status
.ack
= acked
;
3531 wpa_supplicant_event(drv
->ctx
, EVENT_EAPOL_TX_STATUS
, &event
);
3535 static int nl80211_init_bss(struct i802_bss
*bss
)
3537 bss
->nl_cb
= nl_cb_alloc(NL_CB_DEFAULT
);
3541 nl_cb_set(bss
->nl_cb
, NL_CB_SEQ_CHECK
, NL_CB_CUSTOM
,
3542 no_seq_check
, NULL
);
3543 nl_cb_set(bss
->nl_cb
, NL_CB_VALID
, NL_CB_CUSTOM
,
3544 process_bss_event
, bss
);
3550 static void nl80211_destroy_bss(struct i802_bss
*bss
)
3552 nl_cb_put(bss
->nl_cb
);
3558 * wpa_driver_nl80211_init - Initialize nl80211 driver interface
3559 * @ctx: context to be used when calling wpa_supplicant functions,
3560 * e.g., wpa_supplicant_event()
3561 * @ifname: interface name, e.g., wlan0
3562 * @global_priv: private driver global data from global_init()
3563 * Returns: Pointer to private data, %NULL on failure
3565 static void * wpa_driver_nl80211_init(void *ctx
, const char *ifname
,
3568 struct wpa_driver_nl80211_data
*drv
;
3569 struct rfkill_config
*rcfg
;
3570 struct i802_bss
*bss
;
3572 if (global_priv
== NULL
)
3574 drv
= os_zalloc(sizeof(*drv
));
3577 drv
->global
= global_priv
;
3579 bss
= &drv
->first_bss
;
3583 os_strlcpy(bss
->ifname
, ifname
, sizeof(bss
->ifname
));
3584 drv
->monitor_ifidx
= -1;
3585 drv
->monitor_sock
= -1;
3586 drv
->eapol_tx_sock
= -1;
3587 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
3589 if (wpa_driver_nl80211_init_nl(drv
)) {
3594 if (nl80211_init_bss(bss
))
3597 nl80211_get_phy_name(drv
);
3599 rcfg
= os_zalloc(sizeof(*rcfg
));
3603 os_strlcpy(rcfg
->ifname
, ifname
, sizeof(rcfg
->ifname
));
3604 rcfg
->blocked_cb
= wpa_driver_nl80211_rfkill_blocked
;
3605 rcfg
->unblocked_cb
= wpa_driver_nl80211_rfkill_unblocked
;
3606 drv
->rfkill
= rfkill_init(rcfg
);
3607 if (drv
->rfkill
== NULL
) {
3608 wpa_printf(MSG_DEBUG
, "nl80211: RFKILL status not available");
3612 if (wpa_driver_nl80211_finish_drv_init(drv
))
3615 drv
->eapol_tx_sock
= socket(PF_PACKET
, SOCK_DGRAM
, 0);
3616 if (drv
->eapol_tx_sock
< 0)
3619 if (drv
->data_tx_status
) {
3622 if (setsockopt(drv
->eapol_tx_sock
, SOL_SOCKET
, SO_WIFI_STATUS
,
3623 &enabled
, sizeof(enabled
)) < 0) {
3624 wpa_printf(MSG_DEBUG
,
3625 "nl80211: wifi status sockopt failed\n");
3626 drv
->data_tx_status
= 0;
3627 if (!drv
->use_monitor
)
3629 ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS
;
3631 eloop_register_read_sock(drv
->eapol_tx_sock
,
3632 wpa_driver_nl80211_handle_eapol_tx_status
,
3638 dl_list_add(&drv
->global
->interfaces
, &drv
->list
);
3639 drv
->in_interface_list
= 1;
3645 wpa_driver_nl80211_deinit(bss
);
3650 static int nl80211_register_frame(struct i802_bss
*bss
,
3651 struct nl_handle
*nl_handle
,
3652 u16 type
, const u8
*match
, size_t match_len
)
3654 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3658 msg
= nlmsg_alloc();
3662 wpa_printf(MSG_DEBUG
, "nl80211: Register frame type=0x%x nl_handle=%p",
3664 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3667 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REGISTER_ACTION
);
3669 if (nl80211_set_iface_id(msg
, bss
))
3670 goto nla_put_failure
;
3672 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
, type
);
3673 NLA_PUT(msg
, NL80211_ATTR_FRAME_MATCH
, match_len
, match
);
3675 ret
= send_and_recv(drv
->global
, nl_handle
, msg
, NULL
, NULL
);
3678 wpa_printf(MSG_DEBUG
, "nl80211: Register frame command "
3679 "failed (type=%u): ret=%d (%s)",
3680 type
, ret
, strerror(-ret
));
3681 wpa_hexdump(MSG_DEBUG
, "nl80211: Register frame match",
3683 goto nla_put_failure
;
3692 static int nl80211_alloc_mgmt_handle(struct i802_bss
*bss
)
3694 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3697 wpa_printf(MSG_DEBUG
, "nl80211: Mgmt reporting "
3698 "already on! (nl_mgmt=%p)", bss
->nl_mgmt
);
3702 bss
->nl_mgmt
= nl_create_handle(drv
->nl_cb
, "mgmt");
3703 if (bss
->nl_mgmt
== NULL
)
3706 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_mgmt
),
3707 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
3714 static int nl80211_register_action_frame(struct i802_bss
*bss
,
3715 const u8
*match
, size_t match_len
)
3717 u16 type
= (WLAN_FC_TYPE_MGMT
<< 2) | (WLAN_FC_STYPE_ACTION
<< 4);
3718 return nl80211_register_frame(bss
, bss
->nl_mgmt
,
3719 type
, match
, match_len
);
3723 static int nl80211_mgmt_subscribe_non_ap(struct i802_bss
*bss
)
3725 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3727 if (nl80211_alloc_mgmt_handle(bss
))
3729 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with non-AP "
3730 "handle %p", bss
->nl_mgmt
);
3732 #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
3733 /* GAS Initial Request */
3734 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0a", 2) < 0)
3736 /* GAS Initial Response */
3737 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0b", 2) < 0)
3739 /* GAS Comeback Request */
3740 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0c", 2) < 0)
3742 /* GAS Comeback Response */
3743 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0d", 2) < 0)
3745 #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
3747 /* P2P Public Action */
3748 if (nl80211_register_action_frame(bss
,
3749 (u8
*) "\x04\x09\x50\x6f\x9a\x09",
3753 if (nl80211_register_action_frame(bss
,
3754 (u8
*) "\x7f\x50\x6f\x9a\x09",
3757 #endif /* CONFIG_P2P */
3758 #ifdef CONFIG_IEEE80211W
3759 /* SA Query Response */
3760 if (nl80211_register_action_frame(bss
, (u8
*) "\x08\x01", 2) < 0)
3762 #endif /* CONFIG_IEEE80211W */
3764 if ((drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
)) {
3765 /* TDLS Discovery Response */
3766 if (nl80211_register_action_frame(bss
, (u8
*) "\x04\x0e", 2) <
3770 #endif /* CONFIG_TDLS */
3772 /* FT Action frames */
3773 if (nl80211_register_action_frame(bss
, (u8
*) "\x06", 1) < 0)
3776 drv
->capa
.key_mgmt
|= WPA_DRIVER_CAPA_KEY_MGMT_FT
|
3777 WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK
;
3779 /* WNM - BSS Transition Management Request */
3780 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x07", 2) < 0)
3782 /* WNM-Sleep Mode Response */
3783 if (nl80211_register_action_frame(bss
, (u8
*) "\x0a\x11", 2) < 0)
3790 static int nl80211_register_spurious_class3(struct i802_bss
*bss
)
3792 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
3796 msg
= nlmsg_alloc();
3800 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UNEXPECTED_FRAME
);
3802 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
3804 ret
= send_and_recv(drv
->global
, bss
->nl_mgmt
, msg
, NULL
, NULL
);
3807 wpa_printf(MSG_DEBUG
, "nl80211: Register spurious class3 "
3808 "failed: ret=%d (%s)",
3809 ret
, strerror(-ret
));
3810 goto nla_put_failure
;
3819 static int nl80211_mgmt_subscribe_ap(struct i802_bss
*bss
)
3821 static const int stypes
[] = {
3823 WLAN_FC_STYPE_ASSOC_REQ
,
3824 WLAN_FC_STYPE_REASSOC_REQ
,
3825 WLAN_FC_STYPE_DISASSOC
,
3826 WLAN_FC_STYPE_DEAUTH
,
3827 WLAN_FC_STYPE_ACTION
,
3828 WLAN_FC_STYPE_PROBE_REQ
,
3829 /* Beacon doesn't work as mac80211 doesn't currently allow
3830 * it, but it wouldn't really be the right thing anyway as
3831 * it isn't per interface ... maybe just dump the scan
3832 * results periodically for OLBC?
3834 // WLAN_FC_STYPE_BEACON,
3838 if (nl80211_alloc_mgmt_handle(bss
))
3840 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3841 "handle %p", bss
->nl_mgmt
);
3843 for (i
= 0; i
< sizeof(stypes
) / sizeof(stypes
[0]); i
++) {
3844 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3845 (WLAN_FC_TYPE_MGMT
<< 2) |
3852 if (nl80211_register_spurious_class3(bss
))
3855 if (nl80211_get_wiphy_data_ap(bss
) == NULL
)
3861 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3862 nl_destroy_handles(&bss
->nl_mgmt
);
3867 static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss
*bss
)
3869 if (nl80211_alloc_mgmt_handle(bss
))
3871 wpa_printf(MSG_DEBUG
, "nl80211: Subscribe to mgmt frames with AP "
3872 "handle %p (device SME)", bss
->nl_mgmt
);
3874 if (nl80211_register_frame(bss
, bss
->nl_mgmt
,
3875 (WLAN_FC_TYPE_MGMT
<< 2) |
3876 (WLAN_FC_STYPE_ACTION
<< 4),
3883 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3884 nl_destroy_handles(&bss
->nl_mgmt
);
3889 static void nl80211_mgmt_unsubscribe(struct i802_bss
*bss
, const char *reason
)
3891 if (bss
->nl_mgmt
== NULL
)
3893 wpa_printf(MSG_DEBUG
, "nl80211: Unsubscribe mgmt frames handle %p "
3894 "(%s)", bss
->nl_mgmt
, reason
);
3895 eloop_unregister_read_sock(nl_socket_get_fd(bss
->nl_mgmt
));
3896 nl_destroy_handles(&bss
->nl_mgmt
);
3898 nl80211_put_wiphy_data_ap(bss
);
3902 static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx
, void *timeout_ctx
)
3904 wpa_supplicant_event(timeout_ctx
, EVENT_INTERFACE_DISABLED
, NULL
);
3909 wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data
*drv
)
3911 struct i802_bss
*bss
= &drv
->first_bss
;
3912 int send_rfkill_event
= 0;
3914 drv
->ifindex
= if_nametoindex(bss
->ifname
);
3915 drv
->first_bss
.ifindex
= drv
->ifindex
;
3919 * Make sure the interface starts up in station mode unless this is a
3920 * dynamically added interface (e.g., P2P) that was already configured
3921 * with proper iftype.
3923 if (drv
->ifindex
!= drv
->global
->if_add_ifindex
) {
3924 enum nl80211_iftype nlmode
;
3926 nlmode
= nl80211_get_ifmode(bss
);
3927 if (nlmode
!= NL80211_IFTYPE_P2P_DEVICE
)
3928 nlmode
= NL80211_IFTYPE_STATION
;
3930 if (wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0) {
3931 wpa_printf(MSG_ERROR
, "nl80211: Could not configure driver to use %s mode",
3932 nlmode
== NL80211_IFTYPE_STATION
?
3933 "managed" : "P2P-Device");
3937 /* Always use managed mode internally, even for P2P Device */
3938 drv
->nlmode
= NL80211_IFTYPE_STATION
;
3941 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
3942 if (rfkill_is_blocked(drv
->rfkill
)) {
3943 wpa_printf(MSG_DEBUG
, "nl80211: Could not yet enable "
3944 "interface '%s' due to rfkill",
3946 drv
->if_disabled
= 1;
3947 send_rfkill_event
= 1;
3949 wpa_printf(MSG_ERROR
, "nl80211: Could not set "
3950 "interface '%s' UP", bss
->ifname
);
3955 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
,
3956 1, IF_OPER_DORMANT
);
3957 #endif /* HOSTAPD */
3959 if (wpa_driver_nl80211_capa(drv
))
3962 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
3966 if (send_rfkill_event
) {
3967 eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill
,
3975 static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data
*drv
)
3979 msg
= nlmsg_alloc();
3983 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_BEACON
);
3984 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
3986 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
3994 * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
3995 * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
3997 * Shut down driver interface and processing of driver events. Free
3998 * private data buffer if one was allocated in wpa_driver_nl80211_init().
4000 static void wpa_driver_nl80211_deinit(struct i802_bss
*bss
)
4002 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4005 if (drv
->data_tx_status
)
4006 eloop_unregister_read_sock(drv
->eapol_tx_sock
);
4007 if (drv
->eapol_tx_sock
>= 0)
4008 close(drv
->eapol_tx_sock
);
4011 wpa_driver_nl80211_probe_req_report(bss
, 0);
4012 if (bss
->added_if_into_bridge
) {
4013 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
4015 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
4016 "interface %s from bridge %s: %s",
4017 bss
->ifname
, bss
->brname
, strerror(errno
));
4019 if (bss
->added_bridge
) {
4020 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
4021 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
4023 bss
->brname
, strerror(errno
));
4026 nl80211_remove_monitor_interface(drv
);
4028 if (is_ap_interface(drv
->nlmode
))
4029 wpa_driver_nl80211_del_beacon(drv
);
4032 if (drv
->last_freq_ht
) {
4033 /* Clear HT flags from the driver */
4034 struct hostapd_freq_params freq
;
4035 os_memset(&freq
, 0, sizeof(freq
));
4036 freq
.freq
= drv
->last_freq
;
4037 wpa_driver_nl80211_set_freq(bss
, &freq
);
4040 if (drv
->eapol_sock
>= 0) {
4041 eloop_unregister_read_sock(drv
->eapol_sock
);
4042 close(drv
->eapol_sock
);
4045 if (drv
->if_indices
!= drv
->default_if_indices
)
4046 os_free(drv
->if_indices
);
4047 #endif /* HOSTAPD */
4049 if (drv
->disabled_11b_rates
)
4050 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
4052 netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, 0,
4054 rfkill_deinit(drv
->rfkill
);
4056 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
4058 (void) linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0);
4059 wpa_driver_nl80211_set_mode(bss
, NL80211_IFTYPE_STATION
);
4060 nl80211_mgmt_unsubscribe(bss
, "deinit");
4062 nl_cb_put(drv
->nl_cb
);
4064 nl80211_destroy_bss(&drv
->first_bss
);
4066 os_free(drv
->filter_ssids
);
4068 os_free(drv
->auth_ie
);
4070 if (drv
->in_interface_list
)
4071 dl_list_del(&drv
->list
);
4073 os_free(drv
->extended_capa
);
4074 os_free(drv
->extended_capa_mask
);
4080 * wpa_driver_nl80211_scan_timeout - Scan timeout to report scan completion
4081 * @eloop_ctx: Driver private data
4082 * @timeout_ctx: ctx argument given to wpa_driver_nl80211_init()
4084 * This function can be used as registered timeout when starting a scan to
4085 * generate a scan completed event if the driver does not report this.
4087 static void wpa_driver_nl80211_scan_timeout(void *eloop_ctx
, void *timeout_ctx
)
4089 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
4090 if (drv
->ap_scan_as_station
!= NL80211_IFTYPE_UNSPECIFIED
) {
4091 wpa_driver_nl80211_set_mode(&drv
->first_bss
,
4092 drv
->ap_scan_as_station
);
4093 drv
->ap_scan_as_station
= NL80211_IFTYPE_UNSPECIFIED
;
4095 wpa_printf(MSG_DEBUG
, "Scan timeout - try to get results");
4096 wpa_supplicant_event(timeout_ctx
, EVENT_SCAN_RESULTS
, NULL
);
4100 static struct nl_msg
*
4101 nl80211_scan_common(struct wpa_driver_nl80211_data
*drv
, u8 cmd
,
4102 struct wpa_driver_scan_params
*params
, u64
*wdev_id
)
4107 msg
= nlmsg_alloc();
4111 nl80211_cmd(drv
, msg
, 0, cmd
);
4114 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4116 NLA_PUT_U64(msg
, NL80211_ATTR_WDEV
, *wdev_id
);
4118 if (params
->num_ssids
) {
4119 struct nlattr
*ssids
;
4121 ssids
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
4124 for (i
= 0; i
< params
->num_ssids
; i
++) {
4125 wpa_hexdump_ascii(MSG_MSGDUMP
, "nl80211: Scan SSID",
4126 params
->ssids
[i
].ssid
,
4127 params
->ssids
[i
].ssid_len
);
4128 if (nla_put(msg
, i
+ 1, params
->ssids
[i
].ssid_len
,
4129 params
->ssids
[i
].ssid
) < 0)
4132 nla_nest_end(msg
, ssids
);
4135 if (params
->extra_ies
) {
4136 wpa_hexdump(MSG_MSGDUMP
, "nl80211: Scan extra IEs",
4137 params
->extra_ies
, params
->extra_ies_len
);
4138 if (nla_put(msg
, NL80211_ATTR_IE
, params
->extra_ies_len
,
4139 params
->extra_ies
) < 0)
4143 if (params
->freqs
) {
4144 struct nlattr
*freqs
;
4145 freqs
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
4148 for (i
= 0; params
->freqs
[i
]; i
++) {
4149 wpa_printf(MSG_MSGDUMP
, "nl80211: Scan frequency %u "
4150 "MHz", params
->freqs
[i
]);
4151 if (nla_put_u32(msg
, i
+ 1, params
->freqs
[i
]) < 0)
4154 nla_nest_end(msg
, freqs
);
4157 os_free(drv
->filter_ssids
);
4158 drv
->filter_ssids
= params
->filter_ssids
;
4159 params
->filter_ssids
= NULL
;
4160 drv
->num_filter_ssids
= params
->num_filter_ssids
;
4172 * wpa_driver_nl80211_scan - Request the driver to initiate scan
4173 * @bss: Pointer to private driver data from wpa_driver_nl80211_init()
4174 * @params: Scan parameters
4175 * Returns: 0 on success, -1 on failure
4177 static int wpa_driver_nl80211_scan(struct i802_bss
*bss
,
4178 struct wpa_driver_scan_params
*params
)
4180 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4181 int ret
= -1, timeout
;
4182 struct nl_msg
*msg
= NULL
;
4184 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: scan request");
4185 drv
->scan_for_auth
= 0;
4187 msg
= nl80211_scan_common(drv
, NL80211_CMD_TRIGGER_SCAN
, params
,
4188 bss
->wdev_id_set
? &bss
->wdev_id
: NULL
);
4192 if (params
->p2p_probe
) {
4193 struct nlattr
*rates
;
4195 wpa_printf(MSG_DEBUG
, "nl80211: P2P probe - mask SuppRates");
4197 rates
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SUPP_RATES
);
4199 goto nla_put_failure
;
4202 * Remove 2.4 GHz rates 1, 2, 5.5, 11 Mbps from supported rates
4203 * by masking out everything else apart from the OFDM rates 6,
4204 * 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS rates. All 5 GHz
4205 * rates are left enabled.
4207 NLA_PUT(msg
, NL80211_BAND_2GHZ
, 8,
4208 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
4209 nla_nest_end(msg
, rates
);
4211 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
4214 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4217 wpa_printf(MSG_DEBUG
, "nl80211: Scan trigger failed: ret=%d "
4218 "(%s)", ret
, strerror(-ret
));
4220 if (is_ap_interface(drv
->nlmode
)) {
4222 * mac80211 does not allow scan requests in AP mode, so
4223 * try to do this in station mode.
4225 if (wpa_driver_nl80211_set_mode(
4226 bss
, NL80211_IFTYPE_STATION
))
4227 goto nla_put_failure
;
4229 if (wpa_driver_nl80211_scan(bss
, params
)) {
4230 wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
);
4231 goto nla_put_failure
;
4234 /* Restore AP mode when processing scan results */
4235 drv
->ap_scan_as_station
= drv
->nlmode
;
4238 goto nla_put_failure
;
4240 goto nla_put_failure
;
4241 #endif /* HOSTAPD */
4244 /* Not all drivers generate "scan completed" wireless event, so try to
4245 * read results after a timeout. */
4247 if (drv
->scan_complete_events
) {
4249 * The driver seems to deliver events to notify when scan is
4250 * complete, so use longer timeout to avoid race conditions
4251 * with scanning and following association request.
4255 wpa_printf(MSG_DEBUG
, "Scan requested (ret=%d) - scan timeout %d "
4256 "seconds", ret
, timeout
);
4257 eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout
, drv
, drv
->ctx
);
4258 eloop_register_timeout(timeout
, 0, wpa_driver_nl80211_scan_timeout
,
4268 * wpa_driver_nl80211_sched_scan - Initiate a scheduled scan
4269 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
4270 * @params: Scan parameters
4271 * @interval: Interval between scan cycles in milliseconds
4272 * Returns: 0 on success, -1 on failure or if not supported
4274 static int wpa_driver_nl80211_sched_scan(void *priv
,
4275 struct wpa_driver_scan_params
*params
,
4278 struct i802_bss
*bss
= priv
;
4279 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4284 wpa_dbg(drv
->ctx
, MSG_DEBUG
, "nl80211: sched_scan request");
4287 if (!drv
->capa
.sched_scan_supported
)
4288 return android_pno_start(bss
, params
);
4289 #endif /* ANDROID */
4291 msg
= nl80211_scan_common(drv
, NL80211_CMD_START_SCHED_SCAN
, params
,
4292 bss
->wdev_id_set
? &bss
->wdev_id
: NULL
);
4294 goto nla_put_failure
;
4296 NLA_PUT_U32(msg
, NL80211_ATTR_SCHED_SCAN_INTERVAL
, interval
);
4298 if ((drv
->num_filter_ssids
&&
4299 (int) drv
->num_filter_ssids
<= drv
->capa
.max_match_sets
) ||
4300 params
->filter_rssi
) {
4301 struct nlattr
*match_sets
;
4302 match_sets
= nla_nest_start(msg
, NL80211_ATTR_SCHED_SCAN_MATCH
);
4303 if (match_sets
== NULL
)
4304 goto nla_put_failure
;
4306 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4307 struct nlattr
*match_set_ssid
;
4308 wpa_hexdump_ascii(MSG_MSGDUMP
,
4309 "nl80211: Sched scan filter SSID",
4310 drv
->filter_ssids
[i
].ssid
,
4311 drv
->filter_ssids
[i
].ssid_len
);
4313 match_set_ssid
= nla_nest_start(msg
, i
+ 1);
4314 if (match_set_ssid
== NULL
)
4315 goto nla_put_failure
;
4316 NLA_PUT(msg
, NL80211_ATTR_SCHED_SCAN_MATCH_SSID
,
4317 drv
->filter_ssids
[i
].ssid_len
,
4318 drv
->filter_ssids
[i
].ssid
);
4320 nla_nest_end(msg
, match_set_ssid
);
4323 if (params
->filter_rssi
) {
4324 struct nlattr
*match_set_rssi
;
4325 match_set_rssi
= nla_nest_start(msg
, 0);
4326 if (match_set_rssi
== NULL
)
4327 goto nla_put_failure
;
4328 NLA_PUT_U32(msg
, NL80211_SCHED_SCAN_MATCH_ATTR_RSSI
,
4329 params
->filter_rssi
);
4330 wpa_printf(MSG_MSGDUMP
,
4331 "nl80211: Sched scan RSSI filter %d dBm",
4332 params
->filter_rssi
);
4333 nla_nest_end(msg
, match_set_rssi
);
4336 nla_nest_end(msg
, match_sets
);
4339 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4341 /* TODO: if we get an error here, we should fall back to normal scan */
4345 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan start failed: "
4346 "ret=%d (%s)", ret
, strerror(-ret
));
4347 goto nla_put_failure
;
4350 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan requested (ret=%d) - "
4351 "scan interval %d msec", ret
, interval
);
4360 * wpa_driver_nl80211_stop_sched_scan - Stop a scheduled scan
4361 * @priv: Pointer to private driver data from wpa_driver_nl80211_init()
4362 * Returns: 0 on success, -1 on failure or if not supported
4364 static int wpa_driver_nl80211_stop_sched_scan(void *priv
)
4366 struct i802_bss
*bss
= priv
;
4367 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4372 if (!drv
->capa
.sched_scan_supported
)
4373 return android_pno_stop(bss
);
4374 #endif /* ANDROID */
4376 msg
= nlmsg_alloc();
4380 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_STOP_SCHED_SCAN
);
4382 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4384 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4387 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop failed: "
4388 "ret=%d (%s)", ret
, strerror(-ret
));
4389 goto nla_put_failure
;
4392 wpa_printf(MSG_DEBUG
, "nl80211: Sched scan stop sent (ret=%d)", ret
);
4400 static const u8
* nl80211_get_ie(const u8
*ies
, size_t ies_len
, u8 ie
)
4402 const u8
*end
, *pos
;
4408 end
= ies
+ ies_len
;
4410 while (pos
+ 1 < end
) {
4411 if (pos
+ 2 + pos
[1] > end
)
4422 static int nl80211_scan_filtered(struct wpa_driver_nl80211_data
*drv
,
4423 const u8
*ie
, size_t ie_len
)
4428 if (drv
->filter_ssids
== NULL
)
4431 ssid
= nl80211_get_ie(ie
, ie_len
, WLAN_EID_SSID
);
4435 for (i
= 0; i
< drv
->num_filter_ssids
; i
++) {
4436 if (ssid
[1] == drv
->filter_ssids
[i
].ssid_len
&&
4437 os_memcmp(ssid
+ 2, drv
->filter_ssids
[i
].ssid
, ssid
[1]) ==
4446 static int bss_info_handler(struct nl_msg
*msg
, void *arg
)
4448 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
4449 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
4450 struct nlattr
*bss
[NL80211_BSS_MAX
+ 1];
4451 static struct nla_policy bss_policy
[NL80211_BSS_MAX
+ 1] = {
4452 [NL80211_BSS_BSSID
] = { .type
= NLA_UNSPEC
},
4453 [NL80211_BSS_FREQUENCY
] = { .type
= NLA_U32
},
4454 [NL80211_BSS_TSF
] = { .type
= NLA_U64
},
4455 [NL80211_BSS_BEACON_INTERVAL
] = { .type
= NLA_U16
},
4456 [NL80211_BSS_CAPABILITY
] = { .type
= NLA_U16
},
4457 [NL80211_BSS_INFORMATION_ELEMENTS
] = { .type
= NLA_UNSPEC
},
4458 [NL80211_BSS_SIGNAL_MBM
] = { .type
= NLA_U32
},
4459 [NL80211_BSS_SIGNAL_UNSPEC
] = { .type
= NLA_U8
},
4460 [NL80211_BSS_STATUS
] = { .type
= NLA_U32
},
4461 [NL80211_BSS_SEEN_MS_AGO
] = { .type
= NLA_U32
},
4462 [NL80211_BSS_BEACON_IES
] = { .type
= NLA_UNSPEC
},
4464 struct nl80211_bss_info_arg
*_arg
= arg
;
4465 struct wpa_scan_results
*res
= _arg
->res
;
4466 struct wpa_scan_res
**tmp
;
4467 struct wpa_scan_res
*r
;
4468 const u8
*ie
, *beacon_ie
;
4469 size_t ie_len
, beacon_ie_len
;
4473 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
4474 genlmsg_attrlen(gnlh
, 0), NULL
);
4475 if (!tb
[NL80211_ATTR_BSS
])
4477 if (nla_parse_nested(bss
, NL80211_BSS_MAX
, tb
[NL80211_ATTR_BSS
],
4480 if (bss
[NL80211_BSS_STATUS
]) {
4481 enum nl80211_bss_status status
;
4482 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4483 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4484 bss
[NL80211_BSS_FREQUENCY
]) {
4486 nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4487 wpa_printf(MSG_DEBUG
, "nl80211: Associated on %u MHz",
4490 if (status
== NL80211_BSS_STATUS_ASSOCIATED
&&
4491 bss
[NL80211_BSS_BSSID
]) {
4492 os_memcpy(_arg
->assoc_bssid
,
4493 nla_data(bss
[NL80211_BSS_BSSID
]), ETH_ALEN
);
4494 wpa_printf(MSG_DEBUG
, "nl80211: Associated with "
4495 MACSTR
, MAC2STR(_arg
->assoc_bssid
));
4500 if (bss
[NL80211_BSS_INFORMATION_ELEMENTS
]) {
4501 ie
= nla_data(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4502 ie_len
= nla_len(bss
[NL80211_BSS_INFORMATION_ELEMENTS
]);
4507 if (bss
[NL80211_BSS_BEACON_IES
]) {
4508 beacon_ie
= nla_data(bss
[NL80211_BSS_BEACON_IES
]);
4509 beacon_ie_len
= nla_len(bss
[NL80211_BSS_BEACON_IES
]);
4515 if (nl80211_scan_filtered(_arg
->drv
, ie
? ie
: beacon_ie
,
4516 ie
? ie_len
: beacon_ie_len
))
4519 r
= os_zalloc(sizeof(*r
) + ie_len
+ beacon_ie_len
);
4522 if (bss
[NL80211_BSS_BSSID
])
4523 os_memcpy(r
->bssid
, nla_data(bss
[NL80211_BSS_BSSID
]),
4525 if (bss
[NL80211_BSS_FREQUENCY
])
4526 r
->freq
= nla_get_u32(bss
[NL80211_BSS_FREQUENCY
]);
4527 if (bss
[NL80211_BSS_BEACON_INTERVAL
])
4528 r
->beacon_int
= nla_get_u16(bss
[NL80211_BSS_BEACON_INTERVAL
]);
4529 if (bss
[NL80211_BSS_CAPABILITY
])
4530 r
->caps
= nla_get_u16(bss
[NL80211_BSS_CAPABILITY
]);
4531 r
->flags
|= WPA_SCAN_NOISE_INVALID
;
4532 if (bss
[NL80211_BSS_SIGNAL_MBM
]) {
4533 r
->level
= nla_get_u32(bss
[NL80211_BSS_SIGNAL_MBM
]);
4534 r
->level
/= 100; /* mBm to dBm */
4535 r
->flags
|= WPA_SCAN_LEVEL_DBM
| WPA_SCAN_QUAL_INVALID
;
4536 } else if (bss
[NL80211_BSS_SIGNAL_UNSPEC
]) {
4537 r
->level
= nla_get_u8(bss
[NL80211_BSS_SIGNAL_UNSPEC
]);
4538 r
->flags
|= WPA_SCAN_QUAL_INVALID
;
4540 r
->flags
|= WPA_SCAN_LEVEL_INVALID
| WPA_SCAN_QUAL_INVALID
;
4541 if (bss
[NL80211_BSS_TSF
])
4542 r
->tsf
= nla_get_u64(bss
[NL80211_BSS_TSF
]);
4543 if (bss
[NL80211_BSS_SEEN_MS_AGO
])
4544 r
->age
= nla_get_u32(bss
[NL80211_BSS_SEEN_MS_AGO
]);
4546 pos
= (u8
*) (r
+ 1);
4548 os_memcpy(pos
, ie
, ie_len
);
4551 r
->beacon_ie_len
= beacon_ie_len
;
4553 os_memcpy(pos
, beacon_ie
, beacon_ie_len
);
4555 if (bss
[NL80211_BSS_STATUS
]) {
4556 enum nl80211_bss_status status
;
4557 status
= nla_get_u32(bss
[NL80211_BSS_STATUS
]);
4559 case NL80211_BSS_STATUS_AUTHENTICATED
:
4560 r
->flags
|= WPA_SCAN_AUTHENTICATED
;
4562 case NL80211_BSS_STATUS_ASSOCIATED
:
4563 r
->flags
|= WPA_SCAN_ASSOCIATED
;
4571 * cfg80211 maintains separate BSS table entries for APs if the same
4572 * BSSID,SSID pair is seen on multiple channels. wpa_supplicant does
4573 * not use frequency as a separate key in the BSS table, so filter out
4574 * duplicated entries. Prefer associated BSS entry in such a case in
4575 * order to get the correct frequency into the BSS table.
4577 for (i
= 0; i
< res
->num
; i
++) {
4579 if (os_memcmp(res
->res
[i
]->bssid
, r
->bssid
, ETH_ALEN
) != 0)
4582 s1
= nl80211_get_ie((u8
*) (res
->res
[i
] + 1),
4583 res
->res
[i
]->ie_len
, WLAN_EID_SSID
);
4584 s2
= nl80211_get_ie((u8
*) (r
+ 1), r
->ie_len
, WLAN_EID_SSID
);
4585 if (s1
== NULL
|| s2
== NULL
|| s1
[1] != s2
[1] ||
4586 os_memcmp(s1
, s2
, 2 + s1
[1]) != 0)
4589 /* Same BSSID,SSID was already included in scan results */
4590 wpa_printf(MSG_DEBUG
, "nl80211: Remove duplicated scan result "
4591 "for " MACSTR
, MAC2STR(r
->bssid
));
4593 if ((r
->flags
& WPA_SCAN_ASSOCIATED
) &&
4594 !(res
->res
[i
]->flags
& WPA_SCAN_ASSOCIATED
)) {
4595 os_free(res
->res
[i
]);
4602 tmp
= os_realloc_array(res
->res
, res
->num
+ 1,
4603 sizeof(struct wpa_scan_res
*));
4608 tmp
[res
->num
++] = r
;
4615 static void clear_state_mismatch(struct wpa_driver_nl80211_data
*drv
,
4618 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
) {
4619 wpa_printf(MSG_DEBUG
, "nl80211: Clear possible state "
4620 "mismatch (" MACSTR
")", MAC2STR(addr
));
4621 wpa_driver_nl80211_mlme(drv
, addr
,
4622 NL80211_CMD_DEAUTHENTICATE
,
4623 WLAN_REASON_PREV_AUTH_NOT_VALID
, 1);
4628 static void wpa_driver_nl80211_check_bss_status(
4629 struct wpa_driver_nl80211_data
*drv
, struct wpa_scan_results
*res
)
4633 for (i
= 0; i
< res
->num
; i
++) {
4634 struct wpa_scan_res
*r
= res
->res
[i
];
4635 if (r
->flags
& WPA_SCAN_AUTHENTICATED
) {
4636 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4637 "indicates BSS status with " MACSTR
4638 " as authenticated",
4640 if (is_sta_interface(drv
->nlmode
) &&
4641 os_memcmp(r
->bssid
, drv
->bssid
, ETH_ALEN
) != 0 &&
4642 os_memcmp(r
->bssid
, drv
->auth_bssid
, ETH_ALEN
) !=
4644 wpa_printf(MSG_DEBUG
, "nl80211: Unknown BSSID"
4645 " in local state (auth=" MACSTR
4646 " assoc=" MACSTR
")",
4647 MAC2STR(drv
->auth_bssid
),
4648 MAC2STR(drv
->bssid
));
4649 clear_state_mismatch(drv
, r
->bssid
);
4653 if (r
->flags
& WPA_SCAN_ASSOCIATED
) {
4654 wpa_printf(MSG_DEBUG
, "nl80211: Scan results "
4655 "indicate BSS status with " MACSTR
4658 if (is_sta_interface(drv
->nlmode
) &&
4660 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4661 "(not associated) does not match "
4663 clear_state_mismatch(drv
, r
->bssid
);
4664 } else if (is_sta_interface(drv
->nlmode
) &&
4665 os_memcmp(drv
->bssid
, r
->bssid
, ETH_ALEN
) !=
4667 wpa_printf(MSG_DEBUG
, "nl80211: Local state "
4668 "(associated with " MACSTR
") does "
4669 "not match with BSS state",
4670 MAC2STR(drv
->bssid
));
4671 clear_state_mismatch(drv
, r
->bssid
);
4672 clear_state_mismatch(drv
, drv
->bssid
);
4679 static struct wpa_scan_results
*
4680 nl80211_get_scan_results(struct wpa_driver_nl80211_data
*drv
)
4683 struct wpa_scan_results
*res
;
4685 struct nl80211_bss_info_arg arg
;
4687 res
= os_zalloc(sizeof(*res
));
4690 msg
= nlmsg_alloc();
4692 goto nla_put_failure
;
4694 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_SCAN
);
4695 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
4699 ret
= send_and_recv_msgs(drv
, msg
, bss_info_handler
, &arg
);
4702 wpa_printf(MSG_DEBUG
, "nl80211: Received scan results (%lu "
4703 "BSSes)", (unsigned long) res
->num
);
4704 nl80211_get_noise_for_scan_results(drv
, res
);
4707 wpa_printf(MSG_DEBUG
, "nl80211: Scan result fetch failed: ret=%d "
4708 "(%s)", ret
, strerror(-ret
));
4711 wpa_scan_results_free(res
);
4717 * wpa_driver_nl80211_get_scan_results - Fetch the latest scan results
4718 * @priv: Pointer to private wext data from wpa_driver_nl80211_init()
4719 * Returns: Scan results on success, -1 on failure
4721 static struct wpa_scan_results
*
4722 wpa_driver_nl80211_get_scan_results(void *priv
)
4724 struct i802_bss
*bss
= priv
;
4725 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4726 struct wpa_scan_results
*res
;
4728 res
= nl80211_get_scan_results(drv
);
4730 wpa_driver_nl80211_check_bss_status(drv
, res
);
4735 static void nl80211_dump_scan(struct wpa_driver_nl80211_data
*drv
)
4737 struct wpa_scan_results
*res
;
4740 res
= nl80211_get_scan_results(drv
);
4742 wpa_printf(MSG_DEBUG
, "nl80211: Failed to get scan results");
4746 wpa_printf(MSG_DEBUG
, "nl80211: Scan result dump");
4747 for (i
= 0; i
< res
->num
; i
++) {
4748 struct wpa_scan_res
*r
= res
->res
[i
];
4749 wpa_printf(MSG_DEBUG
, "nl80211: %d/%d " MACSTR
"%s%s",
4750 (int) i
, (int) res
->num
, MAC2STR(r
->bssid
),
4751 r
->flags
& WPA_SCAN_AUTHENTICATED
? " [auth]" : "",
4752 r
->flags
& WPA_SCAN_ASSOCIATED
? " [assoc]" : "");
4755 wpa_scan_results_free(res
);
4759 static int wpa_driver_nl80211_set_key(const char *ifname
, struct i802_bss
*bss
,
4760 enum wpa_alg alg
, const u8
*addr
,
4761 int key_idx
, int set_tx
,
4762 const u8
*seq
, size_t seq_len
,
4763 const u8
*key
, size_t key_len
)
4765 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
4770 /* Ignore for P2P Device */
4771 if (drv
->nlmode
== NL80211_IFTYPE_P2P_DEVICE
)
4774 ifindex
= if_nametoindex(ifname
);
4775 wpa_printf(MSG_DEBUG
, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
4776 "set_tx=%d seq_len=%lu key_len=%lu",
4777 __func__
, ifindex
, ifname
, alg
, addr
, key_idx
, set_tx
,
4778 (unsigned long) seq_len
, (unsigned long) key_len
);
4782 #endif /* CONFIG_TDLS */
4784 msg
= nlmsg_alloc();
4788 if (alg
== WPA_ALG_NONE
) {
4789 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_KEY
);
4791 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_KEY
);
4792 NLA_PUT(msg
, NL80211_ATTR_KEY_DATA
, key_len
, key
);
4796 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4797 WLAN_CIPHER_SUITE_WEP40
);
4799 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4800 WLAN_CIPHER_SUITE_WEP104
);
4803 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4804 WLAN_CIPHER_SUITE_TKIP
);
4807 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4808 WLAN_CIPHER_SUITE_CCMP
);
4811 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4812 WLAN_CIPHER_SUITE_GCMP
);
4815 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4816 WLAN_CIPHER_SUITE_AES_CMAC
);
4819 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4820 WLAN_CIPHER_SUITE_SMS4
);
4823 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_CIPHER
,
4824 WLAN_CIPHER_SUITE_KRK
);
4827 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4828 "algorithm %d", __func__
, alg
);
4835 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, seq_len
, seq
);
4837 if (addr
&& !is_broadcast_ether_addr(addr
)) {
4838 wpa_printf(MSG_DEBUG
, " addr=" MACSTR
, MAC2STR(addr
));
4839 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4841 if (alg
!= WPA_ALG_WEP
&& key_idx
&& !set_tx
) {
4842 wpa_printf(MSG_DEBUG
, " RSN IBSS RX GTK");
4843 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
,
4844 NL80211_KEYTYPE_GROUP
);
4846 } else if (addr
&& is_broadcast_ether_addr(addr
)) {
4847 struct nlattr
*types
;
4849 wpa_printf(MSG_DEBUG
, " broadcast key");
4851 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
4853 goto nla_put_failure
;
4854 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4855 nla_nest_end(msg
, types
);
4857 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4858 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4860 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4861 if ((ret
== -ENOENT
|| ret
== -ENOLINK
) && alg
== WPA_ALG_NONE
)
4864 wpa_printf(MSG_DEBUG
, "nl80211: set_key failed; err=%d %s)",
4865 ret
, strerror(-ret
));
4868 * If we failed or don't need to set the default TX key (below),
4871 if (ret
|| !set_tx
|| alg
== WPA_ALG_NONE
)
4873 if (is_ap_interface(drv
->nlmode
) && addr
&&
4874 !is_broadcast_ether_addr(addr
))
4877 msg
= nlmsg_alloc();
4881 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_KEY
);
4882 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
4883 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
4884 if (alg
== WPA_ALG_IGTK
)
4885 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT_MGMT
);
4887 NLA_PUT_FLAG(msg
, NL80211_ATTR_KEY_DEFAULT
);
4888 if (addr
&& is_broadcast_ether_addr(addr
)) {
4889 struct nlattr
*types
;
4891 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
4893 goto nla_put_failure
;
4894 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_MULTICAST
);
4895 nla_nest_end(msg
, types
);
4897 struct nlattr
*types
;
4899 types
= nla_nest_start(msg
, NL80211_ATTR_KEY_DEFAULT_TYPES
);
4901 goto nla_put_failure
;
4902 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_TYPE_UNICAST
);
4903 nla_nest_end(msg
, types
);
4906 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
4910 wpa_printf(MSG_DEBUG
, "nl80211: set_key default failed; "
4911 "err=%d %s)", ret
, strerror(-ret
));
4920 static int nl_add_key(struct nl_msg
*msg
, enum wpa_alg alg
,
4921 int key_idx
, int defkey
,
4922 const u8
*seq
, size_t seq_len
,
4923 const u8
*key
, size_t key_len
)
4925 struct nlattr
*key_attr
= nla_nest_start(msg
, NL80211_ATTR_KEY
);
4929 if (defkey
&& alg
== WPA_ALG_IGTK
)
4930 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT_MGMT
);
4932 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
4934 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, key_idx
);
4939 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4940 WLAN_CIPHER_SUITE_WEP40
);
4942 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4943 WLAN_CIPHER_SUITE_WEP104
);
4946 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_TKIP
);
4949 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_CCMP
);
4952 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, WLAN_CIPHER_SUITE_GCMP
);
4955 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
4956 WLAN_CIPHER_SUITE_AES_CMAC
);
4959 wpa_printf(MSG_ERROR
, "%s: Unsupported encryption "
4960 "algorithm %d", __func__
, alg
);
4965 NLA_PUT(msg
, NL80211_KEY_SEQ
, seq_len
, seq
);
4967 NLA_PUT(msg
, NL80211_KEY_DATA
, key_len
, key
);
4969 nla_nest_end(msg
, key_attr
);
4977 static int nl80211_set_conn_keys(struct wpa_driver_associate_params
*params
,
4981 struct nlattr
*nl_keys
, *nl_key
;
4983 for (i
= 0; i
< 4; i
++) {
4984 if (!params
->wep_key
[i
])
4989 if (params
->wps
== WPS_MODE_PRIVACY
)
4991 if (params
->pairwise_suite
&&
4992 params
->pairwise_suite
!= WPA_CIPHER_NONE
)
4998 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
5000 nl_keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
5002 goto nla_put_failure
;
5004 for (i
= 0; i
< 4; i
++) {
5005 if (!params
->wep_key
[i
])
5008 nl_key
= nla_nest_start(msg
, i
);
5010 goto nla_put_failure
;
5012 NLA_PUT(msg
, NL80211_KEY_DATA
, params
->wep_key_len
[i
],
5013 params
->wep_key
[i
]);
5014 if (params
->wep_key_len
[i
] == 5)
5015 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5016 WLAN_CIPHER_SUITE_WEP40
);
5018 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
,
5019 WLAN_CIPHER_SUITE_WEP104
);
5021 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, i
);
5023 if (i
== params
->wep_tx_keyidx
)
5024 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
5026 nla_nest_end(msg
, nl_key
);
5028 nla_nest_end(msg
, nl_keys
);
5037 static int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data
*drv
,
5038 const u8
*addr
, int cmd
, u16 reason_code
,
5039 int local_state_change
)
5044 msg
= nlmsg_alloc();
5048 nl80211_cmd(drv
, msg
, 0, cmd
);
5050 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5051 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
5053 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5054 if (local_state_change
)
5055 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
5057 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5060 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5061 "nl80211: MLME command failed: reason=%u ret=%d (%s)",
5062 reason_code
, ret
, strerror(-ret
));
5063 goto nla_put_failure
;
5073 static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data
*drv
,
5076 wpa_printf(MSG_DEBUG
, "%s(reason_code=%d)", __func__
, reason_code
);
5077 nl80211_mark_disconnected(drv
);
5078 drv
->ignore_next_local_disconnect
= 0;
5079 /* Disconnect command doesn't need BSSID - it uses cached value */
5080 return wpa_driver_nl80211_mlme(drv
, NULL
, NL80211_CMD_DISCONNECT
,
5085 static int wpa_driver_nl80211_deauthenticate(struct i802_bss
*bss
,
5086 const u8
*addr
, int reason_code
)
5088 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5089 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
))
5090 return wpa_driver_nl80211_disconnect(drv
, reason_code
);
5091 wpa_printf(MSG_DEBUG
, "%s(addr=" MACSTR
" reason_code=%d)",
5092 __func__
, MAC2STR(addr
), reason_code
);
5093 nl80211_mark_disconnected(drv
);
5094 if (drv
->nlmode
== NL80211_IFTYPE_ADHOC
)
5095 return nl80211_leave_ibss(drv
);
5096 return wpa_driver_nl80211_mlme(drv
, addr
, NL80211_CMD_DEAUTHENTICATE
,
5101 static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data
*drv
,
5102 struct wpa_driver_auth_params
*params
)
5106 drv
->auth_freq
= params
->freq
;
5107 drv
->auth_alg
= params
->auth_alg
;
5108 drv
->auth_wep_tx_keyidx
= params
->wep_tx_keyidx
;
5109 drv
->auth_local_state_change
= params
->local_state_change
;
5110 drv
->auth_p2p
= params
->p2p
;
5113 os_memcpy(drv
->auth_bssid_
, params
->bssid
, ETH_ALEN
);
5115 os_memset(drv
->auth_bssid_
, 0, ETH_ALEN
);
5118 os_memcpy(drv
->auth_ssid
, params
->ssid
, params
->ssid_len
);
5119 drv
->auth_ssid_len
= params
->ssid_len
;
5121 drv
->auth_ssid_len
= 0;
5124 os_free(drv
->auth_ie
);
5125 drv
->auth_ie
= NULL
;
5126 drv
->auth_ie_len
= 0;
5128 drv
->auth_ie
= os_malloc(params
->ie_len
);
5130 os_memcpy(drv
->auth_ie
, params
->ie
, params
->ie_len
);
5131 drv
->auth_ie_len
= params
->ie_len
;
5135 for (i
= 0; i
< 4; i
++) {
5136 if (params
->wep_key
[i
] && params
->wep_key_len
[i
] &&
5137 params
->wep_key_len
[i
] <= 16) {
5138 os_memcpy(drv
->auth_wep_key
[i
], params
->wep_key
[i
],
5139 params
->wep_key_len
[i
]);
5140 drv
->auth_wep_key_len
[i
] = params
->wep_key_len
[i
];
5142 drv
->auth_wep_key_len
[i
] = 0;
5147 static int wpa_driver_nl80211_authenticate(
5148 struct i802_bss
*bss
, struct wpa_driver_auth_params
*params
)
5150 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5153 enum nl80211_auth_type type
;
5154 enum nl80211_iftype nlmode
;
5158 is_retry
= drv
->retry_auth
;
5159 drv
->retry_auth
= 0;
5161 nl80211_mark_disconnected(drv
);
5162 os_memset(drv
->auth_bssid
, 0, ETH_ALEN
);
5164 os_memcpy(drv
->auth_attempt_bssid
, params
->bssid
, ETH_ALEN
);
5166 os_memset(drv
->auth_attempt_bssid
, 0, ETH_ALEN
);
5167 /* FIX: IBSS mode */
5168 nlmode
= params
->p2p
?
5169 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
5170 if (drv
->nlmode
!= nlmode
&&
5171 wpa_driver_nl80211_set_mode(bss
, nlmode
) < 0)
5175 msg
= nlmsg_alloc();
5179 wpa_printf(MSG_DEBUG
, "nl80211: Authenticate (ifindex=%d)",
5182 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_AUTHENTICATE
);
5184 for (i
= 0; i
< 4; i
++) {
5185 if (!params
->wep_key
[i
])
5187 wpa_driver_nl80211_set_key(bss
->ifname
, bss
, WPA_ALG_WEP
,
5189 i
== params
->wep_tx_keyidx
, NULL
, 0,
5191 params
->wep_key_len
[i
]);
5192 if (params
->wep_tx_keyidx
!= i
)
5194 if (nl_add_key(msg
, WPA_ALG_WEP
, i
, 1, NULL
, 0,
5195 params
->wep_key
[i
], params
->wep_key_len
[i
])) {
5201 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5202 if (params
->bssid
) {
5203 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
5204 MAC2STR(params
->bssid
));
5205 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
5208 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
5209 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
5212 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
5213 params
->ssid
, params
->ssid_len
);
5214 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
5217 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->ie
, params
->ie_len
);
5219 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->ie_len
, params
->ie
);
5220 if (params
->sae_data
) {
5221 wpa_hexdump(MSG_DEBUG
, " * SAE data", params
->sae_data
,
5222 params
->sae_data_len
);
5223 NLA_PUT(msg
, NL80211_ATTR_SAE_DATA
, params
->sae_data_len
,
5226 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
5227 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
5228 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
5229 type
= NL80211_AUTHTYPE_SHARED_KEY
;
5230 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
5231 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
5232 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
5233 type
= NL80211_AUTHTYPE_FT
;
5234 else if (params
->auth_alg
& WPA_AUTH_ALG_SAE
)
5235 type
= NL80211_AUTHTYPE_SAE
;
5237 goto nla_put_failure
;
5238 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
5239 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
5240 if (params
->local_state_change
) {
5241 wpa_printf(MSG_DEBUG
, " * Local state change only");
5242 NLA_PUT_FLAG(msg
, NL80211_ATTR_LOCAL_STATE_CHANGE
);
5245 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
5248 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
5249 "nl80211: MLME command failed (auth): ret=%d (%s)",
5250 ret
, strerror(-ret
));
5252 if (ret
== -EALREADY
&& count
== 1 && params
->bssid
&&
5253 !params
->local_state_change
) {
5255 * mac80211 does not currently accept new
5256 * authentication if we are already authenticated. As a
5257 * workaround, force deauthentication and try again.
5259 wpa_printf(MSG_DEBUG
, "nl80211: Retry authentication "
5260 "after forced deauthentication");
5261 wpa_driver_nl80211_deauthenticate(
5263 WLAN_REASON_PREV_AUTH_NOT_VALID
);
5268 if (ret
== -ENOENT
&& params
->freq
&& !is_retry
) {
5270 * cfg80211 has likely expired the BSS entry even
5271 * though it was previously available in our internal
5272 * BSS table. To recover quickly, start a single
5273 * channel scan on the specified channel.
5275 struct wpa_driver_scan_params scan
;
5278 os_memset(&scan
, 0, sizeof(scan
));
5281 scan
.ssids
[0].ssid
= params
->ssid
;
5282 scan
.ssids
[0].ssid_len
= params
->ssid_len
;
5284 freqs
[0] = params
->freq
;
5287 wpa_printf(MSG_DEBUG
, "nl80211: Trigger single "
5288 "channel scan to refresh cfg80211 BSS "
5290 ret
= wpa_driver_nl80211_scan(bss
, &scan
);
5292 nl80211_copy_auth_params(drv
, params
);
5293 drv
->scan_for_auth
= 1;
5295 } else if (is_retry
) {
5297 * Need to indicate this with an event since the return
5298 * value from the retry is not delivered to core code.
5300 union wpa_event_data event
;
5301 wpa_printf(MSG_DEBUG
, "nl80211: Authentication retry "
5303 os_memset(&event
, 0, sizeof(event
));
5304 os_memcpy(event
.timeout_event
.addr
, drv
->auth_bssid_
,
5306 wpa_supplicant_event(drv
->ctx
, EVENT_AUTH_TIMED_OUT
,
5310 goto nla_put_failure
;
5313 wpa_printf(MSG_DEBUG
, "nl80211: Authentication request send "
5322 static int wpa_driver_nl80211_authenticate_retry(
5323 struct wpa_driver_nl80211_data
*drv
)
5325 struct wpa_driver_auth_params params
;
5326 struct i802_bss
*bss
= &drv
->first_bss
;
5329 wpa_printf(MSG_DEBUG
, "nl80211: Try to authenticate again");
5331 os_memset(¶ms
, 0, sizeof(params
));
5332 params
.freq
= drv
->auth_freq
;
5333 params
.auth_alg
= drv
->auth_alg
;
5334 params
.wep_tx_keyidx
= drv
->auth_wep_tx_keyidx
;
5335 params
.local_state_change
= drv
->auth_local_state_change
;
5336 params
.p2p
= drv
->auth_p2p
;
5338 if (!is_zero_ether_addr(drv
->auth_bssid_
))
5339 params
.bssid
= drv
->auth_bssid_
;
5341 if (drv
->auth_ssid_len
) {
5342 params
.ssid
= drv
->auth_ssid
;
5343 params
.ssid_len
= drv
->auth_ssid_len
;
5346 params
.ie
= drv
->auth_ie
;
5347 params
.ie_len
= drv
->auth_ie_len
;
5349 for (i
= 0; i
< 4; i
++) {
5350 if (drv
->auth_wep_key_len
[i
]) {
5351 params
.wep_key
[i
] = drv
->auth_wep_key
[i
];
5352 params
.wep_key_len
[i
] = drv
->auth_wep_key_len
[i
];
5356 drv
->retry_auth
= 1;
5357 return wpa_driver_nl80211_authenticate(bss
, ¶ms
);
5361 struct phy_info_arg
{
5363 struct hostapd_hw_modes
*modes
;
5364 int last_mode
, last_chan_idx
;
5367 static void phy_info_ht_capa(struct hostapd_hw_modes
*mode
, struct nlattr
*capa
,
5368 struct nlattr
*ampdu_factor
,
5369 struct nlattr
*ampdu_density
,
5370 struct nlattr
*mcs_set
)
5373 mode
->ht_capab
= nla_get_u16(capa
);
5376 mode
->a_mpdu_params
|= nla_get_u8(ampdu_factor
) & 0x03;
5379 mode
->a_mpdu_params
|= nla_get_u8(ampdu_density
) << 2;
5381 if (mcs_set
&& nla_len(mcs_set
) >= 16) {
5383 mcs
= nla_data(mcs_set
);
5384 os_memcpy(mode
->mcs_set
, mcs
, 16);
5389 static void phy_info_vht_capa(struct hostapd_hw_modes
*mode
,
5390 struct nlattr
*capa
,
5391 struct nlattr
*mcs_set
)
5394 mode
->vht_capab
= nla_get_u32(capa
);
5396 if (mcs_set
&& nla_len(mcs_set
) >= 8) {
5398 mcs
= nla_data(mcs_set
);
5399 os_memcpy(mode
->vht_mcs_set
, mcs
, 8);
5404 static void phy_info_freq(struct hostapd_hw_modes
*mode
,
5405 struct hostapd_channel_data
*chan
,
5406 struct nlattr
*tb_freq
[])
5409 chan
->freq
= nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
]);
5411 if (ieee80211_freq_to_chan(chan
->freq
, &channel
) != NUM_HOSTAPD_MODES
)
5412 chan
->chan
= channel
;
5414 if (tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
5415 chan
->flag
|= HOSTAPD_CHAN_DISABLED
;
5416 if (tb_freq
[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
])
5417 chan
->flag
|= HOSTAPD_CHAN_PASSIVE_SCAN
;
5418 if (tb_freq
[NL80211_FREQUENCY_ATTR_NO_IBSS
])
5419 chan
->flag
|= HOSTAPD_CHAN_NO_IBSS
;
5420 if (tb_freq
[NL80211_FREQUENCY_ATTR_RADAR
])
5421 chan
->flag
|= HOSTAPD_CHAN_RADAR
;
5423 if (tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] &&
5424 !tb_freq
[NL80211_FREQUENCY_ATTR_DISABLED
])
5425 chan
->max_tx_power
= nla_get_u32(
5426 tb_freq
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER
]) / 100;
5427 if (tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]) {
5428 enum nl80211_dfs_state state
=
5429 nla_get_u32(tb_freq
[NL80211_FREQUENCY_ATTR_DFS_STATE
]);
5432 case NL80211_DFS_USABLE
:
5433 chan
->flag
|= HOSTAPD_CHAN_DFS_USABLE
;
5435 case NL80211_DFS_AVAILABLE
:
5436 chan
->flag
|= HOSTAPD_CHAN_DFS_AVAILABLE
;
5438 case NL80211_DFS_UNAVAILABLE
:
5439 chan
->flag
|= HOSTAPD_CHAN_DFS_UNAVAILABLE
;
5446 static int phy_info_freqs(struct phy_info_arg
*phy_info
,
5447 struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5449 static struct nla_policy freq_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5450 [NL80211_FREQUENCY_ATTR_FREQ
] = { .type
= NLA_U32
},
5451 [NL80211_FREQUENCY_ATTR_DISABLED
] = { .type
= NLA_FLAG
},
5452 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
] = { .type
= NLA_FLAG
},
5453 [NL80211_FREQUENCY_ATTR_NO_IBSS
] = { .type
= NLA_FLAG
},
5454 [NL80211_FREQUENCY_ATTR_RADAR
] = { .type
= NLA_FLAG
},
5455 [NL80211_FREQUENCY_ATTR_MAX_TX_POWER
] = { .type
= NLA_U32
},
5456 [NL80211_FREQUENCY_ATTR_DFS_STATE
] = { .type
= NLA_U32
},
5458 int new_channels
= 0;
5459 struct hostapd_channel_data
*channel
;
5460 struct nlattr
*tb_freq
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5461 struct nlattr
*nl_freq
;
5467 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5468 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5469 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5470 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5475 channel
= os_realloc_array(mode
->channels
,
5476 mode
->num_channels
+ new_channels
,
5477 sizeof(struct hostapd_channel_data
));
5481 mode
->channels
= channel
;
5482 mode
->num_channels
+= new_channels
;
5484 idx
= phy_info
->last_chan_idx
;
5486 nla_for_each_nested(nl_freq
, tb
, rem_freq
) {
5487 nla_parse(tb_freq
, NL80211_FREQUENCY_ATTR_MAX
,
5488 nla_data(nl_freq
), nla_len(nl_freq
), freq_policy
);
5489 if (!tb_freq
[NL80211_FREQUENCY_ATTR_FREQ
])
5491 phy_info_freq(mode
, &mode
->channels
[idx
], tb_freq
);
5494 phy_info
->last_chan_idx
= idx
;
5500 static int phy_info_rates(struct hostapd_hw_modes
*mode
, struct nlattr
*tb
)
5502 static struct nla_policy rate_policy
[NL80211_BITRATE_ATTR_MAX
+ 1] = {
5503 [NL80211_BITRATE_ATTR_RATE
] = { .type
= NLA_U32
},
5504 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
] =
5505 { .type
= NLA_FLAG
},
5507 struct nlattr
*tb_rate
[NL80211_BITRATE_ATTR_MAX
+ 1];
5508 struct nlattr
*nl_rate
;
5514 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5515 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5516 nla_data(nl_rate
), nla_len(nl_rate
),
5518 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5523 mode
->rates
= os_calloc(mode
->num_rates
, sizeof(int));
5529 nla_for_each_nested(nl_rate
, tb
, rem_rate
) {
5530 nla_parse(tb_rate
, NL80211_BITRATE_ATTR_MAX
,
5531 nla_data(nl_rate
), nla_len(nl_rate
),
5533 if (!tb_rate
[NL80211_BITRATE_ATTR_RATE
])
5535 mode
->rates
[idx
] = nla_get_u32(
5536 tb_rate
[NL80211_BITRATE_ATTR_RATE
]);
5544 static int phy_info_band(struct phy_info_arg
*phy_info
, struct nlattr
*nl_band
)
5546 struct nlattr
*tb_band
[NL80211_BAND_ATTR_MAX
+ 1];
5547 struct hostapd_hw_modes
*mode
;
5550 if (phy_info
->last_mode
!= nl_band
->nla_type
) {
5551 mode
= os_realloc_array(phy_info
->modes
,
5552 *phy_info
->num_modes
+ 1,
5556 phy_info
->modes
= mode
;
5558 mode
= &phy_info
->modes
[*(phy_info
->num_modes
)];
5559 os_memset(mode
, 0, sizeof(*mode
));
5560 mode
->mode
= NUM_HOSTAPD_MODES
;
5561 mode
->flags
= HOSTAPD_MODE_FLAG_HT_INFO_KNOWN
;
5562 *(phy_info
->num_modes
) += 1;
5563 phy_info
->last_mode
= nl_band
->nla_type
;
5564 phy_info
->last_chan_idx
= 0;
5566 mode
= &phy_info
->modes
[*(phy_info
->num_modes
) - 1];
5568 nla_parse(tb_band
, NL80211_BAND_ATTR_MAX
, nla_data(nl_band
),
5569 nla_len(nl_band
), NULL
);
5571 phy_info_ht_capa(mode
, tb_band
[NL80211_BAND_ATTR_HT_CAPA
],
5572 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_FACTOR
],
5573 tb_band
[NL80211_BAND_ATTR_HT_AMPDU_DENSITY
],
5574 tb_band
[NL80211_BAND_ATTR_HT_MCS_SET
]);
5575 phy_info_vht_capa(mode
, tb_band
[NL80211_BAND_ATTR_VHT_CAPA
],
5576 tb_band
[NL80211_BAND_ATTR_VHT_MCS_SET
]);
5577 ret
= phy_info_freqs(phy_info
, mode
, tb_band
[NL80211_BAND_ATTR_FREQS
]);
5580 ret
= phy_info_rates(mode
, tb_band
[NL80211_BAND_ATTR_RATES
]);
5588 static int phy_info_handler(struct nl_msg
*msg
, void *arg
)
5590 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5591 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5592 struct phy_info_arg
*phy_info
= arg
;
5593 struct nlattr
*nl_band
;
5596 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5597 genlmsg_attrlen(gnlh
, 0), NULL
);
5599 if (!tb_msg
[NL80211_ATTR_WIPHY_BANDS
])
5602 nla_for_each_nested(nl_band
, tb_msg
[NL80211_ATTR_WIPHY_BANDS
], rem_band
)
5604 int res
= phy_info_band(phy_info
, nl_band
);
5613 static struct hostapd_hw_modes
*
5614 wpa_driver_nl80211_postprocess_modes(struct hostapd_hw_modes
*modes
,
5618 struct hostapd_hw_modes
*mode11g
= NULL
, *nmodes
, *mode
;
5619 int i
, mode11g_idx
= -1;
5621 /* heuristic to set up modes */
5622 for (m
= 0; m
< *num_modes
; m
++) {
5623 if (!modes
[m
].num_channels
)
5625 if (modes
[m
].channels
[0].freq
< 4000) {
5626 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211B
;
5627 for (i
= 0; i
< modes
[m
].num_rates
; i
++) {
5628 if (modes
[m
].rates
[i
] > 200) {
5629 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211G
;
5633 } else if (modes
[m
].channels
[0].freq
> 50000)
5634 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211AD
;
5636 modes
[m
].mode
= HOSTAPD_MODE_IEEE80211A
;
5639 /* If only 802.11g mode is included, use it to construct matching
5640 * 802.11b mode data. */
5642 for (m
= 0; m
< *num_modes
; m
++) {
5643 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211B
)
5644 return modes
; /* 802.11b already included */
5645 if (modes
[m
].mode
== HOSTAPD_MODE_IEEE80211G
)
5649 if (mode11g_idx
< 0)
5650 return modes
; /* 2.4 GHz band not supported at all */
5652 nmodes
= os_realloc_array(modes
, *num_modes
+ 1, sizeof(*nmodes
));
5654 return modes
; /* Could not add 802.11b mode */
5656 mode
= &nmodes
[*num_modes
];
5657 os_memset(mode
, 0, sizeof(*mode
));
5661 mode
->mode
= HOSTAPD_MODE_IEEE80211B
;
5663 mode11g
= &modes
[mode11g_idx
];
5664 mode
->num_channels
= mode11g
->num_channels
;
5665 mode
->channels
= os_malloc(mode11g
->num_channels
*
5666 sizeof(struct hostapd_channel_data
));
5667 if (mode
->channels
== NULL
) {
5669 return modes
; /* Could not add 802.11b mode */
5671 os_memcpy(mode
->channels
, mode11g
->channels
,
5672 mode11g
->num_channels
* sizeof(struct hostapd_channel_data
));
5674 mode
->num_rates
= 0;
5675 mode
->rates
= os_malloc(4 * sizeof(int));
5676 if (mode
->rates
== NULL
) {
5677 os_free(mode
->channels
);
5679 return modes
; /* Could not add 802.11b mode */
5682 for (i
= 0; i
< mode11g
->num_rates
; i
++) {
5683 if (mode11g
->rates
[i
] != 10 && mode11g
->rates
[i
] != 20 &&
5684 mode11g
->rates
[i
] != 55 && mode11g
->rates
[i
] != 110)
5686 mode
->rates
[mode
->num_rates
] = mode11g
->rates
[i
];
5688 if (mode
->num_rates
== 4)
5692 if (mode
->num_rates
== 0) {
5693 os_free(mode
->channels
);
5694 os_free(mode
->rates
);
5696 return modes
; /* No 802.11b rates */
5699 wpa_printf(MSG_DEBUG
, "nl80211: Added 802.11b mode based on 802.11g "
5706 static void nl80211_set_ht40_mode(struct hostapd_hw_modes
*mode
, int start
,
5711 for (c
= 0; c
< mode
->num_channels
; c
++) {
5712 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5713 if (chan
->freq
- 10 >= start
&& chan
->freq
+ 10 <= end
)
5714 chan
->flag
|= HOSTAPD_CHAN_HT40
;
5719 static void nl80211_set_ht40_mode_sec(struct hostapd_hw_modes
*mode
, int start
,
5724 for (c
= 0; c
< mode
->num_channels
; c
++) {
5725 struct hostapd_channel_data
*chan
= &mode
->channels
[c
];
5726 if (!(chan
->flag
& HOSTAPD_CHAN_HT40
))
5728 if (chan
->freq
- 30 >= start
&& chan
->freq
- 10 <= end
)
5729 chan
->flag
|= HOSTAPD_CHAN_HT40MINUS
;
5730 if (chan
->freq
+ 10 >= start
&& chan
->freq
+ 30 <= end
)
5731 chan
->flag
|= HOSTAPD_CHAN_HT40PLUS
;
5736 static void nl80211_reg_rule_ht40(struct nlattr
*tb
[],
5737 struct phy_info_arg
*results
)
5739 u32 start
, end
, max_bw
;
5742 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5743 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5744 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
5747 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5748 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5749 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
5751 wpa_printf(MSG_DEBUG
, "nl80211: %u-%u @ %u MHz",
5752 start
, end
, max_bw
);
5756 for (m
= 0; m
< *results
->num_modes
; m
++) {
5757 if (!(results
->modes
[m
].ht_capab
&
5758 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
5760 nl80211_set_ht40_mode(&results
->modes
[m
], start
, end
);
5765 static void nl80211_reg_rule_sec(struct nlattr
*tb
[],
5766 struct phy_info_arg
*results
)
5768 u32 start
, end
, max_bw
;
5771 if (tb
[NL80211_ATTR_FREQ_RANGE_START
] == NULL
||
5772 tb
[NL80211_ATTR_FREQ_RANGE_END
] == NULL
||
5773 tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
] == NULL
)
5776 start
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]) / 1000;
5777 end
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]) / 1000;
5778 max_bw
= nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]) / 1000;
5783 for (m
= 0; m
< *results
->num_modes
; m
++) {
5784 if (!(results
->modes
[m
].ht_capab
&
5785 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET
))
5787 nl80211_set_ht40_mode_sec(&results
->modes
[m
], start
, end
);
5792 static int nl80211_get_reg(struct nl_msg
*msg
, void *arg
)
5794 struct phy_info_arg
*results
= arg
;
5795 struct nlattr
*tb_msg
[NL80211_ATTR_MAX
+ 1];
5796 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
5797 struct nlattr
*nl_rule
;
5798 struct nlattr
*tb_rule
[NL80211_FREQUENCY_ATTR_MAX
+ 1];
5800 static struct nla_policy reg_policy
[NL80211_FREQUENCY_ATTR_MAX
+ 1] = {
5801 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
5802 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
5803 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
5804 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
5805 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
5806 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
5809 nla_parse(tb_msg
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
5810 genlmsg_attrlen(gnlh
, 0), NULL
);
5811 if (!tb_msg
[NL80211_ATTR_REG_ALPHA2
] ||
5812 !tb_msg
[NL80211_ATTR_REG_RULES
]) {
5813 wpa_printf(MSG_DEBUG
, "nl80211: No regulatory information "
5818 wpa_printf(MSG_DEBUG
, "nl80211: Regulatory information - country=%s",
5819 (char *) nla_data(tb_msg
[NL80211_ATTR_REG_ALPHA2
]));
5821 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
5823 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
5824 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
5825 nl80211_reg_rule_ht40(tb_rule
, results
);
5828 nla_for_each_nested(nl_rule
, tb_msg
[NL80211_ATTR_REG_RULES
], rem_rule
)
5830 nla_parse(tb_rule
, NL80211_FREQUENCY_ATTR_MAX
,
5831 nla_data(nl_rule
), nla_len(nl_rule
), reg_policy
);
5832 nl80211_reg_rule_sec(tb_rule
, results
);
5839 static int nl80211_set_ht40_flags(struct wpa_driver_nl80211_data
*drv
,
5840 struct phy_info_arg
*results
)
5844 msg
= nlmsg_alloc();
5848 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_REG
);
5849 return send_and_recv_msgs(drv
, msg
, nl80211_get_reg
, results
);
5853 static struct hostapd_hw_modes
*
5854 wpa_driver_nl80211_get_hw_feature_data(void *priv
, u16
*num_modes
, u16
*flags
)
5857 struct i802_bss
*bss
= priv
;
5858 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5860 struct phy_info_arg result
= {
5861 .num_modes
= num_modes
,
5869 msg
= nlmsg_alloc();
5873 feat
= get_nl80211_protocol_features(drv
);
5874 if (feat
& NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP
)
5875 nl80211_cmd(drv
, msg
, NLM_F_DUMP
, NL80211_CMD_GET_WIPHY
);
5877 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_WIPHY
);
5879 NLA_PUT_FLAG(msg
, NL80211_ATTR_SPLIT_WIPHY_DUMP
);
5880 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
5882 if (send_and_recv_msgs(drv
, msg
, phy_info_handler
, &result
) == 0) {
5883 nl80211_set_ht40_flags(drv
, &result
);
5884 return wpa_driver_nl80211_postprocess_modes(result
.modes
,
5894 static int wpa_driver_nl80211_send_mntr(struct wpa_driver_nl80211_data
*drv
,
5895 const void *data
, size_t len
,
5896 int encrypt
, int noack
)
5899 0x00, 0x00, /* radiotap version */
5900 0x0e, 0x00, /* radiotap length */
5901 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5902 IEEE80211_RADIOTAP_F_FRAG
, /* F_FRAG (fragment if required) */
5904 0x00, 0x00, /* RX and TX flags to indicate that */
5905 0x00, 0x00, /* this is the injected frame directly */
5907 struct iovec iov
[2] = {
5909 .iov_base
= &rtap_hdr
,
5910 .iov_len
= sizeof(rtap_hdr
),
5913 .iov_base
= (void *) data
,
5917 struct msghdr msg
= {
5922 .msg_control
= NULL
,
5923 .msg_controllen
= 0,
5930 rtap_hdr
[8] |= IEEE80211_RADIOTAP_F_WEP
;
5932 if (drv
->monitor_sock
< 0) {
5933 wpa_printf(MSG_DEBUG
, "nl80211: No monitor socket available "
5934 "for %s", __func__
);
5939 txflags
|= IEEE80211_RADIOTAP_F_TX_NOACK
;
5940 WPA_PUT_LE16(&rtap_hdr
[12], txflags
);
5942 res
= sendmsg(drv
->monitor_sock
, &msg
, 0);
5944 wpa_printf(MSG_INFO
, "nl80211: sendmsg: %s", strerror(errno
));
5951 static int wpa_driver_nl80211_send_frame(struct i802_bss
*bss
,
5952 const void *data
, size_t len
,
5953 int encrypt
, int noack
,
5954 unsigned int freq
, int no_cck
,
5955 int offchanok
, unsigned int wait_time
)
5957 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5963 if (drv
->use_monitor
)
5964 return wpa_driver_nl80211_send_mntr(drv
, data
, len
,
5967 return nl80211_send_frame_cmd(bss
, freq
, wait_time
, data
, len
,
5968 &cookie
, no_cck
, noack
, offchanok
);
5972 static int wpa_driver_nl80211_send_mlme(struct i802_bss
*bss
, const u8
*data
,
5973 size_t data_len
, int noack
,
5974 unsigned int freq
, int no_cck
,
5976 unsigned int wait_time
)
5978 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
5979 struct ieee80211_mgmt
*mgmt
;
5983 mgmt
= (struct ieee80211_mgmt
*) data
;
5984 fc
= le_to_host16(mgmt
->frame_control
);
5986 if (is_sta_interface(drv
->nlmode
) &&
5987 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
5988 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_PROBE_RESP
) {
5990 * The use of last_mgmt_freq is a bit of a hack,
5991 * but it works due to the single-threaded nature
5992 * of wpa_supplicant.
5995 freq
= drv
->last_mgmt_freq
;
5996 return nl80211_send_frame_cmd(bss
, freq
, 0,
5997 data
, data_len
, NULL
, 1, noack
,
6001 if (drv
->device_ap_sme
&& is_ap_interface(drv
->nlmode
)) {
6004 return nl80211_send_frame_cmd(bss
, freq
,
6005 (int) freq
== bss
->freq
? 0 :
6008 &drv
->send_action_cookie
,
6009 no_cck
, noack
, offchanok
);
6012 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
&&
6013 WLAN_FC_GET_STYPE(fc
) == WLAN_FC_STYPE_AUTH
) {
6015 * Only one of the authentication frame types is encrypted.
6016 * In order for static WEP encryption to work properly (i.e.,
6017 * to not encrypt the frame), we need to tell mac80211 about
6018 * the frames that must not be encrypted.
6020 u16 auth_alg
= le_to_host16(mgmt
->u
.auth
.auth_alg
);
6021 u16 auth_trans
= le_to_host16(mgmt
->u
.auth
.auth_transaction
);
6022 if (auth_alg
!= WLAN_AUTH_SHARED_KEY
|| auth_trans
!= 3)
6026 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
,
6027 noack
, freq
, no_cck
, offchanok
,
6032 static int nl80211_set_bss(struct i802_bss
*bss
, int cts
, int preamble
,
6033 int slot
, int ht_opmode
, int ap_isolate
,
6036 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6039 msg
= nlmsg_alloc();
6043 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_BSS
);
6046 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_CTS_PROT
, cts
);
6048 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_PREAMBLE
, preamble
);
6050 NLA_PUT_U8(msg
, NL80211_ATTR_BSS_SHORT_SLOT_TIME
, slot
);
6052 NLA_PUT_U16(msg
, NL80211_ATTR_BSS_HT_OPMODE
, ht_opmode
);
6053 if (ap_isolate
>= 0)
6054 NLA_PUT_U8(msg
, NL80211_ATTR_AP_ISOLATE
, ap_isolate
);
6057 u8 rates
[NL80211_MAX_SUPP_RATES
];
6061 for (i
= 0; i
< NL80211_MAX_SUPP_RATES
&& basic_rates
[i
] >= 0;
6063 rates
[rates_len
++] = basic_rates
[i
] / 5;
6065 NLA_PUT(msg
, NL80211_ATTR_BSS_BASIC_RATES
, rates_len
, rates
);
6068 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6070 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6077 static int wpa_driver_nl80211_set_acl(void *priv
,
6078 struct hostapd_acl_params
*params
)
6080 struct i802_bss
*bss
= priv
;
6081 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6087 if (!(drv
->capa
.max_acl_mac_addrs
))
6090 if (params
->num_mac_acl
> drv
->capa
.max_acl_mac_addrs
)
6093 msg
= nlmsg_alloc();
6097 wpa_printf(MSG_DEBUG
, "nl80211: Set %s ACL (num_mac_acl=%u)",
6098 params
->acl_policy
? "Accept" : "Deny", params
->num_mac_acl
);
6100 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_MAC_ACL
);
6102 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6104 NLA_PUT_U32(msg
, NL80211_ATTR_ACL_POLICY
, params
->acl_policy
?
6105 NL80211_ACL_POLICY_DENY_UNLESS_LISTED
:
6106 NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED
);
6108 acl
= nla_nest_start(msg
, NL80211_ATTR_MAC_ADDRS
);
6110 goto nla_put_failure
;
6112 for (i
= 0; i
< params
->num_mac_acl
; i
++)
6113 NLA_PUT(msg
, i
+ 1, ETH_ALEN
, params
->mac_acl
[i
].addr
);
6115 nla_nest_end(msg
, acl
);
6117 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6120 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set MAC ACL: %d (%s)",
6121 ret
, strerror(-ret
));
6131 static int wpa_driver_nl80211_set_ap(void *priv
,
6132 struct wpa_driver_ap_params
*params
)
6134 struct i802_bss
*bss
= priv
;
6135 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6137 u8 cmd
= NL80211_CMD_NEW_BEACON
;
6140 int ifindex
= if_nametoindex(bss
->ifname
);
6145 beacon_set
= bss
->beacon_set
;
6147 msg
= nlmsg_alloc();
6151 wpa_printf(MSG_DEBUG
, "nl80211: Set beacon (beacon_set=%d)",
6154 cmd
= NL80211_CMD_SET_BEACON
;
6156 nl80211_cmd(drv
, msg
, 0, cmd
);
6157 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon head",
6158 params
->head
, params
->head_len
);
6159 NLA_PUT(msg
, NL80211_ATTR_BEACON_HEAD
, params
->head_len
, params
->head
);
6160 wpa_hexdump(MSG_DEBUG
, "nl80211: Beacon tail",
6161 params
->tail
, params
->tail_len
);
6162 NLA_PUT(msg
, NL80211_ATTR_BEACON_TAIL
, params
->tail_len
, params
->tail
);
6163 wpa_printf(MSG_DEBUG
, "nl80211: ifindex=%d", ifindex
);
6164 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
6165 wpa_printf(MSG_DEBUG
, "nl80211: beacon_int=%d", params
->beacon_int
);
6166 NLA_PUT_U32(msg
, NL80211_ATTR_BEACON_INTERVAL
, params
->beacon_int
);
6167 wpa_printf(MSG_DEBUG
, "nl80211: dtim_period=%d", params
->dtim_period
);
6168 NLA_PUT_U32(msg
, NL80211_ATTR_DTIM_PERIOD
, params
->dtim_period
);
6169 wpa_hexdump_ascii(MSG_DEBUG
, "nl80211: ssid",
6170 params
->ssid
, params
->ssid_len
);
6171 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
6173 if (params
->proberesp
&& params
->proberesp_len
) {
6174 wpa_hexdump(MSG_DEBUG
, "nl80211: proberesp (offload)",
6175 params
->proberesp
, params
->proberesp_len
);
6176 NLA_PUT(msg
, NL80211_ATTR_PROBE_RESP
, params
->proberesp_len
,
6179 switch (params
->hide_ssid
) {
6180 case NO_SSID_HIDING
:
6181 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID not in use");
6182 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6183 NL80211_HIDDEN_SSID_NOT_IN_USE
);
6185 case HIDDEN_SSID_ZERO_LEN
:
6186 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero len");
6187 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6188 NL80211_HIDDEN_SSID_ZERO_LEN
);
6190 case HIDDEN_SSID_ZERO_CONTENTS
:
6191 wpa_printf(MSG_DEBUG
, "nl80211: hidden SSID zero contents");
6192 NLA_PUT_U32(msg
, NL80211_ATTR_HIDDEN_SSID
,
6193 NL80211_HIDDEN_SSID_ZERO_CONTENTS
);
6196 wpa_printf(MSG_DEBUG
, "nl80211: privacy=%d", params
->privacy
);
6197 if (params
->privacy
)
6198 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
6199 wpa_printf(MSG_DEBUG
, "nl80211: auth_algs=0x%x", params
->auth_algs
);
6200 if ((params
->auth_algs
& (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) ==
6201 (WPA_AUTH_ALG_OPEN
| WPA_AUTH_ALG_SHARED
)) {
6202 /* Leave out the attribute */
6203 } else if (params
->auth_algs
& WPA_AUTH_ALG_SHARED
)
6204 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
6205 NL80211_AUTHTYPE_SHARED_KEY
);
6207 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
,
6208 NL80211_AUTHTYPE_OPEN_SYSTEM
);
6210 wpa_printf(MSG_DEBUG
, "nl80211: wpa_version=0x%x", params
->wpa_version
);
6212 if (params
->wpa_version
& WPA_PROTO_WPA
)
6213 ver
|= NL80211_WPA_VERSION_1
;
6214 if (params
->wpa_version
& WPA_PROTO_RSN
)
6215 ver
|= NL80211_WPA_VERSION_2
;
6217 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
6219 wpa_printf(MSG_DEBUG
, "nl80211: key_mgmt_suites=0x%x",
6220 params
->key_mgmt_suites
);
6222 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
)
6223 suites
[num_suites
++] = WLAN_AKM_SUITE_8021X
;
6224 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_PSK
)
6225 suites
[num_suites
++] = WLAN_AKM_SUITE_PSK
;
6227 NLA_PUT(msg
, NL80211_ATTR_AKM_SUITES
,
6228 num_suites
* sizeof(u32
), suites
);
6231 if (params
->key_mgmt_suites
& WPA_KEY_MGMT_IEEE8021X
&&
6232 params
->pairwise_ciphers
& (WPA_CIPHER_WEP104
| WPA_CIPHER_WEP40
))
6233 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
);
6235 wpa_printf(MSG_DEBUG
, "nl80211: pairwise_ciphers=0x%x",
6236 params
->pairwise_ciphers
);
6238 if (params
->pairwise_ciphers
& WPA_CIPHER_CCMP
)
6239 suites
[num_suites
++] = WLAN_CIPHER_SUITE_CCMP
;
6240 if (params
->pairwise_ciphers
& WPA_CIPHER_GCMP
)
6241 suites
[num_suites
++] = WLAN_CIPHER_SUITE_GCMP
;
6242 if (params
->pairwise_ciphers
& WPA_CIPHER_TKIP
)
6243 suites
[num_suites
++] = WLAN_CIPHER_SUITE_TKIP
;
6244 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP104
)
6245 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP104
;
6246 if (params
->pairwise_ciphers
& WPA_CIPHER_WEP40
)
6247 suites
[num_suites
++] = WLAN_CIPHER_SUITE_WEP40
;
6249 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
,
6250 num_suites
* sizeof(u32
), suites
);
6253 wpa_printf(MSG_DEBUG
, "nl80211: group_cipher=0x%x",
6254 params
->group_cipher
);
6255 switch (params
->group_cipher
) {
6256 case WPA_CIPHER_CCMP
:
6257 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6258 WLAN_CIPHER_SUITE_CCMP
);
6260 case WPA_CIPHER_GCMP
:
6261 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6262 WLAN_CIPHER_SUITE_GCMP
);
6264 case WPA_CIPHER_TKIP
:
6265 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6266 WLAN_CIPHER_SUITE_TKIP
);
6268 case WPA_CIPHER_WEP104
:
6269 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6270 WLAN_CIPHER_SUITE_WEP104
);
6272 case WPA_CIPHER_WEP40
:
6273 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
,
6274 WLAN_CIPHER_SUITE_WEP40
);
6278 if (params
->beacon_ies
) {
6279 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: beacon_ies",
6280 params
->beacon_ies
);
6281 NLA_PUT(msg
, NL80211_ATTR_IE
, wpabuf_len(params
->beacon_ies
),
6282 wpabuf_head(params
->beacon_ies
));
6284 if (params
->proberesp_ies
) {
6285 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: proberesp_ies",
6286 params
->proberesp_ies
);
6287 NLA_PUT(msg
, NL80211_ATTR_IE_PROBE_RESP
,
6288 wpabuf_len(params
->proberesp_ies
),
6289 wpabuf_head(params
->proberesp_ies
));
6291 if (params
->assocresp_ies
) {
6292 wpa_hexdump_buf(MSG_DEBUG
, "nl80211: assocresp_ies",
6293 params
->assocresp_ies
);
6294 NLA_PUT(msg
, NL80211_ATTR_IE_ASSOC_RESP
,
6295 wpabuf_len(params
->assocresp_ies
),
6296 wpabuf_head(params
->assocresp_ies
));
6299 if (drv
->capa
.flags
& WPA_DRIVER_FLAGS_INACTIVITY_TIMER
) {
6300 wpa_printf(MSG_DEBUG
, "nl80211: ap_max_inactivity=%d",
6301 params
->ap_max_inactivity
);
6302 NLA_PUT_U16(msg
, NL80211_ATTR_INACTIVITY_TIMEOUT
,
6303 params
->ap_max_inactivity
);
6306 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6308 wpa_printf(MSG_DEBUG
, "nl80211: Beacon set failed: %d (%s)",
6309 ret
, strerror(-ret
));
6311 bss
->beacon_set
= 1;
6312 nl80211_set_bss(bss
, params
->cts_protect
, params
->preamble
,
6313 params
->short_slot_time
, params
->ht_opmode
,
6314 params
->isolate
, params
->basic_rates
);
6323 static int wpa_driver_nl80211_set_freq(struct i802_bss
*bss
,
6324 struct hostapd_freq_params
*freq
)
6326 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6330 wpa_printf(MSG_DEBUG
, "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d,"
6331 " bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
6332 freq
->freq
, freq
->ht_enabled
, freq
->vht_enabled
,
6333 freq
->bandwidth
, freq
->center_freq1
, freq
->center_freq2
);
6334 msg
= nlmsg_alloc();
6338 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
6340 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6341 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
->freq
);
6342 if (freq
->vht_enabled
) {
6343 switch (freq
->bandwidth
) {
6345 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6346 NL80211_CHAN_WIDTH_20
);
6349 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6350 NL80211_CHAN_WIDTH_40
);
6353 if (freq
->center_freq2
)
6354 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6355 NL80211_CHAN_WIDTH_80P80
);
6357 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6358 NL80211_CHAN_WIDTH_80
);
6361 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
,
6362 NL80211_CHAN_WIDTH_160
);
6367 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ1
, freq
->center_freq1
);
6368 if (freq
->center_freq2
)
6369 NLA_PUT_U32(msg
, NL80211_ATTR_CENTER_FREQ2
,
6370 freq
->center_freq2
);
6371 } else if (freq
->ht_enabled
) {
6372 switch (freq
->sec_channel_offset
) {
6374 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6375 NL80211_CHAN_HT40MINUS
);
6378 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6379 NL80211_CHAN_HT40PLUS
);
6382 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
6388 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6391 bss
->freq
= freq
->freq
;
6394 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set channel (freq=%d): "
6395 "%d (%s)", freq
->freq
, ret
, strerror(-ret
));
6402 static u32
sta_flags_nl80211(int flags
)
6406 if (flags
& WPA_STA_AUTHORIZED
)
6407 f
|= BIT(NL80211_STA_FLAG_AUTHORIZED
);
6408 if (flags
& WPA_STA_WMM
)
6409 f
|= BIT(NL80211_STA_FLAG_WME
);
6410 if (flags
& WPA_STA_SHORT_PREAMBLE
)
6411 f
|= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
);
6412 if (flags
& WPA_STA_MFP
)
6413 f
|= BIT(NL80211_STA_FLAG_MFP
);
6414 if (flags
& WPA_STA_TDLS_PEER
)
6415 f
|= BIT(NL80211_STA_FLAG_TDLS_PEER
);
6421 static int wpa_driver_nl80211_sta_add(void *priv
,
6422 struct hostapd_sta_add_params
*params
)
6424 struct i802_bss
*bss
= priv
;
6425 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6427 struct nl80211_sta_flag_update upd
;
6430 if ((params
->flags
& WPA_STA_TDLS_PEER
) &&
6431 !(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
6434 msg
= nlmsg_alloc();
6438 wpa_printf(MSG_DEBUG
, "nl80211: %s STA " MACSTR
,
6439 params
->set
? "Set" : "Add", MAC2STR(params
->addr
));
6440 nl80211_cmd(drv
, msg
, 0, params
->set
? NL80211_CMD_SET_STATION
:
6441 NL80211_CMD_NEW_STATION
);
6443 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
6444 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->addr
);
6445 NLA_PUT(msg
, NL80211_ATTR_STA_SUPPORTED_RATES
, params
->supp_rates_len
,
6446 params
->supp_rates
);
6447 wpa_hexdump(MSG_DEBUG
, " * supported rates", params
->supp_rates
,
6448 params
->supp_rates_len
);
6451 wpa_printf(MSG_DEBUG
, " * aid=%u", params
->aid
);
6452 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, params
->aid
);
6455 * cfg80211 validates that AID is non-zero, so we have
6456 * to make this a non-zero value for the TDLS case where
6457 * a dummy STA entry is used for now.
6459 wpa_printf(MSG_DEBUG
, " * aid=1 (TDLS workaround)");
6460 NLA_PUT_U16(msg
, NL80211_ATTR_STA_AID
, 1);
6462 wpa_printf(MSG_DEBUG
, " * listen_interval=%u",
6463 params
->listen_interval
);
6464 NLA_PUT_U16(msg
, NL80211_ATTR_STA_LISTEN_INTERVAL
,
6465 params
->listen_interval
);
6466 } else if (params
->aid
&& (params
->flags
& WPA_STA_TDLS_PEER
)) {
6467 wpa_printf(MSG_DEBUG
, " * peer_aid=%u", params
->aid
);
6468 NLA_PUT_U16(msg
, NL80211_ATTR_PEER_AID
, params
->aid
);
6470 if (params
->ht_capabilities
) {
6471 wpa_hexdump(MSG_DEBUG
, " * ht_capabilities",
6472 (u8
*) params
->ht_capabilities
,
6473 sizeof(*params
->ht_capabilities
));
6474 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
,
6475 sizeof(*params
->ht_capabilities
),
6476 params
->ht_capabilities
);
6479 if (params
->vht_capabilities
) {
6480 wpa_hexdump(MSG_DEBUG
, " * vht_capabilities",
6481 (u8
*) params
->vht_capabilities
,
6482 sizeof(*params
->vht_capabilities
));
6483 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
,
6484 sizeof(*params
->vht_capabilities
),
6485 params
->vht_capabilities
);
6488 wpa_printf(MSG_DEBUG
, " * capability=0x%x", params
->capability
);
6489 NLA_PUT_U16(msg
, NL80211_ATTR_STA_CAPABILITY
, params
->capability
);
6491 if (params
->ext_capab
) {
6492 wpa_hexdump(MSG_DEBUG
, " * ext_capab",
6493 params
->ext_capab
, params
->ext_capab_len
);
6494 NLA_PUT(msg
, NL80211_ATTR_STA_EXT_CAPABILITY
,
6495 params
->ext_capab_len
, params
->ext_capab
);
6498 os_memset(&upd
, 0, sizeof(upd
));
6499 upd
.mask
= sta_flags_nl80211(params
->flags
);
6501 wpa_printf(MSG_DEBUG
, " * flags set=0x%x mask=0x%x",
6503 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
6505 if (params
->flags
& WPA_STA_WMM
) {
6506 struct nlattr
*wme
= nla_nest_start(msg
, NL80211_ATTR_STA_WME
);
6509 goto nla_put_failure
;
6511 wpa_printf(MSG_DEBUG
, " * qosinfo=0x%x", params
->qosinfo
);
6512 NLA_PUT_U8(msg
, NL80211_STA_WME_UAPSD_QUEUES
,
6513 params
->qosinfo
& WMM_QOSINFO_STA_AC_MASK
);
6514 NLA_PUT_U8(msg
, NL80211_STA_WME_MAX_SP
,
6515 (params
->qosinfo
>> WMM_QOSINFO_STA_SP_SHIFT
) &
6516 WMM_QOSINFO_STA_SP_MASK
);
6517 nla_nest_end(msg
, wme
);
6520 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6523 wpa_printf(MSG_DEBUG
, "nl80211: NL80211_CMD_%s_STATION "
6524 "result: %d (%s)", params
->set
? "SET" : "NEW", ret
,
6534 static int wpa_driver_nl80211_sta_remove(struct i802_bss
*bss
, const u8
*addr
)
6536 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
6540 msg
= nlmsg_alloc();
6544 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
6546 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
6547 if_nametoindex(bss
->ifname
));
6548 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6550 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
6560 static void nl80211_remove_iface(struct wpa_driver_nl80211_data
*drv
,
6565 wpa_printf(MSG_DEBUG
, "nl80211: Remove interface ifindex=%d", ifidx
);
6567 /* stop listening for EAPOL on this interface */
6568 del_ifidx(drv
, ifidx
);
6570 msg
= nlmsg_alloc();
6572 goto nla_put_failure
;
6574 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_INTERFACE
);
6575 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifidx
);
6577 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
6582 wpa_printf(MSG_ERROR
, "Failed to remove interface (ifidx=%d)", ifidx
);
6586 static const char * nl80211_iftype_str(enum nl80211_iftype mode
)
6589 case NL80211_IFTYPE_ADHOC
:
6591 case NL80211_IFTYPE_STATION
:
6593 case NL80211_IFTYPE_AP
:
6595 case NL80211_IFTYPE_AP_VLAN
:
6597 case NL80211_IFTYPE_WDS
:
6599 case NL80211_IFTYPE_MONITOR
:
6601 case NL80211_IFTYPE_MESH_POINT
:
6602 return "MESH_POINT";
6603 case NL80211_IFTYPE_P2P_CLIENT
:
6604 return "P2P_CLIENT";
6605 case NL80211_IFTYPE_P2P_GO
:
6607 case NL80211_IFTYPE_P2P_DEVICE
:
6608 return "P2P_DEVICE";
6615 static int nl80211_create_iface_once(struct wpa_driver_nl80211_data
*drv
,
6617 enum nl80211_iftype iftype
,
6618 const u8
*addr
, int wds
,
6619 int (*handler
)(struct nl_msg
*, void *),
6626 wpa_printf(MSG_DEBUG
, "nl80211: Create interface iftype %d (%s)",
6627 iftype
, nl80211_iftype_str(iftype
));
6629 msg
= nlmsg_alloc();
6633 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_NEW_INTERFACE
);
6634 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
6635 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, ifname
);
6636 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, iftype
);
6638 if (iftype
== NL80211_IFTYPE_MONITOR
) {
6639 struct nlattr
*flags
;
6641 flags
= nla_nest_start(msg
, NL80211_ATTR_MNTR_FLAGS
);
6643 goto nla_put_failure
;
6645 NLA_PUT_FLAG(msg
, NL80211_MNTR_FLAG_COOK_FRAMES
);
6647 nla_nest_end(msg
, flags
);
6649 NLA_PUT_U8(msg
, NL80211_ATTR_4ADDR
, wds
);
6652 ret
= send_and_recv_msgs(drv
, msg
, handler
, arg
);
6657 wpa_printf(MSG_ERROR
, "Failed to create interface %s: %d (%s)",
6658 ifname
, ret
, strerror(-ret
));
6662 if (iftype
== NL80211_IFTYPE_P2P_DEVICE
) {
6663 wpa_printf(MSG_DEBUG
,
6664 "nl80211: New P2P Device interface %s created",
6669 ifidx
= if_nametoindex(ifname
);
6670 wpa_printf(MSG_DEBUG
, "nl80211: New interface %s created: ifindex=%d",
6676 /* start listening for EAPOL on this interface */
6677 add_ifidx(drv
, ifidx
);
6679 if (addr
&& iftype
!= NL80211_IFTYPE_MONITOR
&&
6680 linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
, addr
)) {
6681 nl80211_remove_iface(drv
, ifidx
);
6689 static int nl80211_create_iface(struct wpa_driver_nl80211_data
*drv
,
6690 const char *ifname
, enum nl80211_iftype iftype
,
6691 const u8
*addr
, int wds
,
6692 int (*handler
)(struct nl_msg
*, void *),
6697 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
, wds
, handler
,
6700 /* if error occurred and interface exists already */
6701 if (ret
== -ENFILE
&& if_nametoindex(ifname
)) {
6702 wpa_printf(MSG_INFO
, "Try to remove and re-create %s", ifname
);
6704 /* Try to remove the interface that was already there. */
6705 nl80211_remove_iface(drv
, if_nametoindex(ifname
));
6707 /* Try to create the interface again */
6708 ret
= nl80211_create_iface_once(drv
, ifname
, iftype
, addr
,
6712 if (ret
>= 0 && is_p2p_net_interface(iftype
))
6713 nl80211_disable_11b_rates(drv
, ret
, 1);
6719 static void handle_tx_callback(void *ctx
, u8
*buf
, size_t len
, int ok
)
6721 struct ieee80211_hdr
*hdr
;
6723 union wpa_event_data event
;
6725 hdr
= (struct ieee80211_hdr
*) buf
;
6726 fc
= le_to_host16(hdr
->frame_control
);
6728 os_memset(&event
, 0, sizeof(event
));
6729 event
.tx_status
.type
= WLAN_FC_GET_TYPE(fc
);
6730 event
.tx_status
.stype
= WLAN_FC_GET_STYPE(fc
);
6731 event
.tx_status
.dst
= hdr
->addr1
;
6732 event
.tx_status
.data
= buf
;
6733 event
.tx_status
.data_len
= len
;
6734 event
.tx_status
.ack
= ok
;
6735 wpa_supplicant_event(ctx
, EVENT_TX_STATUS
, &event
);
6739 static void from_unknown_sta(struct wpa_driver_nl80211_data
*drv
,
6740 u8
*buf
, size_t len
)
6742 struct ieee80211_hdr
*hdr
= (void *)buf
;
6744 union wpa_event_data event
;
6746 if (len
< sizeof(*hdr
))
6749 fc
= le_to_host16(hdr
->frame_control
);
6751 os_memset(&event
, 0, sizeof(event
));
6752 event
.rx_from_unknown
.bssid
= get_hdr_bssid(hdr
, len
);
6753 event
.rx_from_unknown
.addr
= hdr
->addr2
;
6754 event
.rx_from_unknown
.wds
= (fc
& (WLAN_FC_FROMDS
| WLAN_FC_TODS
)) ==
6755 (WLAN_FC_FROMDS
| WLAN_FC_TODS
);
6756 wpa_supplicant_event(drv
->ctx
, EVENT_RX_FROM_UNKNOWN
, &event
);
6760 static void handle_frame(struct wpa_driver_nl80211_data
*drv
,
6761 u8
*buf
, size_t len
, int datarate
, int ssi_signal
)
6763 struct ieee80211_hdr
*hdr
;
6765 union wpa_event_data event
;
6767 hdr
= (struct ieee80211_hdr
*) buf
;
6768 fc
= le_to_host16(hdr
->frame_control
);
6770 switch (WLAN_FC_GET_TYPE(fc
)) {
6771 case WLAN_FC_TYPE_MGMT
:
6772 os_memset(&event
, 0, sizeof(event
));
6773 event
.rx_mgmt
.frame
= buf
;
6774 event
.rx_mgmt
.frame_len
= len
;
6775 event
.rx_mgmt
.datarate
= datarate
;
6776 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
6777 wpa_supplicant_event(drv
->ctx
, EVENT_RX_MGMT
, &event
);
6779 case WLAN_FC_TYPE_CTRL
:
6780 /* can only get here with PS-Poll frames */
6781 wpa_printf(MSG_DEBUG
, "CTRL");
6782 from_unknown_sta(drv
, buf
, len
);
6784 case WLAN_FC_TYPE_DATA
:
6785 from_unknown_sta(drv
, buf
, len
);
6791 static void handle_monitor_read(int sock
, void *eloop_ctx
, void *sock_ctx
)
6793 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
6795 unsigned char buf
[3000];
6796 struct ieee80211_radiotap_iterator iter
;
6798 int datarate
= 0, ssi_signal
= 0;
6799 int injected
= 0, failed
= 0, rxflags
= 0;
6801 len
= recv(sock
, buf
, sizeof(buf
), 0);
6807 if (ieee80211_radiotap_iterator_init(&iter
, (void*)buf
, len
)) {
6808 printf("received invalid radiotap frame\n");
6813 ret
= ieee80211_radiotap_iterator_next(&iter
);
6817 printf("received invalid radiotap frame (%d)\n", ret
);
6820 switch (iter
.this_arg_index
) {
6821 case IEEE80211_RADIOTAP_FLAGS
:
6822 if (*iter
.this_arg
& IEEE80211_RADIOTAP_F_FCS
)
6825 case IEEE80211_RADIOTAP_RX_FLAGS
:
6828 case IEEE80211_RADIOTAP_TX_FLAGS
:
6830 failed
= le_to_host16((*(uint16_t *) iter
.this_arg
)) &
6831 IEEE80211_RADIOTAP_F_TX_FAIL
;
6833 case IEEE80211_RADIOTAP_DATA_RETRIES
:
6835 case IEEE80211_RADIOTAP_CHANNEL
:
6836 /* TODO: convert from freq/flags to channel number */
6838 case IEEE80211_RADIOTAP_RATE
:
6839 datarate
= *iter
.this_arg
* 5;
6841 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL
:
6842 ssi_signal
= (s8
) *iter
.this_arg
;
6847 if (rxflags
&& injected
)
6851 handle_frame(drv
, buf
+ iter
.max_length
,
6852 len
- iter
.max_length
, datarate
, ssi_signal
);
6854 handle_tx_callback(drv
->ctx
, buf
+ iter
.max_length
,
6855 len
- iter
.max_length
, !failed
);
6860 * we post-process the filter code later and rewrite
6861 * this to the offset to the last instruction
6866 static struct sock_filter msock_filter_insns
[] = {
6868 * do a little-endian load of the radiotap length field
6870 /* load lower byte into A */
6871 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 2),
6872 /* put it into X (== index register) */
6873 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6874 /* load upper byte into A */
6875 BPF_STMT(BPF_LD
| BPF_B
| BPF_ABS
, 3),
6876 /* left-shift it by 8 */
6877 BPF_STMT(BPF_ALU
| BPF_LSH
| BPF_K
, 8),
6879 BPF_STMT(BPF_ALU
| BPF_OR
| BPF_X
, 0),
6880 /* put result into X */
6881 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6884 * Allow management frames through, this also gives us those
6885 * management frames that we sent ourselves with status
6887 /* load the lower byte of the IEEE 802.11 frame control field */
6888 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6889 /* mask off frame type and version */
6890 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0xF),
6891 /* accept frame if it's both 0, fall through otherwise */
6892 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0, PASS
, 0),
6895 * TODO: add a bit to radiotap RX flags that indicates
6896 * that the sending station is not associated, then
6897 * add a filter here that filters on our DA and that flag
6898 * to allow us to deauth frames to that bad station.
6900 * For now allow all To DS data frames through.
6902 /* load the IEEE 802.11 frame control field */
6903 BPF_STMT(BPF_LD
| BPF_H
| BPF_IND
, 0),
6904 /* mask off frame type, version and DS status */
6905 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0F03),
6906 /* accept frame if version 0, type 2 and To DS, fall through otherwise
6908 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0801, PASS
, 0),
6912 * drop non-data frames
6914 /* load the lower byte of the frame control field */
6915 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6916 /* mask off QoS bit */
6917 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x0c),
6918 /* drop non-data frames */
6919 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 8, 0, FAIL
),
6921 /* load the upper byte of the frame control field */
6922 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 1),
6923 /* mask off toDS/fromDS */
6924 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x03),
6925 /* accept WDS frames */
6926 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 3, PASS
, 0),
6929 * add header length to index
6931 /* load the lower byte of the frame control field */
6932 BPF_STMT(BPF_LD
| BPF_B
| BPF_IND
, 0),
6933 /* mask off QoS bit */
6934 BPF_STMT(BPF_ALU
| BPF_AND
| BPF_K
, 0x80),
6935 /* right shift it by 6 to give 0 or 2 */
6936 BPF_STMT(BPF_ALU
| BPF_RSH
| BPF_K
, 6),
6937 /* add data frame header length */
6938 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_K
, 24),
6939 /* add index, was start of 802.11 header */
6940 BPF_STMT(BPF_ALU
| BPF_ADD
| BPF_X
, 0),
6941 /* move to index, now start of LL header */
6942 BPF_STMT(BPF_MISC
| BPF_TAX
, 0),
6945 * Accept empty data frames, we use those for
6948 BPF_STMT(BPF_LD
| BPF_W
| BPF_LEN
, 0),
6949 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_X
, 0, PASS
, 0),
6952 * Accept EAPOL frames
6954 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 0),
6955 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0xAAAA0300, 0, FAIL
),
6956 BPF_STMT(BPF_LD
| BPF_W
| BPF_IND
, 4),
6957 BPF_JUMP(BPF_JMP
| BPF_JEQ
| BPF_K
, 0x0000888E, PASS
, FAIL
),
6959 /* keep these last two statements or change the code below */
6960 /* return 0 == "DROP" */
6961 BPF_STMT(BPF_RET
| BPF_K
, 0),
6962 /* return ~0 == "keep all" */
6963 BPF_STMT(BPF_RET
| BPF_K
, ~0),
6966 static struct sock_fprog msock_filter
= {
6967 .len
= sizeof(msock_filter_insns
)/sizeof(msock_filter_insns
[0]),
6968 .filter
= msock_filter_insns
,
6972 static int add_monitor_filter(int s
)
6976 /* rewrite all PASS/FAIL jump offsets */
6977 for (idx
= 0; idx
< msock_filter
.len
; idx
++) {
6978 struct sock_filter
*insn
= &msock_filter_insns
[idx
];
6980 if (BPF_CLASS(insn
->code
) == BPF_JMP
) {
6981 if (insn
->code
== (BPF_JMP
|BPF_JA
)) {
6982 if (insn
->k
== PASS
)
6983 insn
->k
= msock_filter
.len
- idx
- 2;
6984 else if (insn
->k
== FAIL
)
6985 insn
->k
= msock_filter
.len
- idx
- 3;
6988 if (insn
->jt
== PASS
)
6989 insn
->jt
= msock_filter
.len
- idx
- 2;
6990 else if (insn
->jt
== FAIL
)
6991 insn
->jt
= msock_filter
.len
- idx
- 3;
6993 if (insn
->jf
== PASS
)
6994 insn
->jf
= msock_filter
.len
- idx
- 2;
6995 else if (insn
->jf
== FAIL
)
6996 insn
->jf
= msock_filter
.len
- idx
- 3;
7000 if (setsockopt(s
, SOL_SOCKET
, SO_ATTACH_FILTER
,
7001 &msock_filter
, sizeof(msock_filter
))) {
7002 perror("SO_ATTACH_FILTER");
7010 static void nl80211_remove_monitor_interface(
7011 struct wpa_driver_nl80211_data
*drv
)
7013 drv
->monitor_refcount
--;
7014 if (drv
->monitor_refcount
> 0)
7017 if (drv
->monitor_ifidx
>= 0) {
7018 nl80211_remove_iface(drv
, drv
->monitor_ifidx
);
7019 drv
->monitor_ifidx
= -1;
7021 if (drv
->monitor_sock
>= 0) {
7022 eloop_unregister_read_sock(drv
->monitor_sock
);
7023 close(drv
->monitor_sock
);
7024 drv
->monitor_sock
= -1;
7030 nl80211_create_monitor_interface(struct wpa_driver_nl80211_data
*drv
)
7033 struct sockaddr_ll ll
;
7037 if (drv
->monitor_ifidx
>= 0) {
7038 drv
->monitor_refcount
++;
7042 if (os_strncmp(drv
->first_bss
.ifname
, "p2p-", 4) == 0) {
7044 * P2P interface name is of the format p2p-%s-%d. For monitor
7045 * interface name corresponding to P2P GO, replace "p2p-" with
7046 * "mon-" to retain the same interface name length and to
7047 * indicate that it is a monitor interface.
7049 snprintf(buf
, IFNAMSIZ
, "mon-%s", drv
->first_bss
.ifname
+ 4);
7051 /* Non-P2P interface with AP functionality. */
7052 snprintf(buf
, IFNAMSIZ
, "mon.%s", drv
->first_bss
.ifname
);
7055 buf
[IFNAMSIZ
- 1] = '\0';
7057 drv
->monitor_ifidx
=
7058 nl80211_create_iface(drv
, buf
, NL80211_IFTYPE_MONITOR
, NULL
,
7061 if (drv
->monitor_ifidx
== -EOPNOTSUPP
) {
7063 * This is backward compatibility for a few versions of
7064 * the kernel only that didn't advertise the right
7065 * attributes for the only driver that then supported
7066 * AP mode w/o monitor -- ath6kl.
7068 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support "
7069 "monitor interface type - try to run without it");
7070 drv
->device_ap_sme
= 1;
7073 if (drv
->monitor_ifidx
< 0)
7076 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, buf
, 1))
7079 memset(&ll
, 0, sizeof(ll
));
7080 ll
.sll_family
= AF_PACKET
;
7081 ll
.sll_ifindex
= drv
->monitor_ifidx
;
7082 drv
->monitor_sock
= socket(PF_PACKET
, SOCK_RAW
, htons(ETH_P_ALL
));
7083 if (drv
->monitor_sock
< 0) {
7084 perror("socket[PF_PACKET,SOCK_RAW]");
7088 if (add_monitor_filter(drv
->monitor_sock
)) {
7089 wpa_printf(MSG_INFO
, "Failed to set socket filter for monitor "
7090 "interface; do filtering in user space");
7091 /* This works, but will cost in performance. */
7094 if (bind(drv
->monitor_sock
, (struct sockaddr
*) &ll
, sizeof(ll
)) < 0) {
7095 perror("monitor socket bind");
7099 optlen
= sizeof(optval
);
7102 (drv
->monitor_sock
, SOL_SOCKET
, SO_PRIORITY
, &optval
, optlen
)) {
7103 perror("Failed to set socket priority");
7107 if (eloop_register_read_sock(drv
->monitor_sock
, handle_monitor_read
,
7109 printf("Could not register monitor read socket\n");
7115 nl80211_remove_monitor_interface(drv
);
7120 static int nl80211_setup_ap(struct i802_bss
*bss
)
7122 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7124 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP - device_ap_sme=%d "
7125 "use_monitor=%d", drv
->device_ap_sme
, drv
->use_monitor
);
7128 * Disable Probe Request reporting unless we need it in this way for
7129 * devices that include the AP SME, in the other case (unless using
7130 * monitor iface) we'll get it through the nl_mgmt socket instead.
7132 if (!drv
->device_ap_sme
)
7133 wpa_driver_nl80211_probe_req_report(bss
, 0);
7135 if (!drv
->device_ap_sme
&& !drv
->use_monitor
)
7136 if (nl80211_mgmt_subscribe_ap(bss
))
7139 if (drv
->device_ap_sme
&& !drv
->use_monitor
)
7140 if (nl80211_mgmt_subscribe_ap_dev_sme(bss
))
7143 if (!drv
->device_ap_sme
&& drv
->use_monitor
&&
7144 nl80211_create_monitor_interface(drv
) &&
7145 !drv
->device_ap_sme
)
7148 if (drv
->device_ap_sme
&&
7149 wpa_driver_nl80211_probe_req_report(bss
, 1) < 0) {
7150 wpa_printf(MSG_DEBUG
, "nl80211: Failed to enable "
7151 "Probe Request frame reporting in AP mode");
7152 /* Try to survive without this */
7159 static void nl80211_teardown_ap(struct i802_bss
*bss
)
7161 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7163 if (drv
->device_ap_sme
) {
7164 wpa_driver_nl80211_probe_req_report(bss
, 0);
7165 if (!drv
->use_monitor
)
7166 nl80211_mgmt_unsubscribe(bss
, "AP teardown (dev SME)");
7167 } else if (drv
->use_monitor
)
7168 nl80211_remove_monitor_interface(drv
);
7170 nl80211_mgmt_unsubscribe(bss
, "AP teardown");
7172 bss
->beacon_set
= 0;
7176 static int nl80211_send_eapol_data(struct i802_bss
*bss
,
7177 const u8
*addr
, const u8
*data
,
7180 struct sockaddr_ll ll
;
7183 if (bss
->drv
->eapol_tx_sock
< 0) {
7184 wpa_printf(MSG_DEBUG
, "nl80211: No socket to send EAPOL");
7188 os_memset(&ll
, 0, sizeof(ll
));
7189 ll
.sll_family
= AF_PACKET
;
7190 ll
.sll_ifindex
= bss
->ifindex
;
7191 ll
.sll_protocol
= htons(ETH_P_PAE
);
7192 ll
.sll_halen
= ETH_ALEN
;
7193 os_memcpy(ll
.sll_addr
, addr
, ETH_ALEN
);
7194 ret
= sendto(bss
->drv
->eapol_tx_sock
, data
, data_len
, 0,
7195 (struct sockaddr
*) &ll
, sizeof(ll
));
7197 wpa_printf(MSG_ERROR
, "nl80211: EAPOL TX: %s",
7204 static const u8 rfc1042_header
[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
7206 static int wpa_driver_nl80211_hapd_send_eapol(
7207 void *priv
, const u8
*addr
, const u8
*data
,
7208 size_t data_len
, int encrypt
, const u8
*own_addr
, u32 flags
)
7210 struct i802_bss
*bss
= priv
;
7211 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7212 struct ieee80211_hdr
*hdr
;
7216 int qos
= flags
& WPA_STA_WMM
;
7218 if (drv
->device_ap_sme
|| !drv
->use_monitor
)
7219 return nl80211_send_eapol_data(bss
, addr
, data
, data_len
);
7221 len
= sizeof(*hdr
) + (qos
? 2 : 0) + sizeof(rfc1042_header
) + 2 +
7223 hdr
= os_zalloc(len
);
7225 printf("malloc() failed for i802_send_data(len=%lu)\n",
7226 (unsigned long) len
);
7230 hdr
->frame_control
=
7231 IEEE80211_FC(WLAN_FC_TYPE_DATA
, WLAN_FC_STYPE_DATA
);
7232 hdr
->frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
7234 hdr
->frame_control
|= host_to_le16(WLAN_FC_ISWEP
);
7236 hdr
->frame_control
|=
7237 host_to_le16(WLAN_FC_STYPE_QOS_DATA
<< 4);
7240 memcpy(hdr
->IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
7241 memcpy(hdr
->IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
7242 memcpy(hdr
->IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
7243 pos
= (u8
*) (hdr
+ 1);
7246 /* Set highest priority in QoS header */
7252 memcpy(pos
, rfc1042_header
, sizeof(rfc1042_header
));
7253 pos
+= sizeof(rfc1042_header
);
7254 WPA_PUT_BE16(pos
, ETH_P_PAE
);
7256 memcpy(pos
, data
, data_len
);
7258 res
= wpa_driver_nl80211_send_frame(bss
, (u8
*) hdr
, len
, encrypt
, 0,
7261 wpa_printf(MSG_ERROR
, "i802_send_eapol - packet len: %lu - "
7263 (unsigned long) len
, errno
, strerror(errno
));
7271 static int wpa_driver_nl80211_sta_set_flags(void *priv
, const u8
*addr
,
7273 int flags_or
, int flags_and
)
7275 struct i802_bss
*bss
= priv
;
7276 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7278 struct nlattr
*flags
;
7279 struct nl80211_sta_flag_update upd
;
7281 msg
= nlmsg_alloc();
7285 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
7287 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
7288 if_nametoindex(bss
->ifname
));
7289 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
7292 * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
7293 * can be removed eventually.
7295 flags
= nla_nest_start(msg
, NL80211_ATTR_STA_FLAGS
);
7297 goto nla_put_failure
;
7298 if (total_flags
& WPA_STA_AUTHORIZED
)
7299 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_AUTHORIZED
);
7301 if (total_flags
& WPA_STA_WMM
)
7302 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_WME
);
7304 if (total_flags
& WPA_STA_SHORT_PREAMBLE
)
7305 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_SHORT_PREAMBLE
);
7307 if (total_flags
& WPA_STA_MFP
)
7308 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_MFP
);
7310 if (total_flags
& WPA_STA_TDLS_PEER
)
7311 NLA_PUT_FLAG(msg
, NL80211_STA_FLAG_TDLS_PEER
);
7313 nla_nest_end(msg
, flags
);
7315 os_memset(&upd
, 0, sizeof(upd
));
7316 upd
.mask
= sta_flags_nl80211(flags_or
| ~flags_and
);
7317 upd
.set
= sta_flags_nl80211(flags_or
);
7318 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
7320 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7327 static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data
*drv
,
7328 struct wpa_driver_associate_params
*params
)
7330 enum nl80211_iftype nlmode
, old_mode
;
7331 struct hostapd_freq_params freq
= {
7332 .freq
= params
->freq
,
7336 wpa_printf(MSG_DEBUG
, "nl80211: Setup AP operations for P2P "
7338 nlmode
= NL80211_IFTYPE_P2P_GO
;
7340 nlmode
= NL80211_IFTYPE_AP
;
7342 old_mode
= drv
->nlmode
;
7343 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
, nlmode
)) {
7344 nl80211_remove_monitor_interface(drv
);
7348 if (wpa_driver_nl80211_set_freq(&drv
->first_bss
, &freq
)) {
7349 if (old_mode
!= nlmode
)
7350 wpa_driver_nl80211_set_mode(&drv
->first_bss
, old_mode
);
7351 nl80211_remove_monitor_interface(drv
);
7359 static int nl80211_leave_ibss(struct wpa_driver_nl80211_data
*drv
)
7364 msg
= nlmsg_alloc();
7368 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_LEAVE_IBSS
);
7369 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7370 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7373 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS failed: ret=%d "
7374 "(%s)", ret
, strerror(-ret
));
7375 goto nla_put_failure
;
7379 wpa_printf(MSG_DEBUG
, "nl80211: Leave IBSS request sent successfully");
7387 static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data
*drv
,
7388 struct wpa_driver_associate_params
*params
)
7394 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS (ifindex=%d)", drv
->ifindex
);
7396 if (wpa_driver_nl80211_set_mode(&drv
->first_bss
,
7397 NL80211_IFTYPE_ADHOC
)) {
7398 wpa_printf(MSG_INFO
, "nl80211: Failed to set interface into "
7404 msg
= nlmsg_alloc();
7408 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_JOIN_IBSS
);
7409 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7411 if (params
->ssid
== NULL
|| params
->ssid_len
> sizeof(drv
->ssid
))
7412 goto nla_put_failure
;
7414 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7415 params
->ssid
, params
->ssid_len
);
7416 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7418 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7419 drv
->ssid_len
= params
->ssid_len
;
7421 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7422 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7424 ret
= nl80211_set_conn_keys(params
, msg
);
7426 goto nla_put_failure
;
7428 if (params
->bssid
&& params
->fixed_bssid
) {
7429 wpa_printf(MSG_DEBUG
, " * BSSID=" MACSTR
,
7430 MAC2STR(params
->bssid
));
7431 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7434 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
7435 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
7436 params
->key_mgmt_suite
== KEY_MGMT_802_1X_SHA256
||
7437 params
->key_mgmt_suite
== KEY_MGMT_PSK_SHA256
) {
7438 wpa_printf(MSG_DEBUG
, " * control port");
7439 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
7442 if (params
->wpa_ie
) {
7443 wpa_hexdump(MSG_DEBUG
,
7444 " * Extra IEs for Beacon/Probe Response frames",
7445 params
->wpa_ie
, params
->wpa_ie_len
);
7446 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7450 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7453 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS failed: ret=%d (%s)",
7454 ret
, strerror(-ret
));
7456 if (ret
== -EALREADY
&& count
== 1) {
7457 wpa_printf(MSG_DEBUG
, "nl80211: Retry IBSS join after "
7459 nl80211_leave_ibss(drv
);
7464 goto nla_put_failure
;
7467 wpa_printf(MSG_DEBUG
, "nl80211: Join IBSS request sent successfully");
7475 static int wpa_driver_nl80211_try_connect(
7476 struct wpa_driver_nl80211_data
*drv
,
7477 struct wpa_driver_associate_params
*params
)
7480 enum nl80211_auth_type type
;
7484 msg
= nlmsg_alloc();
7488 wpa_printf(MSG_DEBUG
, "nl80211: Connect (ifindex=%d)", drv
->ifindex
);
7489 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CONNECT
);
7491 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7492 if (params
->bssid
) {
7493 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
7494 MAC2STR(params
->bssid
));
7495 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7498 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7499 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7501 if (params
->bg_scan_period
>= 0) {
7502 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
7503 params
->bg_scan_period
);
7504 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
7505 params
->bg_scan_period
);
7508 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7509 params
->ssid
, params
->ssid_len
);
7510 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7512 if (params
->ssid_len
> sizeof(drv
->ssid
))
7513 goto nla_put_failure
;
7514 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7515 drv
->ssid_len
= params
->ssid_len
;
7517 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
7519 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7523 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7525 if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7527 if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7530 wpa_printf(MSG_DEBUG
, " * Leave out Auth Type for automatic "
7532 goto skip_auth_type
;
7535 if (params
->auth_alg
& WPA_AUTH_ALG_OPEN
)
7536 type
= NL80211_AUTHTYPE_OPEN_SYSTEM
;
7537 else if (params
->auth_alg
& WPA_AUTH_ALG_SHARED
)
7538 type
= NL80211_AUTHTYPE_SHARED_KEY
;
7539 else if (params
->auth_alg
& WPA_AUTH_ALG_LEAP
)
7540 type
= NL80211_AUTHTYPE_NETWORK_EAP
;
7541 else if (params
->auth_alg
& WPA_AUTH_ALG_FT
)
7542 type
= NL80211_AUTHTYPE_FT
;
7544 goto nla_put_failure
;
7546 wpa_printf(MSG_DEBUG
, " * Auth Type %d", type
);
7547 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, type
);
7550 if (params
->wpa_proto
) {
7551 enum nl80211_wpa_versions ver
= 0;
7553 if (params
->wpa_proto
& WPA_PROTO_WPA
)
7554 ver
|= NL80211_WPA_VERSION_1
;
7555 if (params
->wpa_proto
& WPA_PROTO_RSN
)
7556 ver
|= NL80211_WPA_VERSION_2
;
7558 wpa_printf(MSG_DEBUG
, " * WPA Versions 0x%x", ver
);
7559 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, ver
);
7562 if (params
->pairwise_suite
!= CIPHER_NONE
) {
7565 switch (params
->pairwise_suite
) {
7567 cipher
= WLAN_CIPHER_SUITE_SMS4
;
7570 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7573 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7576 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7579 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7583 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7586 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
7589 if (params
->group_suite
!= CIPHER_NONE
) {
7592 switch (params
->group_suite
) {
7594 cipher
= WLAN_CIPHER_SUITE_SMS4
;
7597 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7600 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7603 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7606 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7610 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7613 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
7616 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
7617 params
->key_mgmt_suite
== KEY_MGMT_PSK
||
7618 params
->key_mgmt_suite
== KEY_MGMT_FT_802_1X
||
7619 params
->key_mgmt_suite
== KEY_MGMT_FT_PSK
||
7620 params
->key_mgmt_suite
== KEY_MGMT_CCKM
) {
7621 int mgmt
= WLAN_AKM_SUITE_PSK
;
7623 switch (params
->key_mgmt_suite
) {
7625 mgmt
= WLAN_AKM_SUITE_CCKM
;
7627 case KEY_MGMT_802_1X
:
7628 mgmt
= WLAN_AKM_SUITE_8021X
;
7630 case KEY_MGMT_FT_802_1X
:
7631 mgmt
= WLAN_AKM_SUITE_FT_8021X
;
7633 case KEY_MGMT_FT_PSK
:
7634 mgmt
= WLAN_AKM_SUITE_FT_PSK
;
7638 mgmt
= WLAN_AKM_SUITE_PSK
;
7641 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, mgmt
);
7644 #ifdef CONFIG_IEEE80211W
7645 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
7646 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
7647 #endif /* CONFIG_IEEE80211W */
7649 if (params
->disable_ht
)
7650 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
7652 if (params
->htcaps
&& params
->htcaps_mask
) {
7653 int sz
= sizeof(struct ieee80211_ht_capabilities
);
7654 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
7655 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
7656 params
->htcaps_mask
);
7659 #ifdef CONFIG_VHT_OVERRIDES
7660 if (params
->disable_vht
) {
7661 wpa_printf(MSG_DEBUG
, " * VHT disabled");
7662 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
7665 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
7666 int sz
= sizeof(struct ieee80211_vht_capabilities
);
7667 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
7668 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
7669 params
->vhtcaps_mask
);
7671 #endif /* CONFIG_VHT_OVERRIDES */
7673 ret
= nl80211_set_conn_keys(params
, msg
);
7675 goto nla_put_failure
;
7677 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7680 wpa_printf(MSG_DEBUG
, "nl80211: MLME connect failed: ret=%d "
7681 "(%s)", ret
, strerror(-ret
));
7682 goto nla_put_failure
;
7685 wpa_printf(MSG_DEBUG
, "nl80211: Connect request send successfully");
7694 static int wpa_driver_nl80211_connect(
7695 struct wpa_driver_nl80211_data
*drv
,
7696 struct wpa_driver_associate_params
*params
)
7698 int ret
= wpa_driver_nl80211_try_connect(drv
, params
);
7699 if (ret
== -EALREADY
) {
7701 * cfg80211 does not currently accept new connections if
7702 * we are already connected. As a workaround, force
7703 * disconnection and try again.
7705 wpa_printf(MSG_DEBUG
, "nl80211: Explicitly "
7706 "disconnecting before reassociation "
7708 if (wpa_driver_nl80211_disconnect(
7709 drv
, WLAN_REASON_PREV_AUTH_NOT_VALID
))
7711 /* Ignore the next local disconnect message. */
7712 drv
->ignore_next_local_disconnect
= 1;
7713 ret
= wpa_driver_nl80211_try_connect(drv
, params
);
7719 static int wpa_driver_nl80211_associate(
7720 void *priv
, struct wpa_driver_associate_params
*params
)
7722 struct i802_bss
*bss
= priv
;
7723 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7727 if (params
->mode
== IEEE80211_MODE_AP
)
7728 return wpa_driver_nl80211_ap(drv
, params
);
7730 if (params
->mode
== IEEE80211_MODE_IBSS
)
7731 return wpa_driver_nl80211_ibss(drv
, params
);
7733 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_SME
)) {
7734 enum nl80211_iftype nlmode
= params
->p2p
?
7735 NL80211_IFTYPE_P2P_CLIENT
: NL80211_IFTYPE_STATION
;
7737 if (wpa_driver_nl80211_set_mode(priv
, nlmode
) < 0)
7739 return wpa_driver_nl80211_connect(drv
, params
);
7742 nl80211_mark_disconnected(drv
);
7744 msg
= nlmsg_alloc();
7748 wpa_printf(MSG_DEBUG
, "nl80211: Associate (ifindex=%d)",
7750 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_ASSOCIATE
);
7752 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
7753 if (params
->bssid
) {
7754 wpa_printf(MSG_DEBUG
, " * bssid=" MACSTR
,
7755 MAC2STR(params
->bssid
));
7756 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, params
->bssid
);
7759 wpa_printf(MSG_DEBUG
, " * freq=%d", params
->freq
);
7760 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, params
->freq
);
7761 drv
->assoc_freq
= params
->freq
;
7763 drv
->assoc_freq
= 0;
7764 if (params
->bg_scan_period
>= 0) {
7765 wpa_printf(MSG_DEBUG
, " * bg scan period=%d",
7766 params
->bg_scan_period
);
7767 NLA_PUT_U16(msg
, NL80211_ATTR_BG_SCAN_PERIOD
,
7768 params
->bg_scan_period
);
7771 wpa_hexdump_ascii(MSG_DEBUG
, " * SSID",
7772 params
->ssid
, params
->ssid_len
);
7773 NLA_PUT(msg
, NL80211_ATTR_SSID
, params
->ssid_len
,
7775 if (params
->ssid_len
> sizeof(drv
->ssid
))
7776 goto nla_put_failure
;
7777 os_memcpy(drv
->ssid
, params
->ssid
, params
->ssid_len
);
7778 drv
->ssid_len
= params
->ssid_len
;
7780 wpa_hexdump(MSG_DEBUG
, " * IEs", params
->wpa_ie
, params
->wpa_ie_len
);
7782 NLA_PUT(msg
, NL80211_ATTR_IE
, params
->wpa_ie_len
,
7785 if (params
->pairwise_suite
!= CIPHER_NONE
) {
7788 switch (params
->pairwise_suite
) {
7790 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7793 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7796 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7799 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7803 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7806 wpa_printf(MSG_DEBUG
, " * pairwise=0x%x", cipher
);
7807 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher
);
7810 if (params
->group_suite
!= CIPHER_NONE
) {
7813 switch (params
->group_suite
) {
7815 cipher
= WLAN_CIPHER_SUITE_WEP40
;
7818 cipher
= WLAN_CIPHER_SUITE_WEP104
;
7821 cipher
= WLAN_CIPHER_SUITE_CCMP
;
7824 cipher
= WLAN_CIPHER_SUITE_GCMP
;
7828 cipher
= WLAN_CIPHER_SUITE_TKIP
;
7831 wpa_printf(MSG_DEBUG
, " * group=0x%x", cipher
);
7832 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher
);
7835 #ifdef CONFIG_IEEE80211W
7836 if (params
->mgmt_frame_protection
== MGMT_FRAME_PROTECTION_REQUIRED
)
7837 NLA_PUT_U32(msg
, NL80211_ATTR_USE_MFP
, NL80211_MFP_REQUIRED
);
7838 #endif /* CONFIG_IEEE80211W */
7840 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT
);
7842 if (params
->prev_bssid
) {
7843 wpa_printf(MSG_DEBUG
, " * prev_bssid=" MACSTR
,
7844 MAC2STR(params
->prev_bssid
));
7845 NLA_PUT(msg
, NL80211_ATTR_PREV_BSSID
, ETH_ALEN
,
7846 params
->prev_bssid
);
7849 if (params
->disable_ht
)
7850 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_HT
);
7852 if (params
->htcaps
&& params
->htcaps_mask
) {
7853 int sz
= sizeof(struct ieee80211_ht_capabilities
);
7854 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY
, sz
, params
->htcaps
);
7855 NLA_PUT(msg
, NL80211_ATTR_HT_CAPABILITY_MASK
, sz
,
7856 params
->htcaps_mask
);
7859 #ifdef CONFIG_VHT_OVERRIDES
7860 if (params
->disable_vht
) {
7861 wpa_printf(MSG_DEBUG
, " * VHT disabled");
7862 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISABLE_VHT
);
7865 if (params
->vhtcaps
&& params
->vhtcaps_mask
) {
7866 int sz
= sizeof(struct ieee80211_vht_capabilities
);
7867 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY
, sz
, params
->vhtcaps
);
7868 NLA_PUT(msg
, NL80211_ATTR_VHT_CAPABILITY_MASK
, sz
,
7869 params
->vhtcaps_mask
);
7871 #endif /* CONFIG_VHT_OVERRIDES */
7874 wpa_printf(MSG_DEBUG
, " * P2P group");
7876 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7879 wpa_dbg(drv
->ctx
, MSG_DEBUG
,
7880 "nl80211: MLME command failed (assoc): ret=%d (%s)",
7881 ret
, strerror(-ret
));
7882 nl80211_dump_scan(drv
);
7883 goto nla_put_failure
;
7886 wpa_printf(MSG_DEBUG
, "nl80211: Association request send "
7895 static int nl80211_set_mode(struct wpa_driver_nl80211_data
*drv
,
7896 int ifindex
, enum nl80211_iftype mode
)
7901 wpa_printf(MSG_DEBUG
, "nl80211: Set mode ifindex %d iftype %d (%s)",
7902 ifindex
, mode
, nl80211_iftype_str(mode
));
7904 msg
= nlmsg_alloc();
7908 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_INTERFACE
);
7909 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
7910 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, mode
);
7912 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
7918 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface %d to mode %d:"
7919 " %d (%s)", ifindex
, mode
, ret
, strerror(-ret
));
7924 static int wpa_driver_nl80211_set_mode(struct i802_bss
*bss
,
7925 enum nl80211_iftype nlmode
)
7927 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
7930 int was_ap
= is_ap_interface(drv
->nlmode
);
7933 res
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
7935 drv
->nlmode
= nlmode
;
7943 if (nlmode
== drv
->nlmode
) {
7944 wpa_printf(MSG_DEBUG
, "nl80211: Interface already in "
7945 "requested mode - ignore error");
7947 goto done
; /* Already in the requested mode */
7950 /* mac80211 doesn't allow mode changes while the device is up, so
7951 * take the device down, try to set the mode again, and bring the
7954 wpa_printf(MSG_DEBUG
, "nl80211: Try mode change after setting "
7956 for (i
= 0; i
< 10; i
++) {
7957 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
7959 if (res
== -EACCES
|| res
== -ENODEV
)
7962 /* Try to set the mode again while the interface is
7964 ret
= nl80211_set_mode(drv
, drv
->ifindex
, nlmode
);
7967 res
= linux_set_iface_flags(drv
->global
->ioctl_sock
,
7971 else if (ret
!= -EBUSY
)
7974 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set "
7976 os_sleep(0, 100000);
7980 wpa_printf(MSG_DEBUG
, "nl80211: Mode change succeeded while "
7981 "interface is down");
7982 drv
->nlmode
= nlmode
;
7983 drv
->ignore_if_down_event
= 1;
7988 wpa_printf(MSG_DEBUG
, "nl80211: Interface mode change to %d "
7989 "from %d failed", nlmode
, drv
->nlmode
);
7993 if (is_p2p_net_interface(nlmode
))
7994 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 1);
7995 else if (drv
->disabled_11b_rates
)
7996 nl80211_disable_11b_rates(drv
, drv
->ifindex
, 0);
7998 if (is_ap_interface(nlmode
)) {
7999 nl80211_mgmt_unsubscribe(bss
, "start AP");
8000 /* Setup additional AP mode functionality if needed */
8001 if (nl80211_setup_ap(bss
))
8003 } else if (was_ap
) {
8004 /* Remove additional AP mode functionality */
8005 nl80211_teardown_ap(bss
);
8007 nl80211_mgmt_unsubscribe(bss
, "mode change");
8010 if (!bss
->in_deinit
&& !is_ap_interface(nlmode
) &&
8011 nl80211_mgmt_subscribe_non_ap(bss
) < 0)
8012 wpa_printf(MSG_DEBUG
, "nl80211: Failed to register Action "
8013 "frame processing - ignore for now");
8019 static int wpa_driver_nl80211_get_capa(void *priv
,
8020 struct wpa_driver_capa
*capa
)
8022 struct i802_bss
*bss
= priv
;
8023 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8024 if (!drv
->has_capability
)
8026 os_memcpy(capa
, &drv
->capa
, sizeof(*capa
));
8027 if (drv
->extended_capa
&& drv
->extended_capa_mask
) {
8028 capa
->extended_capa
= drv
->extended_capa
;
8029 capa
->extended_capa_mask
= drv
->extended_capa_mask
;
8030 capa
->extended_capa_len
= drv
->extended_capa_len
;
8036 static int wpa_driver_nl80211_set_operstate(void *priv
, int state
)
8038 struct i802_bss
*bss
= priv
;
8039 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8041 wpa_printf(MSG_DEBUG
, "%s: operstate %d->%d (%s)",
8042 __func__
, drv
->operstate
, state
, state
? "UP" : "DORMANT");
8043 drv
->operstate
= state
;
8044 return netlink_send_oper_ifla(drv
->global
->netlink
, drv
->ifindex
, -1,
8045 state
? IF_OPER_UP
: IF_OPER_DORMANT
);
8049 static int wpa_driver_nl80211_set_supp_port(void *priv
, int authorized
)
8051 struct i802_bss
*bss
= priv
;
8052 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8054 struct nl80211_sta_flag_update upd
;
8056 wpa_printf(MSG_DEBUG
, "nl80211: Set supplicant port %sauthorized for "
8057 MACSTR
, authorized
? "" : "un", MAC2STR(drv
->bssid
));
8059 msg
= nlmsg_alloc();
8063 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
8065 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8066 if_nametoindex(bss
->ifname
));
8067 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, drv
->bssid
);
8069 os_memset(&upd
, 0, sizeof(upd
));
8070 upd
.mask
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
8072 upd
.set
= BIT(NL80211_STA_FLAG_AUTHORIZED
);
8073 NLA_PUT(msg
, NL80211_ATTR_STA_FLAGS2
, sizeof(upd
), &upd
);
8075 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8082 /* Set kernel driver on given frequency (MHz) */
8083 static int i802_set_freq(void *priv
, struct hostapd_freq_params
*freq
)
8085 struct i802_bss
*bss
= priv
;
8086 return wpa_driver_nl80211_set_freq(bss
, freq
);
8090 #if defined(HOSTAPD) || defined(CONFIG_AP)
8092 static inline int min_int(int a
, int b
)
8100 static int get_key_handler(struct nl_msg
*msg
, void *arg
)
8102 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8103 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8105 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8106 genlmsg_attrlen(gnlh
, 0), NULL
);
8109 * TODO: validate the key index and mac address!
8110 * Otherwise, there's a race condition as soon as
8111 * the kernel starts sending key notifications.
8114 if (tb
[NL80211_ATTR_KEY_SEQ
])
8115 memcpy(arg
, nla_data(tb
[NL80211_ATTR_KEY_SEQ
]),
8116 min_int(nla_len(tb
[NL80211_ATTR_KEY_SEQ
]), 6));
8121 static int i802_get_seqnum(const char *iface
, void *priv
, const u8
*addr
,
8124 struct i802_bss
*bss
= priv
;
8125 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8128 msg
= nlmsg_alloc();
8132 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_KEY
);
8135 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8136 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, idx
);
8137 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(iface
));
8141 return send_and_recv_msgs(drv
, msg
, get_key_handler
, seq
);
8148 static int i802_set_rts(void *priv
, int rts
)
8150 struct i802_bss
*bss
= priv
;
8151 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8156 msg
= nlmsg_alloc();
8165 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8166 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8167 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
, val
);
8169 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8175 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set RTS threshold %d: "
8176 "%d (%s)", rts
, ret
, strerror(-ret
));
8181 static int i802_set_frag(void *priv
, int frag
)
8183 struct i802_bss
*bss
= priv
;
8184 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8189 msg
= nlmsg_alloc();
8198 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8199 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
8200 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
, val
);
8202 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8208 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set fragmentation threshold "
8209 "%d: %d (%s)", frag
, ret
, strerror(-ret
));
8214 static int i802_flush(void *priv
)
8216 struct i802_bss
*bss
= priv
;
8217 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8221 msg
= nlmsg_alloc();
8225 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_DEL_STATION
);
8228 * XXX: FIX! this needs to flush all VLANs too
8230 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8231 if_nametoindex(bss
->ifname
));
8233 res
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8235 wpa_printf(MSG_DEBUG
, "nl80211: Station flush failed: ret=%d "
8236 "(%s)", res
, strerror(-res
));
8244 #endif /* HOSTAPD || CONFIG_AP */
8247 static int get_sta_handler(struct nl_msg
*msg
, void *arg
)
8249 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8250 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8251 struct hostap_sta_driver_data
*data
= arg
;
8252 struct nlattr
*stats
[NL80211_STA_INFO_MAX
+ 1];
8253 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
8254 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
8255 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
8256 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
8257 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
8258 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
8259 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
8262 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8263 genlmsg_attrlen(gnlh
, 0), NULL
);
8266 * TODO: validate the interface and mac address!
8267 * Otherwise, there's a race condition as soon as
8268 * the kernel starts sending station notifications.
8271 if (!tb
[NL80211_ATTR_STA_INFO
]) {
8272 wpa_printf(MSG_DEBUG
, "sta stats missing!");
8275 if (nla_parse_nested(stats
, NL80211_STA_INFO_MAX
,
8276 tb
[NL80211_ATTR_STA_INFO
],
8278 wpa_printf(MSG_DEBUG
, "failed to parse nested attributes!");
8282 if (stats
[NL80211_STA_INFO_INACTIVE_TIME
])
8283 data
->inactive_msec
=
8284 nla_get_u32(stats
[NL80211_STA_INFO_INACTIVE_TIME
]);
8285 if (stats
[NL80211_STA_INFO_RX_BYTES
])
8286 data
->rx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_RX_BYTES
]);
8287 if (stats
[NL80211_STA_INFO_TX_BYTES
])
8288 data
->tx_bytes
= nla_get_u32(stats
[NL80211_STA_INFO_TX_BYTES
]);
8289 if (stats
[NL80211_STA_INFO_RX_PACKETS
])
8291 nla_get_u32(stats
[NL80211_STA_INFO_RX_PACKETS
]);
8292 if (stats
[NL80211_STA_INFO_TX_PACKETS
])
8294 nla_get_u32(stats
[NL80211_STA_INFO_TX_PACKETS
]);
8295 if (stats
[NL80211_STA_INFO_TX_FAILED
])
8296 data
->tx_retry_failed
=
8297 nla_get_u32(stats
[NL80211_STA_INFO_TX_FAILED
]);
8302 static int i802_read_sta_data(struct i802_bss
*bss
,
8303 struct hostap_sta_driver_data
*data
,
8306 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8309 os_memset(data
, 0, sizeof(*data
));
8310 msg
= nlmsg_alloc();
8314 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_STATION
);
8316 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8317 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8319 return send_and_recv_msgs(drv
, msg
, get_sta_handler
, data
);
8326 #if defined(HOSTAPD) || defined(CONFIG_AP)
8328 static int i802_set_tx_queue_params(void *priv
, int queue
, int aifs
,
8329 int cw_min
, int cw_max
, int burst_time
)
8331 struct i802_bss
*bss
= priv
;
8332 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8334 struct nlattr
*txq
, *params
;
8336 msg
= nlmsg_alloc();
8340 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_WIPHY
);
8342 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
8344 txq
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_TXQ_PARAMS
);
8346 goto nla_put_failure
;
8348 /* We are only sending parameters for a single TXQ at a time */
8349 params
= nla_nest_start(msg
, 1);
8351 goto nla_put_failure
;
8355 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VO
);
8358 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_VI
);
8361 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BE
);
8364 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_QUEUE
, NL80211_TXQ_Q_BK
);
8367 /* Burst time is configured in units of 0.1 msec and TXOP parameter in
8368 * 32 usec, so need to convert the value here. */
8369 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_TXOP
, (burst_time
* 100 + 16) / 32);
8370 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMIN
, cw_min
);
8371 NLA_PUT_U16(msg
, NL80211_TXQ_ATTR_CWMAX
, cw_max
);
8372 NLA_PUT_U8(msg
, NL80211_TXQ_ATTR_AIFS
, aifs
);
8374 nla_nest_end(msg
, params
);
8376 nla_nest_end(msg
, txq
);
8378 if (send_and_recv_msgs(drv
, msg
, NULL
, NULL
) == 0)
8387 static int i802_set_sta_vlan(struct i802_bss
*bss
, const u8
*addr
,
8388 const char *ifname
, int vlan_id
)
8390 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8394 msg
= nlmsg_alloc();
8398 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_STATION
);
8400 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
,
8401 if_nametoindex(bss
->ifname
));
8402 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
8403 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
,
8404 if_nametoindex(ifname
));
8406 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
8409 wpa_printf(MSG_ERROR
, "nl80211: NL80211_ATTR_STA_VLAN (addr="
8410 MACSTR
" ifname=%s vlan_id=%d) failed: %d (%s)",
8411 MAC2STR(addr
), ifname
, vlan_id
, ret
,
8420 static int i802_get_inact_sec(void *priv
, const u8
*addr
)
8422 struct hostap_sta_driver_data data
;
8425 data
.inactive_msec
= (unsigned long) -1;
8426 ret
= i802_read_sta_data(priv
, &data
, addr
);
8427 if (ret
|| data
.inactive_msec
== (unsigned long) -1)
8429 return data
.inactive_msec
/ 1000;
8433 static int i802_sta_clear_stats(void *priv
, const u8
*addr
)
8442 static int i802_sta_deauth(void *priv
, const u8
*own_addr
, const u8
*addr
,
8445 struct i802_bss
*bss
= priv
;
8446 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8447 struct ieee80211_mgmt mgmt
;
8449 if (drv
->device_ap_sme
)
8450 return wpa_driver_nl80211_sta_remove(bss
, addr
);
8452 memset(&mgmt
, 0, sizeof(mgmt
));
8453 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
8454 WLAN_FC_STYPE_DEAUTH
);
8455 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
8456 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
8457 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
8458 mgmt
.u
.deauth
.reason_code
= host_to_le16(reason
);
8459 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
8461 sizeof(mgmt
.u
.deauth
), 0, 0, 0, 0,
8466 static int i802_sta_disassoc(void *priv
, const u8
*own_addr
, const u8
*addr
,
8469 struct i802_bss
*bss
= priv
;
8470 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8471 struct ieee80211_mgmt mgmt
;
8473 if (drv
->device_ap_sme
)
8474 return wpa_driver_nl80211_sta_remove(bss
, addr
);
8476 memset(&mgmt
, 0, sizeof(mgmt
));
8477 mgmt
.frame_control
= IEEE80211_FC(WLAN_FC_TYPE_MGMT
,
8478 WLAN_FC_STYPE_DISASSOC
);
8479 memcpy(mgmt
.da
, addr
, ETH_ALEN
);
8480 memcpy(mgmt
.sa
, own_addr
, ETH_ALEN
);
8481 memcpy(mgmt
.bssid
, own_addr
, ETH_ALEN
);
8482 mgmt
.u
.disassoc
.reason_code
= host_to_le16(reason
);
8483 return wpa_driver_nl80211_send_mlme(bss
, (u8
*) &mgmt
,
8485 sizeof(mgmt
.u
.disassoc
), 0, 0, 0, 0,
8489 #endif /* HOSTAPD || CONFIG_AP */
8493 static void add_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8498 wpa_printf(MSG_DEBUG
, "nl80211: Add own interface ifindex %d",
8500 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8501 if (drv
->if_indices
[i
] == 0) {
8502 drv
->if_indices
[i
] = ifidx
;
8507 if (drv
->if_indices
!= drv
->default_if_indices
)
8508 old
= drv
->if_indices
;
8512 drv
->if_indices
= os_realloc_array(old
, drv
->num_if_indices
+ 1,
8514 if (!drv
->if_indices
) {
8516 drv
->if_indices
= drv
->default_if_indices
;
8518 drv
->if_indices
= old
;
8519 wpa_printf(MSG_ERROR
, "Failed to reallocate memory for "
8521 wpa_printf(MSG_ERROR
, "Ignoring EAPOL on interface %d", ifidx
);
8524 os_memcpy(drv
->if_indices
, drv
->default_if_indices
,
8525 sizeof(drv
->default_if_indices
));
8526 drv
->if_indices
[drv
->num_if_indices
] = ifidx
;
8527 drv
->num_if_indices
++;
8531 static void del_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8535 for (i
= 0; i
< drv
->num_if_indices
; i
++) {
8536 if (drv
->if_indices
[i
] == ifidx
) {
8537 drv
->if_indices
[i
] = 0;
8544 static int have_ifidx(struct wpa_driver_nl80211_data
*drv
, int ifidx
)
8548 for (i
= 0; i
< drv
->num_if_indices
; i
++)
8549 if (drv
->if_indices
[i
] == ifidx
)
8556 static int i802_set_wds_sta(void *priv
, const u8
*addr
, int aid
, int val
,
8557 const char *bridge_ifname
)
8559 struct i802_bss
*bss
= priv
;
8560 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8561 char name
[IFNAMSIZ
+ 1];
8563 os_snprintf(name
, sizeof(name
), "%s.sta%d", bss
->ifname
, aid
);
8564 wpa_printf(MSG_DEBUG
, "nl80211: Set WDS STA addr=" MACSTR
8565 " aid=%d val=%d name=%s", MAC2STR(addr
), aid
, val
, name
);
8567 if (!if_nametoindex(name
)) {
8568 if (nl80211_create_iface(drv
, name
,
8569 NL80211_IFTYPE_AP_VLAN
,
8570 bss
->addr
, 1, NULL
, NULL
) < 0)
8572 if (bridge_ifname
&&
8573 linux_br_add_if(drv
->global
->ioctl_sock
,
8574 bridge_ifname
, name
) < 0)
8577 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, name
, 1)) {
8578 wpa_printf(MSG_ERROR
, "nl80211: Failed to set WDS STA "
8579 "interface %s up", name
);
8581 return i802_set_sta_vlan(priv
, addr
, name
, 0);
8584 linux_br_del_if(drv
->global
->ioctl_sock
, bridge_ifname
,
8587 i802_set_sta_vlan(priv
, addr
, bss
->ifname
, 0);
8588 return wpa_driver_nl80211_if_remove(priv
, WPA_IF_AP_VLAN
,
8594 static void handle_eapol(int sock
, void *eloop_ctx
, void *sock_ctx
)
8596 struct wpa_driver_nl80211_data
*drv
= eloop_ctx
;
8597 struct sockaddr_ll lladdr
;
8598 unsigned char buf
[3000];
8600 socklen_t fromlen
= sizeof(lladdr
);
8602 len
= recvfrom(sock
, buf
, sizeof(buf
), 0,
8603 (struct sockaddr
*)&lladdr
, &fromlen
);
8609 if (have_ifidx(drv
, lladdr
.sll_ifindex
))
8610 drv_event_eapol_rx(drv
->ctx
, lladdr
.sll_addr
, buf
, len
);
8614 static int i802_check_bridge(struct wpa_driver_nl80211_data
*drv
,
8615 struct i802_bss
*bss
,
8616 const char *brname
, const char *ifname
)
8619 char in_br
[IFNAMSIZ
];
8621 os_strlcpy(bss
->brname
, brname
, IFNAMSIZ
);
8622 ifindex
= if_nametoindex(brname
);
8625 * Bridge was configured, but the bridge device does
8626 * not exist. Try to add it now.
8628 if (linux_br_add(drv
->global
->ioctl_sock
, brname
) < 0) {
8629 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the "
8630 "bridge interface %s: %s",
8631 brname
, strerror(errno
));
8634 bss
->added_bridge
= 1;
8635 add_ifidx(drv
, if_nametoindex(brname
));
8638 if (linux_br_get(in_br
, ifname
) == 0) {
8639 if (os_strcmp(in_br
, brname
) == 0)
8640 return 0; /* already in the bridge */
8642 wpa_printf(MSG_DEBUG
, "nl80211: Removing interface %s from "
8643 "bridge %s", ifname
, in_br
);
8644 if (linux_br_del_if(drv
->global
->ioctl_sock
, in_br
, ifname
) <
8646 wpa_printf(MSG_ERROR
, "nl80211: Failed to "
8647 "remove interface %s from bridge "
8649 ifname
, brname
, strerror(errno
));
8654 wpa_printf(MSG_DEBUG
, "nl80211: Adding interface %s into bridge %s",
8656 if (linux_br_add_if(drv
->global
->ioctl_sock
, brname
, ifname
) < 0) {
8657 wpa_printf(MSG_ERROR
, "nl80211: Failed to add interface %s "
8658 "into bridge %s: %s",
8659 ifname
, brname
, strerror(errno
));
8662 bss
->added_if_into_bridge
= 1;
8668 static void *i802_init(struct hostapd_data
*hapd
,
8669 struct wpa_init_params
*params
)
8671 struct wpa_driver_nl80211_data
*drv
;
8672 struct i802_bss
*bss
;
8674 char brname
[IFNAMSIZ
];
8675 int ifindex
, br_ifindex
;
8678 bss
= wpa_driver_nl80211_init(hapd
, params
->ifname
,
8679 params
->global_priv
);
8684 drv
->nlmode
= NL80211_IFTYPE_AP
;
8685 drv
->eapol_sock
= -1;
8687 if (linux_br_get(brname
, params
->ifname
) == 0) {
8688 wpa_printf(MSG_DEBUG
, "nl80211: Interface %s is in bridge %s",
8689 params
->ifname
, brname
);
8690 br_ifindex
= if_nametoindex(brname
);
8696 drv
->num_if_indices
= sizeof(drv
->default_if_indices
) / sizeof(int);
8697 drv
->if_indices
= drv
->default_if_indices
;
8698 for (i
= 0; i
< params
->num_bridge
; i
++) {
8699 if (params
->bridge
[i
]) {
8700 ifindex
= if_nametoindex(params
->bridge
[i
]);
8702 add_ifidx(drv
, ifindex
);
8703 if (ifindex
== br_ifindex
)
8707 if (!br_added
&& br_ifindex
&&
8708 (params
->num_bridge
== 0 || !params
->bridge
[0]))
8709 add_ifidx(drv
, br_ifindex
);
8711 /* start listening for EAPOL on the default AP interface */
8712 add_ifidx(drv
, drv
->ifindex
);
8714 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 0))
8717 if (params
->bssid
) {
8718 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8723 if (wpa_driver_nl80211_set_mode(bss
, drv
->nlmode
)) {
8724 wpa_printf(MSG_ERROR
, "nl80211: Failed to set interface %s "
8725 "into AP mode", bss
->ifname
);
8729 if (params
->num_bridge
&& params
->bridge
[0] &&
8730 i802_check_bridge(drv
, bss
, params
->bridge
[0], params
->ifname
) < 0)
8733 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1))
8736 drv
->eapol_sock
= socket(PF_PACKET
, SOCK_DGRAM
, htons(ETH_P_PAE
));
8737 if (drv
->eapol_sock
< 0) {
8738 perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
8742 if (eloop_register_read_sock(drv
->eapol_sock
, handle_eapol
, drv
, NULL
))
8744 printf("Could not register read socket for eapol\n");
8748 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8752 memcpy(bss
->addr
, params
->own_addr
, ETH_ALEN
);
8757 wpa_driver_nl80211_deinit(bss
);
8762 static void i802_deinit(void *priv
)
8764 struct i802_bss
*bss
= priv
;
8765 wpa_driver_nl80211_deinit(bss
);
8768 #endif /* HOSTAPD */
8771 static enum nl80211_iftype
wpa_driver_nl80211_if_type(
8772 enum wpa_driver_if_type type
)
8775 case WPA_IF_STATION
:
8776 return NL80211_IFTYPE_STATION
;
8777 case WPA_IF_P2P_CLIENT
:
8778 case WPA_IF_P2P_GROUP
:
8779 return NL80211_IFTYPE_P2P_CLIENT
;
8780 case WPA_IF_AP_VLAN
:
8781 return NL80211_IFTYPE_AP_VLAN
;
8783 return NL80211_IFTYPE_AP
;
8785 return NL80211_IFTYPE_P2P_GO
;
8786 case WPA_IF_P2P_DEVICE
:
8787 return NL80211_IFTYPE_P2P_DEVICE
;
8795 static int nl80211_addr_in_use(struct nl80211_global
*global
, const u8
*addr
)
8797 struct wpa_driver_nl80211_data
*drv
;
8798 dl_list_for_each(drv
, &global
->interfaces
,
8799 struct wpa_driver_nl80211_data
, list
) {
8800 if (os_memcmp(addr
, drv
->first_bss
.addr
, ETH_ALEN
) == 0)
8807 static int nl80211_p2p_interface_addr(struct wpa_driver_nl80211_data
*drv
,
8815 os_memcpy(new_addr
, drv
->first_bss
.addr
, ETH_ALEN
);
8816 for (idx
= 0; idx
< 64; idx
++) {
8817 new_addr
[0] = drv
->first_bss
.addr
[0] | 0x02;
8818 new_addr
[0] ^= idx
<< 2;
8819 if (!nl80211_addr_in_use(drv
->global
, new_addr
))
8825 wpa_printf(MSG_DEBUG
, "nl80211: Assigned new P2P Interface Address "
8826 MACSTR
, MAC2STR(new_addr
));
8831 #endif /* CONFIG_P2P */
8834 static int nl80211_create_p2p_dev_handler(struct nl_msg
*msg
, void *arg
)
8836 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
8837 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
8838 struct i802_bss
*p2p_dev
= arg
;
8840 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
8841 genlmsg_attrlen(gnlh
, 0), NULL
);
8842 if (tb
[NL80211_ATTR_WDEV
]) {
8843 p2p_dev
->wdev_id
= nla_get_u64(tb
[NL80211_ATTR_WDEV
]);
8844 p2p_dev
->wdev_id_set
= 1;
8847 if (tb
[NL80211_ATTR_MAC
])
8848 os_memcpy(p2p_dev
->addr
, nla_data(tb
[NL80211_ATTR_MAC
]),
8855 static int wpa_driver_nl80211_if_add(void *priv
, enum wpa_driver_if_type type
,
8856 const char *ifname
, const u8
*addr
,
8857 void *bss_ctx
, void **drv_priv
,
8858 char *force_ifname
, u8
*if_addr
,
8861 enum nl80211_iftype nlmode
;
8862 struct i802_bss
*bss
= priv
;
8863 struct i802_bss
*p2pdev
;
8864 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8867 struct i802_bss
*new_bss
= NULL
;
8869 if (type
== WPA_IF_AP_BSS
) {
8870 new_bss
= os_zalloc(sizeof(*new_bss
));
8871 if (new_bss
== NULL
)
8874 #endif /* HOSTAPD */
8877 os_memcpy(if_addr
, addr
, ETH_ALEN
);
8878 nlmode
= wpa_driver_nl80211_if_type(type
);
8879 if (nlmode
== NL80211_IFTYPE_P2P_DEVICE
) {
8880 p2pdev
= os_zalloc(sizeof(*p2pdev
));
8884 os_strlcpy(p2pdev
->ifname
, ifname
, IFNAMSIZ
);
8885 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
8886 0, nl80211_create_p2p_dev_handler
,
8888 if (!p2pdev
->wdev_id_set
|| ifidx
!= 0 ||
8889 is_zero_ether_addr((const u8
*) &p2pdev
->addr
)) {
8890 wpa_printf(MSG_ERROR
, "nl80211: Failed to create a P2P Device interface %s",
8896 ifidx
= nl80211_create_iface(drv
, ifname
, nlmode
, addr
,
8901 #endif /* HOSTAPD */
8907 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8909 nl80211_remove_iface(drv
, ifidx
);
8915 (type
== WPA_IF_P2P_CLIENT
|| type
== WPA_IF_P2P_GROUP
||
8916 type
== WPA_IF_P2P_GO
)) {
8917 /* Enforce unique P2P Interface Address */
8918 u8 new_addr
[ETH_ALEN
], own_addr
[ETH_ALEN
];
8920 if (linux_get_ifhwaddr(drv
->global
->ioctl_sock
, bss
->ifname
,
8922 linux_get_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
8924 nl80211_remove_iface(drv
, ifidx
);
8927 if (os_memcmp(own_addr
, new_addr
, ETH_ALEN
) == 0) {
8928 wpa_printf(MSG_DEBUG
, "nl80211: Allocate new address "
8929 "for P2P group interface");
8930 if (nl80211_p2p_interface_addr(drv
, new_addr
) < 0) {
8931 nl80211_remove_iface(drv
, ifidx
);
8934 if (linux_set_ifhwaddr(drv
->global
->ioctl_sock
, ifname
,
8936 nl80211_remove_iface(drv
, ifidx
);
8940 os_memcpy(if_addr
, new_addr
, ETH_ALEN
);
8942 #endif /* CONFIG_P2P */
8946 i802_check_bridge(drv
, new_bss
, bridge
, ifname
) < 0) {
8947 wpa_printf(MSG_ERROR
, "nl80211: Failed to add the new "
8948 "interface %s to a bridge %s", ifname
, bridge
);
8949 nl80211_remove_iface(drv
, ifidx
);
8954 if (type
== WPA_IF_AP_BSS
) {
8955 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, ifname
, 1))
8957 nl80211_remove_iface(drv
, ifidx
);
8961 os_strlcpy(new_bss
->ifname
, ifname
, IFNAMSIZ
);
8962 os_memcpy(new_bss
->addr
, if_addr
, ETH_ALEN
);
8963 new_bss
->ifindex
= ifidx
;
8965 new_bss
->next
= drv
->first_bss
.next
;
8966 new_bss
->freq
= drv
->first_bss
.freq
;
8967 new_bss
->ctx
= bss_ctx
;
8968 drv
->first_bss
.next
= new_bss
;
8970 *drv_priv
= new_bss
;
8971 nl80211_init_bss(new_bss
);
8973 /* Subscribe management frames for this WPA_IF_AP_BSS */
8974 if (nl80211_setup_ap(new_bss
))
8977 #endif /* HOSTAPD */
8980 drv
->global
->if_add_ifindex
= ifidx
;
8986 static int wpa_driver_nl80211_if_remove(struct i802_bss
*bss
,
8987 enum wpa_driver_if_type type
,
8990 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
8991 int ifindex
= if_nametoindex(ifname
);
8993 wpa_printf(MSG_DEBUG
, "nl80211: %s(type=%d ifname=%s) ifindex=%d",
8994 __func__
, type
, ifname
, ifindex
);
8998 nl80211_remove_iface(drv
, ifindex
);
9001 if (type
!= WPA_IF_AP_BSS
)
9004 if (bss
->added_if_into_bridge
) {
9005 if (linux_br_del_if(drv
->global
->ioctl_sock
, bss
->brname
,
9007 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
9008 "interface %s from bridge %s: %s",
9009 bss
->ifname
, bss
->brname
, strerror(errno
));
9011 if (bss
->added_bridge
) {
9012 if (linux_br_del(drv
->global
->ioctl_sock
, bss
->brname
) < 0)
9013 wpa_printf(MSG_INFO
, "nl80211: Failed to remove "
9015 bss
->brname
, strerror(errno
));
9018 if (bss
!= &drv
->first_bss
) {
9019 struct i802_bss
*tbss
;
9021 for (tbss
= &drv
->first_bss
; tbss
; tbss
= tbss
->next
) {
9022 if (tbss
->next
== bss
) {
9023 tbss
->next
= bss
->next
;
9024 /* Unsubscribe management frames */
9025 nl80211_teardown_ap(bss
);
9026 nl80211_destroy_bss(bss
);
9033 wpa_printf(MSG_INFO
, "nl80211: %s - could not find "
9034 "BSS %p in the list", __func__
, bss
);
9036 #endif /* HOSTAPD */
9042 static int cookie_handler(struct nl_msg
*msg
, void *arg
)
9044 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9045 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9047 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9048 genlmsg_attrlen(gnlh
, 0), NULL
);
9049 if (tb
[NL80211_ATTR_COOKIE
])
9050 *cookie
= nla_get_u64(tb
[NL80211_ATTR_COOKIE
]);
9055 static int nl80211_send_frame_cmd(struct i802_bss
*bss
,
9056 unsigned int freq
, unsigned int wait
,
9057 const u8
*buf
, size_t buf_len
,
9058 u64
*cookie_out
, int no_cck
, int no_ack
,
9061 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9066 msg
= nlmsg_alloc();
9070 wpa_printf(MSG_MSGDUMP
, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
9071 "no_ack=%d offchanok=%d",
9072 freq
, wait
, no_cck
, no_ack
, offchanok
);
9073 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME
);
9075 if (nl80211_set_iface_id(msg
, bss
))
9076 goto nla_put_failure
;
9078 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9080 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, wait
);
9081 if (offchanok
&& (drv
->capa
.flags
& WPA_DRIVER_FLAGS_OFFCHANNEL_TX
))
9082 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
9084 NLA_PUT_FLAG(msg
, NL80211_ATTR_TX_NO_CCK_RATE
);
9086 NLA_PUT_FLAG(msg
, NL80211_ATTR_DONT_WAIT_FOR_ACK
);
9088 NLA_PUT(msg
, NL80211_ATTR_FRAME
, buf_len
, buf
);
9091 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
9094 wpa_printf(MSG_DEBUG
, "nl80211: Frame command failed: ret=%d "
9095 "(%s) (freq=%u wait=%u)", ret
, strerror(-ret
),
9097 goto nla_put_failure
;
9099 wpa_printf(MSG_MSGDUMP
, "nl80211: Frame TX command accepted%s; "
9100 "cookie 0x%llx", no_ack
? " (no ACK)" : "",
9101 (long long unsigned int) cookie
);
9104 *cookie_out
= no_ack
? (u64
) -1 : cookie
;
9112 static int wpa_driver_nl80211_send_action(struct i802_bss
*bss
,
9114 unsigned int wait_time
,
9115 const u8
*dst
, const u8
*src
,
9117 const u8
*data
, size_t data_len
,
9120 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9123 struct ieee80211_hdr
*hdr
;
9125 wpa_printf(MSG_DEBUG
, "nl80211: Send Action frame (ifindex=%d, "
9126 "freq=%u MHz wait=%d ms no_cck=%d)",
9127 drv
->ifindex
, freq
, wait_time
, no_cck
);
9129 buf
= os_zalloc(24 + data_len
);
9132 os_memcpy(buf
+ 24, data
, data_len
);
9133 hdr
= (struct ieee80211_hdr
*) buf
;
9134 hdr
->frame_control
=
9135 IEEE80211_FC(WLAN_FC_TYPE_MGMT
, WLAN_FC_STYPE_ACTION
);
9136 os_memcpy(hdr
->addr1
, dst
, ETH_ALEN
);
9137 os_memcpy(hdr
->addr2
, src
, ETH_ALEN
);
9138 os_memcpy(hdr
->addr3
, bssid
, ETH_ALEN
);
9140 if (is_ap_interface(drv
->nlmode
))
9141 ret
= wpa_driver_nl80211_send_mlme(bss
, buf
, 24 + data_len
,
9145 ret
= nl80211_send_frame_cmd(bss
, freq
, wait_time
, buf
,
9147 &drv
->send_action_cookie
,
9155 static void wpa_driver_nl80211_send_action_cancel_wait(void *priv
)
9157 struct i802_bss
*bss
= priv
;
9158 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9162 msg
= nlmsg_alloc();
9166 wpa_printf(MSG_DEBUG
, "nl80211: Cancel TX frame wait: cookie=0x%llx",
9167 (long long unsigned int) drv
->send_action_cookie
);
9168 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_FRAME_WAIT_CANCEL
);
9170 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9171 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->send_action_cookie
);
9173 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9176 wpa_printf(MSG_DEBUG
, "nl80211: wait cancel failed: ret=%d "
9177 "(%s)", ret
, strerror(-ret
));
9184 static int wpa_driver_nl80211_remain_on_channel(void *priv
, unsigned int freq
,
9185 unsigned int duration
)
9187 struct i802_bss
*bss
= priv
;
9188 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9193 msg
= nlmsg_alloc();
9197 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_REMAIN_ON_CHANNEL
);
9199 if (nl80211_set_iface_id(msg
, bss
))
9200 goto nla_put_failure
;
9202 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9203 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
9206 ret
= send_and_recv_msgs(drv
, msg
, cookie_handler
, &cookie
);
9209 wpa_printf(MSG_DEBUG
, "nl80211: Remain-on-channel cookie "
9210 "0x%llx for freq=%u MHz duration=%u",
9211 (long long unsigned int) cookie
, freq
, duration
);
9212 drv
->remain_on_chan_cookie
= cookie
;
9213 drv
->pending_remain_on_chan
= 1;
9216 wpa_printf(MSG_DEBUG
, "nl80211: Failed to request remain-on-channel "
9217 "(freq=%d duration=%u): %d (%s)",
9218 freq
, duration
, ret
, strerror(-ret
));
9225 static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv
)
9227 struct i802_bss
*bss
= priv
;
9228 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9232 if (!drv
->pending_remain_on_chan
) {
9233 wpa_printf(MSG_DEBUG
, "nl80211: No pending remain-on-channel "
9238 wpa_printf(MSG_DEBUG
, "nl80211: Cancel remain-on-channel with cookie "
9240 (long long unsigned int) drv
->remain_on_chan_cookie
);
9242 msg
= nlmsg_alloc();
9246 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
);
9248 if (nl80211_set_iface_id(msg
, bss
))
9249 goto nla_put_failure
;
9251 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, drv
->remain_on_chan_cookie
);
9253 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9257 wpa_printf(MSG_DEBUG
, "nl80211: Failed to cancel remain-on-channel: "
9258 "%d (%s)", ret
, strerror(-ret
));
9265 static int wpa_driver_nl80211_probe_req_report(struct i802_bss
*bss
, int report
)
9267 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9270 if (bss
->nl_preq
&& drv
->device_ap_sme
&&
9271 is_ap_interface(drv
->nlmode
)) {
9273 * Do not disable Probe Request reporting that was
9274 * enabled in nl80211_setup_ap().
9276 wpa_printf(MSG_DEBUG
, "nl80211: Skip disabling of "
9277 "Probe Request reporting nl_preq=%p while "
9278 "in AP mode", bss
->nl_preq
);
9279 } else if (bss
->nl_preq
) {
9280 wpa_printf(MSG_DEBUG
, "nl80211: Disable Probe Request "
9281 "reporting nl_preq=%p", bss
->nl_preq
);
9282 eloop_unregister_read_sock(
9283 nl_socket_get_fd(bss
->nl_preq
));
9284 nl_destroy_handles(&bss
->nl_preq
);
9290 wpa_printf(MSG_DEBUG
, "nl80211: Probe Request reporting "
9291 "already on! nl_preq=%p", bss
->nl_preq
);
9295 bss
->nl_preq
= nl_create_handle(drv
->global
->nl_cb
, "preq");
9296 if (bss
->nl_preq
== NULL
)
9298 wpa_printf(MSG_DEBUG
, "nl80211: Enable Probe Request "
9299 "reporting nl_preq=%p", bss
->nl_preq
);
9301 if (nl80211_register_frame(bss
, bss
->nl_preq
,
9302 (WLAN_FC_TYPE_MGMT
<< 2) |
9303 (WLAN_FC_STYPE_PROBE_REQ
<< 4),
9307 eloop_register_read_sock(nl_socket_get_fd(bss
->nl_preq
),
9308 wpa_driver_nl80211_event_receive
, bss
->nl_cb
,
9314 nl_destroy_handles(&bss
->nl_preq
);
9319 static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data
*drv
,
9320 int ifindex
, int disabled
)
9323 struct nlattr
*bands
, *band
;
9326 msg
= nlmsg_alloc();
9330 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_TX_BITRATE_MASK
);
9331 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, ifindex
);
9333 bands
= nla_nest_start(msg
, NL80211_ATTR_TX_RATES
);
9335 goto nla_put_failure
;
9338 * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
9339 * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
9340 * rates. All 5 GHz rates are left enabled.
9342 band
= nla_nest_start(msg
, NL80211_BAND_2GHZ
);
9344 goto nla_put_failure
;
9346 NLA_PUT(msg
, NL80211_TXRATE_LEGACY
, 8,
9347 "\x0c\x12\x18\x24\x30\x48\x60\x6c");
9349 nla_nest_end(msg
, band
);
9351 nla_nest_end(msg
, bands
);
9353 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9356 wpa_printf(MSG_DEBUG
, "nl80211: Set TX rates failed: ret=%d "
9357 "(%s)", ret
, strerror(-ret
));
9359 drv
->disabled_11b_rates
= disabled
;
9369 static int wpa_driver_nl80211_deinit_ap(void *priv
)
9371 struct i802_bss
*bss
= priv
;
9372 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9373 if (!is_ap_interface(drv
->nlmode
))
9375 wpa_driver_nl80211_del_beacon(drv
);
9376 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
9380 static int wpa_driver_nl80211_stop_ap(void *priv
)
9382 struct i802_bss
*bss
= priv
;
9383 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9384 if (!is_ap_interface(drv
->nlmode
))
9386 wpa_driver_nl80211_del_beacon(drv
);
9387 bss
->beacon_set
= 0;
9392 static int wpa_driver_nl80211_deinit_p2p_cli(void *priv
)
9394 struct i802_bss
*bss
= priv
;
9395 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9396 if (drv
->nlmode
!= NL80211_IFTYPE_P2P_CLIENT
)
9398 return wpa_driver_nl80211_set_mode(priv
, NL80211_IFTYPE_STATION
);
9402 static void wpa_driver_nl80211_resume(void *priv
)
9404 struct i802_bss
*bss
= priv
;
9405 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9406 if (linux_set_iface_flags(drv
->global
->ioctl_sock
, bss
->ifname
, 1)) {
9407 wpa_printf(MSG_DEBUG
, "nl80211: Failed to set interface up on "
9413 static int nl80211_send_ft_action(void *priv
, u8 action
, const u8
*target_ap
,
9414 const u8
*ies
, size_t ies_len
)
9416 struct i802_bss
*bss
= priv
;
9417 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9421 const u8
*own_addr
= bss
->addr
;
9424 wpa_printf(MSG_ERROR
, "nl80211: Unsupported send_ft_action "
9425 "action %d", action
);
9430 * Action frame payload:
9431 * Category[1] = 6 (Fast BSS Transition)
9432 * Action[1] = 1 (Fast BSS Transition Request)
9438 data_len
= 2 + 2 * ETH_ALEN
+ ies_len
;
9439 data
= os_malloc(data_len
);
9443 *pos
++ = 0x06; /* FT Action category */
9445 os_memcpy(pos
, own_addr
, ETH_ALEN
);
9447 os_memcpy(pos
, target_ap
, ETH_ALEN
);
9449 os_memcpy(pos
, ies
, ies_len
);
9451 ret
= wpa_driver_nl80211_send_action(bss
, drv
->assoc_freq
, 0,
9452 drv
->bssid
, own_addr
, drv
->bssid
,
9460 static int nl80211_signal_monitor(void *priv
, int threshold
, int hysteresis
)
9462 struct i802_bss
*bss
= priv
;
9463 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9468 wpa_printf(MSG_DEBUG
, "nl80211: Signal monitor threshold=%d "
9469 "hysteresis=%d", threshold
, hysteresis
);
9471 msg
= nlmsg_alloc();
9475 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_CQM
);
9477 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9479 cqm
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
9481 goto nla_put_failure
;
9483 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THOLD
, threshold
);
9484 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_HYST
, hysteresis
);
9485 nla_nest_end(msg
, cqm
);
9487 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9496 /* Converts nl80211_chan_width to a common format */
9497 static enum chan_width
convert2width(int width
)
9500 case NL80211_CHAN_WIDTH_20_NOHT
:
9501 return CHAN_WIDTH_20_NOHT
;
9502 case NL80211_CHAN_WIDTH_20
:
9503 return CHAN_WIDTH_20
;
9504 case NL80211_CHAN_WIDTH_40
:
9505 return CHAN_WIDTH_40
;
9506 case NL80211_CHAN_WIDTH_80
:
9507 return CHAN_WIDTH_80
;
9508 case NL80211_CHAN_WIDTH_80P80
:
9509 return CHAN_WIDTH_80P80
;
9510 case NL80211_CHAN_WIDTH_160
:
9511 return CHAN_WIDTH_160
;
9513 return CHAN_WIDTH_UNKNOWN
;
9517 static int get_channel_width(struct nl_msg
*msg
, void *arg
)
9519 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
9520 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
9521 struct wpa_signal_info
*sig_change
= arg
;
9523 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
9524 genlmsg_attrlen(gnlh
, 0), NULL
);
9526 sig_change
->center_frq1
= -1;
9527 sig_change
->center_frq2
= -1;
9528 sig_change
->chanwidth
= CHAN_WIDTH_UNKNOWN
;
9530 if (tb
[NL80211_ATTR_CHANNEL_WIDTH
]) {
9531 sig_change
->chanwidth
= convert2width(
9532 nla_get_u32(tb
[NL80211_ATTR_CHANNEL_WIDTH
]));
9533 if (tb
[NL80211_ATTR_CENTER_FREQ1
])
9534 sig_change
->center_frq1
=
9535 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ1
]);
9536 if (tb
[NL80211_ATTR_CENTER_FREQ2
])
9537 sig_change
->center_frq2
=
9538 nla_get_u32(tb
[NL80211_ATTR_CENTER_FREQ2
]);
9545 static int nl80211_get_channel_width(struct wpa_driver_nl80211_data
*drv
,
9546 struct wpa_signal_info
*sig
)
9550 msg
= nlmsg_alloc();
9554 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_GET_INTERFACE
);
9555 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9557 return send_and_recv_msgs(drv
, msg
, get_channel_width
, sig
);
9565 static int nl80211_signal_poll(void *priv
, struct wpa_signal_info
*si
)
9567 struct i802_bss
*bss
= priv
;
9568 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9571 os_memset(si
, 0, sizeof(*si
));
9572 res
= nl80211_get_link_signal(drv
, si
);
9576 res
= nl80211_get_channel_width(drv
, si
);
9580 return nl80211_get_link_noise(drv
, si
);
9584 static int wpa_driver_nl80211_shared_freq(void *priv
)
9586 struct i802_bss
*bss
= priv
;
9587 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9588 struct wpa_driver_nl80211_data
*driver
;
9592 * If the same PHY is in connected state with some other interface,
9593 * then retrieve the assoc freq.
9595 wpa_printf(MSG_DEBUG
, "nl80211: Get shared freq for PHY %s",
9598 dl_list_for_each(driver
, &drv
->global
->interfaces
,
9599 struct wpa_driver_nl80211_data
, list
) {
9600 if (drv
== driver
||
9601 os_strcmp(drv
->phyname
, driver
->phyname
) != 0 ||
9602 !driver
->associated
)
9605 wpa_printf(MSG_DEBUG
, "nl80211: Found a match for PHY %s - %s "
9607 driver
->phyname
, driver
->first_bss
.ifname
,
9608 MAC2STR(driver
->first_bss
.addr
));
9609 if (is_ap_interface(driver
->nlmode
))
9610 freq
= driver
->first_bss
.freq
;
9612 freq
= nl80211_get_assoc_freq(driver
);
9613 wpa_printf(MSG_DEBUG
, "nl80211: Shared freq for PHY %s: %d",
9614 drv
->phyname
, freq
);
9618 wpa_printf(MSG_DEBUG
, "nl80211: No shared interface for "
9619 "PHY (%s) in associated state", drv
->phyname
);
9625 static int nl80211_send_frame(void *priv
, const u8
*data
, size_t data_len
,
9628 struct i802_bss
*bss
= priv
;
9629 return wpa_driver_nl80211_send_frame(bss
, data
, data_len
, encrypt
, 0,
9634 static int nl80211_set_param(void *priv
, const char *param
)
9636 wpa_printf(MSG_DEBUG
, "nl80211: driver param='%s'", param
);
9641 if (os_strstr(param
, "use_p2p_group_interface=1")) {
9642 struct i802_bss
*bss
= priv
;
9643 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9645 wpa_printf(MSG_DEBUG
, "nl80211: Use separate P2P group "
9647 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_CONCURRENT
;
9648 drv
->capa
.flags
|= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
;
9650 #endif /* CONFIG_P2P */
9656 static void * nl80211_global_init(void)
9658 struct nl80211_global
*global
;
9659 struct netlink_config
*cfg
;
9661 global
= os_zalloc(sizeof(*global
));
9664 global
->ioctl_sock
= -1;
9665 dl_list_init(&global
->interfaces
);
9666 global
->if_add_ifindex
= -1;
9668 cfg
= os_zalloc(sizeof(*cfg
));
9673 cfg
->newlink_cb
= wpa_driver_nl80211_event_rtm_newlink
;
9674 cfg
->dellink_cb
= wpa_driver_nl80211_event_rtm_dellink
;
9675 global
->netlink
= netlink_init(cfg
);
9676 if (global
->netlink
== NULL
) {
9681 if (wpa_driver_nl80211_init_nl_global(global
) < 0)
9684 global
->ioctl_sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
9685 if (global
->ioctl_sock
< 0) {
9686 perror("socket(PF_INET,SOCK_DGRAM)");
9693 nl80211_global_deinit(global
);
9698 static void nl80211_global_deinit(void *priv
)
9700 struct nl80211_global
*global
= priv
;
9703 if (!dl_list_empty(&global
->interfaces
)) {
9704 wpa_printf(MSG_ERROR
, "nl80211: %u interface(s) remain at "
9705 "nl80211_global_deinit",
9706 dl_list_len(&global
->interfaces
));
9709 if (global
->netlink
)
9710 netlink_deinit(global
->netlink
);
9712 nl_destroy_handles(&global
->nl
);
9714 if (global
->nl_event
) {
9715 eloop_unregister_read_sock(
9716 nl_socket_get_fd(global
->nl_event
));
9717 nl_destroy_handles(&global
->nl_event
);
9720 nl_cb_put(global
->nl_cb
);
9722 if (global
->ioctl_sock
>= 0)
9723 close(global
->ioctl_sock
);
9729 static const char * nl80211_get_radio_name(void *priv
)
9731 struct i802_bss
*bss
= priv
;
9732 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9733 return drv
->phyname
;
9737 static int nl80211_pmkid(struct i802_bss
*bss
, int cmd
, const u8
*bssid
,
9742 msg
= nlmsg_alloc();
9746 nl80211_cmd(bss
->drv
, msg
, 0, cmd
);
9748 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, if_nametoindex(bss
->ifname
));
9750 NLA_PUT(msg
, NL80211_ATTR_PMKID
, 16, pmkid
);
9752 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
9754 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
9761 static int nl80211_add_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
9763 struct i802_bss
*bss
= priv
;
9764 wpa_printf(MSG_DEBUG
, "nl80211: Add PMKID for " MACSTR
, MAC2STR(bssid
));
9765 return nl80211_pmkid(bss
, NL80211_CMD_SET_PMKSA
, bssid
, pmkid
);
9769 static int nl80211_remove_pmkid(void *priv
, const u8
*bssid
, const u8
*pmkid
)
9771 struct i802_bss
*bss
= priv
;
9772 wpa_printf(MSG_DEBUG
, "nl80211: Delete PMKID for " MACSTR
,
9774 return nl80211_pmkid(bss
, NL80211_CMD_DEL_PMKSA
, bssid
, pmkid
);
9778 static int nl80211_flush_pmkid(void *priv
)
9780 struct i802_bss
*bss
= priv
;
9781 wpa_printf(MSG_DEBUG
, "nl80211: Flush PMKIDs");
9782 return nl80211_pmkid(bss
, NL80211_CMD_FLUSH_PMKSA
, NULL
, NULL
);
9786 static void nl80211_set_rekey_info(void *priv
, const u8
*kek
, const u8
*kck
,
9787 const u8
*replay_ctr
)
9789 struct i802_bss
*bss
= priv
;
9790 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9791 struct nlattr
*replay_nested
;
9794 msg
= nlmsg_alloc();
9798 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
9800 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9802 replay_nested
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
9804 goto nla_put_failure
;
9806 NLA_PUT(msg
, NL80211_REKEY_DATA_KEK
, NL80211_KEK_LEN
, kek
);
9807 NLA_PUT(msg
, NL80211_REKEY_DATA_KCK
, NL80211_KCK_LEN
, kck
);
9808 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
, NL80211_REPLAY_CTR_LEN
,
9811 nla_nest_end(msg
, replay_nested
);
9813 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9820 static void nl80211_send_null_frame(struct i802_bss
*bss
, const u8
*own_addr
,
9821 const u8
*addr
, int qos
)
9823 /* send data frame to poll STA and check whether
9824 * this frame is ACKed */
9826 struct ieee80211_hdr hdr
;
9828 } STRUCT_PACKED nulldata
;
9831 /* Send data frame to poll STA and check whether this frame is ACKed */
9833 os_memset(&nulldata
, 0, sizeof(nulldata
));
9836 nulldata
.hdr
.frame_control
=
9837 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
9838 WLAN_FC_STYPE_QOS_NULL
);
9839 size
= sizeof(nulldata
);
9841 nulldata
.hdr
.frame_control
=
9842 IEEE80211_FC(WLAN_FC_TYPE_DATA
,
9843 WLAN_FC_STYPE_NULLFUNC
);
9844 size
= sizeof(struct ieee80211_hdr
);
9847 nulldata
.hdr
.frame_control
|= host_to_le16(WLAN_FC_FROMDS
);
9848 os_memcpy(nulldata
.hdr
.IEEE80211_DA_FROMDS
, addr
, ETH_ALEN
);
9849 os_memcpy(nulldata
.hdr
.IEEE80211_BSSID_FROMDS
, own_addr
, ETH_ALEN
);
9850 os_memcpy(nulldata
.hdr
.IEEE80211_SA_FROMDS
, own_addr
, ETH_ALEN
);
9852 if (wpa_driver_nl80211_send_mlme(bss
, (u8
*) &nulldata
, size
, 0, 0, 0,
9854 wpa_printf(MSG_DEBUG
, "nl80211_send_null_frame: Failed to "
9858 static void nl80211_poll_client(void *priv
, const u8
*own_addr
, const u8
*addr
,
9861 struct i802_bss
*bss
= priv
;
9862 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9865 if (!drv
->poll_command_supported
) {
9866 nl80211_send_null_frame(bss
, own_addr
, addr
, qos
);
9870 msg
= nlmsg_alloc();
9874 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_PROBE_CLIENT
);
9876 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9877 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
9879 send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9886 static int nl80211_set_power_save(struct i802_bss
*bss
, int enabled
)
9890 msg
= nlmsg_alloc();
9894 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_SET_POWER_SAVE
);
9895 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, bss
->ifindex
);
9896 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
,
9897 enabled
? NL80211_PS_ENABLED
: NL80211_PS_DISABLED
);
9898 return send_and_recv_msgs(bss
->drv
, msg
, NULL
, NULL
);
9905 static int nl80211_set_p2p_powersave(void *priv
, int legacy_ps
, int opp_ps
,
9908 struct i802_bss
*bss
= priv
;
9910 wpa_printf(MSG_DEBUG
, "nl80211: set_p2p_powersave (legacy_ps=%d "
9911 "opp_ps=%d ctwindow=%d)", legacy_ps
, opp_ps
, ctwindow
);
9913 if (opp_ps
!= -1 || ctwindow
!= -1)
9914 return -1; /* Not yet supported */
9916 if (legacy_ps
== -1)
9918 if (legacy_ps
!= 0 && legacy_ps
!= 1)
9919 return -1; /* Not yet supported */
9921 return nl80211_set_power_save(bss
, legacy_ps
);
9925 static int nl80211_start_radar_detection(void *priv
, int freq
)
9927 struct i802_bss
*bss
= priv
;
9928 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9932 wpa_printf(MSG_DEBUG
, "nl80211: Start radar detection (CAC)");
9933 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_RADAR
)) {
9934 wpa_printf(MSG_DEBUG
, "nl80211: Driver does not support radar "
9939 msg
= nlmsg_alloc();
9943 nl80211_cmd(bss
->drv
, msg
, 0, NL80211_CMD_RADAR_DETECT
);
9944 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9945 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
9947 /* only HT20 is supported at this point */
9948 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, NL80211_CHAN_HT20
);
9950 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9953 wpa_printf(MSG_DEBUG
, "nl80211: Failed to start radar detection: "
9954 "%d (%s)", ret
, strerror(-ret
));
9961 static int nl80211_send_tdls_mgmt(void *priv
, const u8
*dst
, u8 action_code
,
9962 u8 dialog_token
, u16 status_code
,
9963 const u8
*buf
, size_t len
)
9965 struct i802_bss
*bss
= priv
;
9966 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
9969 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
9975 msg
= nlmsg_alloc();
9979 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_MGMT
);
9980 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
9981 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
9982 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_ACTION
, action_code
);
9983 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_DIALOG_TOKEN
, dialog_token
);
9984 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status_code
);
9985 NLA_PUT(msg
, NL80211_ATTR_IE
, len
, buf
);
9987 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
9995 static int nl80211_tdls_oper(void *priv
, enum tdls_oper oper
, const u8
*peer
)
9997 struct i802_bss
*bss
= priv
;
9998 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10000 enum nl80211_tdls_operation nl80211_oper
;
10002 if (!(drv
->capa
.flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
))
10003 return -EOPNOTSUPP
;
10006 case TDLS_DISCOVERY_REQ
:
10007 nl80211_oper
= NL80211_TDLS_DISCOVERY_REQ
;
10010 nl80211_oper
= NL80211_TDLS_SETUP
;
10012 case TDLS_TEARDOWN
:
10013 nl80211_oper
= NL80211_TDLS_TEARDOWN
;
10015 case TDLS_ENABLE_LINK
:
10016 nl80211_oper
= NL80211_TDLS_ENABLE_LINK
;
10018 case TDLS_DISABLE_LINK
:
10019 nl80211_oper
= NL80211_TDLS_DISABLE_LINK
;
10029 msg
= nlmsg_alloc();
10033 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_TDLS_OPER
);
10034 NLA_PUT_U8(msg
, NL80211_ATTR_TDLS_OPERATION
, nl80211_oper
);
10035 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10036 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
10038 return send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10045 #endif /* CONFIG TDLS */
10050 typedef struct android_wifi_priv_cmd
{
10054 } android_wifi_priv_cmd
;
10056 static int drv_errors
= 0;
10058 static void wpa_driver_send_hang_msg(struct wpa_driver_nl80211_data
*drv
)
10061 if (drv_errors
> DRV_NUMBER_SEQUENTIAL_ERRORS
) {
10063 wpa_msg(drv
->ctx
, MSG_INFO
, WPA_EVENT_DRIVER_STATE
"HANGED");
10068 static int android_priv_cmd(struct i802_bss
*bss
, const char *cmd
)
10070 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10072 android_wifi_priv_cmd priv_cmd
;
10073 char buf
[MAX_DRV_CMD_SIZE
];
10076 os_memset(&ifr
, 0, sizeof(ifr
));
10077 os_memset(&priv_cmd
, 0, sizeof(priv_cmd
));
10078 os_strlcpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
10080 os_memset(buf
, 0, sizeof(buf
));
10081 os_strlcpy(buf
, cmd
, sizeof(buf
));
10083 priv_cmd
.buf
= buf
;
10084 priv_cmd
.used_len
= sizeof(buf
);
10085 priv_cmd
.total_len
= sizeof(buf
);
10086 ifr
.ifr_data
= &priv_cmd
;
10088 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
10090 wpa_printf(MSG_ERROR
, "%s: failed to issue private commands",
10092 wpa_driver_send_hang_msg(drv
);
10101 static int android_pno_start(struct i802_bss
*bss
,
10102 struct wpa_driver_scan_params
*params
)
10104 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10106 android_wifi_priv_cmd priv_cmd
;
10107 int ret
= 0, i
= 0, bp
;
10108 char buf
[WEXT_PNO_MAX_COMMAND_SIZE
];
10110 bp
= WEXT_PNOSETUP_HEADER_SIZE
;
10111 os_memcpy(buf
, WEXT_PNOSETUP_HEADER
, bp
);
10112 buf
[bp
++] = WEXT_PNO_TLV_PREFIX
;
10113 buf
[bp
++] = WEXT_PNO_TLV_VERSION
;
10114 buf
[bp
++] = WEXT_PNO_TLV_SUBVERSION
;
10115 buf
[bp
++] = WEXT_PNO_TLV_RESERVED
;
10117 while (i
< WEXT_PNO_AMOUNT
&& (size_t) i
< params
->num_ssids
) {
10118 /* Check that there is enough space needed for 1 more SSID, the
10119 * other sections and null termination */
10120 if ((bp
+ WEXT_PNO_SSID_HEADER_SIZE
+ MAX_SSID_LEN
+
10121 WEXT_PNO_NONSSID_SECTIONS_SIZE
+ 1) >= (int) sizeof(buf
))
10123 wpa_hexdump_ascii(MSG_DEBUG
, "For PNO Scan",
10124 params
->ssids
[i
].ssid
,
10125 params
->ssids
[i
].ssid_len
);
10126 buf
[bp
++] = WEXT_PNO_SSID_SECTION
;
10127 buf
[bp
++] = params
->ssids
[i
].ssid_len
;
10128 os_memcpy(&buf
[bp
], params
->ssids
[i
].ssid
,
10129 params
->ssids
[i
].ssid_len
);
10130 bp
+= params
->ssids
[i
].ssid_len
;
10134 buf
[bp
++] = WEXT_PNO_SCAN_INTERVAL_SECTION
;
10135 os_snprintf(&buf
[bp
], WEXT_PNO_SCAN_INTERVAL_LENGTH
+ 1, "%x",
10136 WEXT_PNO_SCAN_INTERVAL
);
10137 bp
+= WEXT_PNO_SCAN_INTERVAL_LENGTH
;
10139 buf
[bp
++] = WEXT_PNO_REPEAT_SECTION
;
10140 os_snprintf(&buf
[bp
], WEXT_PNO_REPEAT_LENGTH
+ 1, "%x",
10142 bp
+= WEXT_PNO_REPEAT_LENGTH
;
10144 buf
[bp
++] = WEXT_PNO_MAX_REPEAT_SECTION
;
10145 os_snprintf(&buf
[bp
], WEXT_PNO_MAX_REPEAT_LENGTH
+ 1, "%x",
10146 WEXT_PNO_MAX_REPEAT
);
10147 bp
+= WEXT_PNO_MAX_REPEAT_LENGTH
+ 1;
10149 memset(&ifr
, 0, sizeof(ifr
));
10150 memset(&priv_cmd
, 0, sizeof(priv_cmd
));
10151 os_strncpy(ifr
.ifr_name
, bss
->ifname
, IFNAMSIZ
);
10153 priv_cmd
.buf
= buf
;
10154 priv_cmd
.used_len
= bp
;
10155 priv_cmd
.total_len
= bp
;
10156 ifr
.ifr_data
= &priv_cmd
;
10158 ret
= ioctl(drv
->global
->ioctl_sock
, SIOCDEVPRIVATE
+ 1, &ifr
);
10161 wpa_printf(MSG_ERROR
, "ioctl[SIOCSIWPRIV] (pnosetup): %d",
10163 wpa_driver_send_hang_msg(drv
);
10169 return android_priv_cmd(bss
, "PNOFORCE 1");
10173 static int android_pno_stop(struct i802_bss
*bss
)
10175 return android_priv_cmd(bss
, "PNOFORCE 0");
10178 #endif /* ANDROID */
10181 static int driver_nl80211_set_key(const char *ifname
, void *priv
,
10182 enum wpa_alg alg
, const u8
*addr
,
10183 int key_idx
, int set_tx
,
10184 const u8
*seq
, size_t seq_len
,
10185 const u8
*key
, size_t key_len
)
10187 struct i802_bss
*bss
= priv
;
10188 return wpa_driver_nl80211_set_key(ifname
, bss
, alg
, addr
, key_idx
,
10189 set_tx
, seq
, seq_len
, key
, key_len
);
10193 static int driver_nl80211_scan2(void *priv
,
10194 struct wpa_driver_scan_params
*params
)
10196 struct i802_bss
*bss
= priv
;
10197 return wpa_driver_nl80211_scan(bss
, params
);
10201 static int driver_nl80211_deauthenticate(void *priv
, const u8
*addr
,
10204 struct i802_bss
*bss
= priv
;
10205 return wpa_driver_nl80211_deauthenticate(bss
, addr
, reason_code
);
10209 static int driver_nl80211_authenticate(void *priv
,
10210 struct wpa_driver_auth_params
*params
)
10212 struct i802_bss
*bss
= priv
;
10213 return wpa_driver_nl80211_authenticate(bss
, params
);
10217 static void driver_nl80211_deinit(void *priv
)
10219 struct i802_bss
*bss
= priv
;
10220 wpa_driver_nl80211_deinit(bss
);
10224 static int driver_nl80211_if_remove(void *priv
, enum wpa_driver_if_type type
,
10225 const char *ifname
)
10227 struct i802_bss
*bss
= priv
;
10228 return wpa_driver_nl80211_if_remove(bss
, type
, ifname
);
10232 static int driver_nl80211_send_mlme(void *priv
, const u8
*data
,
10233 size_t data_len
, int noack
)
10235 struct i802_bss
*bss
= priv
;
10236 return wpa_driver_nl80211_send_mlme(bss
, data
, data_len
, noack
,
10241 static int driver_nl80211_sta_remove(void *priv
, const u8
*addr
)
10243 struct i802_bss
*bss
= priv
;
10244 return wpa_driver_nl80211_sta_remove(bss
, addr
);
10248 #if defined(HOSTAPD) || defined(CONFIG_AP)
10249 static int driver_nl80211_set_sta_vlan(void *priv
, const u8
*addr
,
10250 const char *ifname
, int vlan_id
)
10252 struct i802_bss
*bss
= priv
;
10253 return i802_set_sta_vlan(bss
, addr
, ifname
, vlan_id
);
10255 #endif /* HOSTAPD || CONFIG_AP */
10258 static int driver_nl80211_read_sta_data(void *priv
,
10259 struct hostap_sta_driver_data
*data
,
10262 struct i802_bss
*bss
= priv
;
10263 return i802_read_sta_data(bss
, data
, addr
);
10267 static int driver_nl80211_send_action(void *priv
, unsigned int freq
,
10268 unsigned int wait_time
,
10269 const u8
*dst
, const u8
*src
,
10271 const u8
*data
, size_t data_len
,
10274 struct i802_bss
*bss
= priv
;
10275 return wpa_driver_nl80211_send_action(bss
, freq
, wait_time
, dst
, src
,
10276 bssid
, data
, data_len
, no_cck
);
10280 static int driver_nl80211_probe_req_report(void *priv
, int report
)
10282 struct i802_bss
*bss
= priv
;
10283 return wpa_driver_nl80211_probe_req_report(bss
, report
);
10287 static int wpa_driver_nl80211_update_ft_ies(void *priv
, const u8
*md
,
10288 const u8
*ies
, size_t ies_len
)
10291 struct nl_msg
*msg
;
10292 struct i802_bss
*bss
= priv
;
10293 struct wpa_driver_nl80211_data
*drv
= bss
->drv
;
10294 u16 mdid
= WPA_GET_LE16(md
);
10296 msg
= nlmsg_alloc();
10300 wpa_printf(MSG_DEBUG
, "nl80211: Updating FT IEs");
10301 nl80211_cmd(drv
, msg
, 0, NL80211_CMD_UPDATE_FT_IES
);
10302 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, drv
->ifindex
);
10303 NLA_PUT(msg
, NL80211_ATTR_IE
, ies_len
, ies
);
10304 NLA_PUT_U16(msg
, NL80211_ATTR_MDID
, mdid
);
10306 ret
= send_and_recv_msgs(drv
, msg
, NULL
, NULL
);
10308 wpa_printf(MSG_DEBUG
, "nl80211: update_ft_ies failed "
10309 "err=%d (%s)", ret
, strerror(-ret
));
10320 const struct wpa_driver_ops wpa_driver_nl80211_ops
= {
10322 .desc
= "Linux nl80211/cfg80211",
10323 .get_bssid
= wpa_driver_nl80211_get_bssid
,
10324 .get_ssid
= wpa_driver_nl80211_get_ssid
,
10325 .set_key
= driver_nl80211_set_key
,
10326 .scan2
= driver_nl80211_scan2
,
10327 .sched_scan
= wpa_driver_nl80211_sched_scan
,
10328 .stop_sched_scan
= wpa_driver_nl80211_stop_sched_scan
,
10329 .get_scan_results2
= wpa_driver_nl80211_get_scan_results
,
10330 .deauthenticate
= driver_nl80211_deauthenticate
,
10331 .authenticate
= driver_nl80211_authenticate
,
10332 .associate
= wpa_driver_nl80211_associate
,
10333 .global_init
= nl80211_global_init
,
10334 .global_deinit
= nl80211_global_deinit
,
10335 .init2
= wpa_driver_nl80211_init
,
10336 .deinit
= driver_nl80211_deinit
,
10337 .get_capa
= wpa_driver_nl80211_get_capa
,
10338 .set_operstate
= wpa_driver_nl80211_set_operstate
,
10339 .set_supp_port
= wpa_driver_nl80211_set_supp_port
,
10340 .set_country
= wpa_driver_nl80211_set_country
,
10341 .set_ap
= wpa_driver_nl80211_set_ap
,
10342 .set_acl
= wpa_driver_nl80211_set_acl
,
10343 .if_add
= wpa_driver_nl80211_if_add
,
10344 .if_remove
= driver_nl80211_if_remove
,
10345 .send_mlme
= driver_nl80211_send_mlme
,
10346 .get_hw_feature_data
= wpa_driver_nl80211_get_hw_feature_data
,
10347 .sta_add
= wpa_driver_nl80211_sta_add
,
10348 .sta_remove
= driver_nl80211_sta_remove
,
10349 .hapd_send_eapol
= wpa_driver_nl80211_hapd_send_eapol
,
10350 .sta_set_flags
= wpa_driver_nl80211_sta_set_flags
,
10352 .hapd_init
= i802_init
,
10353 .hapd_deinit
= i802_deinit
,
10354 .set_wds_sta
= i802_set_wds_sta
,
10355 #endif /* HOSTAPD */
10356 #if defined(HOSTAPD) || defined(CONFIG_AP)
10357 .get_seqnum
= i802_get_seqnum
,
10358 .flush
= i802_flush
,
10359 .get_inact_sec
= i802_get_inact_sec
,
10360 .sta_clear_stats
= i802_sta_clear_stats
,
10361 .set_rts
= i802_set_rts
,
10362 .set_frag
= i802_set_frag
,
10363 .set_tx_queue_params
= i802_set_tx_queue_params
,
10364 .set_sta_vlan
= driver_nl80211_set_sta_vlan
,
10365 .sta_deauth
= i802_sta_deauth
,
10366 .sta_disassoc
= i802_sta_disassoc
,
10367 #endif /* HOSTAPD || CONFIG_AP */
10368 .read_sta_data
= driver_nl80211_read_sta_data
,
10369 .set_freq
= i802_set_freq
,
10370 .send_action
= driver_nl80211_send_action
,
10371 .send_action_cancel_wait
= wpa_driver_nl80211_send_action_cancel_wait
,
10372 .remain_on_channel
= wpa_driver_nl80211_remain_on_channel
,
10373 .cancel_remain_on_channel
=
10374 wpa_driver_nl80211_cancel_remain_on_channel
,
10375 .probe_req_report
= driver_nl80211_probe_req_report
,
10376 .deinit_ap
= wpa_driver_nl80211_deinit_ap
,
10377 .deinit_p2p_cli
= wpa_driver_nl80211_deinit_p2p_cli
,
10378 .resume
= wpa_driver_nl80211_resume
,
10379 .send_ft_action
= nl80211_send_ft_action
,
10380 .signal_monitor
= nl80211_signal_monitor
,
10381 .signal_poll
= nl80211_signal_poll
,
10382 .send_frame
= nl80211_send_frame
,
10383 .shared_freq
= wpa_driver_nl80211_shared_freq
,
10384 .set_param
= nl80211_set_param
,
10385 .get_radio_name
= nl80211_get_radio_name
,
10386 .add_pmkid
= nl80211_add_pmkid
,
10387 .remove_pmkid
= nl80211_remove_pmkid
,
10388 .flush_pmkid
= nl80211_flush_pmkid
,
10389 .set_rekey_info
= nl80211_set_rekey_info
,
10390 .poll_client
= nl80211_poll_client
,
10391 .set_p2p_powersave
= nl80211_set_p2p_powersave
,
10392 .start_dfs_cac
= nl80211_start_radar_detection
,
10393 .stop_ap
= wpa_driver_nl80211_stop_ap
,
10395 .send_tdls_mgmt
= nl80211_send_tdls_mgmt
,
10396 .tdls_oper
= nl80211_tdls_oper
,
10397 #endif /* CONFIG_TDLS */
10398 .update_ft_ies
= wpa_driver_nl80211_update_ft_ies
,