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