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