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