LCOV - code coverage report
Current view: top level - wpa_supplicant - ap.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1401264779 Lines: 496 622 79.7 %
Date: 2014-05-28 Functions: 40 44 90.9 %

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

Generated by: LCOV version 1.10