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