Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - Basic AP mode support routines |
| 3 | * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi> |
| 4 | * Copyright (c) 2009, Atheros Communications |
| 5 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include "utils/includes.h" |
| 11 | |
| 12 | #include "utils/common.h" |
| 13 | #include "utils/eloop.h" |
| 14 | #include "utils/uuid.h" |
| 15 | #include "common/ieee802_11_defs.h" |
| 16 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 17 | #include "eapol_supp/eapol_supp_sm.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 18 | #include "crypto/dh_group5.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 19 | #include "ap/hostapd.h" |
| 20 | #include "ap/ap_config.h" |
| 21 | #include "ap/ap_drv_ops.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 22 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 23 | #include "ap/ieee802_11.h" |
| 24 | #endif /* NEED_AP_MLME */ |
| 25 | #include "ap/beacon.h" |
| 26 | #include "ap/ieee802_1x.h" |
| 27 | #include "ap/wps_hostapd.h" |
| 28 | #include "ap/ctrl_iface_ap.h" |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 29 | #include "ap/dfs.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "wps/wps.h" |
| 31 | #include "common/ieee802_11_defs.h" |
| 32 | #include "config_ssid.h" |
| 33 | #include "config.h" |
| 34 | #include "wpa_supplicant_i.h" |
| 35 | #include "driver_i.h" |
| 36 | #include "p2p_supplicant.h" |
| 37 | #include "ap.h" |
| 38 | #include "ap/sta_info.h" |
| 39 | #include "notify.h" |
| 40 | |
| 41 | |
| 42 | #ifdef CONFIG_WPS |
| 43 | static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx); |
| 44 | #endif /* CONFIG_WPS */ |
| 45 | |
| 46 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 47 | #ifdef CONFIG_IEEE80211N |
| 48 | static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s, |
| 49 | struct hostapd_config *conf, |
| 50 | struct hostapd_hw_modes *mode) |
| 51 | { |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 52 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 53 | u8 center_chan = 0; |
| 54 | u8 channel = conf->channel; |
| 55 | |
| 56 | if (!conf->secondary_channel) |
| 57 | goto no_vht; |
| 58 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 59 | switch (conf->vht_oper_chwidth) { |
| 60 | case VHT_CHANWIDTH_80MHZ: |
| 61 | case VHT_CHANWIDTH_80P80MHZ: |
| 62 | center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel); |
| 63 | break; |
| 64 | case VHT_CHANWIDTH_160MHZ: |
| 65 | center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel); |
| 66 | break; |
| 67 | default: |
| 68 | /* |
| 69 | * conf->vht_oper_chwidth might not be set for non-P2P GO cases, |
| 70 | * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is |
| 71 | * not supported. |
| 72 | */ |
| 73 | conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ; |
| 74 | center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel); |
| 75 | if (!center_chan) { |
| 76 | conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ; |
| 77 | center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, |
| 78 | channel); |
| 79 | } |
| 80 | break; |
| 81 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 82 | if (!center_chan) |
| 83 | goto no_vht; |
| 84 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 85 | conf->vht_oper_centr_freq_seg0_idx = center_chan; |
| 86 | return; |
| 87 | |
| 88 | no_vht: |
| 89 | conf->vht_oper_centr_freq_seg0_idx = |
| 90 | channel + conf->secondary_channel * 2; |
Dmitry Shmidt | 21de214 | 2014-04-08 10:50:52 -0700 | [diff] [blame] | 91 | #else /* CONFIG_P2P */ |
| 92 | conf->vht_oper_centr_freq_seg0_idx = |
| 93 | conf->channel + conf->secondary_channel * 2; |
| 94 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | b97e428 | 2016-02-08 10:16:07 -0800 | [diff] [blame] | 95 | conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 96 | } |
| 97 | #endif /* CONFIG_IEEE80211N */ |
| 98 | |
| 99 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 100 | int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s, |
| 101 | struct wpa_ssid *ssid, |
| 102 | struct hostapd_config *conf) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 103 | { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 104 | conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency, |
| 105 | &conf->channel); |
| 106 | |
| 107 | if (conf->hw_mode == NUM_HOSTAPD_MODES) { |
| 108 | wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz", |
| 109 | ssid->frequency); |
| 110 | return -1; |
| 111 | } |
| 112 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 113 | /* TODO: enable HT40 if driver supports it; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 114 | * drop to 11b if driver does not support 11g */ |
| 115 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 116 | #ifdef CONFIG_IEEE80211N |
| 117 | /* |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 118 | * Enable HT20 if the driver supports it, by setting conf->ieee80211n |
| 119 | * and a mask of allowed capabilities within conf->ht_capab. |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 120 | * Using default config settings for: conf->ht_op_mode_fixed, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 121 | * conf->secondary_channel, conf->require_ht |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 122 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 123 | if (wpa_s->hw.modes) { |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 124 | struct hostapd_hw_modes *mode = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 125 | int i, no_ht = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 126 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 127 | if (wpa_s->hw.modes[i].mode == conf->hw_mode) { |
| 128 | mode = &wpa_s->hw.modes[i]; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 129 | break; |
| 130 | } |
| 131 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 132 | |
| 133 | #ifdef CONFIG_HT_OVERRIDES |
| 134 | if (ssid->disable_ht) { |
| 135 | conf->ieee80211n = 0; |
| 136 | conf->ht_capab = 0; |
| 137 | no_ht = 1; |
| 138 | } |
| 139 | #endif /* CONFIG_HT_OVERRIDES */ |
| 140 | |
| 141 | if (!no_ht && mode && mode->ht_capab) { |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 142 | conf->ieee80211n = 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 143 | #ifdef CONFIG_P2P |
| 144 | if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A && |
| 145 | (mode->ht_capab & |
| 146 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) && |
| 147 | ssid->ht40) |
| 148 | conf->secondary_channel = |
| 149 | wpas_p2p_get_ht40_mode(wpa_s, mode, |
| 150 | conf->channel); |
| 151 | if (conf->secondary_channel) |
| 152 | conf->ht_capab |= |
| 153 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET; |
| 154 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 155 | |
| 156 | /* |
| 157 | * white-list capabilities that won't cause issues |
| 158 | * to connecting stations, while leaving the current |
| 159 | * capabilities intact (currently disabled SMPS). |
| 160 | */ |
| 161 | conf->ht_capab |= mode->ht_capab & |
| 162 | (HT_CAP_INFO_GREEN_FIELD | |
| 163 | HT_CAP_INFO_SHORT_GI20MHZ | |
| 164 | HT_CAP_INFO_SHORT_GI40MHZ | |
| 165 | HT_CAP_INFO_RX_STBC_MASK | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 166 | HT_CAP_INFO_TX_STBC | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 167 | HT_CAP_INFO_MAX_AMSDU_SIZE); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 168 | |
| 169 | if (mode->vht_capab && ssid->vht) { |
| 170 | conf->ieee80211ac = 1; |
| 171 | wpas_conf_ap_vht(wpa_s, conf, mode); |
| 172 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 173 | } |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 174 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 175 | |
| 176 | if (conf->secondary_channel) { |
| 177 | struct wpa_supplicant *iface; |
| 178 | |
| 179 | for (iface = wpa_s->global->ifaces; iface; iface = iface->next) |
| 180 | { |
| 181 | if (iface == wpa_s || |
| 182 | iface->wpa_state < WPA_AUTHENTICATING || |
| 183 | (int) iface->assoc_freq != ssid->frequency) |
| 184 | continue; |
| 185 | |
| 186 | /* |
| 187 | * Do not allow 40 MHz co-ex PRI/SEC switch to force us |
| 188 | * to change our PRI channel since we have an existing, |
| 189 | * concurrent connection on that channel and doing |
| 190 | * multi-channel concurrency is likely to cause more |
| 191 | * harm than using different PRI/SEC selection in |
| 192 | * environment with multiple BSSes on these two channels |
| 193 | * with mixed 20 MHz or PRI channel selection. |
| 194 | */ |
| 195 | conf->no_pri_sec_switch = 1; |
| 196 | } |
| 197 | } |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 198 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 199 | |
| 200 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
| 204 | static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s, |
| 205 | struct wpa_ssid *ssid, |
| 206 | struct hostapd_config *conf) |
| 207 | { |
| 208 | struct hostapd_bss_config *bss = conf->bss[0]; |
| 209 | |
| 210 | conf->driver = wpa_s->driver; |
| 211 | |
| 212 | os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface)); |
| 213 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 214 | if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 215 | return -1; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 216 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 217 | if (ssid->pbss > 1) { |
| 218 | wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode", |
| 219 | ssid->pbss); |
| 220 | return -1; |
| 221 | } |
| 222 | bss->pbss = ssid->pbss; |
| 223 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 224 | #ifdef CONFIG_ACS |
| 225 | if (ssid->acs) { |
| 226 | /* Setting channel to 0 in order to enable ACS */ |
| 227 | conf->channel = 0; |
| 228 | wpa_printf(MSG_DEBUG, "Use automatic channel selection"); |
| 229 | } |
| 230 | #endif /* CONFIG_ACS */ |
| 231 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 232 | if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) { |
| 233 | conf->ieee80211h = 1; |
| 234 | conf->ieee80211d = 1; |
| 235 | conf->country[0] = wpa_s->conf->country[0]; |
| 236 | conf->country[1] = wpa_s->conf->country[1]; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame^] | 237 | conf->country[2] = ' '; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 240 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 241 | if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G && |
| 242 | (ssid->mode == WPAS_MODE_P2P_GO || |
| 243 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 244 | /* Remove 802.11b rates from supported and basic rate sets */ |
| 245 | int *list = os_malloc(4 * sizeof(int)); |
| 246 | if (list) { |
| 247 | list[0] = 60; |
| 248 | list[1] = 120; |
| 249 | list[2] = 240; |
| 250 | list[3] = -1; |
| 251 | } |
| 252 | conf->basic_rates = list; |
| 253 | |
| 254 | list = os_malloc(9 * sizeof(int)); |
| 255 | if (list) { |
| 256 | list[0] = 60; |
| 257 | list[1] = 90; |
| 258 | list[2] = 120; |
| 259 | list[3] = 180; |
| 260 | list[4] = 240; |
| 261 | list[5] = 360; |
| 262 | list[6] = 480; |
| 263 | list[7] = 540; |
| 264 | list[8] = -1; |
| 265 | } |
| 266 | conf->supported_rates = list; |
| 267 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 268 | |
| 269 | bss->isolate = !wpa_s->conf->p2p_intra_bss; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 270 | bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 271 | |
| 272 | if (ssid->p2p_group) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 273 | os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4); |
| 274 | os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 275 | 4); |
| 276 | os_memcpy(bss->ip_addr_start, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 277 | wpa_s->p2pdev->conf->ip_addr_start, 4); |
| 278 | os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end, |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 279 | 4); |
| 280 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 281 | #endif /* CONFIG_P2P */ |
| 282 | |
| 283 | if (ssid->ssid_len == 0) { |
| 284 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); |
| 285 | return -1; |
| 286 | } |
| 287 | os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 288 | bss->ssid.ssid_len = ssid->ssid_len; |
| 289 | bss->ssid.ssid_set = 1; |
| 290 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 291 | bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid; |
| 292 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 293 | if (ssid->auth_alg) |
| 294 | bss->auth_algs = ssid->auth_alg; |
| 295 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 296 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) |
| 297 | bss->wpa = ssid->proto; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 298 | if (ssid->key_mgmt == DEFAULT_KEY_MGMT) |
| 299 | bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK; |
| 300 | else |
| 301 | bss->wpa_key_mgmt = ssid->key_mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 302 | bss->wpa_pairwise = ssid->pairwise_cipher; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 303 | if (ssid->psk_set) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 304 | bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 305 | bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); |
| 306 | if (bss->ssid.wpa_psk == NULL) |
| 307 | return -1; |
| 308 | os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN); |
| 309 | bss->ssid.wpa_psk->group = 1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 310 | bss->ssid.wpa_psk_set = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 311 | } else if (ssid->passphrase) { |
| 312 | bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 313 | } else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] || |
| 314 | ssid->wep_key_len[2] || ssid->wep_key_len[3]) { |
| 315 | struct hostapd_wep_keys *wep = &bss->ssid.wep; |
| 316 | int i; |
| 317 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 318 | if (ssid->wep_key_len[i] == 0) |
| 319 | continue; |
| 320 | wep->key[i] = os_malloc(ssid->wep_key_len[i]); |
| 321 | if (wep->key[i] == NULL) |
| 322 | return -1; |
| 323 | os_memcpy(wep->key[i], ssid->wep_key[i], |
| 324 | ssid->wep_key_len[i]); |
| 325 | wep->len[i] = ssid->wep_key_len[i]; |
| 326 | } |
| 327 | wep->idx = ssid->wep_tx_keyidx; |
| 328 | wep->keys_set = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 331 | if (ssid->ap_max_inactivity) |
| 332 | bss->ap_max_inactivity = ssid->ap_max_inactivity; |
| 333 | |
| 334 | if (ssid->dtim_period) |
| 335 | bss->dtim_period = ssid->dtim_period; |
Dmitry Shmidt | 7a5e50a | 2013-03-05 12:37:16 -0800 | [diff] [blame] | 336 | else if (wpa_s->conf->dtim_period) |
| 337 | bss->dtim_period = wpa_s->conf->dtim_period; |
| 338 | |
| 339 | if (ssid->beacon_int) |
| 340 | conf->beacon_int = ssid->beacon_int; |
| 341 | else if (wpa_s->conf->beacon_int) |
| 342 | conf->beacon_int = wpa_s->conf->beacon_int; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 343 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 344 | #ifdef CONFIG_P2P |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 345 | if (ssid->mode == WPAS_MODE_P2P_GO || |
| 346 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 347 | if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) { |
| 348 | wpa_printf(MSG_INFO, |
| 349 | "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it", |
| 350 | wpa_s->conf->p2p_go_ctwindow, |
| 351 | conf->beacon_int); |
| 352 | conf->p2p_go_ctwindow = 0; |
| 353 | } else { |
| 354 | conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow; |
| 355 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 356 | } |
| 357 | #endif /* CONFIG_P2P */ |
| 358 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 359 | if ((bss->wpa & 2) && bss->rsn_pairwise == 0) |
| 360 | bss->rsn_pairwise = bss->wpa_pairwise; |
| 361 | bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise, |
| 362 | bss->rsn_pairwise); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 363 | |
| 364 | if (bss->wpa && bss->ieee802_1x) |
| 365 | bss->ssid.security_policy = SECURITY_WPA; |
| 366 | else if (bss->wpa) |
| 367 | bss->ssid.security_policy = SECURITY_WPA_PSK; |
| 368 | else if (bss->ieee802_1x) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 369 | int cipher = WPA_CIPHER_NONE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 370 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; |
| 371 | bss->ssid.wep.default_len = bss->default_wep_key_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 372 | if (bss->default_wep_key_len) |
| 373 | cipher = bss->default_wep_key_len >= 13 ? |
| 374 | WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40; |
| 375 | bss->wpa_group = cipher; |
| 376 | bss->wpa_pairwise = cipher; |
| 377 | bss->rsn_pairwise = cipher; |
| 378 | } else if (bss->ssid.wep.keys_set) { |
| 379 | int cipher = WPA_CIPHER_WEP40; |
| 380 | if (bss->ssid.wep.len[0] >= 13) |
| 381 | cipher = WPA_CIPHER_WEP104; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 382 | bss->ssid.security_policy = SECURITY_STATIC_WEP; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 383 | bss->wpa_group = cipher; |
| 384 | bss->wpa_pairwise = cipher; |
| 385 | bss->rsn_pairwise = cipher; |
| 386 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 387 | bss->ssid.security_policy = SECURITY_PLAINTEXT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 388 | bss->wpa_group = WPA_CIPHER_NONE; |
| 389 | bss->wpa_pairwise = WPA_CIPHER_NONE; |
| 390 | bss->rsn_pairwise = WPA_CIPHER_NONE; |
| 391 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 392 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 393 | if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) && |
| 394 | (bss->wpa_group == WPA_CIPHER_CCMP || |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 395 | bss->wpa_group == WPA_CIPHER_GCMP || |
| 396 | bss->wpa_group == WPA_CIPHER_CCMP_256 || |
| 397 | bss->wpa_group == WPA_CIPHER_GCMP_256)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 398 | /* |
| 399 | * Strong ciphers do not need frequent rekeying, so increase |
| 400 | * the default GTK rekeying period to 24 hours. |
| 401 | */ |
| 402 | bss->wpa_group_rekey = 86400; |
| 403 | } |
| 404 | |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 405 | #ifdef CONFIG_IEEE80211W |
| 406 | if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT) |
| 407 | bss->ieee80211w = ssid->ieee80211w; |
| 408 | #endif /* CONFIG_IEEE80211W */ |
| 409 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 410 | #ifdef CONFIG_WPS |
| 411 | /* |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 412 | * Enable WPS by default for open and WPA/WPA2-Personal network, but |
| 413 | * require user interaction to actually use it. Only the internal |
| 414 | * Registrar is supported. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 415 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 416 | if (bss->ssid.security_policy != SECURITY_WPA_PSK && |
| 417 | bss->ssid.security_policy != SECURITY_PLAINTEXT) |
| 418 | goto no_wps; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 419 | if (bss->ssid.security_policy == SECURITY_WPA_PSK && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 420 | (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) || |
| 421 | !(bss->wpa & 2))) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 422 | goto no_wps; /* WPS2 does not allow WPA/TKIP-only |
| 423 | * configuration */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 424 | if (ssid->wps_disabled) |
| 425 | goto no_wps; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | bss->eap_server = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 427 | |
| 428 | if (!ssid->ignore_broadcast_ssid) |
| 429 | bss->wps_state = 2; |
| 430 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 431 | bss->ap_setup_locked = 2; |
| 432 | if (wpa_s->conf->config_methods) |
| 433 | bss->config_methods = os_strdup(wpa_s->conf->config_methods); |
| 434 | os_memcpy(bss->device_type, wpa_s->conf->device_type, |
| 435 | WPS_DEV_TYPE_LEN); |
| 436 | if (wpa_s->conf->device_name) { |
| 437 | bss->device_name = os_strdup(wpa_s->conf->device_name); |
| 438 | bss->friendly_name = os_strdup(wpa_s->conf->device_name); |
| 439 | } |
| 440 | if (wpa_s->conf->manufacturer) |
| 441 | bss->manufacturer = os_strdup(wpa_s->conf->manufacturer); |
| 442 | if (wpa_s->conf->model_name) |
| 443 | bss->model_name = os_strdup(wpa_s->conf->model_name); |
| 444 | if (wpa_s->conf->model_number) |
| 445 | bss->model_number = os_strdup(wpa_s->conf->model_number); |
| 446 | if (wpa_s->conf->serial_number) |
| 447 | bss->serial_number = os_strdup(wpa_s->conf->serial_number); |
| 448 | if (is_nil_uuid(wpa_s->conf->uuid)) |
| 449 | os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN); |
| 450 | else |
| 451 | os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN); |
| 452 | os_memcpy(bss->os_version, wpa_s->conf->os_version, 4); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 453 | bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1; |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 454 | if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE) |
| 455 | bss->fragment_size = ssid->eap.fragment_size; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 456 | no_wps: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 457 | #endif /* CONFIG_WPS */ |
| 458 | |
| 459 | if (wpa_s->max_stations && |
| 460 | wpa_s->max_stations < wpa_s->conf->max_num_sta) |
| 461 | bss->max_num_sta = wpa_s->max_stations; |
| 462 | else |
| 463 | bss->max_num_sta = wpa_s->conf->max_num_sta; |
| 464 | |
| 465 | bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack; |
| 466 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 467 | if (wpa_s->conf->ap_vendor_elements) { |
| 468 | bss->vendor_elements = |
| 469 | wpabuf_dup(wpa_s->conf->ap_vendor_elements); |
| 470 | } |
| 471 | |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 472 | bss->ftm_responder = wpa_s->conf->ftm_responder; |
| 473 | bss->ftm_initiator = wpa_s->conf->ftm_initiator; |
| 474 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq) |
| 480 | { |
| 481 | #ifdef CONFIG_P2P |
| 482 | struct wpa_supplicant *wpa_s = ctx; |
| 483 | const struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 484 | |
| 485 | mgmt = (const struct ieee80211_mgmt *) buf; |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 486 | if (len < IEEE80211_HDRLEN + 1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 487 | return; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 488 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC) |
| 489 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 490 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 491 | mgmt->u.action.category, |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 492 | buf + IEEE80211_HDRLEN + 1, |
| 493 | len - IEEE80211_HDRLEN - 1, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 494 | #endif /* CONFIG_P2P */ |
| 495 | } |
| 496 | |
| 497 | |
| 498 | static void ap_wps_event_cb(void *ctx, enum wps_event event, |
| 499 | union wps_event_data *data) |
| 500 | { |
| 501 | #ifdef CONFIG_P2P |
| 502 | struct wpa_supplicant *wpa_s = ctx; |
| 503 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 504 | if (event == WPS_EV_FAIL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 505 | struct wps_event_fail *fail = &data->fail; |
| 506 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 507 | if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s && |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 508 | wpa_s == wpa_s->global->p2p_group_formation) { |
| 509 | /* |
| 510 | * src/ap/wps_hostapd.c has already sent this on the |
| 511 | * main interface, so only send on the parent interface |
| 512 | * here if needed. |
| 513 | */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 514 | wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 515 | "msg=%d config_error=%d", |
| 516 | fail->msg, fail->config_error); |
| 517 | } |
| 518 | wpas_p2p_wps_failed(wpa_s, fail); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 519 | } |
| 520 | #endif /* CONFIG_P2P */ |
| 521 | } |
| 522 | |
| 523 | |
| 524 | static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 525 | int authorized, const u8 *p2p_dev_addr) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 526 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 527 | wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 531 | #ifdef CONFIG_P2P |
| 532 | static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr, |
| 533 | const u8 *psk, size_t psk_len) |
| 534 | { |
| 535 | |
| 536 | struct wpa_supplicant *wpa_s = ctx; |
| 537 | if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL) |
| 538 | return; |
| 539 | wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len); |
| 540 | } |
| 541 | #endif /* CONFIG_P2P */ |
| 542 | |
| 543 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 544 | static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq) |
| 545 | { |
| 546 | #ifdef CONFIG_P2P |
| 547 | struct wpa_supplicant *wpa_s = ctx; |
| 548 | const struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 549 | |
| 550 | mgmt = (const struct ieee80211_mgmt *) buf; |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 551 | if (len < IEEE80211_HDRLEN + 1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 552 | return -1; |
| 553 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 554 | mgmt->u.action.category, |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 555 | buf + IEEE80211_HDRLEN + 1, |
| 556 | len - IEEE80211_HDRLEN - 1, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 557 | #endif /* CONFIG_P2P */ |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 562 | static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 563 | const u8 *bssid, const u8 *ie, size_t ie_len, |
| 564 | int ssi_signal) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 565 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 566 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 567 | unsigned int freq = 0; |
| 568 | |
| 569 | if (wpa_s->ap_iface) |
| 570 | freq = wpa_s->ap_iface->freq; |
| 571 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 572 | return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 573 | freq, ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | |
| 577 | static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr, |
| 578 | const u8 *uuid_e) |
| 579 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 580 | struct wpa_supplicant *wpa_s = ctx; |
| 581 | wpas_p2p_wps_success(wpa_s, mac_addr, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | |
| 585 | static void wpas_ap_configured_cb(void *ctx) |
| 586 | { |
| 587 | struct wpa_supplicant *wpa_s = ctx; |
| 588 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 589 | #ifdef CONFIG_ACS |
| 590 | if (wpa_s->current_ssid && wpa_s->current_ssid->acs) |
| 591 | wpa_s->assoc_freq = wpa_s->ap_iface->freq; |
| 592 | #endif /* CONFIG_ACS */ |
| 593 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 594 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 595 | |
| 596 | if (wpa_s->ap_configured_cb) |
| 597 | wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx, |
| 598 | wpa_s->ap_configured_cb_data); |
| 599 | } |
| 600 | |
| 601 | |
| 602 | int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s, |
| 603 | struct wpa_ssid *ssid) |
| 604 | { |
| 605 | struct wpa_driver_associate_params params; |
| 606 | struct hostapd_iface *hapd_iface; |
| 607 | struct hostapd_config *conf; |
| 608 | size_t i; |
| 609 | |
| 610 | if (ssid->ssid == NULL || ssid->ssid_len == 0) { |
| 611 | wpa_printf(MSG_ERROR, "No SSID configured for AP mode"); |
| 612 | return -1; |
| 613 | } |
| 614 | |
| 615 | wpa_supplicant_ap_deinit(wpa_s); |
| 616 | |
| 617 | wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')", |
| 618 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 619 | |
| 620 | os_memset(¶ms, 0, sizeof(params)); |
| 621 | params.ssid = ssid->ssid; |
| 622 | params.ssid_len = ssid->ssid_len; |
| 623 | switch (ssid->mode) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 624 | case WPAS_MODE_AP: |
| 625 | case WPAS_MODE_P2P_GO: |
| 626 | case WPAS_MODE_P2P_GROUP_FORMATION: |
| 627 | params.mode = IEEE80211_MODE_AP; |
| 628 | break; |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 629 | default: |
| 630 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 631 | } |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 632 | if (ssid->frequency == 0) |
| 633 | ssid->frequency = 2462; /* default channel 11 */ |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 634 | params.freq.freq = ssid->frequency; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 635 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 636 | params.wpa_proto = ssid->proto; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 637 | if (ssid->key_mgmt & WPA_KEY_MGMT_PSK) |
| 638 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK; |
| 639 | else |
| 640 | wpa_s->key_mgmt = WPA_KEY_MGMT_NONE; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 641 | params.key_mgmt_suite = wpa_s->key_mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 642 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 643 | wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher, |
| 644 | 1); |
| 645 | if (wpa_s->pairwise_cipher < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 646 | wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise " |
| 647 | "cipher."); |
| 648 | return -1; |
| 649 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 650 | params.pairwise_suite = wpa_s->pairwise_cipher; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 651 | params.group_suite = params.pairwise_suite; |
| 652 | |
| 653 | #ifdef CONFIG_P2P |
| 654 | if (ssid->mode == WPAS_MODE_P2P_GO || |
| 655 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
| 656 | params.p2p = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 657 | #endif /* CONFIG_P2P */ |
| 658 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 659 | if (wpa_s->p2pdev->set_ap_uapsd) |
| 660 | params.uapsd = wpa_s->p2pdev->ap_uapsd; |
Dmitry Shmidt | ec58b16 | 2014-02-19 12:44:18 -0800 | [diff] [blame] | 661 | else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD)) |
| 662 | params.uapsd = 1; /* mandatory for P2P GO */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 663 | else |
| 664 | params.uapsd = -1; |
| 665 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 666 | if (ieee80211_is_dfs(params.freq.freq)) |
| 667 | params.freq.freq = 0; /* set channel after CAC */ |
| 668 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 669 | if (params.p2p) |
| 670 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO); |
| 671 | else |
| 672 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS); |
| 673 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 674 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { |
| 675 | wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality"); |
| 676 | return -1; |
| 677 | } |
| 678 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 679 | wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 680 | if (hapd_iface == NULL) |
| 681 | return -1; |
| 682 | hapd_iface->owner = wpa_s; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 683 | hapd_iface->drv_flags = wpa_s->drv_flags; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 684 | hapd_iface->smps_modes = wpa_s->drv_smps_modes; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 685 | hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 686 | hapd_iface->extended_capa = wpa_s->extended_capa; |
| 687 | hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask; |
| 688 | hapd_iface->extended_capa_len = wpa_s->extended_capa_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 689 | |
| 690 | wpa_s->ap_iface->conf = conf = hostapd_config_defaults(); |
| 691 | if (conf == NULL) { |
| 692 | wpa_supplicant_ap_deinit(wpa_s); |
| 693 | return -1; |
| 694 | } |
| 695 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 696 | /* Use the maximum oper channel width if it's given. */ |
| 697 | if (ssid->max_oper_chwidth) |
| 698 | conf->vht_oper_chwidth = ssid->max_oper_chwidth; |
| 699 | |
| 700 | ieee80211_freq_to_chan(ssid->vht_center_freq2, |
| 701 | &conf->vht_oper_centr_freq_seg1_idx); |
| 702 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 703 | os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params, |
| 704 | wpa_s->conf->wmm_ac_params, |
| 705 | sizeof(wpa_s->conf->wmm_ac_params)); |
| 706 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 707 | if (params.uapsd > 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 708 | conf->bss[0]->wmm_enabled = 1; |
| 709 | conf->bss[0]->wmm_uapsd = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 710 | } |
| 711 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 712 | if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) { |
| 713 | wpa_printf(MSG_ERROR, "Failed to create AP configuration"); |
| 714 | wpa_supplicant_ap_deinit(wpa_s); |
| 715 | return -1; |
| 716 | } |
| 717 | |
| 718 | #ifdef CONFIG_P2P |
| 719 | if (ssid->mode == WPAS_MODE_P2P_GO) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 720 | conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 721 | else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 722 | conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 723 | P2P_GROUP_FORMATION; |
| 724 | #endif /* CONFIG_P2P */ |
| 725 | |
| 726 | hapd_iface->num_bss = conf->num_bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 727 | hapd_iface->bss = os_calloc(conf->num_bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 728 | sizeof(struct hostapd_data *)); |
| 729 | if (hapd_iface->bss == NULL) { |
| 730 | wpa_supplicant_ap_deinit(wpa_s); |
| 731 | return -1; |
| 732 | } |
| 733 | |
| 734 | for (i = 0; i < conf->num_bss; i++) { |
| 735 | hapd_iface->bss[i] = |
| 736 | hostapd_alloc_bss_data(hapd_iface, conf, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 737 | conf->bss[i]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 738 | if (hapd_iface->bss[i] == NULL) { |
| 739 | wpa_supplicant_ap_deinit(wpa_s); |
| 740 | return -1; |
| 741 | } |
| 742 | |
| 743 | hapd_iface->bss[i]->msg_ctx = wpa_s; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 744 | hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 745 | hapd_iface->bss[i]->public_action_cb = ap_public_action_rx; |
| 746 | hapd_iface->bss[i]->public_action_cb_ctx = wpa_s; |
| 747 | hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx; |
| 748 | hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s; |
| 749 | hostapd_register_probereq_cb(hapd_iface->bss[i], |
| 750 | ap_probe_req_rx, wpa_s); |
| 751 | hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb; |
| 752 | hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s; |
| 753 | hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb; |
| 754 | hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s; |
| 755 | hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb; |
| 756 | hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s; |
| 757 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 758 | hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb; |
| 759 | hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 760 | hapd_iface->bss[i]->p2p = wpa_s->global->p2p; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 761 | hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s, |
| 762 | ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 763 | #endif /* CONFIG_P2P */ |
| 764 | hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb; |
| 765 | hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 766 | #ifdef CONFIG_TESTING_OPTIONS |
| 767 | hapd_iface->bss[i]->ext_eapol_frame_io = |
| 768 | wpa_s->ext_eapol_frame_io; |
| 769 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN); |
| 773 | hapd_iface->bss[0]->driver = wpa_s->driver; |
| 774 | hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv; |
| 775 | |
| 776 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 777 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 778 | os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN); |
| 779 | wpa_s->assoc_freq = ssid->frequency; |
| 780 | |
| 781 | if (hostapd_setup_interface(wpa_s->ap_iface)) { |
| 782 | wpa_printf(MSG_ERROR, "Failed to initialize AP interface"); |
| 783 | wpa_supplicant_ap_deinit(wpa_s); |
| 784 | return -1; |
| 785 | } |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | |
| 791 | void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s) |
| 792 | { |
| 793 | #ifdef CONFIG_WPS |
| 794 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 795 | #endif /* CONFIG_WPS */ |
| 796 | |
| 797 | if (wpa_s->ap_iface == NULL) |
| 798 | return; |
| 799 | |
| 800 | wpa_s->current_ssid = NULL; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 801 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | wpa_s->assoc_freq = 0; |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 803 | wpas_p2p_ap_deinit(wpa_s); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 804 | wpa_s->ap_iface->driver_ap_teardown = |
| 805 | !!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT); |
| 806 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 807 | hostapd_interface_deinit(wpa_s->ap_iface); |
| 808 | hostapd_interface_free(wpa_s->ap_iface); |
| 809 | wpa_s->ap_iface = NULL; |
| 810 | wpa_drv_deinit_ap(wpa_s); |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 811 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
| 812 | " reason=%d locally_generated=1", |
| 813 | MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | |
| 817 | void ap_tx_status(void *ctx, const u8 *addr, |
| 818 | const u8 *buf, size_t len, int ack) |
| 819 | { |
| 820 | #ifdef NEED_AP_MLME |
| 821 | struct wpa_supplicant *wpa_s = ctx; |
| 822 | hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack); |
| 823 | #endif /* NEED_AP_MLME */ |
| 824 | } |
| 825 | |
| 826 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 827 | void ap_eapol_tx_status(void *ctx, const u8 *dst, |
| 828 | const u8 *data, size_t len, int ack) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 829 | { |
| 830 | #ifdef NEED_AP_MLME |
| 831 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 832 | if (!wpa_s->ap_iface) |
| 833 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 834 | hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack); |
| 835 | #endif /* NEED_AP_MLME */ |
| 836 | } |
| 837 | |
| 838 | |
| 839 | void ap_client_poll_ok(void *ctx, const u8 *addr) |
| 840 | { |
| 841 | #ifdef NEED_AP_MLME |
| 842 | struct wpa_supplicant *wpa_s = ctx; |
| 843 | if (wpa_s->ap_iface) |
| 844 | hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr); |
| 845 | #endif /* NEED_AP_MLME */ |
| 846 | } |
| 847 | |
| 848 | |
| 849 | void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds) |
| 850 | { |
| 851 | #ifdef NEED_AP_MLME |
| 852 | struct wpa_supplicant *wpa_s = ctx; |
| 853 | ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 854 | #endif /* NEED_AP_MLME */ |
| 855 | } |
| 856 | |
| 857 | |
| 858 | void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt) |
| 859 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 860 | #ifdef NEED_AP_MLME |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 861 | struct wpa_supplicant *wpa_s = ctx; |
| 862 | struct hostapd_frame_info fi; |
| 863 | os_memset(&fi, 0, sizeof(fi)); |
| 864 | fi.datarate = rx_mgmt->datarate; |
| 865 | fi.ssi_signal = rx_mgmt->ssi_signal; |
| 866 | ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame, |
| 867 | rx_mgmt->frame_len, &fi); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 868 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | |
| 872 | void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok) |
| 873 | { |
| 874 | #ifdef NEED_AP_MLME |
| 875 | struct wpa_supplicant *wpa_s = ctx; |
| 876 | ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok); |
| 877 | #endif /* NEED_AP_MLME */ |
| 878 | } |
| 879 | |
| 880 | |
| 881 | void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s, |
| 882 | const u8 *src_addr, const u8 *buf, size_t len) |
| 883 | { |
| 884 | ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | #ifdef CONFIG_WPS |
| 889 | |
| 890 | int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid, |
| 891 | const u8 *p2p_dev_addr) |
| 892 | { |
| 893 | if (!wpa_s->ap_iface) |
| 894 | return -1; |
| 895 | return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0], |
| 896 | p2p_dev_addr); |
| 897 | } |
| 898 | |
| 899 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 900 | int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s) |
| 901 | { |
| 902 | struct wps_registrar *reg; |
| 903 | int reg_sel = 0, wps_sta = 0; |
| 904 | |
| 905 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps) |
| 906 | return -1; |
| 907 | |
| 908 | reg = wpa_s->ap_iface->bss[0]->wps->registrar; |
| 909 | reg_sel = wps_registrar_wps_cancel(reg); |
| 910 | wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0], |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 911 | ap_sta_wps_cancel, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 912 | |
| 913 | if (!reg_sel && !wps_sta) { |
| 914 | wpa_printf(MSG_DEBUG, "No WPS operation in progress at this " |
| 915 | "time"); |
| 916 | return -1; |
| 917 | } |
| 918 | |
| 919 | /* |
| 920 | * There are 2 cases to return wps cancel as success: |
| 921 | * 1. When wps cancel was initiated but no connection has been |
| 922 | * established with client yet. |
| 923 | * 2. Client is in the middle of exchanging WPS messages. |
| 924 | */ |
| 925 | |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 931 | const char *pin, char *buf, size_t buflen, |
| 932 | int timeout) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 933 | { |
| 934 | int ret, ret_len = 0; |
| 935 | |
| 936 | if (!wpa_s->ap_iface) |
| 937 | return -1; |
| 938 | |
| 939 | if (pin == NULL) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 940 | unsigned int rpin; |
| 941 | |
| 942 | if (wps_generate_pin(&rpin) < 0) |
| 943 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 944 | ret_len = os_snprintf(buf, buflen, "%08d", rpin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 945 | if (os_snprintf_error(buflen, ret_len)) |
| 946 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 947 | pin = buf; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 948 | } else if (buf) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 949 | ret_len = os_snprintf(buf, buflen, "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 950 | if (os_snprintf_error(buflen, ret_len)) |
| 951 | return -1; |
| 952 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 953 | |
| 954 | ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 955 | timeout); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 956 | if (ret) |
| 957 | return -1; |
| 958 | return ret_len; |
| 959 | } |
| 960 | |
| 961 | |
| 962 | static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx) |
| 963 | { |
| 964 | struct wpa_supplicant *wpa_s = eloop_data; |
| 965 | wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out"); |
| 966 | wpas_wps_ap_pin_disable(wpa_s); |
| 967 | } |
| 968 | |
| 969 | |
| 970 | static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout) |
| 971 | { |
| 972 | struct hostapd_data *hapd; |
| 973 | |
| 974 | if (wpa_s->ap_iface == NULL) |
| 975 | return; |
| 976 | hapd = wpa_s->ap_iface->bss[0]; |
| 977 | wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout); |
| 978 | hapd->ap_pin_failures = 0; |
| 979 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 980 | if (timeout > 0) |
| 981 | eloop_register_timeout(timeout, 0, |
| 982 | wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 983 | } |
| 984 | |
| 985 | |
| 986 | void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s) |
| 987 | { |
| 988 | struct hostapd_data *hapd; |
| 989 | |
| 990 | if (wpa_s->ap_iface == NULL) |
| 991 | return; |
| 992 | wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN"); |
| 993 | hapd = wpa_s->ap_iface->bss[0]; |
| 994 | os_free(hapd->conf->ap_pin); |
| 995 | hapd->conf->ap_pin = NULL; |
| 996 | eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL); |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout) |
| 1001 | { |
| 1002 | struct hostapd_data *hapd; |
| 1003 | unsigned int pin; |
| 1004 | char pin_txt[9]; |
| 1005 | |
| 1006 | if (wpa_s->ap_iface == NULL) |
| 1007 | return NULL; |
| 1008 | hapd = wpa_s->ap_iface->bss[0]; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1009 | if (wps_generate_pin(&pin) < 0) |
| 1010 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1011 | os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1012 | os_free(hapd->conf->ap_pin); |
| 1013 | hapd->conf->ap_pin = os_strdup(pin_txt); |
| 1014 | if (hapd->conf->ap_pin == NULL) |
| 1015 | return NULL; |
| 1016 | wpas_wps_ap_pin_enable(wpa_s, timeout); |
| 1017 | |
| 1018 | return hapd->conf->ap_pin; |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s) |
| 1023 | { |
| 1024 | struct hostapd_data *hapd; |
| 1025 | if (wpa_s->ap_iface == NULL) |
| 1026 | return NULL; |
| 1027 | hapd = wpa_s->ap_iface->bss[0]; |
| 1028 | return hapd->conf->ap_pin; |
| 1029 | } |
| 1030 | |
| 1031 | |
| 1032 | int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin, |
| 1033 | int timeout) |
| 1034 | { |
| 1035 | struct hostapd_data *hapd; |
| 1036 | char pin_txt[9]; |
| 1037 | int ret; |
| 1038 | |
| 1039 | if (wpa_s->ap_iface == NULL) |
| 1040 | return -1; |
| 1041 | hapd = wpa_s->ap_iface->bss[0]; |
| 1042 | ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1043 | if (os_snprintf_error(sizeof(pin_txt), ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1044 | return -1; |
| 1045 | os_free(hapd->conf->ap_pin); |
| 1046 | hapd->conf->ap_pin = os_strdup(pin_txt); |
| 1047 | if (hapd->conf->ap_pin == NULL) |
| 1048 | return -1; |
| 1049 | wpas_wps_ap_pin_enable(wpa_s, timeout); |
| 1050 | |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s) |
| 1056 | { |
| 1057 | struct hostapd_data *hapd; |
| 1058 | |
| 1059 | if (wpa_s->ap_iface == NULL) |
| 1060 | return; |
| 1061 | hapd = wpa_s->ap_iface->bss[0]; |
| 1062 | |
| 1063 | /* |
| 1064 | * Registrar failed to prove its knowledge of the AP PIN. Disable AP |
| 1065 | * PIN if this happens multiple times to slow down brute force attacks. |
| 1066 | */ |
| 1067 | hapd->ap_pin_failures++; |
| 1068 | wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u", |
| 1069 | hapd->ap_pin_failures); |
| 1070 | if (hapd->ap_pin_failures < 3) |
| 1071 | return; |
| 1072 | |
| 1073 | wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN"); |
| 1074 | hapd->ap_pin_failures = 0; |
| 1075 | os_free(hapd->conf->ap_pin); |
| 1076 | hapd->conf->ap_pin = NULL; |
| 1077 | } |
| 1078 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1079 | |
| 1080 | #ifdef CONFIG_WPS_NFC |
| 1081 | |
| 1082 | struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s, |
| 1083 | int ndef) |
| 1084 | { |
| 1085 | struct hostapd_data *hapd; |
| 1086 | |
| 1087 | if (wpa_s->ap_iface == NULL) |
| 1088 | return NULL; |
| 1089 | hapd = wpa_s->ap_iface->bss[0]; |
| 1090 | return hostapd_wps_nfc_config_token(hapd, ndef); |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s, |
| 1095 | int ndef) |
| 1096 | { |
| 1097 | struct hostapd_data *hapd; |
| 1098 | |
| 1099 | if (wpa_s->ap_iface == NULL) |
| 1100 | return NULL; |
| 1101 | hapd = wpa_s->ap_iface->bss[0]; |
| 1102 | return hostapd_wps_nfc_hs_cr(hapd, ndef); |
| 1103 | } |
| 1104 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1105 | |
| 1106 | int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s, |
| 1107 | const struct wpabuf *req, |
| 1108 | const struct wpabuf *sel) |
| 1109 | { |
| 1110 | struct hostapd_data *hapd; |
| 1111 | |
| 1112 | if (wpa_s->ap_iface == NULL) |
| 1113 | return -1; |
| 1114 | hapd = wpa_s->ap_iface->bss[0]; |
| 1115 | return hostapd_wps_nfc_report_handover(hapd, req, sel); |
| 1116 | } |
| 1117 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1118 | #endif /* CONFIG_WPS_NFC */ |
| 1119 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1120 | #endif /* CONFIG_WPS */ |
| 1121 | |
| 1122 | |
| 1123 | #ifdef CONFIG_CTRL_IFACE |
| 1124 | |
| 1125 | int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s, |
| 1126 | char *buf, size_t buflen) |
| 1127 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1128 | struct hostapd_data *hapd; |
| 1129 | |
| 1130 | if (wpa_s->ap_iface) |
| 1131 | hapd = wpa_s->ap_iface->bss[0]; |
| 1132 | else if (wpa_s->ifmsh) |
| 1133 | hapd = wpa_s->ifmsh->bss[0]; |
| 1134 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1135 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1136 | return hostapd_ctrl_iface_sta_first(hapd, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | |
| 1140 | int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr, |
| 1141 | char *buf, size_t buflen) |
| 1142 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1143 | struct hostapd_data *hapd; |
| 1144 | |
| 1145 | if (wpa_s->ap_iface) |
| 1146 | hapd = wpa_s->ap_iface->bss[0]; |
| 1147 | else if (wpa_s->ifmsh) |
| 1148 | hapd = wpa_s->ifmsh->bss[0]; |
| 1149 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1150 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1151 | return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr, |
| 1156 | char *buf, size_t buflen) |
| 1157 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1158 | struct hostapd_data *hapd; |
| 1159 | |
| 1160 | if (wpa_s->ap_iface) |
| 1161 | hapd = wpa_s->ap_iface->bss[0]; |
| 1162 | else if (wpa_s->ifmsh) |
| 1163 | hapd = wpa_s->ifmsh->bss[0]; |
| 1164 | else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1165 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1166 | return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1170 | int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s, |
| 1171 | const char *txtaddr) |
| 1172 | { |
| 1173 | if (wpa_s->ap_iface == NULL) |
| 1174 | return -1; |
| 1175 | return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0], |
| 1176 | txtaddr); |
| 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s, |
| 1181 | const char *txtaddr) |
| 1182 | { |
| 1183 | if (wpa_s->ap_iface == NULL) |
| 1184 | return -1; |
| 1185 | return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0], |
| 1186 | txtaddr); |
| 1187 | } |
| 1188 | |
| 1189 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1190 | int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf, |
| 1191 | size_t buflen, int verbose) |
| 1192 | { |
| 1193 | char *pos = buf, *end = buf + buflen; |
| 1194 | int ret; |
| 1195 | struct hostapd_bss_config *conf; |
| 1196 | |
| 1197 | if (wpa_s->ap_iface == NULL) |
| 1198 | return -1; |
| 1199 | |
| 1200 | conf = wpa_s->ap_iface->bss[0]->conf; |
| 1201 | if (conf->wpa == 0) |
| 1202 | return 0; |
| 1203 | |
| 1204 | ret = os_snprintf(pos, end - pos, |
| 1205 | "pairwise_cipher=%s\n" |
| 1206 | "group_cipher=%s\n" |
| 1207 | "key_mgmt=%s\n", |
| 1208 | wpa_cipher_txt(conf->rsn_pairwise), |
| 1209 | wpa_cipher_txt(conf->wpa_group), |
| 1210 | wpa_key_mgmt_txt(conf->wpa_key_mgmt, |
| 1211 | conf->wpa)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1212 | if (os_snprintf_error(end - pos, ret)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1213 | return pos - buf; |
| 1214 | pos += ret; |
| 1215 | return pos - buf; |
| 1216 | } |
| 1217 | |
| 1218 | #endif /* CONFIG_CTRL_IFACE */ |
| 1219 | |
| 1220 | |
| 1221 | int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s) |
| 1222 | { |
| 1223 | struct hostapd_iface *iface = wpa_s->ap_iface; |
| 1224 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1225 | struct hostapd_data *hapd; |
| 1226 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1227 | if (ssid == NULL || wpa_s->ap_iface == NULL || |
| 1228 | ssid->mode == WPAS_MODE_INFRA || |
| 1229 | ssid->mode == WPAS_MODE_IBSS) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1230 | return -1; |
| 1231 | |
| 1232 | #ifdef CONFIG_P2P |
| 1233 | if (ssid->mode == WPAS_MODE_P2P_GO) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1234 | iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1235 | else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1236 | iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1237 | P2P_GROUP_FORMATION; |
| 1238 | #endif /* CONFIG_P2P */ |
| 1239 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1240 | hapd = iface->bss[0]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1241 | if (hapd->drv_priv == NULL) |
| 1242 | return -1; |
| 1243 | ieee802_11_set_beacons(iface); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1244 | hostapd_set_ap_wps_ie(hapd); |
| 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1250 | int ap_switch_channel(struct wpa_supplicant *wpa_s, |
| 1251 | struct csa_settings *settings) |
| 1252 | { |
| 1253 | #ifdef NEED_AP_MLME |
| 1254 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]) |
| 1255 | return -1; |
| 1256 | |
| 1257 | return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings); |
| 1258 | #else /* NEED_AP_MLME */ |
| 1259 | return -1; |
| 1260 | #endif /* NEED_AP_MLME */ |
| 1261 | } |
| 1262 | |
| 1263 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1264 | #ifdef CONFIG_CTRL_IFACE |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1265 | int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos) |
| 1266 | { |
| 1267 | struct csa_settings settings; |
| 1268 | int ret = hostapd_parse_csa_settings(pos, &settings); |
| 1269 | |
| 1270 | if (ret) |
| 1271 | return ret; |
| 1272 | |
| 1273 | return ap_switch_channel(wpa_s, &settings); |
| 1274 | } |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1275 | #endif /* CONFIG_CTRL_IFACE */ |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1276 | |
| 1277 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1278 | void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1279 | int offset, int width, int cf1, int cf2) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1280 | { |
| 1281 | if (!wpa_s->ap_iface) |
| 1282 | return; |
| 1283 | |
| 1284 | wpa_s->assoc_freq = freq; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1285 | if (wpa_s->current_ssid) |
| 1286 | wpa_s->current_ssid->frequency = freq; |
| 1287 | hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, |
| 1288 | offset, width, cf1, cf2); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1292 | int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s, |
| 1293 | const u8 *addr) |
| 1294 | { |
| 1295 | struct hostapd_data *hapd; |
| 1296 | struct hostapd_bss_config *conf; |
| 1297 | |
| 1298 | if (!wpa_s->ap_iface) |
| 1299 | return -1; |
| 1300 | |
| 1301 | if (addr) |
| 1302 | wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR, |
| 1303 | MAC2STR(addr)); |
| 1304 | else |
| 1305 | wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter"); |
| 1306 | |
| 1307 | hapd = wpa_s->ap_iface->bss[0]; |
| 1308 | conf = hapd->conf; |
| 1309 | |
| 1310 | os_free(conf->accept_mac); |
| 1311 | conf->accept_mac = NULL; |
| 1312 | conf->num_accept_mac = 0; |
| 1313 | os_free(conf->deny_mac); |
| 1314 | conf->deny_mac = NULL; |
| 1315 | conf->num_deny_mac = 0; |
| 1316 | |
| 1317 | if (addr == NULL) { |
| 1318 | conf->macaddr_acl = ACCEPT_UNLESS_DENIED; |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
| 1322 | conf->macaddr_acl = DENY_UNLESS_ACCEPTED; |
| 1323 | conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry)); |
| 1324 | if (conf->accept_mac == NULL) |
| 1325 | return -1; |
| 1326 | os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN); |
| 1327 | conf->num_accept_mac = 1; |
| 1328 | |
| 1329 | return 0; |
| 1330 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1331 | |
| 1332 | |
| 1333 | #ifdef CONFIG_WPS_NFC |
| 1334 | int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id, |
| 1335 | const struct wpabuf *pw, const u8 *pubkey_hash) |
| 1336 | { |
| 1337 | struct hostapd_data *hapd; |
| 1338 | struct wps_context *wps; |
| 1339 | |
| 1340 | if (!wpa_s->ap_iface) |
| 1341 | return -1; |
| 1342 | hapd = wpa_s->ap_iface->bss[0]; |
| 1343 | wps = hapd->wps; |
| 1344 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1345 | if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL || |
| 1346 | wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1347 | wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known"); |
| 1348 | return -1; |
| 1349 | } |
| 1350 | |
| 1351 | dh5_free(wps->dh_ctx); |
| 1352 | wpabuf_free(wps->dh_pubkey); |
| 1353 | wpabuf_free(wps->dh_privkey); |
| 1354 | wps->dh_privkey = wpabuf_dup( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1355 | wpa_s->p2pdev->conf->wps_nfc_dh_privkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1356 | wps->dh_pubkey = wpabuf_dup( |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1357 | wpa_s->p2pdev->conf->wps_nfc_dh_pubkey); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 1358 | if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) { |
| 1359 | wps->dh_ctx = NULL; |
| 1360 | wpabuf_free(wps->dh_pubkey); |
| 1361 | wps->dh_pubkey = NULL; |
| 1362 | wpabuf_free(wps->dh_privkey); |
| 1363 | wps->dh_privkey = NULL; |
| 1364 | return -1; |
| 1365 | } |
| 1366 | wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey); |
| 1367 | if (wps->dh_ctx == NULL) |
| 1368 | return -1; |
| 1369 | |
| 1370 | return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash, |
| 1371 | pw_id, |
| 1372 | pw ? wpabuf_head(pw) : NULL, |
| 1373 | pw ? wpabuf_len(pw) : 0, 1); |
| 1374 | } |
| 1375 | #endif /* CONFIG_WPS_NFC */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1376 | |
| 1377 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 1378 | #ifdef CONFIG_CTRL_IFACE |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1379 | int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s) |
| 1380 | { |
| 1381 | struct hostapd_data *hapd; |
| 1382 | |
| 1383 | if (!wpa_s->ap_iface) |
| 1384 | return -1; |
| 1385 | hapd = wpa_s->ap_iface->bss[0]; |
| 1386 | return hostapd_ctrl_iface_stop_ap(hapd); |
| 1387 | } |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1388 | |
| 1389 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1390 | int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf, |
| 1391 | size_t len) |
| 1392 | { |
| 1393 | size_t reply_len = 0, i; |
| 1394 | char ap_delimiter[] = "---- AP ----\n"; |
| 1395 | char mesh_delimiter[] = "---- mesh ----\n"; |
| 1396 | size_t dlen; |
| 1397 | |
| 1398 | if (wpa_s->ap_iface) { |
| 1399 | dlen = os_strlen(ap_delimiter); |
| 1400 | if (dlen > len - reply_len) |
| 1401 | return reply_len; |
| 1402 | os_memcpy(&buf[reply_len], ap_delimiter, dlen); |
| 1403 | reply_len += dlen; |
| 1404 | |
| 1405 | for (i = 0; i < wpa_s->ap_iface->num_bss; i++) { |
| 1406 | reply_len += hostapd_ctrl_iface_pmksa_list( |
| 1407 | wpa_s->ap_iface->bss[i], |
| 1408 | &buf[reply_len], len - reply_len); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | if (wpa_s->ifmsh) { |
| 1413 | dlen = os_strlen(mesh_delimiter); |
| 1414 | if (dlen > len - reply_len) |
| 1415 | return reply_len; |
| 1416 | os_memcpy(&buf[reply_len], mesh_delimiter, dlen); |
| 1417 | reply_len += dlen; |
| 1418 | |
| 1419 | reply_len += hostapd_ctrl_iface_pmksa_list( |
| 1420 | wpa_s->ifmsh->bss[0], &buf[reply_len], |
| 1421 | len - reply_len); |
| 1422 | } |
| 1423 | |
| 1424 | return reply_len; |
| 1425 | } |
| 1426 | |
| 1427 | |
| 1428 | void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s) |
| 1429 | { |
| 1430 | size_t i; |
| 1431 | |
| 1432 | if (wpa_s->ap_iface) { |
| 1433 | for (i = 0; i < wpa_s->ap_iface->num_bss; i++) |
| 1434 | hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]); |
| 1435 | } |
| 1436 | |
| 1437 | if (wpa_s->ifmsh) |
| 1438 | hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]); |
| 1439 | } |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame^] | 1440 | |
| 1441 | |
| 1442 | #ifdef CONFIG_PMKSA_CACHE_EXTERNAL |
| 1443 | #ifdef CONFIG_MESH |
| 1444 | |
| 1445 | int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 1446 | char *buf, size_t len) |
| 1447 | { |
| 1448 | return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr, |
| 1449 | &buf[0], len); |
| 1450 | } |
| 1451 | |
| 1452 | |
| 1453 | int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd) |
| 1454 | { |
| 1455 | struct external_pmksa_cache *entry; |
| 1456 | void *pmksa_cache; |
| 1457 | |
| 1458 | pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr, |
| 1459 | cmd); |
| 1460 | if (!pmksa_cache) |
| 1461 | return -1; |
| 1462 | |
| 1463 | entry = os_zalloc(sizeof(struct external_pmksa_cache)); |
| 1464 | if (!entry) |
| 1465 | return -1; |
| 1466 | |
| 1467 | entry->pmksa_cache = pmksa_cache; |
| 1468 | |
| 1469 | dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list); |
| 1470 | |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
| 1474 | #endif /* CONFIG_MESH */ |
| 1475 | #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */ |
| 1476 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1477 | #endif /* CONFIG_CTRL_IFACE */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1478 | |
| 1479 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1480 | #ifdef NEED_AP_MLME |
| 1481 | void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s, |
| 1482 | struct dfs_event *radar) |
| 1483 | { |
| 1484 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]) |
| 1485 | return; |
| 1486 | wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq); |
| 1487 | hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq, |
| 1488 | radar->ht_enabled, radar->chan_offset, |
| 1489 | radar->chan_width, |
| 1490 | radar->cf1, radar->cf2); |
| 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s, |
| 1495 | struct dfs_event *radar) |
| 1496 | { |
| 1497 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]) |
| 1498 | return; |
| 1499 | wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq); |
| 1500 | hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq, |
| 1501 | radar->ht_enabled, radar->chan_offset, |
| 1502 | radar->chan_width, radar->cf1, radar->cf2); |
| 1503 | } |
| 1504 | |
| 1505 | |
| 1506 | void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s, |
| 1507 | struct dfs_event *radar) |
| 1508 | { |
| 1509 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]) |
| 1510 | return; |
| 1511 | wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq); |
| 1512 | hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq, |
| 1513 | radar->ht_enabled, radar->chan_offset, |
| 1514 | radar->chan_width, radar->cf1, radar->cf2); |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s, |
| 1519 | struct dfs_event *radar) |
| 1520 | { |
| 1521 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]) |
| 1522 | return; |
| 1523 | wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq); |
| 1524 | hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq, |
| 1525 | radar->ht_enabled, radar->chan_offset, |
| 1526 | radar->chan_width, radar->cf1, radar->cf2); |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s, |
| 1531 | struct dfs_event *radar) |
| 1532 | { |
| 1533 | if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]) |
| 1534 | return; |
| 1535 | wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq); |
| 1536 | hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq, |
| 1537 | radar->ht_enabled, radar->chan_offset, |
| 1538 | radar->chan_width, radar->cf1, radar->cf2); |
| 1539 | } |
| 1540 | #endif /* NEED_AP_MLME */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1541 | |
| 1542 | |
| 1543 | void ap_periodic(struct wpa_supplicant *wpa_s) |
| 1544 | { |
| 1545 | if (wpa_s->ap_iface) |
| 1546 | hostapd_periodic_iface(wpa_s->ap_iface); |
| 1547 | } |