Home | History | Annotate | Line # | Download | only in wpa_supplicant
ap.c revision 1.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  christos #include "common/ieee802_11_defs.h"
     20  1.1  christos #include "ap/hostapd.h"
     21  1.1  christos #include "ap/ap_config.h"
     22  1.1  christos #ifdef NEED_AP_MLME
     23  1.1  christos #include "ap/ieee802_11.h"
     24  1.1  christos #endif /* NEED_AP_MLME */
     25  1.1  christos #include "ap/ieee802_1x.h"
     26  1.1  christos #include "ap/wps_hostapd.h"
     27  1.1  christos #include "ap/ctrl_iface_ap.h"
     28  1.1  christos #include "eap_common/eap_defs.h"
     29  1.1  christos #include "eap_server/eap_methods.h"
     30  1.1  christos #include "eap_common/eap_wsc_common.h"
     31  1.1  christos #include "wps/wps.h"
     32  1.1  christos #include "config_ssid.h"
     33  1.1  christos #include "config.h"
     34  1.1  christos #include "wpa_supplicant_i.h"
     35  1.1  christos #include "driver_i.h"
     36  1.1  christos #include "ap.h"
     37  1.1  christos 
     38  1.1  christos 
     39  1.1  christos static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
     40  1.1  christos 				  struct wpa_ssid *ssid,
     41  1.1  christos 				  struct hostapd_config *conf)
     42  1.1  christos {
     43  1.1  christos 	struct hostapd_bss_config *bss = &conf->bss[0];
     44  1.1  christos 	int pairwise;
     45  1.1  christos 
     46  1.1  christos 	conf->driver = wpa_s->driver;
     47  1.1  christos 
     48  1.1  christos 	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
     49  1.1  christos 
     50  1.1  christos 	if (ssid->frequency == 0) {
     51  1.1  christos 		/* default channel 11 */
     52  1.1  christos 		conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
     53  1.1  christos 		conf->channel = 11;
     54  1.1  christos 	} else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
     55  1.1  christos 		conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
     56  1.1  christos 		conf->channel = (ssid->frequency - 2407) / 5;
     57  1.1  christos 	} else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
     58  1.1  christos 		   (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
     59  1.1  christos 		conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
     60  1.1  christos 		conf->channel = (ssid->frequency - 5000) / 5;
     61  1.1  christos 	} else {
     62  1.1  christos 		wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
     63  1.1  christos 			   ssid->frequency);
     64  1.1  christos 		return -1;
     65  1.1  christos 	}
     66  1.1  christos 
     67  1.1  christos 	/* TODO: enable HT if driver supports it;
     68  1.1  christos 	 * drop to 11b if driver does not support 11g */
     69  1.1  christos 
     70  1.1  christos 	if (ssid->ssid_len == 0) {
     71  1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
     72  1.1  christos 		return -1;
     73  1.1  christos 	}
     74  1.1  christos 	os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
     75  1.1  christos 	bss->ssid.ssid[ssid->ssid_len] = '\0';
     76  1.1  christos 	bss->ssid.ssid_len = ssid->ssid_len;
     77  1.1  christos 	bss->ssid.ssid_set = 1;
     78  1.1  christos 
     79  1.1  christos 	if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
     80  1.1  christos 		bss->wpa = ssid->proto;
     81  1.1  christos 	bss->wpa_key_mgmt = ssid->key_mgmt;
     82  1.1  christos 	bss->wpa_pairwise = ssid->pairwise_cipher;
     83  1.1  christos 	if (ssid->passphrase) {
     84  1.1  christos 		bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
     85  1.1  christos 	} else if (ssid->psk_set) {
     86  1.1  christos 		os_free(bss->ssid.wpa_psk);
     87  1.1  christos 		bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
     88  1.1  christos 		if (bss->ssid.wpa_psk == NULL)
     89  1.1  christos 			return -1;
     90  1.1  christos 		os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
     91  1.1  christos 		bss->ssid.wpa_psk->group = 1;
     92  1.1  christos 	}
     93  1.1  christos 
     94  1.1  christos 	/* Select group cipher based on the enabled pairwise cipher suites */
     95  1.1  christos 	pairwise = 0;
     96  1.1  christos 	if (bss->wpa & 1)
     97  1.1  christos 		pairwise |= bss->wpa_pairwise;
     98  1.1  christos 	if (bss->wpa & 2) {
     99  1.1  christos 		if (bss->rsn_pairwise == 0)
    100  1.1  christos 			bss->rsn_pairwise = bss->wpa_pairwise;
    101  1.1  christos 		pairwise |= bss->rsn_pairwise;
    102  1.1  christos 	}
    103  1.1  christos 	if (pairwise & WPA_CIPHER_TKIP)
    104  1.1  christos 		bss->wpa_group = WPA_CIPHER_TKIP;
    105  1.1  christos 	else
    106  1.1  christos 		bss->wpa_group = WPA_CIPHER_CCMP;
    107  1.1  christos 
    108  1.1  christos 	if (bss->wpa && bss->ieee802_1x)
    109  1.1  christos 		bss->ssid.security_policy = SECURITY_WPA;
    110  1.1  christos 	else if (bss->wpa)
    111  1.1  christos 		bss->ssid.security_policy = SECURITY_WPA_PSK;
    112  1.1  christos 	else if (bss->ieee802_1x) {
    113  1.1  christos 		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
    114  1.1  christos 		bss->ssid.wep.default_len = bss->default_wep_key_len;
    115  1.1  christos 	} else if (bss->ssid.wep.keys_set)
    116  1.1  christos 		bss->ssid.security_policy = SECURITY_STATIC_WEP;
    117  1.1  christos 	else
    118  1.1  christos 		bss->ssid.security_policy = SECURITY_PLAINTEXT;
    119  1.1  christos 
    120  1.1  christos #ifdef CONFIG_WPS
    121  1.1  christos 	/*
    122  1.1  christos 	 * Enable WPS by default, but require user interaction to actually use
    123  1.1  christos 	 * it. Only the internal Registrar is supported.
    124  1.1  christos 	 */
    125  1.1  christos 	bss->eap_server = 1;
    126  1.1  christos 	bss->wps_state = 2;
    127  1.1  christos 	bss->ap_setup_locked = 1;
    128  1.1  christos 	if (wpa_s->conf->config_methods)
    129  1.1  christos 		bss->config_methods = os_strdup(wpa_s->conf->config_methods);
    130  1.1  christos 	if (wpa_s->conf->device_type)
    131  1.1  christos 		bss->device_type = os_strdup(wpa_s->conf->device_type);
    132  1.1  christos #endif /* CONFIG_WPS */
    133  1.1  christos 
    134  1.1  christos 	return 0;
    135  1.1  christos }
    136  1.1  christos 
    137  1.1  christos 
    138  1.1  christos static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    139  1.1  christos {
    140  1.1  christos }
    141  1.1  christos 
    142  1.1  christos 
    143  1.1  christos static int ap_probe_req_rx(void *ctx, const u8 *addr, const u8 *ie,
    144  1.1  christos 			   size_t ie_len)
    145  1.1  christos {
    146  1.1  christos 	return 0;
    147  1.1  christos }
    148  1.1  christos 
    149  1.1  christos 
    150  1.1  christos static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
    151  1.1  christos 				  const u8 *uuid_e)
    152  1.1  christos {
    153  1.1  christos }
    154  1.1  christos 
    155  1.1  christos 
    156  1.1  christos int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
    157  1.1  christos 			     struct wpa_ssid *ssid)
    158  1.1  christos {
    159  1.1  christos 	struct wpa_driver_associate_params params;
    160  1.1  christos 	struct hostapd_iface *hapd_iface;
    161  1.1  christos 	struct hostapd_config *conf;
    162  1.1  christos 	size_t i;
    163  1.1  christos 
    164  1.1  christos 	if (ssid->ssid == NULL || ssid->ssid_len == 0) {
    165  1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    166  1.1  christos 		return -1;
    167  1.1  christos 	}
    168  1.1  christos 
    169  1.1  christos 	wpa_supplicant_ap_deinit(wpa_s);
    170  1.1  christos 
    171  1.1  christos 	wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
    172  1.1  christos 		   wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
    173  1.1  christos 
    174  1.1  christos 	os_memset(&params, 0, sizeof(params));
    175  1.1  christos 	params.ssid = ssid->ssid;
    176  1.1  christos 	params.ssid_len = ssid->ssid_len;
    177  1.1  christos 	switch (ssid->mode) {
    178  1.1  christos 	case WPAS_MODE_INFRA:
    179  1.1  christos 		params.mode = IEEE80211_MODE_INFRA;
    180  1.1  christos 		break;
    181  1.1  christos 	case WPAS_MODE_IBSS:
    182  1.1  christos 		params.mode = IEEE80211_MODE_IBSS;
    183  1.1  christos 		break;
    184  1.1  christos 	case WPAS_MODE_AP:
    185  1.1  christos 		params.mode = IEEE80211_MODE_AP;
    186  1.1  christos 		break;
    187  1.1  christos 	}
    188  1.1  christos 	params.freq = ssid->frequency;
    189  1.1  christos 
    190  1.1  christos 	if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
    191  1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
    192  1.1  christos 	else
    193  1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
    194  1.1  christos 	params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
    195  1.1  christos 
    196  1.1  christos 	if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
    197  1.1  christos 		wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
    198  1.1  christos 	else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
    199  1.1  christos 		wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
    200  1.1  christos 	else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
    201  1.1  christos 		wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
    202  1.1  christos 	else {
    203  1.1  christos 		wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
    204  1.1  christos 			   "cipher.");
    205  1.1  christos 		return -1;
    206  1.1  christos 	}
    207  1.1  christos 	params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
    208  1.1  christos 	params.group_suite = params.pairwise_suite;
    209  1.1  christos 
    210  1.1  christos 	if (wpa_drv_associate(wpa_s, &params) < 0) {
    211  1.1  christos 		wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
    212  1.1  christos 		return -1;
    213  1.1  christos 	}
    214  1.1  christos 
    215  1.1  christos 	wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
    216  1.1  christos 	if (hapd_iface == NULL)
    217  1.1  christos 		return -1;
    218  1.1  christos 	hapd_iface->owner = wpa_s;
    219  1.1  christos 
    220  1.1  christos 	wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
    221  1.1  christos 	if (conf == NULL) {
    222  1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    223  1.1  christos 		return -1;
    224  1.1  christos 	}
    225  1.1  christos 
    226  1.1  christos 	if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
    227  1.1  christos 		wpa_printf(MSG_ERROR, "Failed to create AP configuration");
    228  1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    229  1.1  christos 		return -1;
    230  1.1  christos 	}
    231  1.1  christos 
    232  1.1  christos 	hapd_iface->num_bss = conf->num_bss;
    233  1.1  christos 	hapd_iface->bss = os_zalloc(conf->num_bss *
    234  1.1  christos 				    sizeof(struct hostapd_data *));
    235  1.1  christos 	if (hapd_iface->bss == NULL) {
    236  1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    237  1.1  christos 		return -1;
    238  1.1  christos 	}
    239  1.1  christos 
    240  1.1  christos 	for (i = 0; i < conf->num_bss; i++) {
    241  1.1  christos 		hapd_iface->bss[i] =
    242  1.1  christos 			hostapd_alloc_bss_data(hapd_iface, conf,
    243  1.1  christos 					       &conf->bss[i]);
    244  1.1  christos 		if (hapd_iface->bss[i] == NULL) {
    245  1.1  christos 			wpa_supplicant_ap_deinit(wpa_s);
    246  1.1  christos 			return -1;
    247  1.1  christos 		}
    248  1.1  christos 
    249  1.1  christos 		hapd_iface->bss[i]->msg_ctx = wpa_s;
    250  1.1  christos 		hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
    251  1.1  christos 		hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
    252  1.1  christos 		hostapd_register_probereq_cb(hapd_iface->bss[i],
    253  1.1  christos 					     ap_probe_req_rx, wpa_s);
    254  1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
    255  1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
    256  1.1  christos 	}
    257  1.1  christos 
    258  1.1  christos 	os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
    259  1.1  christos 	hapd_iface->bss[0]->driver = wpa_s->driver;
    260  1.1  christos 	hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
    261  1.1  christos 
    262  1.1  christos 	if (hostapd_setup_interface(wpa_s->ap_iface)) {
    263  1.1  christos 		wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
    264  1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    265  1.1  christos 		return -1;
    266  1.1  christos 	}
    267  1.1  christos 
    268  1.1  christos 	wpa_s->current_ssid = ssid;
    269  1.1  christos 	os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
    270  1.1  christos 	wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    271  1.1  christos 
    272  1.1  christos 	if (wpa_s->ap_configured_cb)
    273  1.1  christos 		wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
    274  1.1  christos 					wpa_s->ap_configured_cb_data);
    275  1.1  christos 
    276  1.1  christos 	return 0;
    277  1.1  christos }
    278  1.1  christos 
    279  1.1  christos 
    280  1.1  christos void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
    281  1.1  christos {
    282  1.1  christos 	if (wpa_s->ap_iface == NULL)
    283  1.1  christos 		return;
    284  1.1  christos 
    285  1.1  christos 	wpa_s->current_ssid = NULL;
    286  1.1  christos 	hostapd_interface_deinit(wpa_s->ap_iface);
    287  1.1  christos 	hostapd_interface_free(wpa_s->ap_iface);
    288  1.1  christos 	wpa_s->ap_iface = NULL;
    289  1.1  christos 	wpa_drv_deinit_ap(wpa_s);
    290  1.1  christos }
    291  1.1  christos 
    292  1.1  christos 
    293  1.1  christos void ap_tx_status(void *ctx, const u8 *addr,
    294  1.1  christos 		  const u8 *buf, size_t len, int ack)
    295  1.1  christos {
    296  1.1  christos #ifdef NEED_AP_MLME
    297  1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    298  1.1  christos 	hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
    299  1.1  christos #endif /* NEED_AP_MLME */
    300  1.1  christos }
    301  1.1  christos 
    302  1.1  christos 
    303  1.1  christos void ap_rx_from_unknown_sta(void *ctx, const u8 *frame, size_t len)
    304  1.1  christos {
    305  1.1  christos #ifdef NEED_AP_MLME
    306  1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    307  1.1  christos 	const struct ieee80211_hdr *hdr =
    308  1.1  christos 		(const struct ieee80211_hdr *) frame;
    309  1.1  christos 	u16 fc = le_to_host16(hdr->frame_control);
    310  1.1  christos 	ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], hdr->addr2,
    311  1.1  christos 				   (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
    312  1.1  christos 				   (WLAN_FC_TODS | WLAN_FC_FROMDS));
    313  1.1  christos #endif /* NEED_AP_MLME */
    314  1.1  christos }
    315  1.1  christos 
    316  1.1  christos 
    317  1.1  christos void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
    318  1.1  christos {
    319  1.1  christos #ifdef NEED_AP_MLME
    320  1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    321  1.1  christos 	struct hostapd_frame_info fi;
    322  1.1  christos 	os_memset(&fi, 0, sizeof(fi));
    323  1.1  christos 	fi.datarate = rx_mgmt->datarate;
    324  1.1  christos 	fi.ssi_signal = rx_mgmt->ssi_signal;
    325  1.1  christos 	ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
    326  1.1  christos 			rx_mgmt->frame_len, &fi);
    327  1.1  christos #endif /* NEED_AP_MLME */
    328  1.1  christos }
    329  1.1  christos 
    330  1.1  christos 
    331  1.1  christos void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
    332  1.1  christos {
    333  1.1  christos #ifdef NEED_AP_MLME
    334  1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    335  1.1  christos 	ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
    336  1.1  christos #endif /* NEED_AP_MLME */
    337  1.1  christos }
    338  1.1  christos 
    339  1.1  christos 
    340  1.1  christos void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
    341  1.1  christos 				const u8 *src_addr, const u8 *buf, size_t len)
    342  1.1  christos {
    343  1.1  christos 	ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
    344  1.1  christos }
    345  1.1  christos 
    346  1.1  christos 
    347  1.1  christos #ifdef CONFIG_WPS
    348  1.1  christos 
    349  1.1  christos int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid)
    350  1.1  christos {
    351  1.1  christos 	if (!wpa_s->ap_iface)
    352  1.1  christos 		return -1;
    353  1.1  christos 	return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0]);
    354  1.1  christos }
    355  1.1  christos 
    356  1.1  christos 
    357  1.1  christos int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
    358  1.1  christos 			      const char *pin, char *buf, size_t buflen)
    359  1.1  christos {
    360  1.1  christos 	int ret, ret_len = 0;
    361  1.1  christos 
    362  1.1  christos 	if (!wpa_s->ap_iface)
    363  1.1  christos 		return -1;
    364  1.1  christos 
    365  1.1  christos 	if (pin == NULL) {
    366  1.1  christos 		unsigned int rpin = wps_generate_pin();
    367  1.1  christos 		ret_len = os_snprintf(buf, buflen, "%d", rpin);
    368  1.1  christos 		pin = buf;
    369  1.1  christos 	}
    370  1.1  christos 
    371  1.1  christos 	ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], "any", pin, 0);
    372  1.1  christos 	if (ret)
    373  1.1  christos 		return -1;
    374  1.1  christos 	return ret_len;
    375  1.1  christos }
    376  1.1  christos 
    377  1.1  christos #endif /* CONFIG_WPS */
    378  1.1  christos 
    379  1.1  christos 
    380  1.1  christos #ifdef CONFIG_CTRL_IFACE
    381  1.1  christos 
    382  1.1  christos int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
    383  1.1  christos 			    char *buf, size_t buflen)
    384  1.1  christos {
    385  1.1  christos 	if (wpa_s->ap_iface == NULL)
    386  1.1  christos 		return -1;
    387  1.1  christos 	return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
    388  1.1  christos 					    buf, buflen);
    389  1.1  christos }
    390  1.1  christos 
    391  1.1  christos 
    392  1.1  christos int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
    393  1.1  christos 		      char *buf, size_t buflen)
    394  1.1  christos {
    395  1.1  christos 	if (wpa_s->ap_iface == NULL)
    396  1.1  christos 		return -1;
    397  1.1  christos 	return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
    398  1.1  christos 				      buf, buflen);
    399  1.1  christos }
    400  1.1  christos 
    401  1.1  christos 
    402  1.1  christos int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
    403  1.1  christos 			   char *buf, size_t buflen)
    404  1.1  christos {
    405  1.1  christos 	if (wpa_s->ap_iface == NULL)
    406  1.1  christos 		return -1;
    407  1.1  christos 	return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
    408  1.1  christos 					   buf, buflen);
    409  1.1  christos }
    410  1.1  christos 
    411  1.1  christos 
    412  1.1  christos int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
    413  1.1  christos 				 size_t buflen, int verbose)
    414  1.1  christos {
    415  1.1  christos 	char *pos = buf, *end = buf + buflen;
    416  1.1  christos 	int ret;
    417  1.1  christos 	struct hostapd_bss_config *conf;
    418  1.1  christos 
    419  1.1  christos 	if (wpa_s->ap_iface == NULL)
    420  1.1  christos 		return -1;
    421  1.1  christos 
    422  1.1  christos 	conf = wpa_s->ap_iface->bss[0]->conf;
    423  1.1  christos 	if (conf->wpa == 0)
    424  1.1  christos 		return 0;
    425  1.1  christos 
    426  1.1  christos 	ret = os_snprintf(pos, end - pos,
    427  1.1  christos 			  "pairwise_cipher=%s\n"
    428  1.1  christos 			  "group_cipher=%s\n"
    429  1.1  christos 			  "key_mgmt=%s\n",
    430  1.1  christos 			  wpa_cipher_txt(conf->rsn_pairwise),
    431  1.1  christos 			  wpa_cipher_txt(conf->wpa_group),
    432  1.1  christos 			  wpa_key_mgmt_txt(conf->wpa_key_mgmt,
    433  1.1  christos 					   conf->wpa));
    434  1.1  christos 	if (ret < 0 || ret >= end - pos)
    435  1.1  christos 		return pos - buf;
    436  1.1  christos 	pos += ret;
    437  1.1  christos 	return pos - buf;
    438  1.1  christos }
    439  1.1  christos 
    440  1.1  christos #endif /* CONFIG_CTRL_IFACE */
    441  1.1  christos 
    442  1.1  christos 
    443  1.1  christos int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
    444  1.1  christos 				      const u8 *addr)
    445  1.1  christos {
    446  1.1  christos 	struct hostapd_data *hapd;
    447  1.1  christos 	struct hostapd_bss_config *conf;
    448  1.1  christos 
    449  1.1  christos 	if (!wpa_s->ap_iface)
    450  1.1  christos 		return -1;
    451  1.1  christos 
    452  1.1  christos 	if (addr)
    453  1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
    454  1.1  christos 			   MAC2STR(addr));
    455  1.1  christos 	else
    456  1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
    457  1.1  christos 
    458  1.1  christos 	hapd = wpa_s->ap_iface->bss[0];
    459  1.1  christos 	conf = hapd->conf;
    460  1.1  christos 
    461  1.1  christos 	os_free(conf->accept_mac);
    462  1.1  christos 	conf->accept_mac = NULL;
    463  1.1  christos 	conf->num_accept_mac = 0;
    464  1.1  christos 	os_free(conf->deny_mac);
    465  1.1  christos 	conf->deny_mac = NULL;
    466  1.1  christos 	conf->num_deny_mac = 0;
    467  1.1  christos 
    468  1.1  christos 	if (addr == NULL) {
    469  1.1  christos 		conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
    470  1.1  christos 		return 0;
    471  1.1  christos 	}
    472  1.1  christos 
    473  1.1  christos 	conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
    474  1.1  christos 	conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
    475  1.1  christos 	if (conf->accept_mac == NULL)
    476  1.1  christos 		return -1;
    477  1.1  christos 	os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
    478  1.1  christos 	conf->num_accept_mac = 1;
    479  1.1  christos 
    480  1.1  christos 	return 0;
    481  1.1  christos }
    482