LCOV - code coverage report
Current view: top level - src/wps - wps.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1401264779 Lines: 238 289 82.4 %
Date: 2014-05-28 Functions: 17 17 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Wi-Fi Protected Setup
       3             :  * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
       4             :  *
       5             :  * This software may be distributed under the terms of the BSD license.
       6             :  * See README for more details.
       7             :  */
       8             : 
       9             : #include "includes.h"
      10             : 
      11             : #include "common.h"
      12             : #include "crypto/dh_group5.h"
      13             : #include "common/ieee802_11_defs.h"
      14             : #include "wps_i.h"
      15             : #include "wps_dev_attr.h"
      16             : 
      17             : 
      18             : #ifdef CONFIG_WPS_TESTING
      19             : int wps_version_number = 0x20;
      20             : int wps_testing_dummy_cred = 0;
      21             : int wps_corrupt_pkhash = 0;
      22             : #endif /* CONFIG_WPS_TESTING */
      23             : 
      24             : 
      25             : /**
      26             :  * wps_init - Initialize WPS Registration protocol data
      27             :  * @cfg: WPS configuration
      28             :  * Returns: Pointer to allocated data or %NULL on failure
      29             :  *
      30             :  * This function is used to initialize WPS data for a registration protocol
      31             :  * instance (i.e., each run of registration protocol as a Registrar of
      32             :  * Enrollee. The caller is responsible for freeing this data after the
      33             :  * registration run has been completed by calling wps_deinit().
      34             :  */
      35         422 : struct wps_data * wps_init(const struct wps_config *cfg)
      36             : {
      37         422 :         struct wps_data *data = os_zalloc(sizeof(*data));
      38         422 :         if (data == NULL)
      39           0 :                 return NULL;
      40         422 :         data->wps = cfg->wps;
      41         422 :         data->registrar = cfg->registrar;
      42         422 :         if (cfg->registrar) {
      43         210 :                 os_memcpy(data->uuid_r, cfg->wps->uuid, WPS_UUID_LEN);
      44             :         } else {
      45         212 :                 os_memcpy(data->mac_addr_e, cfg->wps->dev.mac_addr, ETH_ALEN);
      46         212 :                 os_memcpy(data->uuid_e, cfg->wps->uuid, WPS_UUID_LEN);
      47             :         }
      48         422 :         if (cfg->pin) {
      49         198 :                 data->dev_pw_id = cfg->dev_pw_id;
      50         198 :                 data->dev_password = os_malloc(cfg->pin_len);
      51         198 :                 if (data->dev_password == NULL) {
      52           0 :                         os_free(data);
      53           0 :                         return NULL;
      54             :                 }
      55         198 :                 os_memcpy(data->dev_password, cfg->pin, cfg->pin_len);
      56         198 :                 data->dev_password_len = cfg->pin_len;
      57         396 :                 wpa_hexdump_key(MSG_DEBUG, "WPS: AP PIN dev_password",
      58         198 :                                 data->dev_password, data->dev_password_len);
      59             :         }
      60             : 
      61             : #ifdef CONFIG_WPS_NFC
      62         646 :         if (cfg->pin == NULL &&
      63         224 :             cfg->dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER)
      64          17 :                 data->dev_pw_id = cfg->dev_pw_id;
      65             : 
      66         422 :         if (cfg->wps->ap && !cfg->registrar && cfg->wps->ap_nfc_dev_pw_id) {
      67             :                 /* Keep AP PIN as alternative Device Password */
      68           1 :                 data->alt_dev_pw_id = data->dev_pw_id;
      69           1 :                 data->alt_dev_password = data->dev_password;
      70           1 :                 data->alt_dev_password_len = data->dev_password_len;
      71             : 
      72           1 :                 data->dev_pw_id = cfg->wps->ap_nfc_dev_pw_id;
      73           1 :                 data->dev_password =
      74           1 :                         os_malloc(wpabuf_len(cfg->wps->ap_nfc_dev_pw));
      75           1 :                 if (data->dev_password == NULL) {
      76           0 :                         os_free(data);
      77           0 :                         return NULL;
      78             :                 }
      79           1 :                 os_memcpy(data->dev_password,
      80             :                           wpabuf_head(cfg->wps->ap_nfc_dev_pw),
      81             :                           wpabuf_len(cfg->wps->ap_nfc_dev_pw));
      82           1 :                 data->dev_password_len = wpabuf_len(cfg->wps->ap_nfc_dev_pw);
      83           2 :                 wpa_hexdump_key(MSG_DEBUG, "WPS: NFC dev_password",
      84           1 :                             data->dev_password, data->dev_password_len);
      85             :         }
      86             : #endif /* CONFIG_WPS_NFC */
      87             : 
      88         422 :         data->pbc = cfg->pbc;
      89         422 :         if (cfg->pbc) {
      90             :                 /* Use special PIN '00000000' for PBC */
      91          30 :                 data->dev_pw_id = DEV_PW_PUSHBUTTON;
      92          30 :                 os_free(data->dev_password);
      93          30 :                 data->dev_password = (u8 *) os_strdup("00000000");
      94          30 :                 if (data->dev_password == NULL) {
      95           0 :                         os_free(data);
      96           0 :                         return NULL;
      97             :                 }
      98          30 :                 data->dev_password_len = 8;
      99             :         }
     100             : 
     101         422 :         data->state = data->registrar ? RECV_M1 : SEND_M1;
     102             : 
     103         422 :         if (cfg->assoc_wps_ie) {
     104             :                 struct wps_parse_attr attr;
     105         200 :                 wpa_hexdump_buf(MSG_DEBUG, "WPS: WPS IE from (Re)AssocReq",
     106             :                                 cfg->assoc_wps_ie);
     107         200 :                 if (wps_parse_msg(cfg->assoc_wps_ie, &attr) < 0) {
     108           0 :                         wpa_printf(MSG_DEBUG, "WPS: Failed to parse WPS IE "
     109             :                                    "from (Re)AssocReq");
     110         200 :                 } else if (attr.request_type == NULL) {
     111           0 :                         wpa_printf(MSG_DEBUG, "WPS: No Request Type attribute "
     112             :                                    "in (Re)AssocReq WPS IE");
     113             :                 } else {
     114         200 :                         wpa_printf(MSG_DEBUG, "WPS: Request Type (from WPS IE "
     115             :                                    "in (Re)AssocReq WPS IE): %d",
     116         200 :                                    *attr.request_type);
     117         200 :                         data->request_type = *attr.request_type;
     118             :                 }
     119             :         }
     120             : 
     121         422 :         if (cfg->new_ap_settings) {
     122          17 :                 data->new_ap_settings =
     123          17 :                         os_malloc(sizeof(*data->new_ap_settings));
     124          17 :                 if (data->new_ap_settings == NULL) {
     125           0 :                         os_free(data->dev_password);
     126           0 :                         os_free(data);
     127           0 :                         return NULL;
     128             :                 }
     129          17 :                 os_memcpy(data->new_ap_settings, cfg->new_ap_settings,
     130             :                           sizeof(*data->new_ap_settings));
     131             :         }
     132             : 
     133         422 :         if (cfg->peer_addr)
     134         208 :                 os_memcpy(data->peer_dev.mac_addr, cfg->peer_addr, ETH_ALEN);
     135         422 :         if (cfg->p2p_dev_addr)
     136         106 :                 os_memcpy(data->p2p_dev_addr, cfg->p2p_dev_addr, ETH_ALEN);
     137             : 
     138         422 :         data->use_psk_key = cfg->use_psk_key;
     139         422 :         data->pbc_in_m1 = cfg->pbc_in_m1;
     140             : 
     141         422 :         if (cfg->peer_pubkey_hash) {
     142          17 :                 os_memcpy(data->peer_pubkey_hash, cfg->peer_pubkey_hash,
     143             :                           WPS_OOB_PUBKEY_HASH_LEN);
     144          17 :                 data->peer_pubkey_hash_set = 1;
     145             :         }
     146             : 
     147         422 :         return data;
     148             : }
     149             : 
     150             : 
     151             : /**
     152             :  * wps_deinit - Deinitialize WPS Registration protocol data
     153             :  * @data: WPS Registration protocol data from wps_init()
     154             :  */
     155         422 : void wps_deinit(struct wps_data *data)
     156             : {
     157             : #ifdef CONFIG_WPS_NFC
     158         422 :         if (data->registrar && data->nfc_pw_token)
     159          27 :                 wps_registrar_remove_nfc_pw_token(data->wps->registrar,
     160             :                                                   data->nfc_pw_token);
     161             : #endif /* CONFIG_WPS_NFC */
     162             : 
     163         422 :         if (data->wps_pin_revealed) {
     164           4 :                 wpa_printf(MSG_DEBUG, "WPS: Full PIN information revealed and "
     165             :                            "negotiation failed");
     166           4 :                 if (data->registrar)
     167           4 :                         wps_registrar_invalidate_pin(data->wps->registrar,
     168           4 :                                                      data->uuid_e);
     169         418 :         } else if (data->registrar)
     170         206 :                 wps_registrar_unlock_pin(data->wps->registrar, data->uuid_e);
     171             : 
     172         422 :         wpabuf_free(data->dh_privkey);
     173         422 :         wpabuf_free(data->dh_pubkey_e);
     174         422 :         wpabuf_free(data->dh_pubkey_r);
     175         422 :         wpabuf_free(data->last_msg);
     176         422 :         os_free(data->dev_password);
     177         422 :         os_free(data->alt_dev_password);
     178         422 :         os_free(data->new_psk);
     179         422 :         wps_device_data_free(&data->peer_dev);
     180         422 :         os_free(data->new_ap_settings);
     181         422 :         dh5_free(data->dh_ctx);
     182         422 :         os_free(data);
     183         422 : }
     184             : 
     185             : 
     186             : /**
     187             :  * wps_process_msg - Process a WPS message
     188             :  * @wps: WPS Registration protocol data from wps_init()
     189             :  * @op_code: Message OP Code
     190             :  * @msg: Message data
     191             :  * Returns: Processing result
     192             :  *
     193             :  * This function is used to process WPS messages with OP Codes WSC_ACK,
     194             :  * WSC_NACK, WSC_MSG, and WSC_Done. The caller (e.g., EAP server/peer) is
     195             :  * responsible for reassembling the messages before calling this function.
     196             :  * Response to this message is built by calling wps_get_msg().
     197             :  */
     198        1637 : enum wps_process_res wps_process_msg(struct wps_data *wps,
     199             :                                      enum wsc_op_code op_code,
     200             :                                      const struct wpabuf *msg)
     201             : {
     202        1637 :         if (wps->registrar)
     203         926 :                 return wps_registrar_process_msg(wps, op_code, msg);
     204             :         else
     205         711 :                 return wps_enrollee_process_msg(wps, op_code, msg);
     206             : }
     207             : 
     208             : 
     209             : /**
     210             :  * wps_get_msg - Build a WPS message
     211             :  * @wps: WPS Registration protocol data from wps_init()
     212             :  * @op_code: Buffer for returning message OP Code
     213             :  * Returns: The generated WPS message or %NULL on failure
     214             :  *
     215             :  * This function is used to build a response to a message processed by calling
     216             :  * wps_process_msg(). The caller is responsible for freeing the buffer.
     217             :  */
     218        1619 : struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code)
     219             : {
     220        1619 :         if (wps->registrar)
     221         735 :                 return wps_registrar_get_msg(wps, op_code);
     222             :         else
     223         884 :                 return wps_enrollee_get_msg(wps, op_code);
     224             : }
     225             : 
     226             : 
     227             : /**
     228             :  * wps_is_selected_pbc_registrar - Check whether WPS IE indicates active PBC
     229             :  * @msg: WPS IE contents from Beacon or Probe Response frame
     230             :  * Returns: 1 if PBC Registrar is active, 0 if not
     231             :  */
     232         550 : int wps_is_selected_pbc_registrar(const struct wpabuf *msg)
     233             : {
     234             :         struct wps_parse_attr attr;
     235             : 
     236             :         /*
     237             :          * In theory, this could also verify that attr.sel_reg_config_methods
     238             :          * includes WPS_CONFIG_PUSHBUTTON, but some deployed AP implementations
     239             :          * do not set Selected Registrar Config Methods attribute properly, so
     240             :          * it is safer to just use Device Password ID here.
     241             :          */
     242             : 
     243        1100 :         if (wps_parse_msg(msg, &attr) < 0 ||
     244        1162 :             !attr.selected_registrar || *attr.selected_registrar == 0 ||
     245         612 :             !attr.dev_password_id ||
     246         306 :             WPA_GET_BE16(attr.dev_password_id) != DEV_PW_PUSHBUTTON)
     247         432 :                 return 0;
     248             : 
     249             : #ifdef CONFIG_WPS_STRICT
     250             :         if (!attr.sel_reg_config_methods ||
     251             :             !(WPA_GET_BE16(attr.sel_reg_config_methods) &
     252             :               WPS_CONFIG_PUSHBUTTON))
     253             :                 return 0;
     254             : #endif /* CONFIG_WPS_STRICT */
     255             : 
     256         118 :         return 1;
     257             : }
     258             : 
     259             : 
     260         204 : static int is_selected_pin_registrar(struct wps_parse_attr *attr)
     261             : {
     262             :         /*
     263             :          * In theory, this could also verify that attr.sel_reg_config_methods
     264             :          * includes WPS_CONFIG_LABEL, WPS_CONFIG_DISPLAY, or WPS_CONFIG_KEYPAD,
     265             :          * but some deployed AP implementations do not set Selected Registrar
     266             :          * Config Methods attribute properly, so it is safer to just use
     267             :          * Device Password ID here.
     268             :          */
     269             : 
     270         204 :         if (!attr->selected_registrar || *attr->selected_registrar == 0)
     271         193 :                 return 0;
     272             : 
     273          22 :         if (attr->dev_password_id != NULL &&
     274          11 :             WPA_GET_BE16(attr->dev_password_id) == DEV_PW_PUSHBUTTON)
     275           0 :                 return 0;
     276             : 
     277             : #ifdef CONFIG_WPS_STRICT
     278             :         if (!attr->sel_reg_config_methods ||
     279             :             !(WPA_GET_BE16(attr->sel_reg_config_methods) &
     280             :               (WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD)))
     281             :                 return 0;
     282             : #endif /* CONFIG_WPS_STRICT */
     283             : 
     284          11 :         return 1;
     285             : }
     286             : 
     287             : 
     288             : /**
     289             :  * wps_is_selected_pin_registrar - Check whether WPS IE indicates active PIN
     290             :  * @msg: WPS IE contents from Beacon or Probe Response frame
     291             :  * Returns: 1 if PIN Registrar is active, 0 if not
     292             :  */
     293         200 : int wps_is_selected_pin_registrar(const struct wpabuf *msg)
     294             : {
     295             :         struct wps_parse_attr attr;
     296             : 
     297         200 :         if (wps_parse_msg(msg, &attr) < 0)
     298           0 :                 return 0;
     299             : 
     300         200 :         return is_selected_pin_registrar(&attr);
     301             : }
     302             : 
     303             : 
     304             : /**
     305             :  * wps_is_addr_authorized - Check whether WPS IE authorizes MAC address
     306             :  * @msg: WPS IE contents from Beacon or Probe Response frame
     307             :  * @addr: MAC address to search for
     308             :  * @ver1_compat: Whether to use version 1 compatibility mode
     309             :  * Returns: 2 if the specified address is explicit authorized, 1 if address is
     310             :  * authorized (broadcast), 0 if not
     311             :  */
     312         941 : int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
     313             :                            int ver1_compat)
     314             : {
     315             :         struct wps_parse_attr attr;
     316             :         unsigned int i;
     317             :         const u8 *pos;
     318         941 :         const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
     319             : 
     320         941 :         if (wps_parse_msg(msg, &attr) < 0)
     321           0 :                 return 0;
     322             : 
     323         941 :         if (!attr.version2 && ver1_compat) {
     324             :                 /*
     325             :                  * Version 1.0 AP - AuthorizedMACs not used, so revert back to
     326             :                  * old mechanism of using SelectedRegistrar.
     327             :                  */
     328           4 :                 return is_selected_pin_registrar(&attr);
     329             :         }
     330             : 
     331         937 :         if (!attr.authorized_macs)
     332         425 :                 return 0;
     333             : 
     334         512 :         pos = attr.authorized_macs;
     335         523 :         for (i = 0; i < attr.authorized_macs_len / ETH_ALEN; i++) {
     336         512 :                 if (os_memcmp(pos, addr, ETH_ALEN) == 0)
     337         201 :                         return 2;
     338         311 :                 if (os_memcmp(pos, bcast, ETH_ALEN) == 0)
     339         300 :                         return 1;
     340          11 :                 pos += ETH_ALEN;
     341             :         }
     342             : 
     343          11 :         return 0;
     344             : }
     345             : 
     346             : 
     347             : /**
     348             :  * wps_ap_priority_compar - Prioritize WPS IE from two APs
     349             :  * @wps_a: WPS IE contents from Beacon or Probe Response frame
     350             :  * @wps_b: WPS IE contents from Beacon or Probe Response frame
     351             :  * Returns: 1 if wps_b is considered more likely selection for WPS
     352             :  * provisioning, -1 if wps_a is considered more like, or 0 if no preference
     353             :  */
     354          51 : int wps_ap_priority_compar(const struct wpabuf *wps_a,
     355             :                            const struct wpabuf *wps_b)
     356             : {
     357             :         struct wps_parse_attr attr_a, attr_b;
     358             :         int sel_a, sel_b;
     359             : 
     360          51 :         if (wps_a == NULL || wps_parse_msg(wps_a, &attr_a) < 0)
     361           0 :                 return 1;
     362          51 :         if (wps_b == NULL || wps_parse_msg(wps_b, &attr_b) < 0)
     363           0 :                 return -1;
     364             : 
     365          51 :         sel_a = attr_a.selected_registrar && *attr_a.selected_registrar != 0;
     366          51 :         sel_b = attr_b.selected_registrar && *attr_b.selected_registrar != 0;
     367             : 
     368          51 :         if (sel_a && !sel_b)
     369           7 :                 return -1;
     370          44 :         if (!sel_a && sel_b)
     371          19 :                 return 1;
     372             : 
     373          25 :         return 0;
     374             : }
     375             : 
     376             : 
     377             : /**
     378             :  * wps_get_uuid_e - Get UUID-E from WPS IE
     379             :  * @msg: WPS IE contents from Beacon or Probe Response frame
     380             :  * Returns: Pointer to UUID-E or %NULL if not included
     381             :  *
     382             :  * The returned pointer is to the msg contents and it remains valid only as
     383             :  * long as the msg buffer is valid.
     384             :  */
     385          37 : const u8 * wps_get_uuid_e(const struct wpabuf *msg)
     386             : {
     387             :         struct wps_parse_attr attr;
     388             : 
     389          37 :         if (wps_parse_msg(msg, &attr) < 0)
     390           0 :                 return NULL;
     391          37 :         return attr.uuid_e;
     392             : }
     393             : 
     394             : 
     395             : /**
     396             :  * wps_is_20 - Check whether WPS attributes claim support for WPS 2.0
     397             :  */
     398         200 : int wps_is_20(const struct wpabuf *msg)
     399             : {
     400             :         struct wps_parse_attr attr;
     401             : 
     402         200 :         if (msg == NULL || wps_parse_msg(msg, &attr) < 0)
     403           0 :                 return 0;
     404         200 :         return attr.version2 != NULL;
     405             : }
     406             : 
     407             : 
     408             : /**
     409             :  * wps_build_assoc_req_ie - Build WPS IE for (Re)Association Request
     410             :  * @req_type: Value for Request Type attribute
     411             :  * Returns: WPS IE or %NULL on failure
     412             :  *
     413             :  * The caller is responsible for freeing the buffer.
     414             :  */
     415         200 : struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type)
     416             : {
     417             :         struct wpabuf *ie;
     418             :         u8 *len;
     419             : 
     420         200 :         wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
     421             :                    "Request");
     422         200 :         ie = wpabuf_alloc(100);
     423         200 :         if (ie == NULL)
     424           0 :                 return NULL;
     425             : 
     426         200 :         wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
     427         200 :         len = wpabuf_put(ie, 1);
     428         200 :         wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
     429             : 
     430         400 :         if (wps_build_version(ie) ||
     431         400 :             wps_build_req_type(ie, req_type) ||
     432         200 :             wps_build_wfa_ext(ie, 0, NULL, 0)) {
     433           0 :                 wpabuf_free(ie);
     434           0 :                 return NULL;
     435             :         }
     436             : 
     437         200 :         *len = wpabuf_len(ie) - 2;
     438             : 
     439         200 :         return ie;
     440             : }
     441             : 
     442             : 
     443             : /**
     444             :  * wps_build_assoc_resp_ie - Build WPS IE for (Re)Association Response
     445             :  * Returns: WPS IE or %NULL on failure
     446             :  *
     447             :  * The caller is responsible for freeing the buffer.
     448             :  */
     449        1325 : struct wpabuf * wps_build_assoc_resp_ie(void)
     450             : {
     451             :         struct wpabuf *ie;
     452             :         u8 *len;
     453             : 
     454        1325 :         wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
     455             :                    "Response");
     456        1325 :         ie = wpabuf_alloc(100);
     457        1325 :         if (ie == NULL)
     458           0 :                 return NULL;
     459             : 
     460        1325 :         wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
     461        1325 :         len = wpabuf_put(ie, 1);
     462        1325 :         wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
     463             : 
     464        2650 :         if (wps_build_version(ie) ||
     465        2650 :             wps_build_resp_type(ie, WPS_RESP_AP) ||
     466        1325 :             wps_build_wfa_ext(ie, 0, NULL, 0)) {
     467           0 :                 wpabuf_free(ie);
     468           0 :                 return NULL;
     469             :         }
     470             : 
     471        1325 :         *len = wpabuf_len(ie) - 2;
     472             : 
     473        1325 :         return ie;
     474             : }
     475             : 
     476             : 
     477             : /**
     478             :  * wps_build_probe_req_ie - Build WPS IE for Probe Request
     479             :  * @pw_id: Password ID (DEV_PW_PUSHBUTTON for active PBC and DEV_PW_DEFAULT for
     480             :  * most other use cases)
     481             :  * @dev: Device attributes
     482             :  * @uuid: Own UUID
     483             :  * @req_type: Value for Request Type attribute
     484             :  * @num_req_dev_types: Number of requested device types
     485             :  * @req_dev_types: Requested device types (8 * num_req_dev_types octets) or
     486             :  *      %NULL if none
     487             :  * Returns: WPS IE or %NULL on failure
     488             :  *
     489             :  * The caller is responsible for freeing the buffer.
     490             :  */
     491        1837 : struct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev,
     492             :                                        const u8 *uuid,
     493             :                                        enum wps_request_type req_type,
     494             :                                        unsigned int num_req_dev_types,
     495             :                                        const u8 *req_dev_types)
     496             : {
     497             :         struct wpabuf *ie;
     498             : 
     499        1837 :         wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for Probe Request");
     500             : 
     501        1837 :         ie = wpabuf_alloc(500);
     502        1837 :         if (ie == NULL)
     503           0 :                 return NULL;
     504             : 
     505        3674 :         if (wps_build_version(ie) ||
     506        3674 :             wps_build_req_type(ie, req_type) ||
     507        3674 :             wps_build_config_methods(ie, dev->config_methods) ||
     508        3674 :             wps_build_uuid_e(ie, uuid) ||
     509        3674 :             wps_build_primary_dev_type(dev, ie) ||
     510        3674 :             wps_build_rf_bands(dev, ie, 0) ||
     511        3674 :             wps_build_assoc_state(NULL, ie) ||
     512        3674 :             wps_build_config_error(ie, WPS_CFG_NO_ERROR) ||
     513        3674 :             wps_build_dev_password_id(ie, pw_id) ||
     514        3674 :             wps_build_manufacturer(dev, ie) ||
     515        3674 :             wps_build_model_name(dev, ie) ||
     516        3674 :             wps_build_model_number(dev, ie) ||
     517        3674 :             wps_build_dev_name(dev, ie) ||
     518        3674 :             wps_build_wfa_ext(ie, req_type == WPS_REQ_ENROLLEE, NULL, 0) ||
     519        1837 :             wps_build_req_dev_type(dev, ie, num_req_dev_types, req_dev_types)
     520        1837 :             ||
     521        1837 :             wps_build_secondary_dev_type(dev, ie)
     522             :                 ) {
     523           0 :                 wpabuf_free(ie);
     524           0 :                 return NULL;
     525             :         }
     526             : 
     527        1837 :         return wps_ie_encapsulate(ie);
     528             : }
     529             : 
     530             : 
     531         201 : void wps_free_pending_msgs(struct upnp_pending_message *msgs)
     532             : {
     533             :         struct upnp_pending_message *p, *prev;
     534         201 :         p = msgs;
     535         402 :         while (p) {
     536           0 :                 prev = p;
     537           0 :                 p = p->next;
     538           0 :                 wpabuf_free(prev->msg);
     539           0 :                 os_free(prev);
     540             :         }
     541         201 : }
     542             : 
     543             : 
     544          33 : int wps_attr_text(struct wpabuf *data, char *buf, char *end)
     545             : {
     546             :         struct wps_parse_attr attr;
     547          33 :         char *pos = buf;
     548             :         int ret;
     549             : 
     550          33 :         if (wps_parse_msg(data, &attr) < 0)
     551           0 :                 return -1;
     552             : 
     553          33 :         if (attr.wps_state) {
     554          33 :                 if (*attr.wps_state == WPS_STATE_NOT_CONFIGURED)
     555           9 :                         ret = os_snprintf(pos, end - pos,
     556             :                                           "wps_state=unconfigured\n");
     557          24 :                 else if (*attr.wps_state == WPS_STATE_CONFIGURED)
     558          24 :                         ret = os_snprintf(pos, end - pos,
     559             :                                           "wps_state=configured\n");
     560             :                 else
     561           0 :                         ret = 0;
     562          33 :                 if (ret < 0 || ret >= end - pos)
     563           0 :                         return pos - buf;
     564          33 :                 pos += ret;
     565             :         }
     566             : 
     567          33 :         if (attr.ap_setup_locked && *attr.ap_setup_locked) {
     568           0 :                 ret = os_snprintf(pos, end - pos,
     569             :                                   "wps_ap_setup_locked=1\n");
     570           0 :                 if (ret < 0 || ret >= end - pos)
     571           0 :                         return pos - buf;
     572           0 :                 pos += ret;
     573             :         }
     574             : 
     575          33 :         if (attr.selected_registrar && *attr.selected_registrar) {
     576          18 :                 ret = os_snprintf(pos, end - pos,
     577             :                                   "wps_selected_registrar=1\n");
     578          18 :                 if (ret < 0 || ret >= end - pos)
     579           0 :                         return pos - buf;
     580          18 :                 pos += ret;
     581             :         }
     582             : 
     583          33 :         if (attr.dev_password_id) {
     584          18 :                 ret = os_snprintf(pos, end - pos,
     585             :                                   "wps_device_password_id=%u\n",
     586          18 :                                   WPA_GET_BE16(attr.dev_password_id));
     587          18 :                 if (ret < 0 || ret >= end - pos)
     588           0 :                         return pos - buf;
     589          18 :                 pos += ret;
     590             :         }
     591             : 
     592          33 :         if (attr.sel_reg_config_methods) {
     593          18 :                 ret = os_snprintf(pos, end - pos,
     594             :                                   "wps_selected_registrar_config_methods="
     595             :                                   "0x%04x\n",
     596          18 :                                   WPA_GET_BE16(attr.sel_reg_config_methods));
     597          18 :                 if (ret < 0 || ret >= end - pos)
     598           0 :                         return pos - buf;
     599          18 :                 pos += ret;
     600             :         }
     601             : 
     602          33 :         if (attr.primary_dev_type) {
     603             :                 char devtype[WPS_DEV_TYPE_BUFSIZE];
     604          33 :                 ret = os_snprintf(pos, end - pos,
     605             :                                   "wps_primary_device_type=%s\n",
     606             :                                   wps_dev_type_bin2str(attr.primary_dev_type,
     607             :                                                        devtype,
     608             :                                                        sizeof(devtype)));
     609          33 :                 if (ret < 0 || ret >= end - pos)
     610           0 :                         return pos - buf;
     611          33 :                 pos += ret;
     612             :         }
     613             : 
     614          33 :         if (attr.dev_name) {
     615          33 :                 char *str = os_malloc(attr.dev_name_len + 1);
     616             :                 size_t i;
     617          33 :                 if (str == NULL)
     618           0 :                         return pos - buf;
     619         155 :                 for (i = 0; i < attr.dev_name_len; i++) {
     620         122 :                         if (attr.dev_name[i] < 32)
     621           0 :                                 str[i] = '_';
     622             :                         else
     623         122 :                                 str[i] = attr.dev_name[i];
     624             :                 }
     625          33 :                 str[i] = '\0';
     626          33 :                 ret = os_snprintf(pos, end - pos, "wps_device_name=%s\n", str);
     627          33 :                 os_free(str);
     628          33 :                 if (ret < 0 || ret >= end - pos)
     629           0 :                         return pos - buf;
     630          33 :                 pos += ret;
     631             :         }
     632             : 
     633          33 :         if (attr.config_methods) {
     634          33 :                 ret = os_snprintf(pos, end - pos,
     635             :                                   "wps_config_methods=0x%04x\n",
     636          33 :                                   WPA_GET_BE16(attr.config_methods));
     637          33 :                 if (ret < 0 || ret >= end - pos)
     638           0 :                         return pos - buf;
     639          33 :                 pos += ret;
     640             :         }
     641             : 
     642          33 :         return pos - buf;
     643             : }
     644             : 
     645             : 
     646           3 : const char * wps_ei_str(enum wps_error_indication ei)
     647             : {
     648           3 :         switch (ei) {
     649             :         case WPS_EI_NO_ERROR:
     650           0 :                 return "No Error";
     651             :         case WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED:
     652           0 :                 return "TKIP Only Prohibited";
     653             :         case WPS_EI_SECURITY_WEP_PROHIBITED:
     654           3 :                 return "WEP Prohibited";
     655             :         case WPS_EI_AUTH_FAILURE:
     656           0 :                 return "Authentication Failure";
     657             :         default:
     658           0 :                 return "Unknown";
     659             :         }
     660             : }

Generated by: LCOV version 1.10