Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver interaction with Linux nl80211/cfg80211 |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 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 |
| 8 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9 | * This software may be distributed under the terms of the BSD license. |
| 10 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "includes.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include <sys/types.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | #include <fcntl.h> |
| 16 | #include <net/if.h> |
| 17 | #include <netlink/genl/genl.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include <netlink/genl/ctrl.h> |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_LIBNL3_ROUTE |
| 20 | #include <netlink/route/neighbour.h> |
| 21 | #endif /* CONFIG_LIBNL3_ROUTE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include <linux/rtnetlink.h> |
| 23 | #include <netpacket/packet.h> |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 24 | #include <linux/errqueue.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | |
| 26 | #include "common.h" |
| 27 | #include "eloop.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 28 | #include "common/qca-vendor.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 29 | #include "common/qca-vendor-attr.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 31 | #include "common/ieee802_11_common.h" |
| 32 | #include "l2_packet/l2_packet.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 34 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "linux_ioctl.h" |
| 36 | #include "radiotap.h" |
| 37 | #include "radiotap_iter.h" |
| 38 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 39 | #include "driver_nl80211.h" |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 40 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 41 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 42 | #ifndef CONFIG_LIBNL20 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | /* |
| 44 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 45 | * but when you free a socket again it will mess up its bitmap and |
| 46 | * and use the wrong number the next time it needs a socket ID. |
| 47 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 48 | * accounting. |
| 49 | */ |
| 50 | static uint32_t port_bitmap[32] = { 0 }; |
| 51 | |
| 52 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 53 | { |
| 54 | struct nl_handle *handle; |
| 55 | uint32_t pid = getpid() & 0x3FFFFF; |
| 56 | int i; |
| 57 | |
| 58 | handle = nl_handle_alloc_cb(cb); |
| 59 | |
| 60 | for (i = 0; i < 1024; i++) { |
| 61 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 62 | continue; |
| 63 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 64 | pid += i << 22; |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | nl_socket_set_local_port(handle, pid); |
| 69 | |
| 70 | return handle; |
| 71 | } |
| 72 | |
| 73 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 74 | { |
| 75 | uint32_t port = nl_socket_get_local_port(handle); |
| 76 | |
| 77 | port >>= 22; |
| 78 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 79 | |
| 80 | nl_handle_destroy(handle); |
| 81 | } |
| 82 | #endif /* CONFIG_LIBNL20 */ |
| 83 | |
| 84 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 85 | #ifdef ANDROID |
| 86 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 87 | #undef nl_socket_set_nonblocking |
| 88 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 89 | |
| 90 | #define genl_ctrl_resolve android_genl_ctrl_resolve |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 91 | #endif /* ANDROID */ |
| 92 | |
| 93 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 94 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 95 | { |
| 96 | struct nl_handle *handle; |
| 97 | |
| 98 | handle = nl80211_handle_alloc(cb); |
| 99 | if (handle == NULL) { |
| 100 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 101 | "callbacks (%s)", dbg); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | if (genl_connect(handle)) { |
| 106 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 107 | "netlink (%s)", dbg); |
| 108 | nl80211_handle_destroy(handle); |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | return handle; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static void nl_destroy_handles(struct nl_handle **handle) |
| 117 | { |
| 118 | if (*handle == NULL) |
| 119 | return; |
| 120 | nl80211_handle_destroy(*handle); |
| 121 | *handle = NULL; |
| 122 | } |
| 123 | |
| 124 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 125 | #if __WORDSIZE == 64 |
| 126 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 127 | #else |
| 128 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 129 | #endif |
| 130 | |
| 131 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 132 | eloop_sock_handler handler, |
| 133 | void *eloop_data) |
| 134 | { |
| 135 | nl_socket_set_nonblocking(*handle); |
| 136 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 137 | eloop_data, *handle); |
| 138 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) |
| 143 | { |
| 144 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 145 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 146 | nl_destroy_handles(handle); |
| 147 | } |
| 148 | |
| 149 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 150 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 151 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 152 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 153 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 154 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 155 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 156 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 157 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 158 | const u8 *set_addr, int first, |
| 159 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 160 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 161 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 162 | const u8 *buf, size_t buf_len, u64 *cookie, |
| 163 | int no_cck, int no_ack, int offchanok); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 164 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 165 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 166 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 167 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 168 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
| 169 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 170 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 171 | static int nl80211_set_channel(struct i802_bss *bss, |
| 172 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 173 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 174 | int ifindex, int disabled); |
| 175 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 176 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 177 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 178 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 179 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 180 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 181 | |
| 182 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 183 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 184 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 185 | { |
| 186 | switch (width) { |
| 187 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 188 | return CHAN_WIDTH_20_NOHT; |
| 189 | case NL80211_CHAN_WIDTH_20: |
| 190 | return CHAN_WIDTH_20; |
| 191 | case NL80211_CHAN_WIDTH_40: |
| 192 | return CHAN_WIDTH_40; |
| 193 | case NL80211_CHAN_WIDTH_80: |
| 194 | return CHAN_WIDTH_80; |
| 195 | case NL80211_CHAN_WIDTH_80P80: |
| 196 | return CHAN_WIDTH_80P80; |
| 197 | case NL80211_CHAN_WIDTH_160: |
| 198 | return CHAN_WIDTH_160; |
| 199 | } |
| 200 | return CHAN_WIDTH_UNKNOWN; |
| 201 | } |
| 202 | |
| 203 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 204 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 205 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 206 | return nlmode == NL80211_IFTYPE_AP || |
| 207 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 211 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 212 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 213 | return nlmode == NL80211_IFTYPE_STATION || |
| 214 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 218 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 219 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 220 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 221 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 222 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 223 | |
| 224 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 225 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 226 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 227 | { |
| 228 | struct i802_bss *bss; |
| 229 | |
| 230 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 231 | if (bss->ifindex == ifindex) |
| 232 | return bss; |
| 233 | } |
| 234 | |
| 235 | return NULL; |
| 236 | } |
| 237 | |
| 238 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 239 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 240 | { |
| 241 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 242 | } |
| 243 | |
| 244 | |
| 245 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 246 | { |
| 247 | if (drv->associated) |
| 248 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 249 | drv->associated = 0; |
| 250 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 251 | } |
| 252 | |
| 253 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 254 | /* nl80211 code */ |
| 255 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 256 | { |
| 257 | int *err = arg; |
| 258 | *err = 0; |
| 259 | return NL_STOP; |
| 260 | } |
| 261 | |
| 262 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 263 | { |
| 264 | int *ret = arg; |
| 265 | *ret = 0; |
| 266 | return NL_SKIP; |
| 267 | } |
| 268 | |
| 269 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 270 | void *arg) |
| 271 | { |
| 272 | int *ret = arg; |
| 273 | *ret = err->error; |
| 274 | return NL_SKIP; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 279 | { |
| 280 | return NL_OK; |
| 281 | } |
| 282 | |
| 283 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 284 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 285 | { |
| 286 | /* |
| 287 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 288 | * heap memory for unnecessarily long time. |
| 289 | */ |
| 290 | if (msg) { |
| 291 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 292 | void *data = nlmsg_data(hdr); |
| 293 | /* |
| 294 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 295 | * only libnl were to maintain a stable API.. Neither will work |
| 296 | * with all released versions, so just calculate the length |
| 297 | * here. |
| 298 | */ |
| 299 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 300 | |
| 301 | os_memset(data, 0, len); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 306 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 307 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 308 | int (*valid_handler)(struct nl_msg *, void *), |
| 309 | void *valid_data) |
| 310 | { |
| 311 | struct nl_cb *cb; |
| 312 | int err = -ENOMEM; |
| 313 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 314 | if (!msg) |
| 315 | return -ENOMEM; |
| 316 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 317 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 318 | if (!cb) |
| 319 | goto out; |
| 320 | |
| 321 | err = nl_send_auto_complete(nl_handle, msg); |
| 322 | if (err < 0) |
| 323 | goto out; |
| 324 | |
| 325 | err = 1; |
| 326 | |
| 327 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 328 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 329 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 330 | |
| 331 | if (valid_handler) |
| 332 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 333 | valid_handler, valid_data); |
| 334 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 335 | while (err > 0) { |
| 336 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 337 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 338 | wpa_printf(MSG_INFO, |
| 339 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 340 | __func__, res); |
| 341 | } |
| 342 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 343 | out: |
| 344 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 345 | if (!valid_handler && valid_data == (void *) -1) |
| 346 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 347 | nlmsg_free(msg); |
| 348 | return err; |
| 349 | } |
| 350 | |
| 351 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 352 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 353 | struct nl_msg *msg, |
| 354 | int (*valid_handler)(struct nl_msg *, void *), |
| 355 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 356 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 357 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 358 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
| 362 | struct family_data { |
| 363 | const char *group; |
| 364 | int id; |
| 365 | }; |
| 366 | |
| 367 | |
| 368 | static int family_handler(struct nl_msg *msg, void *arg) |
| 369 | { |
| 370 | struct family_data *res = arg; |
| 371 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 372 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 373 | struct nlattr *mcgrp; |
| 374 | int i; |
| 375 | |
| 376 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 377 | genlmsg_attrlen(gnlh, 0), NULL); |
| 378 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 379 | return NL_SKIP; |
| 380 | |
| 381 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 382 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 383 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 384 | nla_len(mcgrp), NULL); |
| 385 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 386 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 387 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 388 | res->group, |
| 389 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 390 | continue; |
| 391 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 392 | break; |
| 393 | }; |
| 394 | |
| 395 | return NL_SKIP; |
| 396 | } |
| 397 | |
| 398 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 399 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 400 | const char *family, const char *group) |
| 401 | { |
| 402 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 403 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 404 | struct family_data res = { group, -ENOENT }; |
| 405 | |
| 406 | msg = nlmsg_alloc(); |
| 407 | if (!msg) |
| 408 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 409 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 410 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 411 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 412 | nlmsg_free(msg); |
| 413 | return -1; |
| 414 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 415 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 416 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 417 | if (ret == 0) |
| 418 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 423 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 424 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 425 | { |
| 426 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 427 | 0, flags, cmd, 0); |
| 428 | } |
| 429 | |
| 430 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 431 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 432 | { |
| 433 | if (bss->wdev_id_set) |
| 434 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 435 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 436 | } |
| 437 | |
| 438 | |
| 439 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 440 | { |
| 441 | struct nl_msg *msg; |
| 442 | |
| 443 | msg = nlmsg_alloc(); |
| 444 | if (!msg) |
| 445 | return NULL; |
| 446 | |
| 447 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 448 | nl80211_set_iface_id(msg, bss) < 0) { |
| 449 | nlmsg_free(msg); |
| 450 | return NULL; |
| 451 | } |
| 452 | |
| 453 | return msg; |
| 454 | } |
| 455 | |
| 456 | |
| 457 | static struct nl_msg * |
| 458 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 459 | int flags, uint8_t cmd) |
| 460 | { |
| 461 | struct nl_msg *msg; |
| 462 | |
| 463 | msg = nlmsg_alloc(); |
| 464 | if (!msg) |
| 465 | return NULL; |
| 466 | |
| 467 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 468 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 469 | nlmsg_free(msg); |
| 470 | return NULL; |
| 471 | } |
| 472 | |
| 473 | return msg; |
| 474 | } |
| 475 | |
| 476 | |
| 477 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 478 | uint8_t cmd) |
| 479 | { |
| 480 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 481 | } |
| 482 | |
| 483 | |
| 484 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 485 | { |
| 486 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 487 | } |
| 488 | |
| 489 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 490 | struct wiphy_idx_data { |
| 491 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 492 | enum nl80211_iftype nlmode; |
| 493 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 494 | }; |
| 495 | |
| 496 | |
| 497 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 498 | { |
| 499 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 500 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 501 | struct wiphy_idx_data *info = arg; |
| 502 | |
| 503 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 504 | genlmsg_attrlen(gnlh, 0), NULL); |
| 505 | |
| 506 | if (tb[NL80211_ATTR_WIPHY]) |
| 507 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 508 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 509 | if (tb[NL80211_ATTR_IFTYPE]) |
| 510 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 511 | |
| 512 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 513 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 514 | ETH_ALEN); |
| 515 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 516 | return NL_SKIP; |
| 517 | } |
| 518 | |
| 519 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 520 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 521 | { |
| 522 | struct nl_msg *msg; |
| 523 | struct wiphy_idx_data data = { |
| 524 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 525 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 526 | }; |
| 527 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 528 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 529 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 530 | |
| 531 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 532 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 533 | return -1; |
| 534 | } |
| 535 | |
| 536 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 537 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 538 | { |
| 539 | struct nl_msg *msg; |
| 540 | struct wiphy_idx_data data = { |
| 541 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 542 | .macaddr = NULL, |
| 543 | }; |
| 544 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 545 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 546 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 547 | |
| 548 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 549 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 550 | return NL80211_IFTYPE_UNSPECIFIED; |
| 551 | } |
| 552 | |
| 553 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 554 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 555 | { |
| 556 | struct nl_msg *msg; |
| 557 | struct wiphy_idx_data data = { |
| 558 | .macaddr = bss->addr, |
| 559 | }; |
| 560 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 561 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 562 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 563 | |
| 564 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 565 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 566 | |
| 567 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 568 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 569 | struct nl80211_wiphy_data *w) |
| 570 | { |
| 571 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 572 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 573 | |
| 574 | msg = nlmsg_alloc(); |
| 575 | if (!msg) |
| 576 | return -1; |
| 577 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 578 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 579 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 580 | nlmsg_free(msg); |
| 581 | return -1; |
| 582 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 583 | |
| 584 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 585 | if (ret) { |
| 586 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 587 | "failed: ret=%d (%s)", |
| 588 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 589 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 590 | return ret; |
| 591 | } |
| 592 | |
| 593 | |
| 594 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 595 | { |
| 596 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 597 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 598 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 599 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 600 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 601 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 602 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 603 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 604 | __func__, res); |
| 605 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | |
| 609 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 610 | { |
| 611 | struct nl80211_wiphy_data *w = arg; |
| 612 | struct wpa_driver_nl80211_data *drv; |
| 613 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 614 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 615 | union wpa_event_data event; |
| 616 | |
| 617 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 618 | genlmsg_attrlen(gnlh, 0), NULL); |
| 619 | |
| 620 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 621 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 622 | gnlh->cmd); |
| 623 | return NL_SKIP; |
| 624 | } |
| 625 | |
| 626 | if (!tb[NL80211_ATTR_FRAME]) |
| 627 | return NL_SKIP; |
| 628 | |
| 629 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 630 | wiphy_list) { |
| 631 | os_memset(&event, 0, sizeof(event)); |
| 632 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 633 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 634 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 635 | } |
| 636 | |
| 637 | return NL_SKIP; |
| 638 | } |
| 639 | |
| 640 | |
| 641 | static struct nl80211_wiphy_data * |
| 642 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 643 | { |
| 644 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 645 | struct nl80211_wiphy_data *w; |
| 646 | int wiphy_idx, found = 0; |
| 647 | struct i802_bss *tmp_bss; |
| 648 | |
| 649 | if (bss->wiphy_data != NULL) |
| 650 | return bss->wiphy_data; |
| 651 | |
| 652 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 653 | |
| 654 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 655 | if (w->wiphy_idx == wiphy_idx) |
| 656 | goto add; |
| 657 | } |
| 658 | |
| 659 | /* alloc new one */ |
| 660 | w = os_zalloc(sizeof(*w)); |
| 661 | if (w == NULL) |
| 662 | return NULL; |
| 663 | w->wiphy_idx = wiphy_idx; |
| 664 | dl_list_init(&w->bsss); |
| 665 | dl_list_init(&w->drvs); |
| 666 | |
| 667 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 668 | if (!w->nl_cb) { |
| 669 | os_free(w); |
| 670 | return NULL; |
| 671 | } |
| 672 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 673 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 674 | w); |
| 675 | |
| 676 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 677 | "wiphy beacons"); |
| 678 | if (w->nl_beacons == NULL) { |
| 679 | os_free(w); |
| 680 | return NULL; |
| 681 | } |
| 682 | |
| 683 | if (nl80211_register_beacons(bss->drv, w)) { |
| 684 | nl_destroy_handles(&w->nl_beacons); |
| 685 | os_free(w); |
| 686 | return NULL; |
| 687 | } |
| 688 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 689 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 690 | |
| 691 | dl_list_add(&nl80211_wiphys, &w->list); |
| 692 | |
| 693 | add: |
| 694 | /* drv entry for this bss already there? */ |
| 695 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 696 | if (tmp_bss->drv == bss->drv) { |
| 697 | found = 1; |
| 698 | break; |
| 699 | } |
| 700 | } |
| 701 | /* if not add it */ |
| 702 | if (!found) |
| 703 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 704 | |
| 705 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 706 | bss->wiphy_data = w; |
| 707 | return w; |
| 708 | } |
| 709 | |
| 710 | |
| 711 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 712 | { |
| 713 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 714 | struct i802_bss *tmp_bss; |
| 715 | int found = 0; |
| 716 | |
| 717 | if (w == NULL) |
| 718 | return; |
| 719 | bss->wiphy_data = NULL; |
| 720 | dl_list_del(&bss->wiphy_list); |
| 721 | |
| 722 | /* still any for this drv present? */ |
| 723 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 724 | if (tmp_bss->drv == bss->drv) { |
| 725 | found = 1; |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | /* if not remove it */ |
| 730 | if (!found) |
| 731 | dl_list_del(&bss->drv->wiphy_list); |
| 732 | |
| 733 | if (!dl_list_empty(&w->bsss)) |
| 734 | return; |
| 735 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 736 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 737 | |
| 738 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 739 | dl_list_del(&w->list); |
| 740 | os_free(w); |
| 741 | } |
| 742 | |
| 743 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 744 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 745 | { |
| 746 | struct i802_bss *bss = priv; |
| 747 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 748 | if (!drv->associated) |
| 749 | return -1; |
| 750 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | |
| 755 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 756 | { |
| 757 | struct i802_bss *bss = priv; |
| 758 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 759 | if (!drv->associated) |
| 760 | return -1; |
| 761 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 762 | return drv->ssid_len; |
| 763 | } |
| 764 | |
| 765 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 766 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 767 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 768 | { |
| 769 | union wpa_event_data event; |
| 770 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 771 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 772 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 773 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 774 | drv->first_bss->ifname); |
| 775 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 776 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 777 | if (!drv->if_removed) |
| 778 | return; |
| 779 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 780 | drv->first_bss->ifname); |
| 781 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 784 | os_memset(&event, 0, sizeof(event)); |
| 785 | os_strlcpy(event.interface_status.ifname, ifname, |
| 786 | sizeof(event.interface_status.ifname)); |
| 787 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
| 788 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 789 | } |
| 790 | |
| 791 | |
| 792 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 793 | struct wpa_driver_nl80211_data *drv, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 794 | { |
| 795 | union wpa_event_data event; |
| 796 | |
| 797 | if (os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
| 798 | if (drv->if_removed) { |
| 799 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 800 | ifname); |
| 801 | return; |
| 802 | } |
| 803 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 804 | ifname); |
| 805 | drv->if_removed = 1; |
| 806 | } else { |
| 807 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 808 | ifname); |
| 809 | } |
| 810 | |
| 811 | os_memset(&event, 0, sizeof(event)); |
| 812 | os_strlcpy(event.interface_status.ifname, ifname, |
| 813 | sizeof(event.interface_status.ifname)); |
| 814 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 815 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 816 | } |
| 817 | |
| 818 | |
| 819 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 820 | u8 *buf, size_t len) |
| 821 | { |
| 822 | int attrlen, rta_len; |
| 823 | struct rtattr *attr; |
| 824 | |
| 825 | attrlen = len; |
| 826 | attr = (struct rtattr *) buf; |
| 827 | |
| 828 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 829 | while (RTA_OK(attr, attrlen)) { |
| 830 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 831 | if (os_strcmp(((char *) attr) + rta_len, |
| 832 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 833 | return 1; |
| 834 | else |
| 835 | break; |
| 836 | } |
| 837 | attr = RTA_NEXT(attr, attrlen); |
| 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | |
| 844 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 845 | int ifindex, u8 *buf, size_t len) |
| 846 | { |
| 847 | if (drv->ifindex == ifindex) |
| 848 | return 1; |
| 849 | |
| 850 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 851 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 852 | "interface"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 853 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 854 | return 1; |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 861 | static struct wpa_driver_nl80211_data * |
| 862 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 863 | { |
| 864 | struct wpa_driver_nl80211_data *drv; |
| 865 | dl_list_for_each(drv, &global->interfaces, |
| 866 | struct wpa_driver_nl80211_data, list) { |
| 867 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
| 868 | have_ifidx(drv, idx)) |
| 869 | return drv; |
| 870 | } |
| 871 | return NULL; |
| 872 | } |
| 873 | |
| 874 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 875 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 876 | struct ifinfomsg *ifi, |
| 877 | u8 *buf, size_t len) |
| 878 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 879 | struct nl80211_global *global = ctx; |
| 880 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 881 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 882 | struct rtattr *attr; |
| 883 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 884 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 885 | char ifname[IFNAMSIZ + 1]; |
| 886 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 887 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 888 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 889 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 890 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d", |
| 891 | ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 892 | return; |
| 893 | } |
| 894 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 895 | extra[0] = '\0'; |
| 896 | pos = extra; |
| 897 | end = pos + sizeof(extra); |
| 898 | ifname[0] = '\0'; |
| 899 | |
| 900 | attrlen = len; |
| 901 | attr = (struct rtattr *) buf; |
| 902 | while (RTA_OK(attr, attrlen)) { |
| 903 | switch (attr->rta_type) { |
| 904 | case IFLA_IFNAME: |
| 905 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 906 | break; |
| 907 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 908 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 909 | break; |
| 910 | case IFLA_MASTER: |
| 911 | brid = nla_get_u32((struct nlattr *) attr); |
| 912 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 913 | break; |
| 914 | case IFLA_WIRELESS: |
| 915 | pos += os_snprintf(pos, end - pos, " wext"); |
| 916 | break; |
| 917 | case IFLA_OPERSTATE: |
| 918 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 919 | nla_get_u32((struct nlattr *) attr)); |
| 920 | break; |
| 921 | case IFLA_LINKMODE: |
| 922 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 923 | nla_get_u32((struct nlattr *) attr)); |
| 924 | break; |
| 925 | } |
| 926 | attr = RTA_NEXT(attr, attrlen); |
| 927 | } |
| 928 | extra[sizeof(extra) - 1] = '\0'; |
| 929 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 930 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 931 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 932 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 933 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 934 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 935 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 936 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 937 | |
| 938 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 939 | if (if_indextoname(ifi->ifi_index, namebuf) && |
| 940 | linux_iface_up(drv->global->ioctl_sock, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 941 | drv->first_bss->ifname) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 942 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 943 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 944 | drv->ignore_if_down_event = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 945 | return; |
| 946 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 947 | wpa_printf(MSG_DEBUG, "nl80211: Interface down"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 948 | if (drv->ignore_if_down_event) { |
| 949 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 950 | "event generated by mode change"); |
| 951 | drv->ignore_if_down_event = 0; |
| 952 | } else { |
| 953 | drv->if_disabled = 1; |
| 954 | wpa_supplicant_event(drv->ctx, |
| 955 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 956 | |
| 957 | /* |
| 958 | * Try to get drv again, since it may be removed as |
| 959 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 960 | * dynamic interfaces |
| 961 | */ |
| 962 | drv = nl80211_find_drv(global, ifi->ifi_index, |
| 963 | buf, len); |
| 964 | if (!drv) |
| 965 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 966 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 970 | if (if_indextoname(ifi->ifi_index, namebuf) && |
| 971 | linux_iface_up(drv->global->ioctl_sock, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 972 | drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 973 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 974 | "event since interface %s is down", |
| 975 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 976 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 977 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 978 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 979 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 980 | } else if (drv->if_removed) { |
| 981 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 982 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 983 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 984 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 985 | struct i802_bss *bss; |
| 986 | u8 addr[ETH_ALEN]; |
| 987 | |
| 988 | /* Re-read MAC address as it may have changed */ |
| 989 | bss = get_bss_ifindex(drv, ifi->ifi_index); |
| 990 | if (bss && |
| 991 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 992 | bss->ifname, addr) < 0) { |
| 993 | wpa_printf(MSG_DEBUG, |
| 994 | "nl80211: %s: failed to re-read MAC address", |
| 995 | bss->ifname); |
| 996 | } else if (bss && |
| 997 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 998 | wpa_printf(MSG_DEBUG, |
| 999 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1000 | MACSTR " to " MACSTR, |
| 1001 | ifi->ifi_index, bss->ifname, |
| 1002 | MAC2STR(bss->addr), |
| 1003 | MAC2STR(addr)); |
| 1004 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 1005 | } |
| 1006 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1007 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1008 | drv->if_disabled = 0; |
| 1009 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1010 | NULL); |
| 1011 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * Some drivers send the association event before the operup event--in |
| 1016 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1017 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1018 | * IEEE 802.1X authentication |
| 1019 | */ |
| 1020 | if (drv->operstate == 1 && |
| 1021 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1022 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1023 | wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1024 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1025 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | } |
| 1027 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1028 | if (ifname[0]) |
| 1029 | wpa_driver_nl80211_event_newlink(drv, ifname); |
| 1030 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1031 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1032 | struct i802_bss *bss; |
| 1033 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1034 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1035 | if (!if_indextoname(brid, namebuf)) { |
| 1036 | wpa_printf(MSG_DEBUG, |
| 1037 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1038 | brid); |
| 1039 | return; |
| 1040 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1041 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1042 | brid, namebuf); |
| 1043 | add_ifidx(drv, brid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1044 | |
| 1045 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1046 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1047 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1048 | break; |
| 1049 | } |
| 1050 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1051 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1056 | struct ifinfomsg *ifi, |
| 1057 | u8 *buf, size_t len) |
| 1058 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1059 | struct nl80211_global *global = ctx; |
| 1060 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1061 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1062 | struct rtattr *attr; |
| 1063 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1064 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1065 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1066 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1067 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 1068 | if (!drv) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1069 | wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d", |
| 1070 | ifi->ifi_index); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1071 | return; |
| 1072 | } |
| 1073 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1074 | extra[0] = '\0'; |
| 1075 | pos = extra; |
| 1076 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1077 | ifname[0] = '\0'; |
| 1078 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1079 | attrlen = len; |
| 1080 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1081 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1082 | switch (attr->rta_type) { |
| 1083 | case IFLA_IFNAME: |
| 1084 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1085 | break; |
| 1086 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1087 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1088 | break; |
| 1089 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1090 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1091 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1092 | break; |
| 1093 | case IFLA_OPERSTATE: |
| 1094 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1095 | nla_get_u32((struct nlattr *) attr)); |
| 1096 | break; |
| 1097 | case IFLA_LINKMODE: |
| 1098 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1099 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1100 | break; |
| 1101 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1102 | attr = RTA_NEXT(attr, attrlen); |
| 1103 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1104 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1105 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1106 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1107 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1108 | ifi->ifi_flags, |
| 1109 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1110 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1111 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1112 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1113 | |
| 1114 | if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid)) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1115 | wpa_driver_nl80211_event_dellink(drv, ifname); |
| 1116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1117 | if (ifi->ifi_family == AF_BRIDGE && brid) { |
| 1118 | /* device has been removed from bridge */ |
| 1119 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1120 | |
| 1121 | if (!if_indextoname(brid, namebuf)) { |
| 1122 | wpa_printf(MSG_DEBUG, |
| 1123 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1124 | brid); |
| 1125 | } else { |
| 1126 | wpa_printf(MSG_DEBUG, |
| 1127 | "nl80211: Remove ifindex %u for bridge %s", |
| 1128 | brid, namebuf); |
| 1129 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1130 | del_ifidx(drv, brid); |
| 1131 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1135 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1136 | { |
| 1137 | struct nl_msg *msg; |
| 1138 | int ret; |
| 1139 | struct nl80211_bss_info_arg arg; |
| 1140 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1141 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1142 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1143 | arg.drv = drv; |
| 1144 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1145 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1146 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1147 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1148 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1149 | "associated BSS from scan results: %u MHz", freq); |
| 1150 | if (freq) |
| 1151 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1152 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1153 | } |
| 1154 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1155 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1156 | return drv->assoc_freq; |
| 1157 | } |
| 1158 | |
| 1159 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1160 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1161 | { |
| 1162 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1163 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1164 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1165 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1166 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1167 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1168 | }; |
| 1169 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1170 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1171 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1172 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1173 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1174 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1175 | }; |
| 1176 | struct wpa_signal_info *sig_change = arg; |
| 1177 | |
| 1178 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1179 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1180 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1181 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1182 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1183 | return NL_SKIP; |
| 1184 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1185 | return NL_SKIP; |
| 1186 | |
| 1187 | sig_change->current_signal = |
| 1188 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1189 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1190 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1191 | sig_change->avg_signal = |
| 1192 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1193 | else |
| 1194 | sig_change->avg_signal = 0; |
| 1195 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1196 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1197 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1198 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1199 | rate_policy)) { |
| 1200 | sig_change->current_txrate = 0; |
| 1201 | } else { |
| 1202 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1203 | sig_change->current_txrate = |
| 1204 | nla_get_u16(rinfo[ |
| 1205 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1206 | } |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | return NL_SKIP; |
| 1211 | } |
| 1212 | |
| 1213 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1214 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1215 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1216 | { |
| 1217 | struct nl_msg *msg; |
| 1218 | |
| 1219 | sig->current_signal = -9999; |
| 1220 | sig->current_txrate = 0; |
| 1221 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1222 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1223 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1224 | nlmsg_free(msg); |
| 1225 | return -ENOBUFS; |
| 1226 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1227 | |
| 1228 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1233 | { |
| 1234 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1235 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1236 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1237 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1238 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1239 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1240 | }; |
| 1241 | struct wpa_signal_info *sig_change = arg; |
| 1242 | |
| 1243 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1244 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1245 | |
| 1246 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1247 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1248 | return NL_SKIP; |
| 1249 | } |
| 1250 | |
| 1251 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1252 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1253 | survey_policy)) { |
| 1254 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1255 | "attributes!"); |
| 1256 | return NL_SKIP; |
| 1257 | } |
| 1258 | |
| 1259 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1260 | return NL_SKIP; |
| 1261 | |
| 1262 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1263 | sig_change->frequency) |
| 1264 | return NL_SKIP; |
| 1265 | |
| 1266 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1267 | return NL_SKIP; |
| 1268 | |
| 1269 | sig_change->current_noise = |
| 1270 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1271 | |
| 1272 | return NL_SKIP; |
| 1273 | } |
| 1274 | |
| 1275 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1276 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1277 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1278 | { |
| 1279 | struct nl_msg *msg; |
| 1280 | |
| 1281 | sig_change->current_noise = 9999; |
| 1282 | sig_change->frequency = drv->assoc_freq; |
| 1283 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1284 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1285 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1290 | void *handle) |
| 1291 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1292 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1293 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1294 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1295 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1296 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1297 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1298 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1299 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1300 | __func__, res); |
| 1301 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1302 | } |
| 1303 | |
| 1304 | |
| 1305 | /** |
| 1306 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1307 | * @priv: driver_nl80211 private data |
| 1308 | * @alpha2_arg: country to which to switch to |
| 1309 | * Returns: 0 on success, -1 on failure |
| 1310 | * |
| 1311 | * This asks nl80211 to set the regulatory domain for given |
| 1312 | * country ISO / IEC alpha2. |
| 1313 | */ |
| 1314 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1315 | { |
| 1316 | struct i802_bss *bss = priv; |
| 1317 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1318 | char alpha2[3]; |
| 1319 | struct nl_msg *msg; |
| 1320 | |
| 1321 | msg = nlmsg_alloc(); |
| 1322 | if (!msg) |
| 1323 | return -ENOMEM; |
| 1324 | |
| 1325 | alpha2[0] = alpha2_arg[0]; |
| 1326 | alpha2[1] = alpha2_arg[1]; |
| 1327 | alpha2[2] = '\0'; |
| 1328 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1329 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1330 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1331 | nlmsg_free(msg); |
| 1332 | return -EINVAL; |
| 1333 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1334 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1335 | return -EINVAL; |
| 1336 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1340 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1341 | { |
| 1342 | char *alpha2 = arg; |
| 1343 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1344 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1345 | |
| 1346 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1347 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1348 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1349 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1350 | return NL_SKIP; |
| 1351 | } |
| 1352 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1353 | return NL_SKIP; |
| 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1358 | { |
| 1359 | struct i802_bss *bss = priv; |
| 1360 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1361 | struct nl_msg *msg; |
| 1362 | int ret; |
| 1363 | |
| 1364 | msg = nlmsg_alloc(); |
| 1365 | if (!msg) |
| 1366 | return -ENOMEM; |
| 1367 | |
| 1368 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1369 | alpha2[0] = '\0'; |
| 1370 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1371 | if (!alpha2[0]) |
| 1372 | ret = -1; |
| 1373 | |
| 1374 | return ret; |
| 1375 | } |
| 1376 | |
| 1377 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1378 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1379 | { |
| 1380 | int ret; |
| 1381 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1382 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1383 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1384 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1385 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1386 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1389 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1390 | if (global->nl == NULL) |
| 1391 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1392 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1393 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1394 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1395 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1396 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1397 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1398 | } |
| 1399 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1400 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1401 | if (global->nl_event == NULL) |
| 1402 | goto err; |
| 1403 | |
| 1404 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1405 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1406 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1407 | if (ret < 0) { |
| 1408 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1409 | "membership for scan events: %d (%s)", |
| 1410 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1411 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1414 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1415 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1416 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1417 | if (ret < 0) { |
| 1418 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1419 | "membership for mlme events: %d (%s)", |
| 1420 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1421 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1424 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1425 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1426 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1427 | if (ret < 0) { |
| 1428 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1429 | "membership for regulatory events: %d (%s)", |
| 1430 | ret, strerror(-ret)); |
| 1431 | /* Continue without regulatory events */ |
| 1432 | } |
| 1433 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1434 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1435 | if (ret >= 0) |
| 1436 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1437 | if (ret < 0) { |
| 1438 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1439 | "membership for vendor events: %d (%s)", |
| 1440 | ret, strerror(-ret)); |
| 1441 | /* Continue without vendor events */ |
| 1442 | } |
| 1443 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1444 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1445 | no_seq_check, NULL); |
| 1446 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1447 | process_global_event, global); |
| 1448 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1449 | nl80211_register_eloop_read(&global->nl_event, |
| 1450 | wpa_driver_nl80211_event_receive, |
| 1451 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | |
| 1453 | return 0; |
| 1454 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1455 | err: |
| 1456 | nl_destroy_handles(&global->nl_event); |
| 1457 | nl_destroy_handles(&global->nl); |
| 1458 | nl_cb_put(global->nl_cb); |
| 1459 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1460 | return -1; |
| 1461 | } |
| 1462 | |
| 1463 | |
| 1464 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1465 | { |
| 1466 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
| 1467 | /* |
| 1468 | * This may be for any interface; use ifdown event to disable |
| 1469 | * interface. |
| 1470 | */ |
| 1471 | } |
| 1472 | |
| 1473 | |
| 1474 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1475 | { |
| 1476 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1477 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1478 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1479 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1480 | "after rfkill unblock"); |
| 1481 | return; |
| 1482 | } |
| 1483 | /* rtnetlink ifup handler will report interface as enabled */ |
| 1484 | } |
| 1485 | |
| 1486 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1487 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1488 | void *eloop_ctx, |
| 1489 | void *handle) |
| 1490 | { |
| 1491 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1492 | u8 data[2048]; |
| 1493 | struct msghdr msg; |
| 1494 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1495 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1496 | struct cmsghdr *cmsg; |
| 1497 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1498 | union wpa_event_data event; |
| 1499 | |
| 1500 | memset(&msg, 0, sizeof(msg)); |
| 1501 | msg.msg_iov = &entry; |
| 1502 | msg.msg_iovlen = 1; |
| 1503 | entry.iov_base = data; |
| 1504 | entry.iov_len = sizeof(data); |
| 1505 | msg.msg_control = &control; |
| 1506 | msg.msg_controllen = sizeof(control); |
| 1507 | |
| 1508 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1509 | /* if error or not fitting 802.3 header, return */ |
| 1510 | if (res < 14) |
| 1511 | return; |
| 1512 | |
| 1513 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1514 | { |
| 1515 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1516 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1517 | int *ack; |
| 1518 | |
| 1519 | found_wifi = 1; |
| 1520 | ack = (void *)CMSG_DATA(cmsg); |
| 1521 | acked = *ack; |
| 1522 | } |
| 1523 | |
| 1524 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1525 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1526 | struct sock_extended_err *err = |
| 1527 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1528 | |
| 1529 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1530 | found_ee = 1; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | if (!found_ee || !found_wifi) |
| 1535 | return; |
| 1536 | |
| 1537 | memset(&event, 0, sizeof(event)); |
| 1538 | event.eapol_tx_status.dst = data; |
| 1539 | event.eapol_tx_status.data = data + 14; |
| 1540 | event.eapol_tx_status.data_len = res - 14; |
| 1541 | event.eapol_tx_status.ack = acked; |
| 1542 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1543 | } |
| 1544 | |
| 1545 | |
| 1546 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1547 | { |
| 1548 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1549 | if (!bss->nl_cb) |
| 1550 | return -1; |
| 1551 | |
| 1552 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1553 | no_seq_check, NULL); |
| 1554 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1555 | process_bss_event, bss); |
| 1556 | |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1562 | { |
| 1563 | nl_cb_put(bss->nl_cb); |
| 1564 | bss->nl_cb = NULL; |
| 1565 | } |
| 1566 | |
| 1567 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1568 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1569 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1570 | const u8 *set_addr, |
| 1571 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1572 | { |
| 1573 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1574 | struct rfkill_config *rcfg; |
| 1575 | struct i802_bss *bss; |
| 1576 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1577 | if (global_priv == NULL) |
| 1578 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1579 | drv = os_zalloc(sizeof(*drv)); |
| 1580 | if (drv == NULL) |
| 1581 | return NULL; |
| 1582 | drv->global = global_priv; |
| 1583 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1584 | drv->hostapd = !!hostapd; |
| 1585 | drv->eapol_sock = -1; |
| 1586 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1587 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1588 | |
| 1589 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1590 | if (!drv->first_bss) { |
| 1591 | os_free(drv); |
| 1592 | return NULL; |
| 1593 | } |
| 1594 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1595 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1596 | bss->ctx = ctx; |
| 1597 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1598 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1599 | drv->monitor_ifidx = -1; |
| 1600 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1601 | drv->eapol_tx_sock = -1; |
| 1602 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1603 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1604 | if (nl80211_init_bss(bss)) |
| 1605 | goto failed; |
| 1606 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1608 | if (rcfg == NULL) |
| 1609 | goto failed; |
| 1610 | rcfg->ctx = drv; |
| 1611 | os_strlcpy(rcfg->ifname, ifname, sizeof(rcfg->ifname)); |
| 1612 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1613 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1614 | drv->rfkill = rfkill_init(rcfg); |
| 1615 | if (drv->rfkill == NULL) { |
| 1616 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1617 | os_free(rcfg); |
| 1618 | } |
| 1619 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1620 | if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0) |
| 1621 | drv->start_iface_up = 1; |
| 1622 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1623 | if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1624 | goto failed; |
| 1625 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1626 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1627 | if (drv->eapol_tx_sock < 0) |
| 1628 | goto failed; |
| 1629 | |
| 1630 | if (drv->data_tx_status) { |
| 1631 | int enabled = 1; |
| 1632 | |
| 1633 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1634 | &enabled, sizeof(enabled)) < 0) { |
| 1635 | wpa_printf(MSG_DEBUG, |
| 1636 | "nl80211: wifi status sockopt failed\n"); |
| 1637 | drv->data_tx_status = 0; |
| 1638 | if (!drv->use_monitor) |
| 1639 | drv->capa.flags &= |
| 1640 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1641 | } else { |
| 1642 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1643 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1644 | drv, NULL); |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | if (drv->global) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1649 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1650 | drv->in_interface_list = 1; |
| 1651 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1652 | |
| 1653 | return bss; |
| 1654 | |
| 1655 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1656 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1657 | return NULL; |
| 1658 | } |
| 1659 | |
| 1660 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1661 | /** |
| 1662 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1663 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1664 | * e.g., wpa_supplicant_event() |
| 1665 | * @ifname: interface name, e.g., wlan0 |
| 1666 | * @global_priv: private driver global data from global_init() |
| 1667 | * Returns: Pointer to private data, %NULL on failure |
| 1668 | */ |
| 1669 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1670 | void *global_priv) |
| 1671 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1672 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1673 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1677 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1678 | struct nl_handle *nl_handle, |
| 1679 | u16 type, const u8 *match, size_t match_len) |
| 1680 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1681 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1682 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1683 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1684 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1685 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1686 | buf[0] = '\0'; |
| 1687 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1688 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1689 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1690 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1691 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1692 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1693 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1694 | nlmsg_free(msg); |
| 1695 | return -1; |
| 1696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1697 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1698 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1699 | if (ret) { |
| 1700 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1701 | "failed (type=%u): ret=%d (%s)", |
| 1702 | type, ret, strerror(-ret)); |
| 1703 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1704 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1705 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1706 | return ret; |
| 1707 | } |
| 1708 | |
| 1709 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1710 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1711 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1712 | if (bss->nl_mgmt) { |
| 1713 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1714 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1715 | return -1; |
| 1716 | } |
| 1717 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1718 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1719 | if (bss->nl_mgmt == NULL) |
| 1720 | return -1; |
| 1721 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1722 | return 0; |
| 1723 | } |
| 1724 | |
| 1725 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1726 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1727 | { |
| 1728 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1729 | wpa_driver_nl80211_event_receive, |
| 1730 | bss->nl_cb); |
| 1731 | } |
| 1732 | |
| 1733 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1734 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1735 | const u8 *match, size_t match_len) |
| 1736 | { |
| 1737 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1738 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1739 | type, match, match_len); |
| 1740 | } |
| 1741 | |
| 1742 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1743 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1744 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1745 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1746 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1747 | |
| 1748 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1749 | return -1; |
| 1750 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1751 | "handle %p", bss->nl_mgmt); |
| 1752 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1753 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1754 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1755 | |
| 1756 | /* register for any AUTH message */ |
| 1757 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1758 | } |
| 1759 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1760 | #ifdef CONFIG_INTERWORKING |
| 1761 | /* QoS Map Configure */ |
| 1762 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1763 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1764 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1765 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1766 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1767 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1768 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1769 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1770 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1771 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1772 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1773 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1774 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1775 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1776 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1777 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1778 | /* Protected GAS Initial Request */ |
| 1779 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 1780 | ret = -1; |
| 1781 | /* Protected GAS Initial Response */ |
| 1782 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 1783 | ret = -1; |
| 1784 | /* Protected GAS Comeback Request */ |
| 1785 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 1786 | ret = -1; |
| 1787 | /* Protected GAS Comeback Response */ |
| 1788 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 1789 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1790 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 1791 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1792 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1793 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1794 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 1795 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1796 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1797 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1798 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1799 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 1800 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1801 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1802 | #endif /* CONFIG_P2P */ |
| 1803 | #ifdef CONFIG_IEEE80211W |
| 1804 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1805 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1806 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1807 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1808 | #ifdef CONFIG_TDLS |
| 1809 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 1810 | /* TDLS Discovery Response */ |
| 1811 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 1812 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1813 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1814 | } |
| 1815 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1816 | |
| 1817 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1818 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1819 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1820 | else |
| 1821 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 1822 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 1823 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1824 | /* WNM - BSS Transition Management Request */ |
| 1825 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1826 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1827 | /* WNM-Sleep Mode Response */ |
| 1828 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1829 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1830 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1831 | #ifdef CONFIG_HS20 |
| 1832 | /* WNM-Notification */ |
| 1833 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1834 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1835 | #endif /* CONFIG_HS20 */ |
| 1836 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1837 | /* WMM-AC ADDTS Response */ |
| 1838 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 1839 | ret = -1; |
| 1840 | |
| 1841 | /* WMM-AC DELTS */ |
| 1842 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 1843 | ret = -1; |
| 1844 | |
| 1845 | /* Radio Measurement - Neighbor Report Response */ |
| 1846 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 1847 | ret = -1; |
| 1848 | |
| 1849 | /* Radio Measurement - Link Measurement Request */ |
| 1850 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 1851 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 1852 | ret = -1; |
| 1853 | |
| 1854 | nl80211_mgmt_handle_register_eloop(bss); |
| 1855 | |
| 1856 | return ret; |
| 1857 | } |
| 1858 | |
| 1859 | |
| 1860 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 1861 | { |
| 1862 | int ret = 0; |
| 1863 | |
| 1864 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1865 | return -1; |
| 1866 | |
| 1867 | wpa_printf(MSG_DEBUG, |
| 1868 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 1869 | bss->nl_mgmt); |
| 1870 | |
| 1871 | /* Auth frames for mesh SAE */ |
| 1872 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 1873 | (WLAN_FC_TYPE_MGMT << 2) | |
| 1874 | (WLAN_FC_STYPE_AUTH << 4), |
| 1875 | NULL, 0) < 0) |
| 1876 | ret = -1; |
| 1877 | |
| 1878 | /* Mesh peering open */ |
| 1879 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 1880 | ret = -1; |
| 1881 | /* Mesh peering confirm */ |
| 1882 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 1883 | ret = -1; |
| 1884 | /* Mesh peering close */ |
| 1885 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 1886 | ret = -1; |
| 1887 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1888 | nl80211_mgmt_handle_register_eloop(bss); |
| 1889 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1890 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1894 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 1895 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1896 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1897 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1898 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 1899 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 1900 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1901 | if (ret) { |
| 1902 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 1903 | "failed: ret=%d (%s)", |
| 1904 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1905 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1906 | return ret; |
| 1907 | } |
| 1908 | |
| 1909 | |
| 1910 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 1911 | { |
| 1912 | static const int stypes[] = { |
| 1913 | WLAN_FC_STYPE_AUTH, |
| 1914 | WLAN_FC_STYPE_ASSOC_REQ, |
| 1915 | WLAN_FC_STYPE_REASSOC_REQ, |
| 1916 | WLAN_FC_STYPE_DISASSOC, |
| 1917 | WLAN_FC_STYPE_DEAUTH, |
| 1918 | WLAN_FC_STYPE_ACTION, |
| 1919 | WLAN_FC_STYPE_PROBE_REQ, |
| 1920 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 1921 | * it, but it wouldn't really be the right thing anyway as |
| 1922 | * it isn't per interface ... maybe just dump the scan |
| 1923 | * results periodically for OLBC? |
| 1924 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1925 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1926 | }; |
| 1927 | unsigned int i; |
| 1928 | |
| 1929 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1930 | return -1; |
| 1931 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 1932 | "handle %p", bss->nl_mgmt); |
| 1933 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1934 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1935 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 1936 | (WLAN_FC_TYPE_MGMT << 2) | |
| 1937 | (stypes[i] << 4), |
| 1938 | NULL, 0) < 0) { |
| 1939 | goto out_err; |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | if (nl80211_register_spurious_class3(bss)) |
| 1944 | goto out_err; |
| 1945 | |
| 1946 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 1947 | goto out_err; |
| 1948 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1949 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1950 | return 0; |
| 1951 | |
| 1952 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1953 | nl_destroy_handles(&bss->nl_mgmt); |
| 1954 | return -1; |
| 1955 | } |
| 1956 | |
| 1957 | |
| 1958 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 1959 | { |
| 1960 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1961 | return -1; |
| 1962 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 1963 | "handle %p (device SME)", bss->nl_mgmt); |
| 1964 | |
| 1965 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 1966 | (WLAN_FC_TYPE_MGMT << 2) | |
| 1967 | (WLAN_FC_STYPE_ACTION << 4), |
| 1968 | NULL, 0) < 0) |
| 1969 | goto out_err; |
| 1970 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1971 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1972 | return 0; |
| 1973 | |
| 1974 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1975 | nl_destroy_handles(&bss->nl_mgmt); |
| 1976 | return -1; |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 1981 | { |
| 1982 | if (bss->nl_mgmt == NULL) |
| 1983 | return; |
| 1984 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 1985 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1986 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1987 | |
| 1988 | nl80211_put_wiphy_data_ap(bss); |
| 1989 | } |
| 1990 | |
| 1991 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1992 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 1993 | { |
| 1994 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 1995 | } |
| 1996 | |
| 1997 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1998 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 1999 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2000 | struct nl_msg *msg; |
| 2001 | int ret; |
| 2002 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2003 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2004 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2005 | |
| 2006 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2007 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2008 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | |
| 2012 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2013 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2014 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2015 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2016 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2017 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2018 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2019 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2020 | |
| 2021 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2022 | start ? "Start" : "Stop", |
| 2023 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2024 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2025 | return ret; |
| 2026 | } |
| 2027 | |
| 2028 | |
| 2029 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2030 | { |
| 2031 | enum nl80211_iftype nlmode; |
| 2032 | |
| 2033 | nlmode = nl80211_get_ifmode(bss); |
| 2034 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2035 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2036 | bss->ifname, up); |
| 2037 | } |
| 2038 | |
| 2039 | /* P2P Device has start/stop which is equivalent */ |
| 2040 | return nl80211_set_p2pdev(bss, up); |
| 2041 | } |
| 2042 | |
| 2043 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2044 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2045 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2046 | const u8 *set_addr, int first, |
| 2047 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2048 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2049 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2050 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2051 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2052 | |
| 2053 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2054 | bss->ifindex = drv->ifindex; |
| 2055 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2056 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2057 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2058 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2059 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2060 | drv->global->if_add_wdevid_set = 0; |
| 2061 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2062 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2063 | bss->static_ap = 1; |
| 2064 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2065 | if (wpa_driver_nl80211_capa(drv)) |
| 2066 | return -1; |
| 2067 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2068 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2069 | return -1; |
| 2070 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2071 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2072 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2073 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2074 | if (set_addr && |
| 2075 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2076 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2077 | set_addr))) |
| 2078 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2079 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2080 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2081 | drv->start_mode_ap = 1; |
| 2082 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2083 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2084 | nlmode = NL80211_IFTYPE_AP; |
| 2085 | else if (bss->if_dynamic) |
| 2086 | nlmode = nl80211_get_ifmode(bss); |
| 2087 | else |
| 2088 | nlmode = NL80211_IFTYPE_STATION; |
| 2089 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2090 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2091 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2092 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2093 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2094 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2095 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2096 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2097 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2098 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2099 | int ret = i802_set_iface_flags(bss, 1); |
| 2100 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2101 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2102 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2103 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2104 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2105 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2106 | return ret; |
| 2107 | } else { |
| 2108 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2109 | "interface '%s' due to rfkill", bss->ifname); |
| 2110 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2111 | return 0; |
| 2112 | drv->if_disabled = 1; |
| 2113 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2114 | } |
| 2115 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2116 | if (!drv->hostapd) |
| 2117 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2118 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2119 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2120 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2121 | bss->addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2122 | return -1; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2123 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2124 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2125 | if (send_rfkill_event) { |
| 2126 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2127 | drv, drv->ctx); |
| 2128 | } |
| 2129 | |
| 2130 | return 0; |
| 2131 | } |
| 2132 | |
| 2133 | |
| 2134 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2135 | { |
| 2136 | struct nl_msg *msg; |
| 2137 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2138 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2139 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2140 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2141 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | |
| 2145 | /** |
| 2146 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2147 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2148 | * |
| 2149 | * Shut down driver interface and processing of driver events. Free |
| 2150 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2151 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2152 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2153 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2154 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2155 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2156 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2157 | bss->ifname, drv->disabled_11b_rates); |
| 2158 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2159 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2160 | if (drv->data_tx_status) |
| 2161 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2162 | if (drv->eapol_tx_sock >= 0) |
| 2163 | close(drv->eapol_tx_sock); |
| 2164 | |
| 2165 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2166 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2167 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2168 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2169 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2170 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2171 | "interface %s from bridge %s: %s", |
| 2172 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2173 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2174 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2175 | } |
| 2176 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2177 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2178 | 0) < 0) |
| 2179 | wpa_printf(MSG_INFO, |
| 2180 | "nl80211: Could not set bridge %s down", |
| 2181 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2182 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2183 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2184 | "bridge %s: %s", |
| 2185 | bss->brname, strerror(errno)); |
| 2186 | } |
| 2187 | |
| 2188 | nl80211_remove_monitor_interface(drv); |
| 2189 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2190 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2191 | wpa_driver_nl80211_del_beacon(drv); |
| 2192 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2193 | if (drv->eapol_sock >= 0) { |
| 2194 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2195 | close(drv->eapol_sock); |
| 2196 | } |
| 2197 | |
| 2198 | if (drv->if_indices != drv->default_if_indices) |
| 2199 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2200 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2201 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2202 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2203 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2204 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2205 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2206 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2207 | rfkill_deinit(drv->rfkill); |
| 2208 | |
| 2209 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2210 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2211 | if (!drv->start_iface_up) |
| 2212 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2213 | |
| 2214 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2215 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2216 | 0) < 0) { |
| 2217 | wpa_printf(MSG_DEBUG, |
| 2218 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2219 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2220 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2221 | drv->perm_addr) < 0) { |
| 2222 | wpa_printf(MSG_DEBUG, |
| 2223 | "nl80211: Could not restore permanent MAC address"); |
| 2224 | } |
| 2225 | } |
| 2226 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2227 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2228 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2229 | wpa_driver_nl80211_set_mode(bss, |
| 2230 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2231 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2232 | } else { |
| 2233 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2234 | nl80211_del_p2pdev(bss); |
| 2235 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2236 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2237 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2238 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2239 | os_free(drv->filter_ssids); |
| 2240 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2241 | os_free(drv->auth_ie); |
| 2242 | |
| 2243 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2244 | dl_list_del(&drv->list); |
| 2245 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2246 | os_free(drv->extended_capa); |
| 2247 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2248 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2249 | os_free(drv); |
| 2250 | } |
| 2251 | |
| 2252 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2253 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2254 | { |
| 2255 | switch (alg) { |
| 2256 | case WPA_ALG_WEP: |
| 2257 | if (key_len == 5) |
| 2258 | return WLAN_CIPHER_SUITE_WEP40; |
| 2259 | return WLAN_CIPHER_SUITE_WEP104; |
| 2260 | case WPA_ALG_TKIP: |
| 2261 | return WLAN_CIPHER_SUITE_TKIP; |
| 2262 | case WPA_ALG_CCMP: |
| 2263 | return WLAN_CIPHER_SUITE_CCMP; |
| 2264 | case WPA_ALG_GCMP: |
| 2265 | return WLAN_CIPHER_SUITE_GCMP; |
| 2266 | case WPA_ALG_CCMP_256: |
| 2267 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2268 | case WPA_ALG_GCMP_256: |
| 2269 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2270 | case WPA_ALG_IGTK: |
| 2271 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2272 | case WPA_ALG_BIP_GMAC_128: |
| 2273 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2274 | case WPA_ALG_BIP_GMAC_256: |
| 2275 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2276 | case WPA_ALG_BIP_CMAC_256: |
| 2277 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2278 | case WPA_ALG_SMS4: |
| 2279 | return WLAN_CIPHER_SUITE_SMS4; |
| 2280 | case WPA_ALG_KRK: |
| 2281 | return WLAN_CIPHER_SUITE_KRK; |
| 2282 | case WPA_ALG_NONE: |
| 2283 | case WPA_ALG_PMK: |
| 2284 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2285 | alg); |
| 2286 | return 0; |
| 2287 | } |
| 2288 | |
| 2289 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2290 | alg); |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
| 2294 | |
| 2295 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2296 | { |
| 2297 | switch (cipher) { |
| 2298 | case WPA_CIPHER_CCMP_256: |
| 2299 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2300 | case WPA_CIPHER_GCMP_256: |
| 2301 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2302 | case WPA_CIPHER_CCMP: |
| 2303 | return WLAN_CIPHER_SUITE_CCMP; |
| 2304 | case WPA_CIPHER_GCMP: |
| 2305 | return WLAN_CIPHER_SUITE_GCMP; |
| 2306 | case WPA_CIPHER_TKIP: |
| 2307 | return WLAN_CIPHER_SUITE_TKIP; |
| 2308 | case WPA_CIPHER_WEP104: |
| 2309 | return WLAN_CIPHER_SUITE_WEP104; |
| 2310 | case WPA_CIPHER_WEP40: |
| 2311 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2312 | case WPA_CIPHER_GTK_NOT_USED: |
| 2313 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2314 | } |
| 2315 | |
| 2316 | return 0; |
| 2317 | } |
| 2318 | |
| 2319 | |
| 2320 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2321 | int max_suites) |
| 2322 | { |
| 2323 | int num_suites = 0; |
| 2324 | |
| 2325 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2326 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2327 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2328 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2329 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2330 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2331 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2332 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2333 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2334 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2335 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2336 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2337 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2338 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2339 | |
| 2340 | return num_suites; |
| 2341 | } |
| 2342 | |
| 2343 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2344 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2345 | const u8 *key, size_t key_len) |
| 2346 | { |
| 2347 | struct nl_msg *msg; |
| 2348 | int ret; |
| 2349 | |
| 2350 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2351 | return 0; |
| 2352 | |
| 2353 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2354 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2355 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2356 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2357 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2358 | nl80211_nlmsg_clear(msg); |
| 2359 | nlmsg_free(msg); |
| 2360 | return -1; |
| 2361 | } |
| 2362 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2363 | if (ret) { |
| 2364 | wpa_printf(MSG_DEBUG, |
| 2365 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2366 | ret, strerror(-ret)); |
| 2367 | } |
| 2368 | |
| 2369 | return ret; |
| 2370 | } |
| 2371 | |
| 2372 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2373 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2374 | enum wpa_alg alg, const u8 *addr, |
| 2375 | int key_idx, int set_tx, |
| 2376 | const u8 *seq, size_t seq_len, |
| 2377 | const u8 *key, size_t key_len) |
| 2378 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2379 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2380 | int ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | struct nl_msg *msg; |
| 2382 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2383 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2384 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2385 | /* Ignore for P2P Device */ |
| 2386 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2387 | return 0; |
| 2388 | |
| 2389 | ifindex = if_nametoindex(ifname); |
| 2390 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2391 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2392 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2393 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2394 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2395 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2396 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2397 | tdls = 1; |
| 2398 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2399 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2400 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2401 | if (alg == WPA_ALG_PMK && |
| 2402 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2403 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2404 | __func__); |
| 2405 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2406 | return ret; |
| 2407 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2408 | |
| 2409 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2410 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2411 | if (!msg) |
| 2412 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2413 | } else { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2414 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2415 | if (!msg || |
| 2416 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
| 2417 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, |
| 2418 | wpa_alg_to_cipher_suite(alg, key_len))) |
| 2419 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2420 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2421 | } |
| 2422 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2423 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2424 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2425 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2426 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2427 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2428 | |
| 2429 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2430 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2431 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2432 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2433 | |
| 2434 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2435 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2436 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2437 | NL80211_KEYTYPE_GROUP)) |
| 2438 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2439 | } |
| 2440 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2441 | struct nlattr *types; |
| 2442 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2443 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2444 | |
| 2445 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2446 | if (!types || |
| 2447 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2448 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2449 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2450 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2451 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2452 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2453 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2454 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2455 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2456 | ret = 0; |
| 2457 | if (ret) |
| 2458 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2459 | ret, strerror(-ret)); |
| 2460 | |
| 2461 | /* |
| 2462 | * If we failed or don't need to set the default TX key (below), |
| 2463 | * we're done here. |
| 2464 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2465 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2466 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2467 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2468 | !is_broadcast_ether_addr(addr)) |
| 2469 | return ret; |
| 2470 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2471 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2472 | if (!msg || |
| 2473 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
| 2474 | nla_put_flag(msg, alg == WPA_ALG_IGTK ? |
| 2475 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2476 | NL80211_ATTR_KEY_DEFAULT)) |
| 2477 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2478 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2479 | struct nlattr *types; |
| 2480 | |
| 2481 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2482 | if (!types || |
| 2483 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2484 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2485 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2486 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2487 | struct nlattr *types; |
| 2488 | |
| 2489 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2490 | if (!types || |
| 2491 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2492 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2493 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2497 | if (ret == -ENOENT) |
| 2498 | ret = 0; |
| 2499 | if (ret) |
| 2500 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2501 | "err=%d %s)", ret, strerror(-ret)); |
| 2502 | return ret; |
| 2503 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2504 | fail: |
| 2505 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2506 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2507 | return -ENOBUFS; |
| 2508 | } |
| 2509 | |
| 2510 | |
| 2511 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2512 | int key_idx, int defkey, |
| 2513 | const u8 *seq, size_t seq_len, |
| 2514 | const u8 *key, size_t key_len) |
| 2515 | { |
| 2516 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
| 2517 | if (!key_attr) |
| 2518 | return -1; |
| 2519 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2520 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2521 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2522 | return -1; |
| 2523 | } else if (defkey) { |
| 2524 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2525 | return -1; |
| 2526 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2527 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2528 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
| 2529 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2530 | wpa_alg_to_cipher_suite(alg, key_len)) || |
| 2531 | (seq && seq_len && |
| 2532 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2533 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2534 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2535 | |
| 2536 | nla_nest_end(msg, key_attr); |
| 2537 | |
| 2538 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2543 | struct nl_msg *msg) |
| 2544 | { |
| 2545 | int i, privacy = 0; |
| 2546 | struct nlattr *nl_keys, *nl_key; |
| 2547 | |
| 2548 | for (i = 0; i < 4; i++) { |
| 2549 | if (!params->wep_key[i]) |
| 2550 | continue; |
| 2551 | privacy = 1; |
| 2552 | break; |
| 2553 | } |
| 2554 | if (params->wps == WPS_MODE_PRIVACY) |
| 2555 | privacy = 1; |
| 2556 | if (params->pairwise_suite && |
| 2557 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2558 | privacy = 1; |
| 2559 | |
| 2560 | if (!privacy) |
| 2561 | return 0; |
| 2562 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2563 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2564 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2565 | |
| 2566 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2567 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2568 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2569 | |
| 2570 | for (i = 0; i < 4; i++) { |
| 2571 | if (!params->wep_key[i]) |
| 2572 | continue; |
| 2573 | |
| 2574 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2575 | if (!nl_key || |
| 2576 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2577 | params->wep_key[i]) || |
| 2578 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2579 | params->wep_key_len[i] == 5 ? |
| 2580 | WLAN_CIPHER_SUITE_WEP40 : |
| 2581 | WLAN_CIPHER_SUITE_WEP104) || |
| 2582 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2583 | (i == params->wep_tx_keyidx && |
| 2584 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2585 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2586 | |
| 2587 | nla_nest_end(msg, nl_key); |
| 2588 | } |
| 2589 | nla_nest_end(msg, nl_keys); |
| 2590 | |
| 2591 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2595 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2596 | const u8 *addr, int cmd, u16 reason_code, |
| 2597 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2598 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2599 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2600 | struct nl_msg *msg; |
| 2601 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2602 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2603 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2604 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2605 | (local_state_change && |
| 2606 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2607 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2608 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2609 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2610 | |
| 2611 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2612 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2613 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2614 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2615 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2617 | return ret; |
| 2618 | } |
| 2619 | |
| 2620 | |
| 2621 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2622 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2623 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2624 | int ret; |
| 2625 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2626 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2627 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2628 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2629 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2630 | reason_code, 0); |
| 2631 | /* |
| 2632 | * For locally generated disconnect, supplicant already generates a |
| 2633 | * DEAUTH event, so ignore the event from NL80211. |
| 2634 | */ |
| 2635 | drv->ignore_next_local_disconnect = ret == 0; |
| 2636 | |
| 2637 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2641 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2642 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2643 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2644 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2645 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2646 | |
| 2647 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2648 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2649 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2650 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2651 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2652 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2654 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2655 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2656 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2657 | reason_code, 0); |
| 2658 | /* |
| 2659 | * For locally generated deauthenticate, supplicant already generates a |
| 2660 | * DEAUTH event, so ignore the event from NL80211. |
| 2661 | */ |
| 2662 | drv->ignore_next_local_deauth = ret == 0; |
| 2663 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2664 | } |
| 2665 | |
| 2666 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2667 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2668 | struct wpa_driver_auth_params *params) |
| 2669 | { |
| 2670 | int i; |
| 2671 | |
| 2672 | drv->auth_freq = params->freq; |
| 2673 | drv->auth_alg = params->auth_alg; |
| 2674 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2675 | drv->auth_local_state_change = params->local_state_change; |
| 2676 | drv->auth_p2p = params->p2p; |
| 2677 | |
| 2678 | if (params->bssid) |
| 2679 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2680 | else |
| 2681 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2682 | |
| 2683 | if (params->ssid) { |
| 2684 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2685 | drv->auth_ssid_len = params->ssid_len; |
| 2686 | } else |
| 2687 | drv->auth_ssid_len = 0; |
| 2688 | |
| 2689 | |
| 2690 | os_free(drv->auth_ie); |
| 2691 | drv->auth_ie = NULL; |
| 2692 | drv->auth_ie_len = 0; |
| 2693 | if (params->ie) { |
| 2694 | drv->auth_ie = os_malloc(params->ie_len); |
| 2695 | if (drv->auth_ie) { |
| 2696 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2697 | drv->auth_ie_len = params->ie_len; |
| 2698 | } |
| 2699 | } |
| 2700 | |
| 2701 | for (i = 0; i < 4; i++) { |
| 2702 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2703 | params->wep_key_len[i] <= 16) { |
| 2704 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2705 | params->wep_key_len[i]); |
| 2706 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2707 | } else |
| 2708 | drv->auth_wep_key_len[i] = 0; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2713 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 2714 | { |
| 2715 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2716 | |
| 2717 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 2718 | return; |
| 2719 | |
| 2720 | /* |
| 2721 | * Looks like we failed to unmask 11b rates previously. This could |
| 2722 | * happen, e.g., if the interface was down at the point in time when a |
| 2723 | * P2P group was terminated. |
| 2724 | */ |
| 2725 | wpa_printf(MSG_DEBUG, |
| 2726 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 2727 | bss->ifname); |
| 2728 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2729 | } |
| 2730 | |
| 2731 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2732 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2733 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2734 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2736 | int ret = -1, i; |
| 2737 | struct nl_msg *msg; |
| 2738 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2739 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2740 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2741 | int is_retry; |
| 2742 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2743 | nl80211_unmask_11b_rates(bss); |
| 2744 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2745 | is_retry = drv->retry_auth; |
| 2746 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2747 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2748 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2749 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2750 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2751 | if (params->bssid) |
| 2752 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 2753 | else |
| 2754 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2755 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2756 | nlmode = params->p2p ? |
| 2757 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 2758 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2759 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2760 | return -1; |
| 2761 | |
| 2762 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2763 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 2764 | drv->ifindex); |
| 2765 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2766 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 2767 | if (!msg) |
| 2768 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2769 | |
| 2770 | for (i = 0; i < 4; i++) { |
| 2771 | if (!params->wep_key[i]) |
| 2772 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2773 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2774 | NULL, i, |
| 2775 | i == params->wep_tx_keyidx, NULL, 0, |
| 2776 | params->wep_key[i], |
| 2777 | params->wep_key_len[i]); |
| 2778 | if (params->wep_tx_keyidx != i) |
| 2779 | continue; |
| 2780 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2781 | params->wep_key[i], params->wep_key_len[i])) |
| 2782 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2783 | } |
| 2784 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | if (params->bssid) { |
| 2786 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 2787 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2788 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 2789 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2790 | } |
| 2791 | if (params->freq) { |
| 2792 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2793 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 2794 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2795 | } |
| 2796 | if (params->ssid) { |
| 2797 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 2798 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2799 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 2800 | params->ssid)) |
| 2801 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2802 | } |
| 2803 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2804 | if (params->ie && |
| 2805 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 2806 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2807 | if (params->sae_data) { |
| 2808 | wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data, |
| 2809 | params->sae_data_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2810 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len, |
| 2811 | params->sae_data)) |
| 2812 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2813 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2814 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 2815 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 2816 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 2817 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 2818 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 2819 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 2820 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 2821 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2822 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 2823 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2824 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2825 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2826 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2827 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 2828 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2829 | if (params->local_state_change) { |
| 2830 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2831 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 2832 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2836 | msg = NULL; |
| 2837 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2838 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2839 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 2840 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2841 | count++; |
| 2842 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 2843 | !params->local_state_change) { |
| 2844 | /* |
| 2845 | * mac80211 does not currently accept new |
| 2846 | * authentication if we are already authenticated. As a |
| 2847 | * workaround, force deauthentication and try again. |
| 2848 | */ |
| 2849 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 2850 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2851 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2852 | wpa_driver_nl80211_deauthenticate( |
| 2853 | bss, params->bssid, |
| 2854 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 2855 | nlmsg_free(msg); |
| 2856 | goto retry; |
| 2857 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2858 | |
| 2859 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 2860 | /* |
| 2861 | * cfg80211 has likely expired the BSS entry even |
| 2862 | * though it was previously available in our internal |
| 2863 | * BSS table. To recover quickly, start a single |
| 2864 | * channel scan on the specified channel. |
| 2865 | */ |
| 2866 | struct wpa_driver_scan_params scan; |
| 2867 | int freqs[2]; |
| 2868 | |
| 2869 | os_memset(&scan, 0, sizeof(scan)); |
| 2870 | scan.num_ssids = 1; |
| 2871 | if (params->ssid) { |
| 2872 | scan.ssids[0].ssid = params->ssid; |
| 2873 | scan.ssids[0].ssid_len = params->ssid_len; |
| 2874 | } |
| 2875 | freqs[0] = params->freq; |
| 2876 | freqs[1] = 0; |
| 2877 | scan.freqs = freqs; |
| 2878 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 2879 | "channel scan to refresh cfg80211 BSS " |
| 2880 | "entry"); |
| 2881 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 2882 | if (ret == 0) { |
| 2883 | nl80211_copy_auth_params(drv, params); |
| 2884 | drv->scan_for_auth = 1; |
| 2885 | } |
| 2886 | } else if (is_retry) { |
| 2887 | /* |
| 2888 | * Need to indicate this with an event since the return |
| 2889 | * value from the retry is not delivered to core code. |
| 2890 | */ |
| 2891 | union wpa_event_data event; |
| 2892 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 2893 | "failed"); |
| 2894 | os_memset(&event, 0, sizeof(event)); |
| 2895 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 2896 | ETH_ALEN); |
| 2897 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 2898 | &event); |
| 2899 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2900 | } else { |
| 2901 | wpa_printf(MSG_DEBUG, |
| 2902 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2904 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2905 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2906 | nlmsg_free(msg); |
| 2907 | return ret; |
| 2908 | } |
| 2909 | |
| 2910 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2911 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2912 | { |
| 2913 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2914 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2915 | int i; |
| 2916 | |
| 2917 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 2918 | |
| 2919 | os_memset(¶ms, 0, sizeof(params)); |
| 2920 | params.freq = drv->auth_freq; |
| 2921 | params.auth_alg = drv->auth_alg; |
| 2922 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 2923 | params.local_state_change = drv->auth_local_state_change; |
| 2924 | params.p2p = drv->auth_p2p; |
| 2925 | |
| 2926 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 2927 | params.bssid = drv->auth_bssid_; |
| 2928 | |
| 2929 | if (drv->auth_ssid_len) { |
| 2930 | params.ssid = drv->auth_ssid; |
| 2931 | params.ssid_len = drv->auth_ssid_len; |
| 2932 | } |
| 2933 | |
| 2934 | params.ie = drv->auth_ie; |
| 2935 | params.ie_len = drv->auth_ie_len; |
| 2936 | |
| 2937 | for (i = 0; i < 4; i++) { |
| 2938 | if (drv->auth_wep_key_len[i]) { |
| 2939 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 2940 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | drv->retry_auth = 1; |
| 2945 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 2946 | } |
| 2947 | |
| 2948 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2949 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 2950 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2951 | int encrypt, int noack, |
| 2952 | unsigned int freq, int no_cck, |
| 2953 | int offchanok, unsigned int wait_time) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2954 | { |
| 2955 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 2956 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2957 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2958 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 2959 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2960 | freq = nl80211_get_assoc_freq(drv); |
| 2961 | wpa_printf(MSG_DEBUG, |
| 2962 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 2963 | freq); |
| 2964 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2965 | if (freq == 0) { |
| 2966 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 2967 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2968 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2969 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2970 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2971 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2972 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2973 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 2974 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2975 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2976 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2977 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2978 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
| 2979 | &cookie, no_cck, noack, offchanok); |
| 2980 | if (res == 0 && !noack) { |
| 2981 | const struct ieee80211_mgmt *mgmt; |
| 2982 | u16 fc; |
| 2983 | |
| 2984 | mgmt = (const struct ieee80211_mgmt *) data; |
| 2985 | fc = le_to_host16(mgmt->frame_control); |
| 2986 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 2987 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 2988 | wpa_printf(MSG_MSGDUMP, |
| 2989 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 2990 | (long long unsigned int) |
| 2991 | drv->send_action_cookie, |
| 2992 | (long long unsigned int) cookie); |
| 2993 | drv->send_action_cookie = cookie; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3001 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3002 | size_t data_len, int noack, |
| 3003 | unsigned int freq, int no_cck, |
| 3004 | int offchanok, |
| 3005 | unsigned int wait_time) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3006 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3007 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3008 | struct ieee80211_mgmt *mgmt; |
| 3009 | int encrypt = 1; |
| 3010 | u16 fc; |
| 3011 | |
| 3012 | mgmt = (struct ieee80211_mgmt *) data; |
| 3013 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3014 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3015 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3016 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3017 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3018 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3019 | if ((is_sta_interface(drv->nlmode) || |
| 3020 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3021 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3022 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3023 | /* |
| 3024 | * The use of last_mgmt_freq is a bit of a hack, |
| 3025 | * but it works due to the single-threaded nature |
| 3026 | * of wpa_supplicant. |
| 3027 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3028 | if (freq == 0) { |
| 3029 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3030 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3031 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3032 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3033 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3034 | data, data_len, NULL, 1, noack, |
| 3035 | 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3036 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3037 | |
| 3038 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3039 | if (freq == 0) { |
| 3040 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3041 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3042 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3043 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3044 | return nl80211_send_frame_cmd(bss, freq, |
| 3045 | (int) freq == bss->freq ? 0 : |
| 3046 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3047 | data, data_len, |
| 3048 | &drv->send_action_cookie, |
| 3049 | no_cck, noack, offchanok); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3050 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3051 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3052 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3053 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3054 | /* |
| 3055 | * Only one of the authentication frame types is encrypted. |
| 3056 | * In order for static WEP encryption to work properly (i.e., |
| 3057 | * to not encrypt the frame), we need to tell mac80211 about |
| 3058 | * the frames that must not be encrypted. |
| 3059 | */ |
| 3060 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3061 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3062 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3063 | encrypt = 0; |
| 3064 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3065 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3066 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3067 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3068 | noack, freq, no_cck, offchanok, |
| 3069 | wait_time); |
| 3070 | } |
| 3071 | |
| 3072 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3073 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3074 | int slot, int ht_opmode, int ap_isolate, |
| 3075 | int *basic_rates) |
| 3076 | { |
| 3077 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3078 | struct nl_msg *msg; |
| 3079 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3080 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3081 | (cts >= 0 && |
| 3082 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3083 | (preamble >= 0 && |
| 3084 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3085 | (slot >= 0 && |
| 3086 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3087 | (ht_opmode >= 0 && |
| 3088 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3089 | (ap_isolate >= 0 && |
| 3090 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate))) |
| 3091 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3092 | |
| 3093 | if (basic_rates) { |
| 3094 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3095 | u8 rates_len = 0; |
| 3096 | int i; |
| 3097 | |
| 3098 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; |
| 3099 | i++) |
| 3100 | rates[rates_len++] = basic_rates[i] / 5; |
| 3101 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3102 | if (nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, |
| 3103 | rates)) |
| 3104 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3105 | } |
| 3106 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3107 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3108 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3109 | nlmsg_free(msg); |
| 3110 | return -ENOBUFS; |
| 3111 | } |
| 3112 | |
| 3113 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3114 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3115 | struct hostapd_acl_params *params) |
| 3116 | { |
| 3117 | struct i802_bss *bss = priv; |
| 3118 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3119 | struct nl_msg *msg; |
| 3120 | struct nlattr *acl; |
| 3121 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3122 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3123 | |
| 3124 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3125 | return -ENOTSUP; |
| 3126 | |
| 3127 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3128 | return -ENOTSUP; |
| 3129 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3130 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3131 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3132 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3133 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3134 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3135 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3136 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3137 | (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) { |
| 3138 | nlmsg_free(msg); |
| 3139 | return -ENOMEM; |
| 3140 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3141 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3142 | for (i = 0; i < params->num_mac_acl; i++) { |
| 3143 | if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3144 | nlmsg_free(msg); |
| 3145 | return -ENOMEM; |
| 3146 | } |
| 3147 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3148 | |
| 3149 | nla_nest_end(msg, acl); |
| 3150 | |
| 3151 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3152 | if (ret) { |
| 3153 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3154 | ret, strerror(-ret)); |
| 3155 | } |
| 3156 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3157 | return ret; |
| 3158 | } |
| 3159 | |
| 3160 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3161 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3162 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3163 | { |
| 3164 | struct i802_bss *bss = priv; |
| 3165 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3166 | struct nl_msg *msg; |
| 3167 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3168 | int ret; |
| 3169 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3170 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3171 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3172 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3173 | u32 ver; |
| 3174 | |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3175 | beacon_set = bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3176 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3177 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3178 | beacon_set); |
| 3179 | if (beacon_set) |
| 3180 | cmd = NL80211_CMD_SET_BEACON; |
| 3181 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3182 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3183 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3184 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3185 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3186 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3187 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3188 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3189 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3190 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3191 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3192 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3193 | params->head) || |
| 3194 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3195 | params->tail) || |
| 3196 | nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3197 | params->beacon_int) || |
| 3198 | nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) || |
| 3199 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3200 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3201 | if (params->proberesp && params->proberesp_len) { |
| 3202 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3203 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3204 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3205 | params->proberesp)) |
| 3206 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3207 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3208 | switch (params->hide_ssid) { |
| 3209 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3210 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3211 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3212 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3213 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3214 | break; |
| 3215 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3216 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3217 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3218 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3219 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3220 | break; |
| 3221 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3222 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3223 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3224 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3225 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3226 | break; |
| 3227 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3228 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3229 | if (params->privacy && |
| 3230 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3231 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3232 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3233 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3234 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3235 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3236 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3237 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3238 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3239 | goto fail; |
| 3240 | } else { |
| 3241 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3242 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3243 | goto fail; |
| 3244 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3245 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3246 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3247 | ver = 0; |
| 3248 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3249 | ver |= NL80211_WPA_VERSION_1; |
| 3250 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3251 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3252 | if (ver && |
| 3253 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3254 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3255 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3256 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3257 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3258 | num_suites = 0; |
| 3259 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3260 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3261 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3262 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3263 | if (num_suites && |
| 3264 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3265 | suites)) |
| 3266 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3267 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3268 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 3269 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) && |
| 3270 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)) |
| 3271 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3272 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3273 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3274 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3275 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3276 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3277 | if (num_suites && |
| 3278 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3279 | num_suites * sizeof(u32), suites)) |
| 3280 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3281 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3282 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3283 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3284 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3285 | if (suite && |
| 3286 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3287 | goto fail; |
| 3288 | |
| 3289 | switch (params->smps_mode) { |
| 3290 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3291 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3292 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3293 | break; |
| 3294 | case HT_CAP_INFO_SMPS_STATIC: |
| 3295 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3296 | smps_mode = NL80211_SMPS_STATIC; |
| 3297 | break; |
| 3298 | default: |
| 3299 | /* invalid - fallback to smps off */ |
| 3300 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3301 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3302 | smps_mode = NL80211_SMPS_OFF; |
| 3303 | break; |
| 3304 | } |
| 3305 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3306 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3307 | |
| 3308 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3309 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3310 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3311 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3312 | wpabuf_len(params->beacon_ies), |
| 3313 | wpabuf_head(params->beacon_ies))) |
| 3314 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3315 | } |
| 3316 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3317 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3318 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3319 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3320 | wpabuf_len(params->proberesp_ies), |
| 3321 | wpabuf_head(params->proberesp_ies))) |
| 3322 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3323 | } |
| 3324 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3325 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3326 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3327 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3328 | wpabuf_len(params->assocresp_ies), |
| 3329 | wpabuf_head(params->assocresp_ies))) |
| 3330 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3331 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3332 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3333 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3334 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3335 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3336 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3337 | params->ap_max_inactivity)) |
| 3338 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3341 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3342 | if (ret) { |
| 3343 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3344 | ret, strerror(-ret)); |
| 3345 | } else { |
| 3346 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3347 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3348 | params->short_slot_time, params->ht_opmode, |
| 3349 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3350 | if (beacon_set && params->freq && |
| 3351 | params->freq->bandwidth != bss->bandwidth) { |
| 3352 | wpa_printf(MSG_DEBUG, |
| 3353 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3354 | bss->ifname, bss->bandwidth, |
| 3355 | params->freq->bandwidth); |
| 3356 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3357 | if (ret) { |
| 3358 | wpa_printf(MSG_DEBUG, |
| 3359 | "nl80211: Frequency set failed: %d (%s)", |
| 3360 | ret, strerror(-ret)); |
| 3361 | } else { |
| 3362 | wpa_printf(MSG_DEBUG, |
| 3363 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3364 | bss->bandwidth = params->freq->bandwidth; |
| 3365 | } |
| 3366 | } else if (!beacon_set) { |
| 3367 | /* |
| 3368 | * cfg80211 updates the driver on frequence change in AP |
| 3369 | * mode only at the point when beaconing is started, so |
| 3370 | * set the initial value here. |
| 3371 | */ |
| 3372 | bss->bandwidth = params->freq->bandwidth; |
| 3373 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3374 | } |
| 3375 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3376 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3377 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3378 | return -ENOBUFS; |
| 3379 | } |
| 3380 | |
| 3381 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3382 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3383 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3384 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3385 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3386 | return -ENOBUFS; |
| 3387 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3388 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3389 | enum nl80211_chan_width cw; |
| 3390 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3391 | switch (freq->bandwidth) { |
| 3392 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3393 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3394 | break; |
| 3395 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3396 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3397 | break; |
| 3398 | case 80: |
| 3399 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3400 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3401 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3402 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3403 | break; |
| 3404 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3405 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3406 | break; |
| 3407 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3408 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3409 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3410 | |
| 3411 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3412 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3413 | freq->center_freq1) || |
| 3414 | (freq->center_freq2 && |
| 3415 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3416 | freq->center_freq2))) |
| 3417 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3418 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3419 | enum nl80211_channel_type ct; |
| 3420 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3421 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3422 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3423 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3424 | break; |
| 3425 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3426 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3427 | break; |
| 3428 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3429 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3430 | break; |
| 3431 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3432 | |
| 3433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3434 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3435 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3436 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3437 | } |
| 3438 | |
| 3439 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3440 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3441 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3442 | { |
| 3443 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3444 | struct nl_msg *msg; |
| 3445 | int ret; |
| 3446 | |
| 3447 | wpa_printf(MSG_DEBUG, |
| 3448 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3449 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3450 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3451 | |
| 3452 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3453 | NL80211_CMD_SET_WIPHY); |
| 3454 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3455 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3456 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3457 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3458 | |
| 3459 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3460 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3461 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3462 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3463 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3464 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3465 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3466 | return -1; |
| 3467 | } |
| 3468 | |
| 3469 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3470 | static u32 sta_flags_nl80211(int flags) |
| 3471 | { |
| 3472 | u32 f = 0; |
| 3473 | |
| 3474 | if (flags & WPA_STA_AUTHORIZED) |
| 3475 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3476 | if (flags & WPA_STA_WMM) |
| 3477 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3478 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3479 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3480 | if (flags & WPA_STA_MFP) |
| 3481 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3482 | if (flags & WPA_STA_TDLS_PEER) |
| 3483 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3484 | if (flags & WPA_STA_AUTHENTICATED) |
| 3485 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3486 | |
| 3487 | return f; |
| 3488 | } |
| 3489 | |
| 3490 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3491 | #ifdef CONFIG_MESH |
| 3492 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3493 | { |
| 3494 | switch (state) { |
| 3495 | case PLINK_LISTEN: |
| 3496 | return NL80211_PLINK_LISTEN; |
| 3497 | case PLINK_OPEN_SENT: |
| 3498 | return NL80211_PLINK_OPN_SNT; |
| 3499 | case PLINK_OPEN_RCVD: |
| 3500 | return NL80211_PLINK_OPN_RCVD; |
| 3501 | case PLINK_CNF_RCVD: |
| 3502 | return NL80211_PLINK_CNF_RCVD; |
| 3503 | case PLINK_ESTAB: |
| 3504 | return NL80211_PLINK_ESTAB; |
| 3505 | case PLINK_HOLDING: |
| 3506 | return NL80211_PLINK_HOLDING; |
| 3507 | case PLINK_BLOCKED: |
| 3508 | return NL80211_PLINK_BLOCKED; |
| 3509 | default: |
| 3510 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3511 | state); |
| 3512 | } |
| 3513 | return -1; |
| 3514 | } |
| 3515 | #endif /* CONFIG_MESH */ |
| 3516 | |
| 3517 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3518 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3519 | struct hostapd_sta_add_params *params) |
| 3520 | { |
| 3521 | struct i802_bss *bss = priv; |
| 3522 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3523 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3524 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3525 | int ret = -ENOBUFS; |
| 3526 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3527 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3528 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3529 | return -EOPNOTSUPP; |
| 3530 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3531 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3532 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3533 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3534 | NL80211_CMD_NEW_STATION); |
| 3535 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3536 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3537 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3538 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER)) { |
| 3539 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3540 | params->supp_rates, params->supp_rates_len); |
| 3541 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3542 | params->capability); |
| 3543 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3544 | params->supp_rates_len, params->supp_rates) || |
| 3545 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3546 | params->capability)) |
| 3547 | goto fail; |
| 3548 | |
| 3549 | if (params->ht_capabilities) { |
| 3550 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3551 | (u8 *) params->ht_capabilities, |
| 3552 | sizeof(*params->ht_capabilities)); |
| 3553 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3554 | sizeof(*params->ht_capabilities), |
| 3555 | params->ht_capabilities)) |
| 3556 | goto fail; |
| 3557 | } |
| 3558 | |
| 3559 | if (params->vht_capabilities) { |
| 3560 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3561 | (u8 *) params->vht_capabilities, |
| 3562 | sizeof(*params->vht_capabilities)); |
| 3563 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3564 | sizeof(*params->vht_capabilities), |
| 3565 | params->vht_capabilities)) |
| 3566 | goto fail; |
| 3567 | } |
| 3568 | |
| 3569 | if (params->ext_capab) { |
| 3570 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 3571 | params->ext_capab, params->ext_capab_len); |
| 3572 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 3573 | params->ext_capab_len, params->ext_capab)) |
| 3574 | goto fail; |
| 3575 | } |
| 3576 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3577 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3578 | if (params->aid) { |
| 3579 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3580 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 3581 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3582 | } else { |
| 3583 | /* |
| 3584 | * cfg80211 validates that AID is non-zero, so we have |
| 3585 | * to make this a non-zero value for the TDLS case where |
| 3586 | * a dummy STA entry is used for now. |
| 3587 | */ |
| 3588 | wpa_printf(MSG_DEBUG, " * aid=1 (TDLS workaround)"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3589 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 3590 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3591 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3592 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 3593 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3594 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 3595 | params->listen_interval)) |
| 3596 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3597 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 3598 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3599 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 3600 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3601 | } |
| 3602 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3603 | if (params->vht_opmode_enabled) { |
| 3604 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3605 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 3606 | params->vht_opmode)) |
| 3607 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3610 | if (params->supp_channels) { |
| 3611 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 3612 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3613 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 3614 | params->supp_channels_len, params->supp_channels)) |
| 3615 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
| 3618 | if (params->supp_oper_classes) { |
| 3619 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 3620 | params->supp_oper_classes, |
| 3621 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3622 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 3623 | params->supp_oper_classes_len, |
| 3624 | params->supp_oper_classes)) |
| 3625 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 3626 | } |
| 3627 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3628 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3629 | upd.set = sta_flags_nl80211(params->flags); |
| 3630 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3631 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 3632 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3633 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 3634 | goto fail; |
| 3635 | |
| 3636 | #ifdef CONFIG_MESH |
| 3637 | if (params->plink_state && |
| 3638 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 3639 | sta_plink_state_nl80211(params->plink_state))) |
| 3640 | goto fail; |
| 3641 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3642 | |
| 3643 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3644 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 3645 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3646 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3647 | if (!wme || |
| 3648 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 3649 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 3650 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 3651 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 3652 | WMM_QOSINFO_STA_SP_MASK)) |
| 3653 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3654 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3655 | } |
| 3656 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3657 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3658 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3659 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3660 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 3661 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 3662 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3663 | if (ret == -EEXIST) |
| 3664 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3665 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3666 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3667 | return ret; |
| 3668 | } |
| 3669 | |
| 3670 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3671 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 3672 | { |
| 3673 | #ifdef CONFIG_LIBNL3_ROUTE |
| 3674 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3675 | struct rtnl_neigh *rn; |
| 3676 | struct nl_addr *nl_addr; |
| 3677 | int err; |
| 3678 | |
| 3679 | rn = rtnl_neigh_alloc(); |
| 3680 | if (!rn) |
| 3681 | return; |
| 3682 | |
| 3683 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 3684 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 3685 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 3686 | if (!nl_addr) { |
| 3687 | rtnl_neigh_put(rn); |
| 3688 | return; |
| 3689 | } |
| 3690 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 3691 | |
| 3692 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 3693 | if (err < 0) { |
| 3694 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 3695 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 3696 | bss->ifindex, nl_geterror(err)); |
| 3697 | } else { |
| 3698 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 3699 | MACSTR, MAC2STR(addr)); |
| 3700 | } |
| 3701 | |
| 3702 | nl_addr_put(nl_addr); |
| 3703 | rtnl_neigh_put(rn); |
| 3704 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 3705 | } |
| 3706 | |
| 3707 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3708 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 3709 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3710 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3711 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3712 | struct nl_msg *msg; |
| 3713 | int ret; |
| 3714 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3715 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 3716 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3717 | (deauth == 0 && |
| 3718 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3719 | WLAN_FC_STYPE_DISASSOC)) || |
| 3720 | (deauth == 1 && |
| 3721 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 3722 | WLAN_FC_STYPE_DEAUTH)) || |
| 3723 | (reason_code && |
| 3724 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 3725 | nlmsg_free(msg); |
| 3726 | return -ENOBUFS; |
| 3727 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3728 | |
| 3729 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3730 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 3731 | " --> %d (%s)", |
| 3732 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3733 | |
| 3734 | if (drv->rtnl_sk) |
| 3735 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 3736 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3737 | if (ret == -ENOENT) |
| 3738 | return 0; |
| 3739 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3740 | } |
| 3741 | |
| 3742 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3743 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3744 | { |
| 3745 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3746 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3747 | |
| 3748 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 3749 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3750 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3751 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 3752 | struct wpa_driver_nl80211_data, list) |
| 3753 | del_ifidx(drv2, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3754 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3755 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3756 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 3757 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3758 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 3759 | } |
| 3760 | |
| 3761 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3762 | static const char * nl80211_iftype_str(enum nl80211_iftype mode) |
| 3763 | { |
| 3764 | switch (mode) { |
| 3765 | case NL80211_IFTYPE_ADHOC: |
| 3766 | return "ADHOC"; |
| 3767 | case NL80211_IFTYPE_STATION: |
| 3768 | return "STATION"; |
| 3769 | case NL80211_IFTYPE_AP: |
| 3770 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3771 | case NL80211_IFTYPE_AP_VLAN: |
| 3772 | return "AP_VLAN"; |
| 3773 | case NL80211_IFTYPE_WDS: |
| 3774 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3775 | case NL80211_IFTYPE_MONITOR: |
| 3776 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 3777 | case NL80211_IFTYPE_MESH_POINT: |
| 3778 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3779 | case NL80211_IFTYPE_P2P_CLIENT: |
| 3780 | return "P2P_CLIENT"; |
| 3781 | case NL80211_IFTYPE_P2P_GO: |
| 3782 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3783 | case NL80211_IFTYPE_P2P_DEVICE: |
| 3784 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3785 | default: |
| 3786 | return "unknown"; |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3791 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 3792 | const char *ifname, |
| 3793 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3794 | const u8 *addr, int wds, |
| 3795 | int (*handler)(struct nl_msg *, void *), |
| 3796 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3797 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3798 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3799 | int ifidx; |
| 3800 | int ret = -ENOBUFS; |
| 3801 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3802 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 3803 | iftype, nl80211_iftype_str(iftype)); |
| 3804 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3805 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 3806 | if (!msg || |
| 3807 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 3808 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 3809 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3810 | |
| 3811 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3812 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3813 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3814 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3815 | if (!flags || |
| 3816 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 3817 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3818 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3819 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3820 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3821 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 3822 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3823 | } |
| 3824 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3825 | /* |
| 3826 | * Tell cfg80211 that the interface belongs to the socket that created |
| 3827 | * it, and the interface should be deleted when the socket is closed. |
| 3828 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3829 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 3830 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3831 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3832 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3833 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3834 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3835 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3836 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3837 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 3838 | ifname, ret, strerror(-ret)); |
| 3839 | return ret; |
| 3840 | } |
| 3841 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3842 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 3843 | return 0; |
| 3844 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3845 | ifidx = if_nametoindex(ifname); |
| 3846 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 3847 | ifname, ifidx); |
| 3848 | |
| 3849 | if (ifidx <= 0) |
| 3850 | return -1; |
| 3851 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 3852 | /* |
| 3853 | * Some virtual interfaces need to process EAPOL packets and events on |
| 3854 | * the parent interface. This is used mainly with hostapd. |
| 3855 | */ |
| 3856 | if (drv->hostapd || |
| 3857 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 3858 | iftype == NL80211_IFTYPE_WDS || |
| 3859 | iftype == NL80211_IFTYPE_MONITOR) { |
| 3860 | /* start listening for EAPOL on this interface */ |
| 3861 | add_ifidx(drv, ifidx); |
| 3862 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3863 | |
| 3864 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3865 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3866 | nl80211_remove_iface(drv, ifidx); |
| 3867 | return -1; |
| 3868 | } |
| 3869 | |
| 3870 | return ifidx; |
| 3871 | } |
| 3872 | |
| 3873 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3874 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 3875 | const char *ifname, enum nl80211_iftype iftype, |
| 3876 | const u8 *addr, int wds, |
| 3877 | int (*handler)(struct nl_msg *, void *), |
| 3878 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3879 | { |
| 3880 | int ret; |
| 3881 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3882 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 3883 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3884 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3885 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3886 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3887 | if (use_existing) { |
| 3888 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 3889 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3890 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 3891 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 3892 | addr) < 0 && |
| 3893 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 3894 | ifname, 0) < 0 || |
| 3895 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 3896 | addr) < 0 || |
| 3897 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 3898 | ifname, 1) < 0)) |
| 3899 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3900 | return -ENFILE; |
| 3901 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3902 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 3903 | |
| 3904 | /* Try to remove the interface that was already there. */ |
| 3905 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 3906 | |
| 3907 | /* Try to create the interface again */ |
| 3908 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3909 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3910 | } |
| 3911 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3912 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 3913 | wpa_printf(MSG_DEBUG, |
| 3914 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 3915 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3916 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 3917 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3918 | |
| 3919 | return ret; |
| 3920 | } |
| 3921 | |
| 3922 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3923 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 3924 | { |
| 3925 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3926 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3927 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 3928 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3929 | |
| 3930 | /* |
| 3931 | * Disable Probe Request reporting unless we need it in this way for |
| 3932 | * devices that include the AP SME, in the other case (unless using |
| 3933 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 3934 | */ |
| 3935 | if (!drv->device_ap_sme) |
| 3936 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 3937 | |
| 3938 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 3939 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 3940 | return -1; |
| 3941 | |
| 3942 | if (drv->device_ap_sme && !drv->use_monitor) |
| 3943 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
| 3944 | return -1; |
| 3945 | |
| 3946 | if (!drv->device_ap_sme && drv->use_monitor && |
| 3947 | nl80211_create_monitor_interface(drv) && |
| 3948 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3949 | return -1; |
| 3950 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3951 | if (drv->device_ap_sme && |
| 3952 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 3953 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 3954 | "Probe Request frame reporting in AP mode"); |
| 3955 | /* Try to survive without this */ |
| 3956 | } |
| 3957 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3958 | return 0; |
| 3959 | } |
| 3960 | |
| 3961 | |
| 3962 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 3963 | { |
| 3964 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3965 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3966 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 3967 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3968 | if (drv->device_ap_sme) { |
| 3969 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 3970 | if (!drv->use_monitor) |
| 3971 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 3972 | } else if (drv->use_monitor) |
| 3973 | nl80211_remove_monitor_interface(drv); |
| 3974 | else |
| 3975 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 3976 | |
| 3977 | bss->beacon_set = 0; |
| 3978 | } |
| 3979 | |
| 3980 | |
| 3981 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 3982 | const u8 *addr, const u8 *data, |
| 3983 | size_t data_len) |
| 3984 | { |
| 3985 | struct sockaddr_ll ll; |
| 3986 | int ret; |
| 3987 | |
| 3988 | if (bss->drv->eapol_tx_sock < 0) { |
| 3989 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 3990 | return -1; |
| 3991 | } |
| 3992 | |
| 3993 | os_memset(&ll, 0, sizeof(ll)); |
| 3994 | ll.sll_family = AF_PACKET; |
| 3995 | ll.sll_ifindex = bss->ifindex; |
| 3996 | ll.sll_protocol = htons(ETH_P_PAE); |
| 3997 | ll.sll_halen = ETH_ALEN; |
| 3998 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 3999 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4000 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4001 | if (ret < 0) |
| 4002 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4003 | strerror(errno)); |
| 4004 | |
| 4005 | return ret; |
| 4006 | } |
| 4007 | |
| 4008 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4009 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4010 | |
| 4011 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4012 | void *priv, const u8 *addr, const u8 *data, |
| 4013 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4014 | { |
| 4015 | struct i802_bss *bss = priv; |
| 4016 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4017 | struct ieee80211_hdr *hdr; |
| 4018 | size_t len; |
| 4019 | u8 *pos; |
| 4020 | int res; |
| 4021 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4022 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4023 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4024 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4025 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4026 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4027 | data_len; |
| 4028 | hdr = os_zalloc(len); |
| 4029 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4030 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4031 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4032 | return -1; |
| 4033 | } |
| 4034 | |
| 4035 | hdr->frame_control = |
| 4036 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4037 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4038 | if (encrypt) |
| 4039 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4040 | if (qos) { |
| 4041 | hdr->frame_control |= |
| 4042 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4043 | } |
| 4044 | |
| 4045 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4046 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4047 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4048 | pos = (u8 *) (hdr + 1); |
| 4049 | |
| 4050 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4051 | /* Set highest priority in QoS header */ |
| 4052 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4053 | pos[1] = 0; |
| 4054 | pos += 2; |
| 4055 | } |
| 4056 | |
| 4057 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4058 | pos += sizeof(rfc1042_header); |
| 4059 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4060 | pos += 2; |
| 4061 | memcpy(pos, data, data_len); |
| 4062 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4063 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
| 4064 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4065 | if (res < 0) { |
| 4066 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4067 | "failed: %d (%s)", |
| 4068 | (unsigned long) len, errno, strerror(errno)); |
| 4069 | } |
| 4070 | os_free(hdr); |
| 4071 | |
| 4072 | return res; |
| 4073 | } |
| 4074 | |
| 4075 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4076 | static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr, |
| 4077 | int total_flags, |
| 4078 | int flags_or, int flags_and) |
| 4079 | { |
| 4080 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4081 | struct nl_msg *msg; |
| 4082 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4083 | struct nl80211_sta_flag_update upd; |
| 4084 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4085 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4086 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4087 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4088 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4089 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4090 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4091 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4092 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4093 | |
| 4094 | /* |
| 4095 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4096 | * can be removed eventually. |
| 4097 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4098 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4099 | if (!flags || |
| 4100 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4101 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4102 | ((total_flags & WPA_STA_WMM) && |
| 4103 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4104 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4105 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4106 | ((total_flags & WPA_STA_MFP) && |
| 4107 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4108 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4109 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4110 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4111 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4112 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4113 | |
| 4114 | os_memset(&upd, 0, sizeof(upd)); |
| 4115 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4116 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4117 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4118 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4119 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4120 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4121 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4122 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | return -ENOBUFS; |
| 4124 | } |
| 4125 | |
| 4126 | |
| 4127 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4128 | struct wpa_driver_associate_params *params) |
| 4129 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4130 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4131 | |
| 4132 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4133 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4134 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4135 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4136 | } else |
| 4137 | nlmode = NL80211_IFTYPE_AP; |
| 4138 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4139 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4140 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4141 | nl80211_remove_monitor_interface(drv); |
| 4142 | return -1; |
| 4143 | } |
| 4144 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4145 | if (nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4146 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4147 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4148 | nl80211_remove_monitor_interface(drv); |
| 4149 | return -1; |
| 4150 | } |
| 4151 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4152 | return 0; |
| 4153 | } |
| 4154 | |
| 4155 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4156 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4157 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4158 | { |
| 4159 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4160 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4161 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4162 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4163 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4164 | if (ret) { |
| 4165 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4166 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4167 | } else { |
| 4168 | wpa_printf(MSG_DEBUG, |
| 4169 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4172 | if (reset_mode && |
| 4173 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4174 | NL80211_IFTYPE_STATION)) { |
| 4175 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4176 | "station mode"); |
| 4177 | } |
| 4178 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4179 | return ret; |
| 4180 | } |
| 4181 | |
| 4182 | |
| 4183 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4184 | struct wpa_driver_associate_params *params) |
| 4185 | { |
| 4186 | struct nl_msg *msg; |
| 4187 | int ret = -1; |
| 4188 | int count = 0; |
| 4189 | |
| 4190 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4191 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4192 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4194 | "IBSS mode"); |
| 4195 | return -1; |
| 4196 | } |
| 4197 | |
| 4198 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4199 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4200 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4201 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4202 | |
| 4203 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4204 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4205 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4206 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4207 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4208 | drv->ssid_len = params->ssid_len; |
| 4209 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4210 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
| 4211 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", params->freq.ht_enabled); |
| 4212 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4213 | params->freq.sec_channel_offset); |
| 4214 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", params->freq.vht_enabled); |
| 4215 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", params->freq.center_freq1); |
| 4216 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", params->freq.center_freq2); |
| 4217 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", params->freq.bandwidth); |
| 4218 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4219 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4220 | |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4221 | if (params->beacon_int > 0) { |
| 4222 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4223 | if (nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 4224 | params->beacon_int)) |
| 4225 | goto fail; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 4226 | } |
| 4227 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4228 | ret = nl80211_set_conn_keys(params, msg); |
| 4229 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4230 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4231 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4232 | if (params->bssid && params->fixed_bssid) { |
| 4233 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4234 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4235 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4236 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4237 | } |
| 4238 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4239 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4240 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4241 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4242 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4243 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4244 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4245 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4246 | } |
| 4247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4248 | if (params->wpa_ie) { |
| 4249 | wpa_hexdump(MSG_DEBUG, |
| 4250 | " * Extra IEs for Beacon/Probe Response frames", |
| 4251 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4252 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4253 | params->wpa_ie)) |
| 4254 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4255 | } |
| 4256 | |
| 4257 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4258 | msg = NULL; |
| 4259 | if (ret) { |
| 4260 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4261 | ret, strerror(-ret)); |
| 4262 | count++; |
| 4263 | if (ret == -EALREADY && count == 1) { |
| 4264 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4265 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4266 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4267 | nlmsg_free(msg); |
| 4268 | goto retry; |
| 4269 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4270 | } else { |
| 4271 | wpa_printf(MSG_DEBUG, |
| 4272 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4273 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4274 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4275 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4276 | nlmsg_free(msg); |
| 4277 | return ret; |
| 4278 | } |
| 4279 | |
| 4280 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4281 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4282 | struct wpa_driver_associate_params *params, |
| 4283 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4284 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4285 | if (params->bssid) { |
| 4286 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4287 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4288 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4289 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4290 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4291 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4292 | if (params->bssid_hint) { |
| 4293 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4294 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4295 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4296 | params->bssid_hint)) |
| 4297 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4298 | } |
| 4299 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4300 | if (params->freq.freq) { |
| 4301 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4302 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4303 | params->freq.freq)) |
| 4304 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4305 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4306 | } else |
| 4307 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4308 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4309 | if (params->freq_hint) { |
| 4310 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4311 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4312 | params->freq_hint)) |
| 4313 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4314 | } |
| 4315 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4316 | if (params->bg_scan_period >= 0) { |
| 4317 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4318 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4319 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4320 | params->bg_scan_period)) |
| 4321 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4322 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4323 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4324 | if (params->ssid) { |
| 4325 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4326 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4327 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4328 | params->ssid)) |
| 4329 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4330 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4331 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4332 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4333 | drv->ssid_len = params->ssid_len; |
| 4334 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4335 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4336 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4337 | if (params->wpa_ie && |
| 4338 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4339 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4340 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4341 | if (params->wpa_proto) { |
| 4342 | enum nl80211_wpa_versions ver = 0; |
| 4343 | |
| 4344 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4345 | ver |= NL80211_WPA_VERSION_1; |
| 4346 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4347 | ver |= NL80211_WPA_VERSION_2; |
| 4348 | |
| 4349 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4350 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4351 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4355 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4356 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4357 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4358 | cipher)) |
| 4359 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4360 | } |
| 4361 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4362 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4363 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4364 | /* |
| 4365 | * This is likely to work even though many drivers do not |
| 4366 | * advertise support for operations without GTK. |
| 4367 | */ |
| 4368 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4369 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4370 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4371 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4372 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4373 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4374 | } |
| 4375 | |
| 4376 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4377 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4378 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4379 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4380 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4381 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4382 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4383 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4384 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4385 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4386 | |
| 4387 | switch (params->key_mgmt_suite) { |
| 4388 | case WPA_KEY_MGMT_CCKM: |
| 4389 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4390 | break; |
| 4391 | case WPA_KEY_MGMT_IEEE8021X: |
| 4392 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4393 | break; |
| 4394 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4395 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4396 | break; |
| 4397 | case WPA_KEY_MGMT_FT_PSK: |
| 4398 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4399 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4400 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4401 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4402 | break; |
| 4403 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4404 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4405 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4406 | case WPA_KEY_MGMT_OSEN: |
| 4407 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4408 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4409 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4410 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4411 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4412 | case WPA_KEY_MGMT_PSK: |
| 4413 | default: |
| 4414 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4415 | break; |
| 4416 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4417 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4418 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4419 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4420 | } |
| 4421 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4422 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4423 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4424 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4425 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4426 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4427 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4428 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4429 | if (params->rrm_used) { |
| 4430 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
| 4431 | if (!(drv_rrm_flags & |
| 4432 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) || |
| 4433 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) || |
| 4434 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4435 | return -1; |
| 4436 | } |
| 4437 | |
| 4438 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4439 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4440 | |
| 4441 | if (params->htcaps && params->htcaps_mask) { |
| 4442 | int sz = sizeof(struct ieee80211_ht_capabilities); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 4443 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 4444 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4445 | params->htcaps_mask, sz); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4446 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4447 | params->htcaps) || |
| 4448 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4449 | params->htcaps_mask)) |
| 4450 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | #ifdef CONFIG_VHT_OVERRIDES |
| 4454 | if (params->disable_vht) { |
| 4455 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4456 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4457 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4461 | int sz = sizeof(struct ieee80211_vht_capabilities); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 4462 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 4463 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4464 | params->vhtcaps_mask, sz); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4465 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4466 | params->vhtcaps) || |
| 4467 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4468 | params->vhtcaps_mask)) |
| 4469 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4470 | } |
| 4471 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4472 | |
| 4473 | if (params->p2p) |
| 4474 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4475 | |
| 4476 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4477 | } |
| 4478 | |
| 4479 | |
| 4480 | static int wpa_driver_nl80211_try_connect( |
| 4481 | struct wpa_driver_nl80211_data *drv, |
| 4482 | struct wpa_driver_associate_params *params) |
| 4483 | { |
| 4484 | struct nl_msg *msg; |
| 4485 | enum nl80211_auth_type type; |
| 4486 | int ret; |
| 4487 | int algs; |
| 4488 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4489 | if (params->req_key_mgmt_offload && params->psk && |
| 4490 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4491 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 4492 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 4493 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 4494 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 4495 | if (ret) |
| 4496 | return ret; |
| 4497 | } |
| 4498 | |
| 4499 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 4500 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4501 | if (!msg) |
| 4502 | return -1; |
| 4503 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4504 | ret = nl80211_connect_common(drv, params, msg); |
| 4505 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4506 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4507 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4508 | algs = 0; |
| 4509 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4510 | algs++; |
| 4511 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4512 | algs++; |
| 4513 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4514 | algs++; |
| 4515 | if (algs > 1) { |
| 4516 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 4517 | "selection"); |
| 4518 | goto skip_auth_type; |
| 4519 | } |
| 4520 | |
| 4521 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 4522 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 4523 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 4524 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 4525 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 4526 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 4527 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 4528 | type = NL80211_AUTHTYPE_FT; |
| 4529 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4530 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4531 | |
| 4532 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4533 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 4534 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4535 | |
| 4536 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4537 | ret = nl80211_set_conn_keys(params, msg); |
| 4538 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4539 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4540 | |
| 4541 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4542 | msg = NULL; |
| 4543 | if (ret) { |
| 4544 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 4545 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4546 | } else { |
| 4547 | wpa_printf(MSG_DEBUG, |
| 4548 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4549 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4550 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4551 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4552 | nlmsg_free(msg); |
| 4553 | return ret; |
| 4554 | |
| 4555 | } |
| 4556 | |
| 4557 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4558 | static int wpa_driver_nl80211_connect( |
| 4559 | struct wpa_driver_nl80211_data *drv, |
| 4560 | struct wpa_driver_associate_params *params) |
| 4561 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 4562 | int ret; |
| 4563 | |
| 4564 | /* Store the connection attempted bssid for future use */ |
| 4565 | if (params->bssid) |
| 4566 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 4567 | else |
| 4568 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 4569 | |
| 4570 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4571 | if (ret == -EALREADY) { |
| 4572 | /* |
| 4573 | * cfg80211 does not currently accept new connections if |
| 4574 | * we are already connected. As a workaround, force |
| 4575 | * disconnection and try again. |
| 4576 | */ |
| 4577 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 4578 | "disconnecting before reassociation " |
| 4579 | "attempt"); |
| 4580 | if (wpa_driver_nl80211_disconnect( |
| 4581 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 4582 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4583 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 4584 | } |
| 4585 | return ret; |
| 4586 | } |
| 4587 | |
| 4588 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4589 | static int wpa_driver_nl80211_associate( |
| 4590 | void *priv, struct wpa_driver_associate_params *params) |
| 4591 | { |
| 4592 | struct i802_bss *bss = priv; |
| 4593 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4594 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4595 | struct nl_msg *msg; |
| 4596 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4597 | nl80211_unmask_11b_rates(bss); |
| 4598 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4599 | if (params->mode == IEEE80211_MODE_AP) |
| 4600 | return wpa_driver_nl80211_ap(drv, params); |
| 4601 | |
| 4602 | if (params->mode == IEEE80211_MODE_IBSS) |
| 4603 | return wpa_driver_nl80211_ibss(drv, params); |
| 4604 | |
| 4605 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4606 | enum nl80211_iftype nlmode = params->p2p ? |
| 4607 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 4608 | |
| 4609 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4610 | return -1; |
| 4611 | return wpa_driver_nl80211_connect(drv, params); |
| 4612 | } |
| 4613 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4614 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4615 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4616 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 4617 | drv->ifindex); |
| 4618 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4619 | if (!msg) |
| 4620 | return -1; |
| 4621 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4622 | ret = nl80211_connect_common(drv, params, msg); |
| 4623 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4624 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4625 | |
| 4626 | if (params->prev_bssid) { |
| 4627 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4628 | MAC2STR(params->prev_bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4629 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 4630 | params->prev_bssid)) |
| 4631 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4632 | } |
| 4633 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4634 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4635 | msg = NULL; |
| 4636 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4637 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 4638 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 4639 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4640 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4641 | } else { |
| 4642 | wpa_printf(MSG_DEBUG, |
| 4643 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4644 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4645 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4646 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4647 | nlmsg_free(msg); |
| 4648 | return ret; |
| 4649 | } |
| 4650 | |
| 4651 | |
| 4652 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4653 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4654 | { |
| 4655 | struct nl_msg *msg; |
| 4656 | int ret = -ENOBUFS; |
| 4657 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4658 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 4659 | ifindex, mode, nl80211_iftype_str(mode)); |
| 4660 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4661 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 4662 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 4663 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4664 | |
| 4665 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4666 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4667 | if (!ret) |
| 4668 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4669 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4670 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4671 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 4672 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 4673 | return ret; |
| 4674 | } |
| 4675 | |
| 4676 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4677 | static int wpa_driver_nl80211_set_mode_impl( |
| 4678 | struct i802_bss *bss, |
| 4679 | enum nl80211_iftype nlmode, |
| 4680 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4681 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4682 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4683 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4684 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4685 | int was_ap = is_ap_interface(drv->nlmode); |
| 4686 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4687 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4688 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4689 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4690 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 4691 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4692 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4693 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4694 | drv->nlmode = nlmode; |
| 4695 | ret = 0; |
| 4696 | goto done; |
| 4697 | } |
| 4698 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4699 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4700 | return -1; |
| 4701 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4702 | if (nlmode == drv->nlmode) { |
| 4703 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 4704 | "requested mode - ignore error"); |
| 4705 | ret = 0; |
| 4706 | goto done; /* Already in the requested mode */ |
| 4707 | } |
| 4708 | |
| 4709 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 4710 | * take the device down, try to set the mode again, and bring the |
| 4711 | * device back up. |
| 4712 | */ |
| 4713 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 4714 | "interface down"); |
| 4715 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4716 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4717 | if (res == -EACCES || res == -ENODEV) |
| 4718 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4719 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4720 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 4721 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4722 | os_sleep(0, 100000); |
| 4723 | continue; |
| 4724 | } |
| 4725 | |
| 4726 | /* |
| 4727 | * Setting the mode will fail for some drivers if the phy is |
| 4728 | * on a frequency that the mode is disallowed in. |
| 4729 | */ |
| 4730 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4731 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4732 | if (res) { |
| 4733 | wpa_printf(MSG_DEBUG, |
| 4734 | "nl80211: Failed to set frequency on interface"); |
| 4735 | } |
| 4736 | } |
| 4737 | |
| 4738 | /* Try to set the mode again while the interface is down */ |
| 4739 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 4740 | if (mode_switch_res == -EBUSY) { |
| 4741 | wpa_printf(MSG_DEBUG, |
| 4742 | "nl80211: Delaying mode set while interface going down"); |
| 4743 | os_sleep(0, 100000); |
| 4744 | continue; |
| 4745 | } |
| 4746 | ret = mode_switch_res; |
| 4747 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4748 | } |
| 4749 | |
| 4750 | if (!ret) { |
| 4751 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 4752 | "interface is down"); |
| 4753 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4754 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4757 | /* Bring the interface back up */ |
| 4758 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 4759 | if (res != 0) { |
| 4760 | wpa_printf(MSG_DEBUG, |
| 4761 | "nl80211: Failed to set interface up after switching mode"); |
| 4762 | ret = -1; |
| 4763 | } |
| 4764 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4765 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4766 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4767 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 4768 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4769 | return ret; |
| 4770 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4771 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4772 | if (is_p2p_net_interface(nlmode)) { |
| 4773 | wpa_printf(MSG_DEBUG, |
| 4774 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 4775 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4776 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4777 | } else if (drv->disabled_11b_rates) { |
| 4778 | wpa_printf(MSG_DEBUG, |
| 4779 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 4780 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4781 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4782 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4783 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4784 | if (is_ap_interface(nlmode)) { |
| 4785 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 4786 | /* Setup additional AP mode functionality if needed */ |
| 4787 | if (nl80211_setup_ap(bss)) |
| 4788 | return -1; |
| 4789 | } else if (was_ap) { |
| 4790 | /* Remove additional AP mode functionality */ |
| 4791 | nl80211_teardown_ap(bss); |
| 4792 | } else { |
| 4793 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 4794 | } |
| 4795 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4796 | if (is_mesh_interface(nlmode) && |
| 4797 | nl80211_mgmt_subscribe_mesh(bss)) |
| 4798 | return -1; |
| 4799 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4800 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4801 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4802 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 4803 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 4804 | "frame processing - ignore for now"); |
| 4805 | |
| 4806 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4810 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 4811 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4812 | { |
| 4813 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 4814 | } |
| 4815 | |
| 4816 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4817 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 4818 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4819 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4820 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4821 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
| 4824 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4825 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 4826 | struct wpa_driver_capa *capa) |
| 4827 | { |
| 4828 | struct i802_bss *bss = priv; |
| 4829 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 4830 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4831 | if (!drv->has_capability) |
| 4832 | return -1; |
| 4833 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 4834 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 4835 | capa->extended_capa = drv->extended_capa; |
| 4836 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 4837 | capa->extended_capa_len = drv->extended_capa_len; |
| 4838 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4839 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4840 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4841 | } |
| 4842 | |
| 4843 | |
| 4844 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 4845 | { |
| 4846 | struct i802_bss *bss = priv; |
| 4847 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4848 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4849 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 4850 | bss->ifname, drv->operstate, state, |
| 4851 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4852 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4853 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4854 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 4855 | } |
| 4856 | |
| 4857 | |
| 4858 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 4859 | { |
| 4860 | struct i802_bss *bss = priv; |
| 4861 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4862 | struct nl_msg *msg; |
| 4863 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4864 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4865 | |
| 4866 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 4867 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 4868 | return 0; |
| 4869 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4870 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4871 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 4872 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 4873 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4874 | os_memset(&upd, 0, sizeof(upd)); |
| 4875 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4876 | if (authorized) |
| 4877 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4878 | |
| 4879 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4880 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 4881 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 4882 | nlmsg_free(msg); |
| 4883 | return -ENOBUFS; |
| 4884 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4885 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4886 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4887 | if (!ret) |
| 4888 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4889 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 4890 | ret, strerror(-ret)); |
| 4891 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4892 | } |
| 4893 | |
| 4894 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4895 | /* Set kernel driver on given frequency (MHz) */ |
| 4896 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4897 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4898 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4899 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4900 | } |
| 4901 | |
| 4902 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4903 | static inline int min_int(int a, int b) |
| 4904 | { |
| 4905 | if (a < b) |
| 4906 | return a; |
| 4907 | return b; |
| 4908 | } |
| 4909 | |
| 4910 | |
| 4911 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 4912 | { |
| 4913 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 4914 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 4915 | |
| 4916 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 4917 | genlmsg_attrlen(gnlh, 0), NULL); |
| 4918 | |
| 4919 | /* |
| 4920 | * TODO: validate the key index and mac address! |
| 4921 | * Otherwise, there's a race condition as soon as |
| 4922 | * the kernel starts sending key notifications. |
| 4923 | */ |
| 4924 | |
| 4925 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 4926 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 4927 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 4928 | return NL_SKIP; |
| 4929 | } |
| 4930 | |
| 4931 | |
| 4932 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 4933 | int idx, u8 *seq) |
| 4934 | { |
| 4935 | struct i802_bss *bss = priv; |
| 4936 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4937 | struct nl_msg *msg; |
| 4938 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4939 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 4940 | NL80211_CMD_GET_KEY); |
| 4941 | if (!msg || |
| 4942 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 4943 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 4944 | nlmsg_free(msg); |
| 4945 | return -ENOBUFS; |
| 4946 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4947 | |
| 4948 | memset(seq, 0, 6); |
| 4949 | |
| 4950 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4951 | } |
| 4952 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4953 | |
| 4954 | static int i802_set_rts(void *priv, int rts) |
| 4955 | { |
| 4956 | struct i802_bss *bss = priv; |
| 4957 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4958 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4959 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4960 | u32 val; |
| 4961 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4962 | if (rts >= 2347) |
| 4963 | val = (u32) -1; |
| 4964 | else |
| 4965 | val = rts; |
| 4966 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4967 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 4968 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 4969 | nlmsg_free(msg); |
| 4970 | return -ENOBUFS; |
| 4971 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | |
| 4973 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4974 | if (!ret) |
| 4975 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4976 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 4977 | "%d (%s)", rts, ret, strerror(-ret)); |
| 4978 | return ret; |
| 4979 | } |
| 4980 | |
| 4981 | |
| 4982 | static int i802_set_frag(void *priv, int frag) |
| 4983 | { |
| 4984 | struct i802_bss *bss = priv; |
| 4985 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4986 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4987 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4988 | u32 val; |
| 4989 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4990 | if (frag >= 2346) |
| 4991 | val = (u32) -1; |
| 4992 | else |
| 4993 | val = frag; |
| 4994 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 4995 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 4996 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 4997 | nlmsg_free(msg); |
| 4998 | return -ENOBUFS; |
| 4999 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5000 | |
| 5001 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5002 | if (!ret) |
| 5003 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5004 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5005 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5006 | return ret; |
| 5007 | } |
| 5008 | |
| 5009 | |
| 5010 | static int i802_flush(void *priv) |
| 5011 | { |
| 5012 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5013 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5014 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5015 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5016 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5017 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5018 | |
| 5019 | /* |
| 5020 | * XXX: FIX! this needs to flush all VLANs too |
| 5021 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5022 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5023 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5024 | if (res) { |
| 5025 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5026 | "(%s)", res, strerror(-res)); |
| 5027 | } |
| 5028 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5029 | } |
| 5030 | |
| 5031 | |
| 5032 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5033 | { |
| 5034 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5035 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5036 | struct hostap_sta_driver_data *data = arg; |
| 5037 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5038 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5039 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5040 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5041 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5042 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5043 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5044 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5045 | }; |
| 5046 | |
| 5047 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5048 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5049 | |
| 5050 | /* |
| 5051 | * TODO: validate the interface and mac address! |
| 5052 | * Otherwise, there's a race condition as soon as |
| 5053 | * the kernel starts sending station notifications. |
| 5054 | */ |
| 5055 | |
| 5056 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5057 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5058 | return NL_SKIP; |
| 5059 | } |
| 5060 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5061 | tb[NL80211_ATTR_STA_INFO], |
| 5062 | stats_policy)) { |
| 5063 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5064 | return NL_SKIP; |
| 5065 | } |
| 5066 | |
| 5067 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5068 | data->inactive_msec = |
| 5069 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
| 5070 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5071 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5072 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5073 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
| 5074 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5075 | data->rx_packets = |
| 5076 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5077 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5078 | data->tx_packets = |
| 5079 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5080 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5081 | data->tx_retry_failed = |
| 5082 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5083 | |
| 5084 | return NL_SKIP; |
| 5085 | } |
| 5086 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5087 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5088 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5089 | const u8 *addr) |
| 5090 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5091 | struct nl_msg *msg; |
| 5092 | |
| 5093 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5094 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5095 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5096 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5097 | nlmsg_free(msg); |
| 5098 | return -ENOBUFS; |
| 5099 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5100 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5101 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5102 | } |
| 5103 | |
| 5104 | |
| 5105 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5106 | int cw_min, int cw_max, int burst_time) |
| 5107 | { |
| 5108 | struct i802_bss *bss = priv; |
| 5109 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5110 | struct nl_msg *msg; |
| 5111 | struct nlattr *txq, *params; |
| 5112 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5113 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5114 | if (!msg) |
| 5115 | return -1; |
| 5116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5117 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5118 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5119 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | |
| 5121 | /* We are only sending parameters for a single TXQ at a time */ |
| 5122 | params = nla_nest_start(msg, 1); |
| 5123 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5124 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5125 | |
| 5126 | switch (queue) { |
| 5127 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5128 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5129 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5130 | break; |
| 5131 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5132 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5133 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5134 | break; |
| 5135 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5136 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5137 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5138 | break; |
| 5139 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5140 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5141 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5142 | break; |
| 5143 | } |
| 5144 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5145 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5146 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5147 | (burst_time * 100 + 16) / 32) || |
| 5148 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5149 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5150 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5151 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5152 | |
| 5153 | nla_nest_end(msg, params); |
| 5154 | |
| 5155 | nla_nest_end(msg, txq); |
| 5156 | |
| 5157 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5158 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5159 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5160 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5161 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5162 | return -1; |
| 5163 | } |
| 5164 | |
| 5165 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5166 | static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5167 | const char *ifname, int vlan_id) |
| 5168 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5169 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5170 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5171 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5172 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5173 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5174 | ", ifname=%s[%d], vlan_id=%d)", |
| 5175 | bss->ifname, if_nametoindex(bss->ifname), |
| 5176 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5177 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5178 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5179 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5180 | nlmsg_free(msg); |
| 5181 | return -ENOBUFS; |
| 5182 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5183 | |
| 5184 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5185 | if (ret < 0) { |
| 5186 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5187 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5188 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5189 | strerror(-ret)); |
| 5190 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5191 | return ret; |
| 5192 | } |
| 5193 | |
| 5194 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5195 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5196 | { |
| 5197 | struct hostap_sta_driver_data data; |
| 5198 | int ret; |
| 5199 | |
| 5200 | data.inactive_msec = (unsigned long) -1; |
| 5201 | ret = i802_read_sta_data(priv, &data, addr); |
| 5202 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5203 | return -1; |
| 5204 | return data.inactive_msec / 1000; |
| 5205 | } |
| 5206 | |
| 5207 | |
| 5208 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5209 | { |
| 5210 | #if 0 |
| 5211 | /* TODO */ |
| 5212 | #endif |
| 5213 | return 0; |
| 5214 | } |
| 5215 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5216 | |
| 5217 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5218 | int reason) |
| 5219 | { |
| 5220 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5222 | struct ieee80211_mgmt mgmt; |
| 5223 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5224 | if (is_mesh_interface(drv->nlmode)) |
| 5225 | return -1; |
| 5226 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5227 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5228 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5229 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5230 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5231 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5232 | WLAN_FC_STYPE_DEAUTH); |
| 5233 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5234 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5235 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5236 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5237 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5238 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5239 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
| 5240 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | |
| 5244 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5245 | int reason) |
| 5246 | { |
| 5247 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5248 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5249 | struct ieee80211_mgmt mgmt; |
| 5250 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5251 | if (is_mesh_interface(drv->nlmode)) |
| 5252 | return -1; |
| 5253 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5254 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5255 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5256 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5257 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5258 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5259 | WLAN_FC_STYPE_DISASSOC); |
| 5260 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5261 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5262 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5263 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5264 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5265 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5266 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
| 5267 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5268 | } |
| 5269 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5270 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5271 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5272 | { |
| 5273 | char buf[200], *pos, *end; |
| 5274 | int i, res; |
| 5275 | |
| 5276 | pos = buf; |
| 5277 | end = pos + sizeof(buf); |
| 5278 | |
| 5279 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5280 | if (!drv->if_indices[i]) |
| 5281 | continue; |
| 5282 | res = os_snprintf(pos, end - pos, " %d", drv->if_indices[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5283 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5284 | break; |
| 5285 | pos += res; |
| 5286 | } |
| 5287 | *pos = '\0'; |
| 5288 | |
| 5289 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5290 | drv->num_if_indices, buf); |
| 5291 | } |
| 5292 | |
| 5293 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5294 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5295 | { |
| 5296 | int i; |
| 5297 | int *old; |
| 5298 | |
| 5299 | wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d", |
| 5300 | ifidx); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5301 | if (have_ifidx(drv, ifidx)) { |
| 5302 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5303 | ifidx); |
| 5304 | return; |
| 5305 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5306 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5307 | if (drv->if_indices[i] == 0) { |
| 5308 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5309 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5310 | return; |
| 5311 | } |
| 5312 | } |
| 5313 | |
| 5314 | if (drv->if_indices != drv->default_if_indices) |
| 5315 | old = drv->if_indices; |
| 5316 | else |
| 5317 | old = NULL; |
| 5318 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5319 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5320 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5321 | if (!drv->if_indices) { |
| 5322 | if (!old) |
| 5323 | drv->if_indices = drv->default_if_indices; |
| 5324 | else |
| 5325 | drv->if_indices = old; |
| 5326 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5327 | "interfaces"); |
| 5328 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5329 | return; |
| 5330 | } else if (!old) |
| 5331 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5332 | sizeof(drv->default_if_indices)); |
| 5333 | drv->if_indices[drv->num_if_indices] = ifidx; |
| 5334 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5335 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5336 | } |
| 5337 | |
| 5338 | |
| 5339 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5340 | { |
| 5341 | int i; |
| 5342 | |
| 5343 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5344 | if (drv->if_indices[i] == ifidx) { |
| 5345 | drv->if_indices[i] = 0; |
| 5346 | break; |
| 5347 | } |
| 5348 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5349 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | |
| 5353 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx) |
| 5354 | { |
| 5355 | int i; |
| 5356 | |
| 5357 | for (i = 0; i < drv->num_if_indices; i++) |
| 5358 | if (drv->if_indices[i] == ifidx) |
| 5359 | return 1; |
| 5360 | |
| 5361 | return 0; |
| 5362 | } |
| 5363 | |
| 5364 | |
| 5365 | static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val, |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5366 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5367 | { |
| 5368 | struct i802_bss *bss = priv; |
| 5369 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5370 | char name[IFNAMSIZ + 1]; |
| 5371 | |
| 5372 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5373 | if (ifname_wds) |
| 5374 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5375 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5376 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5377 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5378 | if (val) { |
| 5379 | if (!if_nametoindex(name)) { |
| 5380 | if (nl80211_create_iface(drv, name, |
| 5381 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5382 | bss->addr, 1, NULL, NULL, 0) < |
| 5383 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5384 | return -1; |
| 5385 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5386 | linux_br_add_if(drv->global->ioctl_sock, |
| 5387 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5388 | return -1; |
| 5389 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5390 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5391 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5392 | "interface %s up", name); |
| 5393 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5394 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5395 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5396 | if (bridge_ifname) |
| 5397 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5398 | name); |
| 5399 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5400 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5401 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5402 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | |
| 5407 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 5408 | { |
| 5409 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 5410 | struct sockaddr_ll lladdr; |
| 5411 | unsigned char buf[3000]; |
| 5412 | int len; |
| 5413 | socklen_t fromlen = sizeof(lladdr); |
| 5414 | |
| 5415 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 5416 | (struct sockaddr *)&lladdr, &fromlen); |
| 5417 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5418 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 5419 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5420 | return; |
| 5421 | } |
| 5422 | |
| 5423 | if (have_ifidx(drv, lladdr.sll_ifindex)) |
| 5424 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 5425 | } |
| 5426 | |
| 5427 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5428 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 5429 | struct i802_bss *bss, |
| 5430 | const char *brname, const char *ifname) |
| 5431 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5432 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5433 | char in_br[IFNAMSIZ]; |
| 5434 | |
| 5435 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5436 | br_ifindex = if_nametoindex(brname); |
| 5437 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5438 | /* |
| 5439 | * Bridge was configured, but the bridge device does |
| 5440 | * not exist. Try to add it now. |
| 5441 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5442 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5443 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 5444 | "bridge interface %s: %s", |
| 5445 | brname, strerror(errno)); |
| 5446 | return -1; |
| 5447 | } |
| 5448 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5449 | br_ifindex = if_nametoindex(brname); |
| 5450 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5451 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5452 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5453 | |
| 5454 | if (linux_br_get(in_br, ifname) == 0) { |
| 5455 | if (os_strcmp(in_br, brname) == 0) |
| 5456 | return 0; /* already in the bridge */ |
| 5457 | |
| 5458 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 5459 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5460 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 5461 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5462 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 5463 | "remove interface %s from bridge " |
| 5464 | "%s: %s", |
| 5465 | ifname, brname, strerror(errno)); |
| 5466 | return -1; |
| 5467 | } |
| 5468 | } |
| 5469 | |
| 5470 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 5471 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5472 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5473 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 5474 | "into bridge %s: %s", |
| 5475 | ifname, brname, strerror(errno)); |
| 5476 | return -1; |
| 5477 | } |
| 5478 | bss->added_if_into_bridge = 1; |
| 5479 | |
| 5480 | return 0; |
| 5481 | } |
| 5482 | |
| 5483 | |
| 5484 | static void *i802_init(struct hostapd_data *hapd, |
| 5485 | struct wpa_init_params *params) |
| 5486 | { |
| 5487 | struct wpa_driver_nl80211_data *drv; |
| 5488 | struct i802_bss *bss; |
| 5489 | size_t i; |
| 5490 | char brname[IFNAMSIZ]; |
| 5491 | int ifindex, br_ifindex; |
| 5492 | int br_added = 0; |
| 5493 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5494 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 5495 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5496 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5497 | if (bss == NULL) |
| 5498 | return NULL; |
| 5499 | |
| 5500 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5502 | if (linux_br_get(brname, params->ifname) == 0) { |
| 5503 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
| 5504 | params->ifname, brname); |
| 5505 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5506 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5507 | } else { |
| 5508 | brname[0] = '\0'; |
| 5509 | br_ifindex = 0; |
| 5510 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5511 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5512 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5513 | for (i = 0; i < params->num_bridge; i++) { |
| 5514 | if (params->bridge[i]) { |
| 5515 | ifindex = if_nametoindex(params->bridge[i]); |
| 5516 | if (ifindex) |
| 5517 | add_ifidx(drv, ifindex); |
| 5518 | if (ifindex == br_ifindex) |
| 5519 | br_added = 1; |
| 5520 | } |
| 5521 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5522 | |
| 5523 | /* start listening for EAPOL on the default AP interface */ |
| 5524 | add_ifidx(drv, drv->ifindex); |
| 5525 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5526 | if (params->num_bridge && params->bridge[0]) { |
| 5527 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 5528 | params->ifname) < 0) |
| 5529 | goto failed; |
| 5530 | if (os_strcmp(params->bridge[0], brname) != 0) |
| 5531 | br_added = 1; |
| 5532 | } |
| 5533 | |
| 5534 | if (!br_added && br_ifindex && |
| 5535 | (params->num_bridge == 0 || !params->bridge[0])) |
| 5536 | add_ifidx(drv, br_ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5537 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5538 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5539 | if (bss->added_if_into_bridge) { |
| 5540 | drv->rtnl_sk = nl_socket_alloc(); |
| 5541 | if (drv->rtnl_sk == NULL) { |
| 5542 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 5543 | goto failed; |
| 5544 | } |
| 5545 | |
| 5546 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 5547 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 5548 | strerror(errno)); |
| 5549 | goto failed; |
| 5550 | } |
| 5551 | } |
| 5552 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5553 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5554 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 5555 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5556 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 5557 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5558 | goto failed; |
| 5559 | } |
| 5560 | |
| 5561 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 5562 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5563 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5564 | goto failed; |
| 5565 | } |
| 5566 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5567 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 5568 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5569 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5570 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5571 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5572 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 5573 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5574 | return bss; |
| 5575 | |
| 5576 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5577 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5578 | return NULL; |
| 5579 | } |
| 5580 | |
| 5581 | |
| 5582 | static void i802_deinit(void *priv) |
| 5583 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5584 | struct i802_bss *bss = priv; |
| 5585 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5586 | } |
| 5587 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5588 | |
| 5589 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 5590 | enum wpa_driver_if_type type) |
| 5591 | { |
| 5592 | switch (type) { |
| 5593 | case WPA_IF_STATION: |
| 5594 | return NL80211_IFTYPE_STATION; |
| 5595 | case WPA_IF_P2P_CLIENT: |
| 5596 | case WPA_IF_P2P_GROUP: |
| 5597 | return NL80211_IFTYPE_P2P_CLIENT; |
| 5598 | case WPA_IF_AP_VLAN: |
| 5599 | return NL80211_IFTYPE_AP_VLAN; |
| 5600 | case WPA_IF_AP_BSS: |
| 5601 | return NL80211_IFTYPE_AP; |
| 5602 | case WPA_IF_P2P_GO: |
| 5603 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5604 | case WPA_IF_P2P_DEVICE: |
| 5605 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5606 | case WPA_IF_MESH: |
| 5607 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5608 | } |
| 5609 | return -1; |
| 5610 | } |
| 5611 | |
| 5612 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5613 | #if defined(CONFIG_P2P) || defined(CONFIG_MESH) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5614 | |
| 5615 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 5616 | { |
| 5617 | struct wpa_driver_nl80211_data *drv; |
| 5618 | dl_list_for_each(drv, &global->interfaces, |
| 5619 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5620 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5621 | return 1; |
| 5622 | } |
| 5623 | return 0; |
| 5624 | } |
| 5625 | |
| 5626 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5627 | static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5628 | { |
| 5629 | unsigned int idx; |
| 5630 | |
| 5631 | if (!drv->global) |
| 5632 | return -1; |
| 5633 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5634 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5635 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5636 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5637 | new_addr[0] ^= idx << 2; |
| 5638 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 5639 | break; |
| 5640 | } |
| 5641 | if (idx == 64) |
| 5642 | return -1; |
| 5643 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5644 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5645 | MACSTR, MAC2STR(new_addr)); |
| 5646 | |
| 5647 | return 0; |
| 5648 | } |
| 5649 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5650 | #endif /* CONFIG_P2P || CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5651 | |
| 5652 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5653 | struct wdev_info { |
| 5654 | u64 wdev_id; |
| 5655 | int wdev_id_set; |
| 5656 | u8 macaddr[ETH_ALEN]; |
| 5657 | }; |
| 5658 | |
| 5659 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 5660 | { |
| 5661 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5662 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5663 | struct wdev_info *wi = arg; |
| 5664 | |
| 5665 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5666 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5667 | if (tb[NL80211_ATTR_WDEV]) { |
| 5668 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 5669 | wi->wdev_id_set = 1; |
| 5670 | } |
| 5671 | |
| 5672 | if (tb[NL80211_ATTR_MAC]) |
| 5673 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 5674 | ETH_ALEN); |
| 5675 | |
| 5676 | return NL_SKIP; |
| 5677 | } |
| 5678 | |
| 5679 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5680 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 5681 | const char *ifname, const u8 *addr, |
| 5682 | void *bss_ctx, void **drv_priv, |
| 5683 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5684 | const char *bridge, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5685 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5686 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5687 | struct i802_bss *bss = priv; |
| 5688 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5689 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5690 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5691 | |
| 5692 | if (addr) |
| 5693 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5694 | nlmode = wpa_driver_nl80211_if_type(type); |
| 5695 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 5696 | struct wdev_info p2pdev_info; |
| 5697 | |
| 5698 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 5699 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 5700 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5701 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5702 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 5703 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 5704 | ifname); |
| 5705 | return -1; |
| 5706 | } |
| 5707 | |
| 5708 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 5709 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 5710 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 5711 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 5712 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 5713 | ifname, |
| 5714 | (long long unsigned int) p2pdev_info.wdev_id); |
| 5715 | } else { |
| 5716 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5717 | 0, NULL, NULL, use_existing); |
| 5718 | if (use_existing && ifidx == -ENFILE) { |
| 5719 | added = 0; |
| 5720 | ifidx = if_nametoindex(ifname); |
| 5721 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5722 | return -1; |
| 5723 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5724 | } |
| 5725 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5726 | if (!addr) { |
| 5727 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 5728 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 5729 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 5730 | bss->ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5731 | if (added) |
| 5732 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5733 | return -1; |
| 5734 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5735 | } |
| 5736 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5737 | #if defined(CONFIG_P2P) || defined(CONFIG_MESH) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5738 | if (!addr && |
| 5739 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5740 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5741 | /* Enforce unique P2P Interface Address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5742 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5743 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5744 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5745 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5746 | if (added) |
| 5747 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5748 | return -1; |
| 5749 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5750 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5751 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5752 | "for %s interface", type == WPA_IF_MESH ? |
| 5753 | "mesh" : "P2P group"); |
| 5754 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5755 | if (added) |
| 5756 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5757 | return -1; |
| 5758 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5759 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5760 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5761 | if (added) |
| 5762 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5763 | return -1; |
| 5764 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5765 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5766 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5767 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5768 | #endif /* CONFIG_P2P || CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5769 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5770 | if (type == WPA_IF_AP_BSS) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5771 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 5772 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5773 | if (added) |
| 5774 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5775 | return -1; |
| 5776 | } |
| 5777 | |
| 5778 | if (bridge && |
| 5779 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 5780 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 5781 | "interface %s to a bridge %s", |
| 5782 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5783 | if (added) |
| 5784 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5785 | os_free(new_bss); |
| 5786 | return -1; |
| 5787 | } |
| 5788 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5789 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 5790 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 5791 | if (added) |
| 5792 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5793 | os_free(new_bss); |
| 5794 | return -1; |
| 5795 | } |
| 5796 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5797 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5798 | new_bss->ifindex = ifidx; |
| 5799 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5800 | new_bss->next = drv->first_bss->next; |
| 5801 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5802 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5803 | new_bss->added_if = added; |
| 5804 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5805 | if (drv_priv) |
| 5806 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5807 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5808 | |
| 5809 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 5810 | if (nl80211_setup_ap(new_bss)) |
| 5811 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5812 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5813 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5814 | if (drv->global) |
| 5815 | drv->global->if_add_ifindex = ifidx; |
| 5816 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5817 | /* |
| 5818 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5819 | * the parent interface. This is used mainly with hostapd. |
| 5820 | */ |
| 5821 | if (ifidx > 0 && |
| 5822 | (drv->hostapd || |
| 5823 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 5824 | nlmode == NL80211_IFTYPE_WDS || |
| 5825 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5826 | add_ifidx(drv, ifidx); |
| 5827 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5828 | return 0; |
| 5829 | } |
| 5830 | |
| 5831 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5832 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5833 | enum wpa_driver_if_type type, |
| 5834 | const char *ifname) |
| 5835 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5836 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5837 | int ifindex = if_nametoindex(ifname); |
| 5838 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5839 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 5840 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 5841 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5842 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5843 | else if (ifindex > 0 && !bss->added_if) { |
| 5844 | struct wpa_driver_nl80211_data *drv2; |
| 5845 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 5846 | struct wpa_driver_nl80211_data, list) |
| 5847 | del_ifidx(drv2, ifindex); |
| 5848 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5849 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5850 | if (type != WPA_IF_AP_BSS) |
| 5851 | return 0; |
| 5852 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5853 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5854 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 5855 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5856 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 5857 | "interface %s from bridge %s: %s", |
| 5858 | bss->ifname, bss->brname, strerror(errno)); |
| 5859 | } |
| 5860 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5861 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5862 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 5863 | "bridge %s: %s", |
| 5864 | bss->brname, strerror(errno)); |
| 5865 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5866 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5867 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5868 | struct i802_bss *tbss; |
| 5869 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5870 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 5871 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5872 | if (tbss->next == bss) { |
| 5873 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5874 | /* Unsubscribe management frames */ |
| 5875 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5876 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5877 | if (!bss->added_if) |
| 5878 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5879 | os_free(bss); |
| 5880 | bss = NULL; |
| 5881 | break; |
| 5882 | } |
| 5883 | } |
| 5884 | if (bss) |
| 5885 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 5886 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5887 | } else { |
| 5888 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 5889 | nl80211_teardown_ap(bss); |
| 5890 | if (!bss->added_if && !drv->first_bss->next) |
| 5891 | wpa_driver_nl80211_del_beacon(drv); |
| 5892 | nl80211_destroy_bss(bss); |
| 5893 | if (!bss->added_if) |
| 5894 | i802_set_iface_flags(bss, 0); |
| 5895 | if (drv->first_bss->next) { |
| 5896 | drv->first_bss = drv->first_bss->next; |
| 5897 | drv->ctx = drv->first_bss->ctx; |
| 5898 | os_free(bss); |
| 5899 | } else { |
| 5900 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 5901 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5902 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5903 | |
| 5904 | return 0; |
| 5905 | } |
| 5906 | |
| 5907 | |
| 5908 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 5909 | { |
| 5910 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5911 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5912 | u64 *cookie = arg; |
| 5913 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5914 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5915 | if (tb[NL80211_ATTR_COOKIE]) |
| 5916 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 5917 | return NL_SKIP; |
| 5918 | } |
| 5919 | |
| 5920 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5921 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5922 | unsigned int freq, unsigned int wait, |
| 5923 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5924 | u64 *cookie_out, int no_cck, int no_ack, |
| 5925 | int offchanok) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5926 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5927 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5928 | struct nl_msg *msg; |
| 5929 | u64 cookie; |
| 5930 | int ret = -1; |
| 5931 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5932 | wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d " |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5933 | "no_ack=%d offchanok=%d", |
| 5934 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5935 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5936 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5937 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 5938 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 5939 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 5940 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 5941 | drv->test_use_roc_tx) && |
| 5942 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 5943 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 5944 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
| 5945 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 5946 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5947 | |
| 5948 | cookie = 0; |
| 5949 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 5950 | msg = NULL; |
| 5951 | if (ret) { |
| 5952 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 5953 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 5954 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5955 | } else { |
| 5956 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 5957 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 5958 | (long long unsigned int) cookie); |
| 5959 | |
| 5960 | if (cookie_out) |
| 5961 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5962 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5963 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 5964 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5965 | nlmsg_free(msg); |
| 5966 | return ret; |
| 5967 | } |
| 5968 | |
| 5969 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5970 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 5971 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5972 | unsigned int wait_time, |
| 5973 | const u8 *dst, const u8 *src, |
| 5974 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5975 | const u8 *data, size_t data_len, |
| 5976 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5977 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5978 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5979 | int ret = -1; |
| 5980 | u8 *buf; |
| 5981 | struct ieee80211_hdr *hdr; |
| 5982 | |
| 5983 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5984 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 5985 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5986 | |
| 5987 | buf = os_zalloc(24 + data_len); |
| 5988 | if (buf == NULL) |
| 5989 | return ret; |
| 5990 | os_memcpy(buf + 24, data, data_len); |
| 5991 | hdr = (struct ieee80211_hdr *) buf; |
| 5992 | hdr->frame_control = |
| 5993 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 5994 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 5995 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 5996 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 5997 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5998 | if (is_ap_interface(drv->nlmode) && |
| 5999 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6000 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6001 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6002 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6003 | 0, freq, no_cck, 1, |
| 6004 | wait_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6005 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6006 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6007 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6008 | &drv->send_action_cookie, |
| 6009 | no_cck, 0, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6010 | |
| 6011 | os_free(buf); |
| 6012 | return ret; |
| 6013 | } |
| 6014 | |
| 6015 | |
| 6016 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6017 | { |
| 6018 | struct i802_bss *bss = priv; |
| 6019 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6020 | struct nl_msg *msg; |
| 6021 | int ret; |
| 6022 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6023 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
| 6024 | (long long unsigned int) drv->send_action_cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6025 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
| 6026 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->send_action_cookie)) { |
| 6027 | nlmsg_free(msg); |
| 6028 | return; |
| 6029 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6030 | |
| 6031 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6032 | if (ret) |
| 6033 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6034 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | |
| 6038 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6039 | unsigned int duration) |
| 6040 | { |
| 6041 | struct i802_bss *bss = priv; |
| 6042 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6043 | struct nl_msg *msg; |
| 6044 | int ret; |
| 6045 | u64 cookie; |
| 6046 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6047 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6048 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6049 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6050 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6051 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6052 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6053 | |
| 6054 | cookie = 0; |
| 6055 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6056 | if (ret == 0) { |
| 6057 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6058 | "0x%llx for freq=%u MHz duration=%u", |
| 6059 | (long long unsigned int) cookie, freq, duration); |
| 6060 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6061 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6062 | return 0; |
| 6063 | } |
| 6064 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6065 | "(freq=%d duration=%u): %d (%s)", |
| 6066 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6067 | return -1; |
| 6068 | } |
| 6069 | |
| 6070 | |
| 6071 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6072 | { |
| 6073 | struct i802_bss *bss = priv; |
| 6074 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6075 | struct nl_msg *msg; |
| 6076 | int ret; |
| 6077 | |
| 6078 | if (!drv->pending_remain_on_chan) { |
| 6079 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6080 | "to cancel"); |
| 6081 | return -1; |
| 6082 | } |
| 6083 | |
| 6084 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6085 | "0x%llx", |
| 6086 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6087 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6088 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6089 | if (!msg || |
| 6090 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6091 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6092 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6093 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6094 | |
| 6095 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6096 | if (ret == 0) |
| 6097 | return 0; |
| 6098 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6099 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6100 | return -1; |
| 6101 | } |
| 6102 | |
| 6103 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6104 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6105 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6107 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6108 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6109 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6110 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6111 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6112 | /* |
| 6113 | * Do not disable Probe Request reporting that was |
| 6114 | * enabled in nl80211_setup_ap(). |
| 6115 | */ |
| 6116 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6117 | "Probe Request reporting nl_preq=%p while " |
| 6118 | "in AP mode", bss->nl_preq); |
| 6119 | } else if (bss->nl_preq) { |
| 6120 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6121 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6122 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6123 | } |
| 6124 | return 0; |
| 6125 | } |
| 6126 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6127 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6128 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6129 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6130 | return 0; |
| 6131 | } |
| 6132 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6133 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6134 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6135 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6136 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6137 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6138 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6139 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6140 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6141 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6142 | NULL, 0) < 0) |
| 6143 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6144 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6145 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6146 | wpa_driver_nl80211_event_receive, |
| 6147 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6148 | |
| 6149 | return 0; |
| 6150 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6151 | out_err: |
| 6152 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6153 | return -1; |
| 6154 | } |
| 6155 | |
| 6156 | |
| 6157 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6158 | int ifindex, int disabled) |
| 6159 | { |
| 6160 | struct nl_msg *msg; |
| 6161 | struct nlattr *bands, *band; |
| 6162 | int ret; |
| 6163 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6164 | wpa_printf(MSG_DEBUG, |
| 6165 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6166 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6167 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6168 | |
| 6169 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6170 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6171 | if (!msg) |
| 6172 | return -1; |
| 6173 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6174 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6175 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6176 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6177 | |
| 6178 | /* |
| 6179 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6180 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6181 | * rates. All 5 GHz rates are left enabled. |
| 6182 | */ |
| 6183 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6184 | if (!band || |
| 6185 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6186 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6187 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6188 | nla_nest_end(msg, band); |
| 6189 | |
| 6190 | nla_nest_end(msg, bands); |
| 6191 | |
| 6192 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6193 | if (ret) { |
| 6194 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6195 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6196 | } else |
| 6197 | drv->disabled_11b_rates = disabled; |
| 6198 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6199 | return ret; |
| 6200 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6201 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6202 | nlmsg_free(msg); |
| 6203 | return -1; |
| 6204 | } |
| 6205 | |
| 6206 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6207 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6208 | { |
| 6209 | struct i802_bss *bss = priv; |
| 6210 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6211 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6212 | return -1; |
| 6213 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6214 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6215 | |
| 6216 | /* |
| 6217 | * If the P2P GO interface was dynamically added, then it is |
| 6218 | * possible that the interface change to station is not possible. |
| 6219 | */ |
| 6220 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6221 | return 0; |
| 6222 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6223 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6227 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6228 | { |
| 6229 | struct i802_bss *bss = priv; |
| 6230 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6231 | if (!is_ap_interface(drv->nlmode)) |
| 6232 | return -1; |
| 6233 | wpa_driver_nl80211_del_beacon(drv); |
| 6234 | bss->beacon_set = 0; |
| 6235 | return 0; |
| 6236 | } |
| 6237 | |
| 6238 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6239 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6240 | { |
| 6241 | struct i802_bss *bss = priv; |
| 6242 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6243 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6244 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6245 | |
| 6246 | /* |
| 6247 | * If the P2P Client interface was dynamically added, then it is |
| 6248 | * possible that the interface change to station is not possible. |
| 6249 | */ |
| 6250 | if (bss->if_dynamic) |
| 6251 | return 0; |
| 6252 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6253 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6254 | } |
| 6255 | |
| 6256 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6257 | static void wpa_driver_nl80211_resume(void *priv) |
| 6258 | { |
| 6259 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6260 | |
| 6261 | if (i802_set_iface_flags(bss, 1)) |
| 6262 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6266 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6267 | { |
| 6268 | struct i802_bss *bss = priv; |
| 6269 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6270 | struct nl_msg *msg; |
| 6271 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6272 | |
| 6273 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6274 | "hysteresis=%d", threshold, hysteresis); |
| 6275 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6276 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6277 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6278 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6279 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6280 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6281 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6282 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6283 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6284 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6285 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6289 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6290 | { |
| 6291 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6292 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6293 | struct wpa_signal_info *sig_change = arg; |
| 6294 | |
| 6295 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6296 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6297 | |
| 6298 | sig_change->center_frq1 = -1; |
| 6299 | sig_change->center_frq2 = -1; |
| 6300 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6301 | |
| 6302 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6303 | sig_change->chanwidth = convert2width( |
| 6304 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6305 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6306 | sig_change->center_frq1 = |
| 6307 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6308 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6309 | sig_change->center_frq2 = |
| 6310 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6311 | } |
| 6312 | |
| 6313 | return NL_SKIP; |
| 6314 | } |
| 6315 | |
| 6316 | |
| 6317 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6318 | struct wpa_signal_info *sig) |
| 6319 | { |
| 6320 | struct nl_msg *msg; |
| 6321 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6322 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6323 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6327 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6328 | { |
| 6329 | struct i802_bss *bss = priv; |
| 6330 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6331 | int res; |
| 6332 | |
| 6333 | os_memset(si, 0, sizeof(*si)); |
| 6334 | res = nl80211_get_link_signal(drv, si); |
| 6335 | if (res != 0) |
| 6336 | return res; |
| 6337 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6338 | res = nl80211_get_channel_width(drv, si); |
| 6339 | if (res != 0) |
| 6340 | return res; |
| 6341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6342 | return nl80211_get_link_noise(drv, si); |
| 6343 | } |
| 6344 | |
| 6345 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6346 | static int wpa_driver_nl80211_shared_freq(void *priv) |
| 6347 | { |
| 6348 | struct i802_bss *bss = priv; |
| 6349 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6350 | struct wpa_driver_nl80211_data *driver; |
| 6351 | int freq = 0; |
| 6352 | |
| 6353 | /* |
| 6354 | * If the same PHY is in connected state with some other interface, |
| 6355 | * then retrieve the assoc freq. |
| 6356 | */ |
| 6357 | wpa_printf(MSG_DEBUG, "nl80211: Get shared freq for PHY %s", |
| 6358 | drv->phyname); |
| 6359 | |
| 6360 | dl_list_for_each(driver, &drv->global->interfaces, |
| 6361 | struct wpa_driver_nl80211_data, list) { |
| 6362 | if (drv == driver || |
| 6363 | os_strcmp(drv->phyname, driver->phyname) != 0 || |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6364 | !driver->associated) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6365 | continue; |
| 6366 | |
| 6367 | wpa_printf(MSG_DEBUG, "nl80211: Found a match for PHY %s - %s " |
| 6368 | MACSTR, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6369 | driver->phyname, driver->first_bss->ifname, |
| 6370 | MAC2STR(driver->first_bss->addr)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6371 | if (is_ap_interface(driver->nlmode)) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6372 | freq = driver->first_bss->freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6373 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6374 | freq = nl80211_get_assoc_freq(driver); |
| 6375 | wpa_printf(MSG_DEBUG, "nl80211: Shared freq for PHY %s: %d", |
| 6376 | drv->phyname, freq); |
| 6377 | } |
| 6378 | |
| 6379 | if (!freq) |
| 6380 | wpa_printf(MSG_DEBUG, "nl80211: No shared interface for " |
| 6381 | "PHY (%s) in associated state", drv->phyname); |
| 6382 | |
| 6383 | return freq; |
| 6384 | } |
| 6385 | |
| 6386 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6387 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6388 | int encrypt) |
| 6389 | { |
| 6390 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6391 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
| 6392 | 0, 0, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | |
| 6396 | static int nl80211_set_param(void *priv, const char *param) |
| 6397 | { |
| 6398 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
| 6399 | if (param == NULL) |
| 6400 | return 0; |
| 6401 | |
| 6402 | #ifdef CONFIG_P2P |
| 6403 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
| 6404 | struct i802_bss *bss = priv; |
| 6405 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6406 | |
| 6407 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 6408 | "interface"); |
| 6409 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 6410 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 6411 | } |
| 6412 | #endif /* CONFIG_P2P */ |
| 6413 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6414 | if (os_strstr(param, "use_monitor=1")) { |
| 6415 | struct i802_bss *bss = priv; |
| 6416 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6417 | drv->use_monitor = 1; |
| 6418 | } |
| 6419 | |
| 6420 | if (os_strstr(param, "force_connect_cmd=1")) { |
| 6421 | struct i802_bss *bss = priv; |
| 6422 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6423 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6424 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6425 | } |
| 6426 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 6427 | if (os_strstr(param, "no_offchannel_tx=1")) { |
| 6428 | struct i802_bss *bss = priv; |
| 6429 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6430 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 6431 | drv->test_use_roc_tx = 1; |
| 6432 | } |
| 6433 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6434 | return 0; |
| 6435 | } |
| 6436 | |
| 6437 | |
| 6438 | static void * nl80211_global_init(void) |
| 6439 | { |
| 6440 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6441 | struct netlink_config *cfg; |
| 6442 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6443 | global = os_zalloc(sizeof(*global)); |
| 6444 | if (global == NULL) |
| 6445 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6446 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6447 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6448 | global->if_add_ifindex = -1; |
| 6449 | |
| 6450 | cfg = os_zalloc(sizeof(*cfg)); |
| 6451 | if (cfg == NULL) |
| 6452 | goto err; |
| 6453 | |
| 6454 | cfg->ctx = global; |
| 6455 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 6456 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 6457 | global->netlink = netlink_init(cfg); |
| 6458 | if (global->netlink == NULL) { |
| 6459 | os_free(cfg); |
| 6460 | goto err; |
| 6461 | } |
| 6462 | |
| 6463 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 6464 | goto err; |
| 6465 | |
| 6466 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 6467 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6468 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 6469 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6470 | goto err; |
| 6471 | } |
| 6472 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6473 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6474 | |
| 6475 | err: |
| 6476 | nl80211_global_deinit(global); |
| 6477 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | |
| 6481 | static void nl80211_global_deinit(void *priv) |
| 6482 | { |
| 6483 | struct nl80211_global *global = priv; |
| 6484 | if (global == NULL) |
| 6485 | return; |
| 6486 | if (!dl_list_empty(&global->interfaces)) { |
| 6487 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 6488 | "nl80211_global_deinit", |
| 6489 | dl_list_len(&global->interfaces)); |
| 6490 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6491 | |
| 6492 | if (global->netlink) |
| 6493 | netlink_deinit(global->netlink); |
| 6494 | |
| 6495 | nl_destroy_handles(&global->nl); |
| 6496 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6497 | if (global->nl_event) |
| 6498 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6499 | |
| 6500 | nl_cb_put(global->nl_cb); |
| 6501 | |
| 6502 | if (global->ioctl_sock >= 0) |
| 6503 | close(global->ioctl_sock); |
| 6504 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6505 | os_free(global); |
| 6506 | } |
| 6507 | |
| 6508 | |
| 6509 | static const char * nl80211_get_radio_name(void *priv) |
| 6510 | { |
| 6511 | struct i802_bss *bss = priv; |
| 6512 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6513 | return drv->phyname; |
| 6514 | } |
| 6515 | |
| 6516 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6517 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 6518 | const u8 *pmkid) |
| 6519 | { |
| 6520 | struct nl_msg *msg; |
| 6521 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6522 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 6523 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 6524 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 6525 | nlmsg_free(msg); |
| 6526 | return -ENOBUFS; |
| 6527 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6528 | |
| 6529 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6530 | } |
| 6531 | |
| 6532 | |
| 6533 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6534 | { |
| 6535 | struct i802_bss *bss = priv; |
| 6536 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 6537 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 6538 | } |
| 6539 | |
| 6540 | |
| 6541 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 6542 | { |
| 6543 | struct i802_bss *bss = priv; |
| 6544 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 6545 | MAC2STR(bssid)); |
| 6546 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 6547 | } |
| 6548 | |
| 6549 | |
| 6550 | static int nl80211_flush_pmkid(void *priv) |
| 6551 | { |
| 6552 | struct i802_bss *bss = priv; |
| 6553 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 6554 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 6555 | } |
| 6556 | |
| 6557 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6558 | static void clean_survey_results(struct survey_results *survey_results) |
| 6559 | { |
| 6560 | struct freq_survey *survey, *tmp; |
| 6561 | |
| 6562 | if (dl_list_empty(&survey_results->survey_list)) |
| 6563 | return; |
| 6564 | |
| 6565 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 6566 | struct freq_survey, list) { |
| 6567 | dl_list_del(&survey->list); |
| 6568 | os_free(survey); |
| 6569 | } |
| 6570 | } |
| 6571 | |
| 6572 | |
| 6573 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 6574 | struct dl_list *survey_list) |
| 6575 | { |
| 6576 | struct freq_survey *survey; |
| 6577 | |
| 6578 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 6579 | if (!survey) |
| 6580 | return; |
| 6581 | |
| 6582 | survey->ifidx = ifidx; |
| 6583 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6584 | survey->filled = 0; |
| 6585 | |
| 6586 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 6587 | survey->nf = (int8_t) |
| 6588 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 6589 | survey->filled |= SURVEY_HAS_NF; |
| 6590 | } |
| 6591 | |
| 6592 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 6593 | survey->channel_time = |
| 6594 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 6595 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 6596 | } |
| 6597 | |
| 6598 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 6599 | survey->channel_time_busy = |
| 6600 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 6601 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 6602 | } |
| 6603 | |
| 6604 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 6605 | survey->channel_time_rx = |
| 6606 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 6607 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 6608 | } |
| 6609 | |
| 6610 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 6611 | survey->channel_time_tx = |
| 6612 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 6613 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 6614 | } |
| 6615 | |
| 6616 | wpa_printf(MSG_DEBUG, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)", |
| 6617 | survey->freq, |
| 6618 | survey->nf, |
| 6619 | (unsigned long int) survey->channel_time, |
| 6620 | (unsigned long int) survey->channel_time_busy, |
| 6621 | (unsigned long int) survey->channel_time_tx, |
| 6622 | (unsigned long int) survey->channel_time_rx, |
| 6623 | survey->filled); |
| 6624 | |
| 6625 | dl_list_add_tail(survey_list, &survey->list); |
| 6626 | } |
| 6627 | |
| 6628 | |
| 6629 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 6630 | unsigned int freq_filter) |
| 6631 | { |
| 6632 | if (!freq_filter) |
| 6633 | return 1; |
| 6634 | |
| 6635 | return freq_filter == surveyed_freq; |
| 6636 | } |
| 6637 | |
| 6638 | |
| 6639 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 6640 | { |
| 6641 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6642 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6643 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 6644 | struct survey_results *survey_results; |
| 6645 | u32 surveyed_freq = 0; |
| 6646 | u32 ifidx; |
| 6647 | |
| 6648 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 6649 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 6650 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 6651 | }; |
| 6652 | |
| 6653 | survey_results = (struct survey_results *) arg; |
| 6654 | |
| 6655 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6656 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6657 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 6658 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 6659 | return NL_SKIP; |
| 6660 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6661 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 6662 | |
| 6663 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 6664 | return NL_SKIP; |
| 6665 | |
| 6666 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 6667 | tb[NL80211_ATTR_SURVEY_INFO], |
| 6668 | survey_policy)) |
| 6669 | return NL_SKIP; |
| 6670 | |
| 6671 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 6672 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 6673 | return NL_SKIP; |
| 6674 | } |
| 6675 | |
| 6676 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 6677 | |
| 6678 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 6679 | survey_results->freq_filter)) |
| 6680 | return NL_SKIP; |
| 6681 | |
| 6682 | if (survey_results->freq_filter && |
| 6683 | survey_results->freq_filter != surveyed_freq) { |
| 6684 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 6685 | surveyed_freq); |
| 6686 | return NL_SKIP; |
| 6687 | } |
| 6688 | |
| 6689 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 6690 | |
| 6691 | return NL_SKIP; |
| 6692 | } |
| 6693 | |
| 6694 | |
| 6695 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 6696 | { |
| 6697 | struct i802_bss *bss = priv; |
| 6698 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6699 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6700 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6701 | union wpa_event_data data; |
| 6702 | struct survey_results *survey_results; |
| 6703 | |
| 6704 | os_memset(&data, 0, sizeof(data)); |
| 6705 | survey_results = &data.survey_results; |
| 6706 | |
| 6707 | dl_list_init(&survey_results->survey_list); |
| 6708 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6709 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6710 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6711 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6712 | |
| 6713 | if (freq) |
| 6714 | data.survey_results.freq_filter = freq; |
| 6715 | |
| 6716 | do { |
| 6717 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 6718 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 6719 | survey_results); |
| 6720 | } while (err > 0); |
| 6721 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6722 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6723 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6724 | else |
| 6725 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6726 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6727 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6728 | return err; |
| 6729 | } |
| 6730 | |
| 6731 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6732 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, const u8 *kck, |
| 6733 | const u8 *replay_ctr) |
| 6734 | { |
| 6735 | struct i802_bss *bss = priv; |
| 6736 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6737 | struct nlattr *replay_nested; |
| 6738 | struct nl_msg *msg; |
| 6739 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6740 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 6741 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
| 6742 | nla_put(msg, NL80211_REKEY_DATA_KEK, NL80211_KEK_LEN, kek) || |
| 6743 | nla_put(msg, NL80211_REKEY_DATA_KCK, NL80211_KCK_LEN, kck) || |
| 6744 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 6745 | replay_ctr)) { |
| 6746 | nl80211_nlmsg_clear(msg); |
| 6747 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6748 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6749 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6750 | |
| 6751 | nla_nest_end(msg, replay_nested); |
| 6752 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6753 | send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | |
| 6757 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 6758 | const u8 *addr, int qos) |
| 6759 | { |
| 6760 | /* send data frame to poll STA and check whether |
| 6761 | * this frame is ACKed */ |
| 6762 | struct { |
| 6763 | struct ieee80211_hdr hdr; |
| 6764 | u16 qos_ctl; |
| 6765 | } STRUCT_PACKED nulldata; |
| 6766 | size_t size; |
| 6767 | |
| 6768 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 6769 | |
| 6770 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 6771 | |
| 6772 | if (qos) { |
| 6773 | nulldata.hdr.frame_control = |
| 6774 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6775 | WLAN_FC_STYPE_QOS_NULL); |
| 6776 | size = sizeof(nulldata); |
| 6777 | } else { |
| 6778 | nulldata.hdr.frame_control = |
| 6779 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 6780 | WLAN_FC_STYPE_NULLFUNC); |
| 6781 | size = sizeof(struct ieee80211_hdr); |
| 6782 | } |
| 6783 | |
| 6784 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 6785 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 6786 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 6787 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 6788 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6789 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
| 6790 | 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6791 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 6792 | "send poll frame"); |
| 6793 | } |
| 6794 | |
| 6795 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 6796 | int qos) |
| 6797 | { |
| 6798 | struct i802_bss *bss = priv; |
| 6799 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6800 | struct nl_msg *msg; |
| 6801 | |
| 6802 | if (!drv->poll_command_supported) { |
| 6803 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 6804 | return; |
| 6805 | } |
| 6806 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6807 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 6808 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6809 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6810 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6811 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6812 | |
| 6813 | send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6814 | } |
| 6815 | |
| 6816 | |
| 6817 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 6818 | { |
| 6819 | struct nl_msg *msg; |
| 6820 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6821 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 6822 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 6823 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 6824 | nlmsg_free(msg); |
| 6825 | return -ENOBUFS; |
| 6826 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6827 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6828 | } |
| 6829 | |
| 6830 | |
| 6831 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 6832 | int ctwindow) |
| 6833 | { |
| 6834 | struct i802_bss *bss = priv; |
| 6835 | |
| 6836 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 6837 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 6838 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6839 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6840 | #ifdef ANDROID_P2P |
| 6841 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6842 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6843 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 6844 | #endif /* ANDROID_P2P */ |
| 6845 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6846 | |
| 6847 | if (legacy_ps == -1) |
| 6848 | return 0; |
| 6849 | if (legacy_ps != 0 && legacy_ps != 1) |
| 6850 | return -1; /* Not yet supported */ |
| 6851 | |
| 6852 | return nl80211_set_power_save(bss, legacy_ps); |
| 6853 | } |
| 6854 | |
| 6855 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6856 | static int nl80211_start_radar_detection(void *priv, |
| 6857 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6858 | { |
| 6859 | struct i802_bss *bss = priv; |
| 6860 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6861 | struct nl_msg *msg; |
| 6862 | int ret; |
| 6863 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6864 | wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 6865 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 6866 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 6867 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6868 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 6869 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 6870 | "detection"); |
| 6871 | return -1; |
| 6872 | } |
| 6873 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6874 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 6875 | nl80211_put_freq_params(msg, freq) < 0) { |
| 6876 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6877 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6878 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6879 | |
| 6880 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6881 | if (ret == 0) |
| 6882 | return 0; |
| 6883 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 6884 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6885 | return -1; |
| 6886 | } |
| 6887 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6888 | #ifdef CONFIG_TDLS |
| 6889 | |
| 6890 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 6891 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6892 | u32 peer_capab, int initiator, const u8 *buf, |
| 6893 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6894 | { |
| 6895 | struct i802_bss *bss = priv; |
| 6896 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6897 | struct nl_msg *msg; |
| 6898 | |
| 6899 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 6900 | return -EOPNOTSUPP; |
| 6901 | |
| 6902 | if (!dst) |
| 6903 | return -EINVAL; |
| 6904 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6905 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 6906 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 6907 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 6908 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 6909 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 6910 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6911 | if (peer_capab) { |
| 6912 | /* |
| 6913 | * The internal enum tdls_peer_capability definition is |
| 6914 | * currently identical with the nl80211 enum |
| 6915 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 6916 | * here. |
| 6917 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6918 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 6919 | peer_capab)) |
| 6920 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6921 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6922 | if ((initiator && |
| 6923 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 6924 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 6925 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6926 | |
| 6927 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6928 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6929 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6930 | nlmsg_free(msg); |
| 6931 | return -ENOBUFS; |
| 6932 | } |
| 6933 | |
| 6934 | |
| 6935 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 6936 | { |
| 6937 | struct i802_bss *bss = priv; |
| 6938 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6939 | struct nl_msg *msg; |
| 6940 | enum nl80211_tdls_operation nl80211_oper; |
| 6941 | |
| 6942 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 6943 | return -EOPNOTSUPP; |
| 6944 | |
| 6945 | switch (oper) { |
| 6946 | case TDLS_DISCOVERY_REQ: |
| 6947 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 6948 | break; |
| 6949 | case TDLS_SETUP: |
| 6950 | nl80211_oper = NL80211_TDLS_SETUP; |
| 6951 | break; |
| 6952 | case TDLS_TEARDOWN: |
| 6953 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 6954 | break; |
| 6955 | case TDLS_ENABLE_LINK: |
| 6956 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 6957 | break; |
| 6958 | case TDLS_DISABLE_LINK: |
| 6959 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 6960 | break; |
| 6961 | case TDLS_ENABLE: |
| 6962 | return 0; |
| 6963 | case TDLS_DISABLE: |
| 6964 | return 0; |
| 6965 | default: |
| 6966 | return -EINVAL; |
| 6967 | } |
| 6968 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6969 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 6970 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 6971 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 6972 | nlmsg_free(msg); |
| 6973 | return -ENOBUFS; |
| 6974 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6975 | |
| 6976 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6977 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6978 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 6979 | |
| 6980 | static int |
| 6981 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 6982 | const struct hostapd_freq_params *params) |
| 6983 | { |
| 6984 | struct i802_bss *bss = priv; |
| 6985 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6986 | struct nl_msg *msg; |
| 6987 | int ret = -ENOBUFS; |
| 6988 | |
| 6989 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 6990 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 6991 | return -EOPNOTSUPP; |
| 6992 | |
| 6993 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 6994 | " oper_class=%u freq=%u", |
| 6995 | MAC2STR(addr), oper_class, params->freq); |
| 6996 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 6997 | if (!msg || |
| 6998 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6999 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7000 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7001 | nlmsg_free(msg); |
| 7002 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7003 | return ret; |
| 7004 | } |
| 7005 | |
| 7006 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7007 | } |
| 7008 | |
| 7009 | |
| 7010 | static int |
| 7011 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7012 | { |
| 7013 | struct i802_bss *bss = priv; |
| 7014 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7015 | struct nl_msg *msg; |
| 7016 | |
| 7017 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7018 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7019 | return -EOPNOTSUPP; |
| 7020 | |
| 7021 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7022 | MAC2STR(addr)); |
| 7023 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7024 | if (!msg || |
| 7025 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7026 | nlmsg_free(msg); |
| 7027 | wpa_printf(MSG_DEBUG, |
| 7028 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7029 | return -ENOBUFS; |
| 7030 | } |
| 7031 | |
| 7032 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | #endif /* CONFIG TDLS */ |
| 7036 | |
| 7037 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7038 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7039 | enum wpa_alg alg, const u8 *addr, |
| 7040 | int key_idx, int set_tx, |
| 7041 | const u8 *seq, size_t seq_len, |
| 7042 | const u8 *key, size_t key_len) |
| 7043 | { |
| 7044 | struct i802_bss *bss = priv; |
| 7045 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7046 | set_tx, seq, seq_len, key, key_len); |
| 7047 | } |
| 7048 | |
| 7049 | |
| 7050 | static int driver_nl80211_scan2(void *priv, |
| 7051 | struct wpa_driver_scan_params *params) |
| 7052 | { |
| 7053 | struct i802_bss *bss = priv; |
| 7054 | return wpa_driver_nl80211_scan(bss, params); |
| 7055 | } |
| 7056 | |
| 7057 | |
| 7058 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7059 | int reason_code) |
| 7060 | { |
| 7061 | struct i802_bss *bss = priv; |
| 7062 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7063 | } |
| 7064 | |
| 7065 | |
| 7066 | static int driver_nl80211_authenticate(void *priv, |
| 7067 | struct wpa_driver_auth_params *params) |
| 7068 | { |
| 7069 | struct i802_bss *bss = priv; |
| 7070 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7071 | } |
| 7072 | |
| 7073 | |
| 7074 | static void driver_nl80211_deinit(void *priv) |
| 7075 | { |
| 7076 | struct i802_bss *bss = priv; |
| 7077 | wpa_driver_nl80211_deinit(bss); |
| 7078 | } |
| 7079 | |
| 7080 | |
| 7081 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7082 | const char *ifname) |
| 7083 | { |
| 7084 | struct i802_bss *bss = priv; |
| 7085 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7086 | } |
| 7087 | |
| 7088 | |
| 7089 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
| 7090 | size_t data_len, int noack) |
| 7091 | { |
| 7092 | struct i802_bss *bss = priv; |
| 7093 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
| 7094 | 0, 0, 0, 0); |
| 7095 | } |
| 7096 | |
| 7097 | |
| 7098 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7099 | { |
| 7100 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7101 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7102 | } |
| 7103 | |
| 7104 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7105 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7106 | const char *ifname, int vlan_id) |
| 7107 | { |
| 7108 | struct i802_bss *bss = priv; |
| 7109 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7110 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7111 | |
| 7112 | |
| 7113 | static int driver_nl80211_read_sta_data(void *priv, |
| 7114 | struct hostap_sta_driver_data *data, |
| 7115 | const u8 *addr) |
| 7116 | { |
| 7117 | struct i802_bss *bss = priv; |
| 7118 | return i802_read_sta_data(bss, data, addr); |
| 7119 | } |
| 7120 | |
| 7121 | |
| 7122 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7123 | unsigned int wait_time, |
| 7124 | const u8 *dst, const u8 *src, |
| 7125 | const u8 *bssid, |
| 7126 | const u8 *data, size_t data_len, |
| 7127 | int no_cck) |
| 7128 | { |
| 7129 | struct i802_bss *bss = priv; |
| 7130 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7131 | bssid, data, data_len, no_cck); |
| 7132 | } |
| 7133 | |
| 7134 | |
| 7135 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7136 | { |
| 7137 | struct i802_bss *bss = priv; |
| 7138 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7139 | } |
| 7140 | |
| 7141 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7142 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7143 | const u8 *ies, size_t ies_len) |
| 7144 | { |
| 7145 | int ret; |
| 7146 | struct nl_msg *msg; |
| 7147 | struct i802_bss *bss = priv; |
| 7148 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7149 | u16 mdid = WPA_GET_LE16(md); |
| 7150 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7151 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7152 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7153 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7154 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7155 | nlmsg_free(msg); |
| 7156 | return -ENOBUFS; |
| 7157 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7158 | |
| 7159 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7160 | if (ret) { |
| 7161 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7162 | "err=%d (%s)", ret, strerror(-ret)); |
| 7163 | } |
| 7164 | |
| 7165 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7166 | } |
| 7167 | |
| 7168 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7169 | const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
| 7170 | { |
| 7171 | struct i802_bss *bss = priv; |
| 7172 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7173 | |
| 7174 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7175 | return NULL; |
| 7176 | |
| 7177 | return bss->addr; |
| 7178 | } |
| 7179 | |
| 7180 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7181 | static const char * scan_state_str(enum scan_states scan_state) |
| 7182 | { |
| 7183 | switch (scan_state) { |
| 7184 | case NO_SCAN: |
| 7185 | return "NO_SCAN"; |
| 7186 | case SCAN_REQUESTED: |
| 7187 | return "SCAN_REQUESTED"; |
| 7188 | case SCAN_STARTED: |
| 7189 | return "SCAN_STARTED"; |
| 7190 | case SCAN_COMPLETED: |
| 7191 | return "SCAN_COMPLETED"; |
| 7192 | case SCAN_ABORTED: |
| 7193 | return "SCAN_ABORTED"; |
| 7194 | case SCHED_SCAN_STARTED: |
| 7195 | return "SCHED_SCAN_STARTED"; |
| 7196 | case SCHED_SCAN_STOPPED: |
| 7197 | return "SCHED_SCAN_STOPPED"; |
| 7198 | case SCHED_SCAN_RESULTS: |
| 7199 | return "SCHED_SCAN_RESULTS"; |
| 7200 | } |
| 7201 | |
| 7202 | return "??"; |
| 7203 | } |
| 7204 | |
| 7205 | |
| 7206 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7207 | { |
| 7208 | struct i802_bss *bss = priv; |
| 7209 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7210 | int res; |
| 7211 | char *pos, *end; |
| 7212 | |
| 7213 | pos = buf; |
| 7214 | end = buf + buflen; |
| 7215 | |
| 7216 | res = os_snprintf(pos, end - pos, |
| 7217 | "ifindex=%d\n" |
| 7218 | "ifname=%s\n" |
| 7219 | "brname=%s\n" |
| 7220 | "addr=" MACSTR "\n" |
| 7221 | "freq=%d\n" |
| 7222 | "%s%s%s%s%s", |
| 7223 | bss->ifindex, |
| 7224 | bss->ifname, |
| 7225 | bss->brname, |
| 7226 | MAC2STR(bss->addr), |
| 7227 | bss->freq, |
| 7228 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7229 | bss->added_if_into_bridge ? |
| 7230 | "added_if_into_bridge=1\n" : "", |
| 7231 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7232 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7233 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7234 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7235 | return pos - buf; |
| 7236 | pos += res; |
| 7237 | |
| 7238 | if (bss->wdev_id_set) { |
| 7239 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7240 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7241 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7242 | return pos - buf; |
| 7243 | pos += res; |
| 7244 | } |
| 7245 | |
| 7246 | res = os_snprintf(pos, end - pos, |
| 7247 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7248 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7249 | "drv_ifindex=%d\n" |
| 7250 | "operstate=%d\n" |
| 7251 | "scan_state=%s\n" |
| 7252 | "auth_bssid=" MACSTR "\n" |
| 7253 | "auth_attempt_bssid=" MACSTR "\n" |
| 7254 | "bssid=" MACSTR "\n" |
| 7255 | "prev_bssid=" MACSTR "\n" |
| 7256 | "associated=%d\n" |
| 7257 | "assoc_freq=%u\n" |
| 7258 | "monitor_sock=%d\n" |
| 7259 | "monitor_ifidx=%d\n" |
| 7260 | "monitor_refcount=%d\n" |
| 7261 | "last_mgmt_freq=%u\n" |
| 7262 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7263 | "%s%s%s%s%s%s%s%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7264 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7265 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7266 | drv->ifindex, |
| 7267 | drv->operstate, |
| 7268 | scan_state_str(drv->scan_state), |
| 7269 | MAC2STR(drv->auth_bssid), |
| 7270 | MAC2STR(drv->auth_attempt_bssid), |
| 7271 | MAC2STR(drv->bssid), |
| 7272 | MAC2STR(drv->prev_bssid), |
| 7273 | drv->associated, |
| 7274 | drv->assoc_freq, |
| 7275 | drv->monitor_sock, |
| 7276 | drv->monitor_ifidx, |
| 7277 | drv->monitor_refcount, |
| 7278 | drv->last_mgmt_freq, |
| 7279 | drv->eapol_tx_sock, |
| 7280 | drv->ignore_if_down_event ? |
| 7281 | "ignore_if_down_event=1\n" : "", |
| 7282 | drv->scan_complete_events ? |
| 7283 | "scan_complete_events=1\n" : "", |
| 7284 | drv->disabled_11b_rates ? |
| 7285 | "disabled_11b_rates=1\n" : "", |
| 7286 | drv->pending_remain_on_chan ? |
| 7287 | "pending_remain_on_chan=1\n" : "", |
| 7288 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7289 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7290 | drv->poll_command_supported ? |
| 7291 | "poll_command_supported=1\n" : "", |
| 7292 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7293 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7294 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7295 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7296 | drv->ignore_next_local_disconnect ? |
| 7297 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7298 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7299 | "ignore_next_local_deauth=1\n" : ""); |
| 7300 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7301 | return pos - buf; |
| 7302 | pos += res; |
| 7303 | |
| 7304 | if (drv->has_capability) { |
| 7305 | res = os_snprintf(pos, end - pos, |
| 7306 | "capa.key_mgmt=0x%x\n" |
| 7307 | "capa.enc=0x%x\n" |
| 7308 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7309 | "capa.flags=0x%llx\n" |
| 7310 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7311 | "capa.max_scan_ssids=%d\n" |
| 7312 | "capa.max_sched_scan_ssids=%d\n" |
| 7313 | "capa.sched_scan_supported=%d\n" |
| 7314 | "capa.max_match_sets=%d\n" |
| 7315 | "capa.max_remain_on_chan=%u\n" |
| 7316 | "capa.max_stations=%u\n" |
| 7317 | "capa.probe_resp_offloads=0x%x\n" |
| 7318 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7319 | "capa.num_multichan_concurrent=%u\n" |
| 7320 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
| 7321 | "capa.mac_addr_rand_scan_supported=%d\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7322 | drv->capa.key_mgmt, |
| 7323 | drv->capa.enc, |
| 7324 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7325 | (unsigned long long) drv->capa.flags, |
| 7326 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7327 | drv->capa.max_scan_ssids, |
| 7328 | drv->capa.max_sched_scan_ssids, |
| 7329 | drv->capa.sched_scan_supported, |
| 7330 | drv->capa.max_match_sets, |
| 7331 | drv->capa.max_remain_on_chan, |
| 7332 | drv->capa.max_stations, |
| 7333 | drv->capa.probe_resp_offloads, |
| 7334 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7335 | drv->capa.num_multichan_concurrent, |
| 7336 | drv->capa.mac_addr_rand_sched_scan_supported, |
| 7337 | drv->capa.mac_addr_rand_scan_supported); |
| 7338 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7339 | return pos - buf; |
| 7340 | pos += res; |
| 7341 | } |
| 7342 | |
| 7343 | return pos - buf; |
| 7344 | } |
| 7345 | |
| 7346 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7347 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 7348 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7349 | if ((settings->head && |
| 7350 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 7351 | settings->head_len, settings->head)) || |
| 7352 | (settings->tail && |
| 7353 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 7354 | settings->tail_len, settings->tail)) || |
| 7355 | (settings->beacon_ies && |
| 7356 | nla_put(msg, NL80211_ATTR_IE, |
| 7357 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 7358 | (settings->proberesp_ies && |
| 7359 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 7360 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 7361 | (settings->assocresp_ies && |
| 7362 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 7363 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 7364 | (settings->probe_resp && |
| 7365 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 7366 | settings->probe_resp_len, settings->probe_resp))) |
| 7367 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7368 | |
| 7369 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7370 | } |
| 7371 | |
| 7372 | |
| 7373 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 7374 | { |
| 7375 | struct nl_msg *msg; |
| 7376 | struct i802_bss *bss = priv; |
| 7377 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7378 | struct nlattr *beacon_csa; |
| 7379 | int ret = -ENOBUFS; |
| 7380 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7381 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7382 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 7383 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 7384 | settings->freq_params.center_freq1, |
| 7385 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7386 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7387 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7388 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 7389 | return -EOPNOTSUPP; |
| 7390 | } |
| 7391 | |
| 7392 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 7393 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 7394 | return -EOPNOTSUPP; |
| 7395 | |
| 7396 | /* check settings validity */ |
| 7397 | if (!settings->beacon_csa.tail || |
| 7398 | ((settings->beacon_csa.tail_len <= |
| 7399 | settings->counter_offset_beacon) || |
| 7400 | (settings->beacon_csa.tail[settings->counter_offset_beacon] != |
| 7401 | settings->cs_count))) |
| 7402 | return -EINVAL; |
| 7403 | |
| 7404 | if (settings->beacon_csa.probe_resp && |
| 7405 | ((settings->beacon_csa.probe_resp_len <= |
| 7406 | settings->counter_offset_presp) || |
| 7407 | (settings->beacon_csa.probe_resp[settings->counter_offset_presp] != |
| 7408 | settings->cs_count))) |
| 7409 | return -EINVAL; |
| 7410 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7411 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 7412 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 7413 | settings->cs_count) || |
| 7414 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 7415 | (settings->block_tx && |
| 7416 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7417 | goto error; |
| 7418 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7419 | /* beacon_after params */ |
| 7420 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 7421 | if (ret) |
| 7422 | goto error; |
| 7423 | |
| 7424 | /* beacon_csa params */ |
| 7425 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 7426 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7427 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7428 | |
| 7429 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 7430 | if (ret) |
| 7431 | goto error; |
| 7432 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7433 | if (nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 7434 | settings->counter_offset_beacon) || |
| 7435 | (settings->beacon_csa.probe_resp && |
| 7436 | nla_put_u16(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 7437 | settings->counter_offset_presp))) |
| 7438 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7439 | |
| 7440 | nla_nest_end(msg, beacon_csa); |
| 7441 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7442 | if (ret) { |
| 7443 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 7444 | ret, strerror(-ret)); |
| 7445 | } |
| 7446 | return ret; |
| 7447 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7448 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7449 | ret = -ENOBUFS; |
| 7450 | error: |
| 7451 | nlmsg_free(msg); |
| 7452 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 7453 | return ret; |
| 7454 | } |
| 7455 | |
| 7456 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7457 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 7458 | u8 user_priority, u16 admitted_time) |
| 7459 | { |
| 7460 | struct i802_bss *bss = priv; |
| 7461 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7462 | struct nl_msg *msg; |
| 7463 | int ret; |
| 7464 | |
| 7465 | wpa_printf(MSG_DEBUG, |
| 7466 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 7467 | tsid, admitted_time, user_priority); |
| 7468 | |
| 7469 | if (!is_sta_interface(drv->nlmode)) |
| 7470 | return -ENOTSUP; |
| 7471 | |
| 7472 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 7473 | if (!msg || |
| 7474 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7475 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7476 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 7477 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 7478 | nlmsg_free(msg); |
| 7479 | return -ENOBUFS; |
| 7480 | } |
| 7481 | |
| 7482 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7483 | if (ret) |
| 7484 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 7485 | ret, strerror(-ret)); |
| 7486 | return ret; |
| 7487 | } |
| 7488 | |
| 7489 | |
| 7490 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 7491 | { |
| 7492 | struct i802_bss *bss = priv; |
| 7493 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7494 | struct nl_msg *msg; |
| 7495 | int ret; |
| 7496 | |
| 7497 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 7498 | |
| 7499 | if (!is_sta_interface(drv->nlmode)) |
| 7500 | return -ENOTSUP; |
| 7501 | |
| 7502 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 7503 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 7504 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7505 | nlmsg_free(msg); |
| 7506 | return -ENOBUFS; |
| 7507 | } |
| 7508 | |
| 7509 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7510 | if (ret) |
| 7511 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 7512 | ret, strerror(-ret)); |
| 7513 | return ret; |
| 7514 | } |
| 7515 | |
| 7516 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7517 | #ifdef CONFIG_TESTING_OPTIONS |
| 7518 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 7519 | { |
| 7520 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7521 | struct wpabuf *buf = arg; |
| 7522 | |
| 7523 | if (!buf) |
| 7524 | return NL_SKIP; |
| 7525 | |
| 7526 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 7527 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 7528 | return NL_SKIP; |
| 7529 | } |
| 7530 | |
| 7531 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 7532 | genlmsg_attrlen(gnlh, 0)); |
| 7533 | |
| 7534 | return NL_SKIP; |
| 7535 | } |
| 7536 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7537 | |
| 7538 | |
| 7539 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 7540 | { |
| 7541 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7542 | struct nlattr *nl_vendor_reply, *nl; |
| 7543 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7544 | struct wpabuf *buf = arg; |
| 7545 | int rem; |
| 7546 | |
| 7547 | if (!buf) |
| 7548 | return NL_SKIP; |
| 7549 | |
| 7550 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7551 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7552 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 7553 | |
| 7554 | if (!nl_vendor_reply) |
| 7555 | return NL_SKIP; |
| 7556 | |
| 7557 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 7558 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 7559 | return NL_SKIP; |
| 7560 | } |
| 7561 | |
| 7562 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 7563 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 7564 | } |
| 7565 | |
| 7566 | return NL_SKIP; |
| 7567 | } |
| 7568 | |
| 7569 | |
| 7570 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 7571 | unsigned int subcmd, const u8 *data, |
| 7572 | size_t data_len, struct wpabuf *buf) |
| 7573 | { |
| 7574 | struct i802_bss *bss = priv; |
| 7575 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7576 | struct nl_msg *msg; |
| 7577 | int ret; |
| 7578 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7579 | #ifdef CONFIG_TESTING_OPTIONS |
| 7580 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7581 | msg = nlmsg_alloc(); |
| 7582 | if (!msg) |
| 7583 | return -ENOMEM; |
| 7584 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7585 | nl80211_cmd(drv, msg, 0, subcmd); |
| 7586 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 7587 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7588 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7589 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 7590 | if (ret) |
| 7591 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 7592 | ret); |
| 7593 | return ret; |
| 7594 | } |
| 7595 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 7596 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7597 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 7598 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 7599 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 7600 | (data && |
| 7601 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 7602 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7603 | |
| 7604 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 7605 | if (ret) |
| 7606 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 7607 | ret); |
| 7608 | return ret; |
| 7609 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7610 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7611 | nlmsg_free(msg); |
| 7612 | return -ENOBUFS; |
| 7613 | } |
| 7614 | |
| 7615 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7616 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 7617 | u8 qos_map_set_len) |
| 7618 | { |
| 7619 | struct i802_bss *bss = priv; |
| 7620 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7621 | struct nl_msg *msg; |
| 7622 | int ret; |
| 7623 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7624 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 7625 | qos_map_set, qos_map_set_len); |
| 7626 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7627 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 7628 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 7629 | nlmsg_free(msg); |
| 7630 | return -ENOBUFS; |
| 7631 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7632 | |
| 7633 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7634 | if (ret) |
| 7635 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 7636 | |
| 7637 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7638 | } |
| 7639 | |
| 7640 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7641 | static int nl80211_set_wowlan(void *priv, |
| 7642 | const struct wowlan_triggers *triggers) |
| 7643 | { |
| 7644 | struct i802_bss *bss = priv; |
| 7645 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7646 | struct nl_msg *msg; |
| 7647 | struct nlattr *wowlan_triggers; |
| 7648 | int ret; |
| 7649 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7650 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 7651 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7652 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WOWLAN)) || |
| 7653 | !(wowlan_triggers = nla_nest_start(msg, |
| 7654 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 7655 | (triggers->any && |
| 7656 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 7657 | (triggers->disconnect && |
| 7658 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 7659 | (triggers->magic_pkt && |
| 7660 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 7661 | (triggers->gtk_rekey_failure && |
| 7662 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 7663 | (triggers->eap_identity_req && |
| 7664 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 7665 | (triggers->four_way_handshake && |
| 7666 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 7667 | (triggers->rfkill_release && |
| 7668 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 7669 | nlmsg_free(msg); |
| 7670 | return -ENOBUFS; |
| 7671 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7672 | |
| 7673 | nla_nest_end(msg, wowlan_triggers); |
| 7674 | |
| 7675 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7676 | if (ret) |
| 7677 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 7678 | |
| 7679 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7683 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 7684 | { |
| 7685 | struct i802_bss *bss = priv; |
| 7686 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7687 | struct nl_msg *msg; |
| 7688 | struct nlattr *params; |
| 7689 | |
| 7690 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 7691 | |
| 7692 | if (!drv->roaming_vendor_cmd_avail) { |
| 7693 | wpa_printf(MSG_DEBUG, |
| 7694 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 7695 | return -1; |
| 7696 | } |
| 7697 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7698 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 7699 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 7700 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 7701 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 7702 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 7703 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 7704 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 7705 | QCA_ROAMING_NOT_ALLOWED) || |
| 7706 | (bssid && |
| 7707 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 7708 | nlmsg_free(msg); |
| 7709 | return -1; |
| 7710 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7711 | nla_nest_end(msg, params); |
| 7712 | |
| 7713 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7714 | } |
| 7715 | |
| 7716 | |
| 7717 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 7718 | { |
| 7719 | struct i802_bss *bss = priv; |
| 7720 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7721 | int new_addr = addr != NULL; |
| 7722 | |
| 7723 | if (!addr) |
| 7724 | addr = drv->perm_addr; |
| 7725 | |
| 7726 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 7727 | return -1; |
| 7728 | |
| 7729 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 7730 | { |
| 7731 | wpa_printf(MSG_DEBUG, |
| 7732 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 7733 | bss->ifname, MAC2STR(addr)); |
| 7734 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 7735 | 1) < 0) { |
| 7736 | wpa_printf(MSG_DEBUG, |
| 7737 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 7738 | } |
| 7739 | return -1; |
| 7740 | } |
| 7741 | |
| 7742 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 7743 | bss->ifname, MAC2STR(addr)); |
| 7744 | drv->addr_changed = new_addr; |
| 7745 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 7746 | |
| 7747 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 7748 | { |
| 7749 | wpa_printf(MSG_DEBUG, |
| 7750 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 7751 | } |
| 7752 | |
| 7753 | return 0; |
| 7754 | } |
| 7755 | |
| 7756 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 7757 | #ifdef CONFIG_MESH |
| 7758 | |
| 7759 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 7760 | { |
| 7761 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 7762 | wpa_printf(MSG_INFO, |
| 7763 | "nl80211: Failed to set interface into mesh mode"); |
| 7764 | return -1; |
| 7765 | } |
| 7766 | return 0; |
| 7767 | } |
| 7768 | |
| 7769 | |
| 7770 | static int |
| 7771 | wpa_driver_nl80211_join_mesh(void *priv, |
| 7772 | struct wpa_driver_mesh_join_params *params) |
| 7773 | { |
| 7774 | struct i802_bss *bss = priv; |
| 7775 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7776 | struct nl_msg *msg; |
| 7777 | struct nlattr *container; |
| 7778 | int ret = 0; |
| 7779 | |
| 7780 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 7781 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
| 7782 | if (!msg) |
| 7783 | goto fail; |
| 7784 | if (params->freq) { |
| 7785 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
| 7786 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 7787 | goto fail; |
| 7788 | } |
| 7789 | |
| 7790 | if (params->ht_mode) { |
| 7791 | unsigned int ht_value; |
| 7792 | char *ht_mode = ""; |
| 7793 | |
| 7794 | switch (params->ht_mode) { |
| 7795 | default: |
| 7796 | case CHAN_NO_HT: |
| 7797 | ht_value = NL80211_CHAN_NO_HT; |
| 7798 | ht_mode = "NOHT"; |
| 7799 | break; |
| 7800 | case CHAN_HT20: |
| 7801 | ht_value = NL80211_CHAN_HT20; |
| 7802 | ht_mode = "HT20"; |
| 7803 | break; |
| 7804 | case CHAN_HT40PLUS: |
| 7805 | ht_value = NL80211_CHAN_HT40PLUS; |
| 7806 | ht_mode = "HT40+"; |
| 7807 | break; |
| 7808 | case CHAN_HT40MINUS: |
| 7809 | ht_value = NL80211_CHAN_HT40MINUS; |
| 7810 | ht_mode = "HT40-"; |
| 7811 | break; |
| 7812 | } |
| 7813 | wpa_printf(MSG_DEBUG, " * ht_mode=%s", ht_mode); |
| 7814 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ht_value)) |
| 7815 | goto fail; |
| 7816 | } |
| 7817 | |
| 7818 | if (params->basic_rates) { |
| 7819 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 7820 | u8 rates_len = 0; |
| 7821 | int i; |
| 7822 | |
| 7823 | for (i = 0; i < NL80211_MAX_SUPP_RATES; i++) { |
| 7824 | if (params->basic_rates[i] < 0) |
| 7825 | break; |
| 7826 | rates[rates_len++] = params->basic_rates[i] / 5; |
| 7827 | } |
| 7828 | |
| 7829 | if (nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, |
| 7830 | rates)) |
| 7831 | goto fail; |
| 7832 | } |
| 7833 | |
| 7834 | if (params->meshid) { |
| 7835 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 7836 | params->meshid, params->meshid_len); |
| 7837 | if (nla_put(msg, NL80211_ATTR_MESH_ID, params->meshid_len, |
| 7838 | params->meshid)) |
| 7839 | goto fail; |
| 7840 | } |
| 7841 | |
| 7842 | if (params->beacon_int > 0) { |
| 7843 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", params->beacon_int); |
| 7844 | if (nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 7845 | params->beacon_int)) |
| 7846 | goto fail; |
| 7847 | } |
| 7848 | |
| 7849 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 7850 | |
| 7851 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 7852 | if (!container) |
| 7853 | goto fail; |
| 7854 | |
| 7855 | if (params->ies) { |
| 7856 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 7857 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 7858 | params->ies)) |
| 7859 | goto fail; |
| 7860 | } |
| 7861 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 7862 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 7863 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 7864 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 7865 | goto fail; |
| 7866 | } |
| 7867 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 7868 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 7869 | goto fail; |
| 7870 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 7871 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 7872 | goto fail; |
| 7873 | nla_nest_end(msg, container); |
| 7874 | |
| 7875 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 7876 | if (!container) |
| 7877 | goto fail; |
| 7878 | |
| 7879 | if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 7880 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0)) |
| 7881 | goto fail; |
| 7882 | if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) && |
| 7883 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 7884 | params->max_peer_links)) |
| 7885 | goto fail; |
| 7886 | nla_nest_end(msg, container); |
| 7887 | |
| 7888 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7889 | msg = NULL; |
| 7890 | if (ret) { |
| 7891 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 7892 | ret, strerror(-ret)); |
| 7893 | goto fail; |
| 7894 | } |
| 7895 | ret = 0; |
| 7896 | bss->freq = params->freq; |
| 7897 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 7898 | |
| 7899 | fail: |
| 7900 | nlmsg_free(msg); |
| 7901 | return ret; |
| 7902 | } |
| 7903 | |
| 7904 | |
| 7905 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 7906 | { |
| 7907 | struct i802_bss *bss = priv; |
| 7908 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7909 | struct nl_msg *msg; |
| 7910 | int ret; |
| 7911 | |
| 7912 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 7913 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 7914 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7915 | if (ret) { |
| 7916 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 7917 | ret, strerror(-ret)); |
| 7918 | } else { |
| 7919 | wpa_printf(MSG_DEBUG, |
| 7920 | "nl80211: mesh leave request send successfully"); |
| 7921 | } |
| 7922 | |
| 7923 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 7924 | NL80211_IFTYPE_STATION)) { |
| 7925 | wpa_printf(MSG_INFO, |
| 7926 | "nl80211: Failed to set interface into station mode"); |
| 7927 | } |
| 7928 | return ret; |
| 7929 | } |
| 7930 | |
| 7931 | #endif /* CONFIG_MESH */ |
| 7932 | |
| 7933 | |
| 7934 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 7935 | const u8 *ipaddr, int prefixlen, |
| 7936 | const u8 *addr) |
| 7937 | { |
| 7938 | #ifdef CONFIG_LIBNL3_ROUTE |
| 7939 | struct i802_bss *bss = priv; |
| 7940 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7941 | struct rtnl_neigh *rn; |
| 7942 | struct nl_addr *nl_ipaddr = NULL; |
| 7943 | struct nl_addr *nl_lladdr = NULL; |
| 7944 | int family, addrsize; |
| 7945 | int res; |
| 7946 | |
| 7947 | if (!ipaddr || prefixlen == 0 || !addr) |
| 7948 | return -EINVAL; |
| 7949 | |
| 7950 | if (bss->br_ifindex == 0) { |
| 7951 | wpa_printf(MSG_DEBUG, |
| 7952 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 7953 | return -1; |
| 7954 | } |
| 7955 | |
| 7956 | if (!drv->rtnl_sk) { |
| 7957 | wpa_printf(MSG_DEBUG, |
| 7958 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 7959 | return -1; |
| 7960 | } |
| 7961 | |
| 7962 | if (version == 4) { |
| 7963 | family = AF_INET; |
| 7964 | addrsize = 4; |
| 7965 | } else if (version == 6) { |
| 7966 | family = AF_INET6; |
| 7967 | addrsize = 16; |
| 7968 | } else { |
| 7969 | return -EINVAL; |
| 7970 | } |
| 7971 | |
| 7972 | rn = rtnl_neigh_alloc(); |
| 7973 | if (rn == NULL) |
| 7974 | return -ENOMEM; |
| 7975 | |
| 7976 | /* set the destination ip address for neigh */ |
| 7977 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 7978 | if (nl_ipaddr == NULL) { |
| 7979 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 7980 | res = -ENOMEM; |
| 7981 | goto errout; |
| 7982 | } |
| 7983 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 7984 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 7985 | if (res) { |
| 7986 | wpa_printf(MSG_DEBUG, |
| 7987 | "nl80211: neigh set destination addr failed"); |
| 7988 | goto errout; |
| 7989 | } |
| 7990 | |
| 7991 | /* set the corresponding lladdr for neigh */ |
| 7992 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 7993 | if (nl_lladdr == NULL) { |
| 7994 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 7995 | res = -ENOMEM; |
| 7996 | goto errout; |
| 7997 | } |
| 7998 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 7999 | |
| 8000 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8001 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8002 | |
| 8003 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8004 | if (res) { |
| 8005 | wpa_printf(MSG_DEBUG, |
| 8006 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8007 | strerror(errno)); |
| 8008 | } |
| 8009 | errout: |
| 8010 | if (nl_lladdr) |
| 8011 | nl_addr_put(nl_lladdr); |
| 8012 | if (nl_ipaddr) |
| 8013 | nl_addr_put(nl_ipaddr); |
| 8014 | if (rn) |
| 8015 | rtnl_neigh_put(rn); |
| 8016 | return res; |
| 8017 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8018 | return -1; |
| 8019 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8020 | } |
| 8021 | |
| 8022 | |
| 8023 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8024 | const u8 *ipaddr) |
| 8025 | { |
| 8026 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8027 | struct i802_bss *bss = priv; |
| 8028 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8029 | struct rtnl_neigh *rn; |
| 8030 | struct nl_addr *nl_ipaddr; |
| 8031 | int family, addrsize; |
| 8032 | int res; |
| 8033 | |
| 8034 | if (!ipaddr) |
| 8035 | return -EINVAL; |
| 8036 | |
| 8037 | if (version == 4) { |
| 8038 | family = AF_INET; |
| 8039 | addrsize = 4; |
| 8040 | } else if (version == 6) { |
| 8041 | family = AF_INET6; |
| 8042 | addrsize = 16; |
| 8043 | } else { |
| 8044 | return -EINVAL; |
| 8045 | } |
| 8046 | |
| 8047 | if (bss->br_ifindex == 0) { |
| 8048 | wpa_printf(MSG_DEBUG, |
| 8049 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8050 | return -1; |
| 8051 | } |
| 8052 | |
| 8053 | if (!drv->rtnl_sk) { |
| 8054 | wpa_printf(MSG_DEBUG, |
| 8055 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8056 | return -1; |
| 8057 | } |
| 8058 | |
| 8059 | rn = rtnl_neigh_alloc(); |
| 8060 | if (rn == NULL) |
| 8061 | return -ENOMEM; |
| 8062 | |
| 8063 | /* set the destination ip address for neigh */ |
| 8064 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8065 | if (nl_ipaddr == NULL) { |
| 8066 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8067 | res = -ENOMEM; |
| 8068 | goto errout; |
| 8069 | } |
| 8070 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8071 | if (res) { |
| 8072 | wpa_printf(MSG_DEBUG, |
| 8073 | "nl80211: neigh set destination addr failed"); |
| 8074 | goto errout; |
| 8075 | } |
| 8076 | |
| 8077 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8078 | |
| 8079 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8080 | if (res) { |
| 8081 | wpa_printf(MSG_DEBUG, |
| 8082 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8083 | strerror(errno)); |
| 8084 | } |
| 8085 | errout: |
| 8086 | if (nl_ipaddr) |
| 8087 | nl_addr_put(nl_ipaddr); |
| 8088 | if (rn) |
| 8089 | rtnl_neigh_put(rn); |
| 8090 | return res; |
| 8091 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8092 | return -1; |
| 8093 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8094 | } |
| 8095 | |
| 8096 | |
| 8097 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8098 | { |
| 8099 | char buf[50]; |
| 8100 | int fd, len; |
| 8101 | |
| 8102 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8103 | if (os_snprintf_error(sizeof(buf), len)) |
| 8104 | return -1; |
| 8105 | |
| 8106 | fd = open(path, O_WRONLY); |
| 8107 | if (fd < 0) |
| 8108 | return -1; |
| 8109 | |
| 8110 | if (write(fd, buf, len) < 0) { |
| 8111 | wpa_printf(MSG_DEBUG, |
| 8112 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8113 | path, val); |
| 8114 | close(fd); |
| 8115 | return -1; |
| 8116 | } |
| 8117 | close(fd); |
| 8118 | |
| 8119 | return 0; |
| 8120 | } |
| 8121 | |
| 8122 | |
| 8123 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8124 | { |
| 8125 | switch (attr) { |
| 8126 | case DRV_BR_PORT_ATTR_PROXYARP: |
| 8127 | return "proxyarp"; |
| 8128 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8129 | return "hairpin_mode"; |
| 8130 | } |
| 8131 | |
| 8132 | return NULL; |
| 8133 | } |
| 8134 | |
| 8135 | |
| 8136 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8137 | unsigned int val) |
| 8138 | { |
| 8139 | struct i802_bss *bss = priv; |
| 8140 | char path[128]; |
| 8141 | const char *attr_txt; |
| 8142 | |
| 8143 | attr_txt = drv_br_port_attr_str(attr); |
| 8144 | if (attr_txt == NULL) |
| 8145 | return -EINVAL; |
| 8146 | |
| 8147 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8148 | bss->ifname, attr_txt); |
| 8149 | |
| 8150 | if (linux_write_system_file(path, val)) |
| 8151 | return -1; |
| 8152 | |
| 8153 | return 0; |
| 8154 | } |
| 8155 | |
| 8156 | |
| 8157 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8158 | { |
| 8159 | switch (param) { |
| 8160 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8161 | return "arp_accept"; |
| 8162 | } |
| 8163 | |
| 8164 | return NULL; |
| 8165 | } |
| 8166 | |
| 8167 | |
| 8168 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8169 | unsigned int val) |
| 8170 | { |
| 8171 | struct i802_bss *bss = priv; |
| 8172 | char path[128]; |
| 8173 | const char *param_txt; |
| 8174 | int ip_version = 4; |
| 8175 | |
| 8176 | param_txt = drv_br_net_param_str(param); |
| 8177 | if (param_txt == NULL) |
| 8178 | return -EINVAL; |
| 8179 | |
| 8180 | switch (param) { |
| 8181 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8182 | ip_version = 4; |
| 8183 | break; |
| 8184 | default: |
| 8185 | return -EINVAL; |
| 8186 | } |
| 8187 | |
| 8188 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8189 | ip_version, bss->brname, param_txt); |
| 8190 | |
| 8191 | if (linux_write_system_file(path, val)) |
| 8192 | return -1; |
| 8193 | |
| 8194 | return 0; |
| 8195 | } |
| 8196 | |
| 8197 | |
| 8198 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8199 | { |
| 8200 | switch (hw_mode) { |
| 8201 | case HOSTAPD_MODE_IEEE80211B: |
| 8202 | return QCA_ACS_MODE_IEEE80211B; |
| 8203 | case HOSTAPD_MODE_IEEE80211G: |
| 8204 | return QCA_ACS_MODE_IEEE80211G; |
| 8205 | case HOSTAPD_MODE_IEEE80211A: |
| 8206 | return QCA_ACS_MODE_IEEE80211A; |
| 8207 | case HOSTAPD_MODE_IEEE80211AD: |
| 8208 | return QCA_ACS_MODE_IEEE80211AD; |
| 8209 | default: |
| 8210 | return -1; |
| 8211 | } |
| 8212 | } |
| 8213 | |
| 8214 | |
| 8215 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8216 | { |
| 8217 | struct i802_bss *bss = priv; |
| 8218 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8219 | struct nl_msg *msg; |
| 8220 | struct nlattr *data; |
| 8221 | int ret; |
| 8222 | int mode; |
| 8223 | |
| 8224 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8225 | if (mode < 0) |
| 8226 | return -1; |
| 8227 | |
| 8228 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8229 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8230 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8231 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8232 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8233 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8234 | (params->ht_enabled && |
| 8235 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8236 | (params->ht40_enabled && |
| 8237 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED))) { |
| 8238 | nlmsg_free(msg); |
| 8239 | return -ENOBUFS; |
| 8240 | } |
| 8241 | nla_nest_end(msg, data); |
| 8242 | |
| 8243 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8244 | if (ret) { |
| 8245 | wpa_printf(MSG_DEBUG, |
| 8246 | "nl80211: Failed to invoke driver ACS function: %s", |
| 8247 | strerror(errno)); |
| 8248 | } |
| 8249 | return ret; |
| 8250 | } |
| 8251 | |
| 8252 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8253 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 8254 | .name = "nl80211", |
| 8255 | .desc = "Linux nl80211/cfg80211", |
| 8256 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 8257 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8258 | .set_key = driver_nl80211_set_key, |
| 8259 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8260 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 8261 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8262 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8263 | .deauthenticate = driver_nl80211_deauthenticate, |
| 8264 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8265 | .associate = wpa_driver_nl80211_associate, |
| 8266 | .global_init = nl80211_global_init, |
| 8267 | .global_deinit = nl80211_global_deinit, |
| 8268 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8269 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8270 | .get_capa = wpa_driver_nl80211_get_capa, |
| 8271 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 8272 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 8273 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8274 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8275 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 8276 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8277 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8278 | .if_remove = driver_nl80211_if_remove, |
| 8279 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 8280 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8281 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8282 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8283 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 8284 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8285 | .hapd_init = i802_init, |
| 8286 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8287 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8288 | .get_seqnum = i802_get_seqnum, |
| 8289 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8290 | .get_inact_sec = i802_get_inact_sec, |
| 8291 | .sta_clear_stats = i802_sta_clear_stats, |
| 8292 | .set_rts = i802_set_rts, |
| 8293 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8294 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8295 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8296 | .sta_deauth = i802_sta_deauth, |
| 8297 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8298 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8299 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8300 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8301 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 8302 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 8303 | .cancel_remain_on_channel = |
| 8304 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8305 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8306 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8307 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8308 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8309 | .signal_monitor = nl80211_signal_monitor, |
| 8310 | .signal_poll = nl80211_signal_poll, |
| 8311 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8312 | .shared_freq = wpa_driver_nl80211_shared_freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8313 | .set_param = nl80211_set_param, |
| 8314 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8315 | .add_pmkid = nl80211_add_pmkid, |
| 8316 | .remove_pmkid = nl80211_remove_pmkid, |
| 8317 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8318 | .set_rekey_info = nl80211_set_rekey_info, |
| 8319 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8320 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8321 | .start_dfs_cac = nl80211_start_radar_detection, |
| 8322 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8323 | #ifdef CONFIG_TDLS |
| 8324 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 8325 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 8326 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 8327 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8328 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8329 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8330 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8331 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8332 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8333 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8334 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8335 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8336 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8337 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8338 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 8339 | #ifdef ANDROID |
| 8340 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8341 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8342 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8343 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8344 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8345 | .roaming = nl80211_roaming, |
| 8346 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame^] | 8347 | #ifdef CONFIG_MESH |
| 8348 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 8349 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 8350 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 8351 | #endif /* CONFIG_MESH */ |
| 8352 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 8353 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 8354 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 8355 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 8356 | .add_tx_ts = nl80211_add_ts, |
| 8357 | .del_tx_ts = nl80211_del_ts, |
| 8358 | .do_acs = wpa_driver_do_acs, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8359 | }; |