LCOV - code coverage report
Current view: top level - src/wps - wps_attr_build.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1426431149 Lines: 254 273 93.0 %
Date: 2015-03-15 Functions: 24 24 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Wi-Fi Protected Setup - attribute building
       3             :  * Copyright (c) 2008, 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/aes_wrap.h"
      13             : #include "crypto/crypto.h"
      14             : #include "crypto/dh_group5.h"
      15             : #include "crypto/sha256.h"
      16             : #include "crypto/random.h"
      17             : #include "common/ieee802_11_defs.h"
      18             : #include "wps_i.h"
      19             : 
      20             : 
      21         577 : int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg)
      22             : {
      23             :         struct wpabuf *pubkey;
      24             : 
      25         577 :         wpa_printf(MSG_DEBUG, "WPS:  * Public Key");
      26         577 :         wpabuf_free(wps->dh_privkey);
      27         577 :         wps->dh_privkey = NULL;
      28         705 :         if (wps->dev_pw_id != DEV_PW_DEFAULT && wps->wps->dh_privkey &&
      29         128 :             wps->wps->dh_ctx) {
      30          42 :                 wpa_printf(MSG_DEBUG, "WPS: Using pre-configured DH keys");
      31          42 :                 if (wps->wps->dh_pubkey == NULL) {
      32           0 :                         wpa_printf(MSG_DEBUG,
      33             :                                    "WPS: wps->wps->dh_pubkey == NULL");
      34           0 :                         return -1;
      35             :                 }
      36          42 :                 wps->dh_privkey = wpabuf_dup(wps->wps->dh_privkey);
      37          42 :                 wps->dh_ctx = wps->wps->dh_ctx;
      38          42 :                 wps->wps->dh_ctx = NULL;
      39          42 :                 pubkey = wpabuf_dup(wps->wps->dh_pubkey);
      40             : #ifdef CONFIG_WPS_NFC
      41        1063 :         } else if ((wps->dev_pw_id >= 0x10 ||
      42         544 :                     wps->dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER) &&
      43          20 :                    (wps->wps->ap ||
      44           7 :                     (wps->wps->ap_nfc_dh_pubkey &&
      45           3 :                      wps->wps->ap_nfc_dev_pw_id ==
      46           3 :                      DEV_PW_NFC_CONNECTION_HANDOVER &&
      47          17 :                      wps->dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER)) &&
      48          17 :                    (wps->dev_pw_id == wps->wps->ap_nfc_dev_pw_id ||
      49           3 :                     wps->wps->ap_nfc_dh_pubkey)) {
      50          12 :                 wpa_printf(MSG_DEBUG, "WPS: Using NFC password token DH keys");
      51          12 :                 if (wps->wps->ap_nfc_dh_privkey == NULL) {
      52           0 :                         wpa_printf(MSG_DEBUG,
      53             :                                    "WPS: wps->wps->ap_nfc_dh_privkey == NULL");
      54           0 :                         return -1;
      55             :                 }
      56          12 :                 if (wps->wps->ap_nfc_dh_pubkey == NULL) {
      57           0 :                         wpa_printf(MSG_DEBUG,
      58             :                                    "WPS: wps->wps->ap_nfc_dh_pubkey == NULL");
      59           0 :                         return -1;
      60             :                 }
      61          12 :                 wps->dh_privkey = wpabuf_dup(wps->wps->ap_nfc_dh_privkey);
      62          12 :                 pubkey = wpabuf_dup(wps->wps->ap_nfc_dh_pubkey);
      63          12 :                 wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, pubkey);
      64             : #endif /* CONFIG_WPS_NFC */
      65             :         } else {
      66         523 :                 wpa_printf(MSG_DEBUG, "WPS: Generate new DH keys");
      67         523 :                 dh5_free(wps->dh_ctx);
      68         523 :                 wps->dh_ctx = dh5_init(&wps->dh_privkey, &pubkey);
      69         523 :                 pubkey = wpabuf_zeropad(pubkey, 192);
      70             :         }
      71         577 :         if (wps->dh_ctx == NULL || wps->dh_privkey == NULL || pubkey == NULL) {
      72           0 :                 wpa_printf(MSG_DEBUG, "WPS: Failed to initialize "
      73             :                            "Diffie-Hellman handshake");
      74           0 :                 wpabuf_free(pubkey);
      75           0 :                 return -1;
      76             :         }
      77         577 :         wpa_hexdump_buf_key(MSG_DEBUG, "WPS: DH Private Key", wps->dh_privkey);
      78         577 :         wpa_hexdump_buf(MSG_DEBUG, "WPS: DH own Public Key", pubkey);
      79             : 
      80         577 :         wpabuf_put_be16(msg, ATTR_PUBLIC_KEY);
      81         577 :         wpabuf_put_be16(msg, wpabuf_len(pubkey));
      82         577 :         wpabuf_put_buf(msg, pubkey);
      83             : 
      84         577 :         if (wps->registrar) {
      85         274 :                 wpabuf_free(wps->dh_pubkey_r);
      86         274 :                 wps->dh_pubkey_r = pubkey;
      87             :         } else {
      88         303 :                 wpabuf_free(wps->dh_pubkey_e);
      89         303 :                 wps->dh_pubkey_e = pubkey;
      90             :         }
      91             : 
      92         577 :         return 0;
      93             : }
      94             : 
      95             : 
      96        3132 : int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type)
      97             : {
      98        3132 :         wpa_printf(MSG_DEBUG, "WPS:  * Request Type");
      99        3132 :         wpabuf_put_be16(msg, ATTR_REQUEST_TYPE);
     100        3132 :         wpabuf_put_be16(msg, 1);
     101        3132 :         wpabuf_put_u8(msg, type);
     102        3132 :         return 0;
     103             : }
     104             : 
     105             : 
     106        3208 : int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type)
     107             : {
     108        3208 :         wpa_printf(MSG_DEBUG, "WPS:  * Response Type (%d)", type);
     109        3208 :         wpabuf_put_be16(msg, ATTR_RESPONSE_TYPE);
     110        3208 :         wpabuf_put_be16(msg, 1);
     111        3208 :         wpabuf_put_u8(msg, type);
     112        3208 :         return 0;
     113             : }
     114             : 
     115             : 
     116        3444 : int wps_build_config_methods(struct wpabuf *msg, u16 methods)
     117             : {
     118        3444 :         wpa_printf(MSG_DEBUG, "WPS:  * Config Methods (%x)", methods);
     119        3444 :         wpabuf_put_be16(msg, ATTR_CONFIG_METHODS);
     120        3444 :         wpabuf_put_be16(msg, 2);
     121        3444 :         wpabuf_put_be16(msg, methods);
     122        3444 :         return 0;
     123             : }
     124             : 
     125             : 
     126        6814 : int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid)
     127             : {
     128        6814 :         if (wpabuf_tailroom(msg) < 4 + WPS_UUID_LEN)
     129           0 :                 return -1;
     130        6814 :         wpa_printf(MSG_DEBUG, "WPS:  * UUID-E");
     131        6814 :         wpabuf_put_be16(msg, ATTR_UUID_E);
     132        6814 :         wpabuf_put_be16(msg, WPS_UUID_LEN);
     133        6814 :         wpabuf_put_data(msg, uuid, WPS_UUID_LEN);
     134        6814 :         return 0;
     135             : }
     136             : 
     137             : 
     138        3418 : int wps_build_dev_password_id(struct wpabuf *msg, u16 id)
     139             : {
     140        3418 :         wpa_printf(MSG_DEBUG, "WPS:  * Device Password ID (%d)", id);
     141        3418 :         wpabuf_put_be16(msg, ATTR_DEV_PASSWORD_ID);
     142        3418 :         wpabuf_put_be16(msg, 2);
     143        3418 :         wpabuf_put_be16(msg, id);
     144        3418 :         return 0;
     145             : }
     146             : 
     147             : 
     148        3506 : int wps_build_config_error(struct wpabuf *msg, u16 err)
     149             : {
     150        3506 :         wpa_printf(MSG_DEBUG, "WPS:  * Configuration Error (%d)", err);
     151        3506 :         wpabuf_put_be16(msg, ATTR_CONFIG_ERROR);
     152        3506 :         wpabuf_put_be16(msg, 2);
     153        3506 :         wpabuf_put_be16(msg, err);
     154        3506 :         return 0;
     155             : }
     156             : 
     157             : 
     158        1718 : int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg)
     159             : {
     160             :         u8 hash[SHA256_MAC_LEN];
     161             :         const u8 *addr[2];
     162             :         size_t len[2];
     163             : 
     164        1718 :         if (wps->last_msg == NULL) {
     165           0 :                 wpa_printf(MSG_DEBUG, "WPS: Last message not available for "
     166             :                            "building authenticator");
     167           0 :                 return -1;
     168             :         }
     169             : 
     170             :         /* Authenticator = HMAC-SHA256_AuthKey(M_prev || M_curr*)
     171             :          * (M_curr* is M_curr without the Authenticator attribute)
     172             :          */
     173        1718 :         addr[0] = wpabuf_head(wps->last_msg);
     174        1718 :         len[0] = wpabuf_len(wps->last_msg);
     175        1718 :         addr[1] = wpabuf_head(msg);
     176        1718 :         len[1] = wpabuf_len(msg);
     177        1718 :         hmac_sha256_vector(wps->authkey, WPS_AUTHKEY_LEN, 2, addr, len, hash);
     178             : 
     179        1718 :         wpa_printf(MSG_DEBUG, "WPS:  * Authenticator");
     180        1718 :         wpabuf_put_be16(msg, ATTR_AUTHENTICATOR);
     181        1718 :         wpabuf_put_be16(msg, WPS_AUTHENTICATOR_LEN);
     182        1718 :         wpabuf_put_data(msg, hash, WPS_AUTHENTICATOR_LEN);
     183             : 
     184        1718 :         return 0;
     185             : }
     186             : 
     187             : 
     188       12741 : int wps_build_version(struct wpabuf *msg)
     189             : {
     190             :         /*
     191             :          * Note: This attribute is deprecated and set to hardcoded 0x10 for
     192             :          * backwards compatibility reasons. The real version negotiation is
     193             :          * done with Version2.
     194             :          */
     195       12741 :         if (wpabuf_tailroom(msg) < 5)
     196           0 :                 return -1;
     197       12741 :         wpa_printf(MSG_DEBUG, "WPS:  * Version (hardcoded 0x10)");
     198       12741 :         wpabuf_put_be16(msg, ATTR_VERSION);
     199       12741 :         wpabuf_put_be16(msg, 1);
     200       12741 :         wpabuf_put_u8(msg, 0x10);
     201       12741 :         return 0;
     202             : }
     203             : 
     204             : 
     205       12813 : int wps_build_wfa_ext(struct wpabuf *msg, int req_to_enroll,
     206             :                       const u8 *auth_macs, size_t auth_macs_count)
     207             : {
     208             :         u8 *len;
     209             : 
     210             : #ifdef CONFIG_WPS_TESTING
     211       12813 :         if (WPS_VERSION == 0x10)
     212          41 :                 return 0;
     213             : #endif /* CONFIG_WPS_TESTING */
     214             : 
     215       25544 :         if (wpabuf_tailroom(msg) <
     216       25544 :             7 + 3 + (req_to_enroll ? 3 : 0) +
     217       12772 :             (auth_macs ? 2 + auth_macs_count * ETH_ALEN : 0))
     218           0 :                 return -1;
     219       12772 :         wpabuf_put_be16(msg, ATTR_VENDOR_EXT);
     220       12772 :         len = wpabuf_put(msg, 2); /* to be filled */
     221       12772 :         wpabuf_put_be24(msg, WPS_VENDOR_ID_WFA);
     222             : 
     223       12772 :         wpa_printf(MSG_DEBUG, "WPS:  * Version2 (0x%x)", WPS_VERSION);
     224       12772 :         wpabuf_put_u8(msg, WFA_ELEM_VERSION2);
     225       12772 :         wpabuf_put_u8(msg, 1);
     226       12772 :         wpabuf_put_u8(msg, WPS_VERSION);
     227             : 
     228       12772 :         if (req_to_enroll) {
     229        1189 :                 wpa_printf(MSG_DEBUG, "WPS:  * Request to Enroll (1)");
     230        1189 :                 wpabuf_put_u8(msg, WFA_ELEM_REQUEST_TO_ENROLL);
     231        1189 :                 wpabuf_put_u8(msg, 1);
     232        1189 :                 wpabuf_put_u8(msg, 1);
     233             :         }
     234             : 
     235       12772 :         if (auth_macs && auth_macs_count) {
     236             :                 size_t i;
     237         577 :                 wpa_printf(MSG_DEBUG, "WPS:  * AuthorizedMACs (count=%d)",
     238             :                            (int) auth_macs_count);
     239         577 :                 wpabuf_put_u8(msg, WFA_ELEM_AUTHORIZEDMACS);
     240         577 :                 wpabuf_put_u8(msg, auth_macs_count * ETH_ALEN);
     241         577 :                 wpabuf_put_data(msg, auth_macs, auth_macs_count * ETH_ALEN);
     242        1154 :                 for (i = 0; i < auth_macs_count; i++)
     243        3462 :                         wpa_printf(MSG_DEBUG, "WPS:    AuthorizedMAC: " MACSTR,
     244        3462 :                                    MAC2STR(&auth_macs[i * ETH_ALEN]));
     245             :         }
     246             : 
     247       12772 :         WPA_PUT_BE16(len, (u8 *) wpabuf_put(msg, 0) - len - 2);
     248             : 
     249             : #ifdef CONFIG_WPS_TESTING
     250       12772 :         if (WPS_VERSION > 0x20) {
     251          21 :                 if (wpabuf_tailroom(msg) < 5)
     252           0 :                         return -1;
     253          21 :                 wpa_printf(MSG_DEBUG, "WPS:  * Extensibility Testing - extra "
     254             :                            "attribute");
     255          21 :                 wpabuf_put_be16(msg, ATTR_EXTENSIBILITY_TEST);
     256          21 :                 wpabuf_put_be16(msg, 1);
     257          21 :                 wpabuf_put_u8(msg, 42);
     258             :         }
     259             : #endif /* CONFIG_WPS_TESTING */
     260       12772 :         return 0;
     261             : }
     262             : 
     263             : 
     264        2370 : int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type)
     265             : {
     266        2370 :         wpa_printf(MSG_DEBUG, "WPS:  * Message Type (%d)", msg_type);
     267        2370 :         wpabuf_put_be16(msg, ATTR_MSG_TYPE);
     268        2370 :         wpabuf_put_be16(msg, 1);
     269        2370 :         wpabuf_put_u8(msg, msg_type);
     270        2370 :         return 0;
     271             : }
     272             : 
     273             : 
     274        1637 : int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg)
     275             : {
     276        1637 :         wpa_printf(MSG_DEBUG, "WPS:  * Enrollee Nonce");
     277        1637 :         wpabuf_put_be16(msg, ATTR_ENROLLEE_NONCE);
     278        1637 :         wpabuf_put_be16(msg, WPS_NONCE_LEN);
     279        1637 :         wpabuf_put_data(msg, wps->nonce_e, WPS_NONCE_LEN);
     280        1637 :         return 0;
     281             : }
     282             : 
     283             : 
     284        1354 : int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg)
     285             : {
     286        1354 :         wpa_printf(MSG_DEBUG, "WPS:  * Registrar Nonce");
     287        1354 :         wpabuf_put_be16(msg, ATTR_REGISTRAR_NONCE);
     288        1354 :         wpabuf_put_be16(msg, WPS_NONCE_LEN);
     289        1354 :         wpabuf_put_data(msg, wps->nonce_r, WPS_NONCE_LEN);
     290        1354 :         return 0;
     291             : }
     292             : 
     293             : 
     294         603 : int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg)
     295             : {
     296         603 :         u16 auth_types = WPS_AUTH_TYPES;
     297             :         /* WPA/WPA2-Enterprise enrollment not supported through WPS */
     298         603 :         auth_types &= ~WPS_AUTH_WPA;
     299         603 :         auth_types &= ~WPS_AUTH_WPA2;
     300         603 :         auth_types &= ~WPS_AUTH_SHARED;
     301         603 :         wpa_printf(MSG_DEBUG, "WPS:  * Authentication Type Flags");
     302         603 :         wpabuf_put_be16(msg, ATTR_AUTH_TYPE_FLAGS);
     303         603 :         wpabuf_put_be16(msg, 2);
     304         603 :         wpabuf_put_be16(msg, auth_types);
     305         603 :         return 0;
     306             : }
     307             : 
     308             : 
     309         603 : int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg)
     310             : {
     311         603 :         u16 encr_types = WPS_ENCR_TYPES;
     312         603 :         encr_types &= ~WPS_ENCR_WEP;
     313         603 :         wpa_printf(MSG_DEBUG, "WPS:  * Encryption Type Flags");
     314         603 :         wpabuf_put_be16(msg, ATTR_ENCR_TYPE_FLAGS);
     315         603 :         wpabuf_put_be16(msg, 2);
     316         603 :         wpabuf_put_be16(msg, encr_types);
     317         603 :         return 0;
     318             : }
     319             : 
     320             : 
     321         603 : int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg)
     322             : {
     323         603 :         wpa_printf(MSG_DEBUG, "WPS:  * Connection Type Flags");
     324         603 :         wpabuf_put_be16(msg, ATTR_CONN_TYPE_FLAGS);
     325         603 :         wpabuf_put_be16(msg, 1);
     326         603 :         wpabuf_put_u8(msg, WPS_CONN_ESS);
     327         603 :         return 0;
     328             : }
     329             : 
     330             : 
     331        3444 : int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg)
     332             : {
     333        3444 :         wpa_printf(MSG_DEBUG, "WPS:  * Association State");
     334        3444 :         wpabuf_put_be16(msg, ATTR_ASSOC_STATE);
     335        3444 :         wpabuf_put_be16(msg, 2);
     336        3444 :         wpabuf_put_be16(msg, WPS_ASSOC_NOT_ASSOC);
     337        3444 :         return 0;
     338             : }
     339             : 
     340             : 
     341        1207 : int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg)
     342             : {
     343             :         u8 hash[SHA256_MAC_LEN];
     344             : 
     345        1207 :         wpa_printf(MSG_DEBUG, "WPS:  * Key Wrap Authenticator");
     346        1207 :         hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, wpabuf_head(msg),
     347             :                     wpabuf_len(msg), hash);
     348             : 
     349        1207 :         wpabuf_put_be16(msg, ATTR_KEY_WRAP_AUTH);
     350        1207 :         wpabuf_put_be16(msg, WPS_KWA_LEN);
     351        1207 :         wpabuf_put_data(msg, hash, WPS_KWA_LEN);
     352        1207 :         return 0;
     353             : }
     354             : 
     355             : 
     356        1207 : int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
     357             :                             struct wpabuf *plain)
     358             : {
     359             :         size_t pad_len;
     360        1207 :         const size_t block_size = 16;
     361             :         u8 *iv, *data;
     362             : 
     363        1207 :         wpa_printf(MSG_DEBUG, "WPS:  * Encrypted Settings");
     364             : 
     365             :         /* PKCS#5 v2.0 pad */
     366        1207 :         pad_len = block_size - wpabuf_len(plain) % block_size;
     367        1207 :         os_memset(wpabuf_put(plain, pad_len), pad_len, pad_len);
     368             : 
     369        1207 :         wpabuf_put_be16(msg, ATTR_ENCR_SETTINGS);
     370        1207 :         wpabuf_put_be16(msg, block_size + wpabuf_len(plain));
     371             : 
     372        1207 :         iv = wpabuf_put(msg, block_size);
     373        1207 :         if (random_get_bytes(iv, block_size) < 0)
     374           0 :                 return -1;
     375             : 
     376        1207 :         data = wpabuf_put(msg, 0);
     377        1207 :         wpabuf_put_buf(msg, plain);
     378        1207 :         if (aes_128_cbc_encrypt(wps->keywrapkey, iv, data, wpabuf_len(plain)))
     379           0 :                 return -1;
     380             : 
     381        1207 :         return 0;
     382             : }
     383             : 
     384             : 
     385             : #ifdef CONFIG_WPS_OOB
     386          67 : int wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id,
     387             :                          const struct wpabuf *pubkey, const u8 *dev_pw,
     388             :                          size_t dev_pw_len)
     389             : {
     390             :         size_t hash_len;
     391             :         const u8 *addr[1];
     392             :         u8 pubkey_hash[WPS_HASH_LEN];
     393             : 
     394          67 :         wpa_printf(MSG_DEBUG, "WPS:  * OOB Device Password (dev_pw_id=%u)",
     395             :                    dev_pw_id);
     396          67 :         addr[0] = wpabuf_head(pubkey);
     397          67 :         hash_len = wpabuf_len(pubkey);
     398          67 :         sha256_vector(1, addr, &hash_len, pubkey_hash);
     399             : #ifdef CONFIG_WPS_TESTING
     400          67 :         if (wps_corrupt_pkhash) {
     401           4 :                 wpa_hexdump(MSG_DEBUG, "WPS: Real Public Key Hash",
     402             :                             pubkey_hash, WPS_OOB_PUBKEY_HASH_LEN);
     403           4 :                 wpa_printf(MSG_INFO, "WPS: Testing - corrupt public key hash");
     404           4 :                 pubkey_hash[WPS_OOB_PUBKEY_HASH_LEN - 2]++;
     405             :         }
     406             : #endif /* CONFIG_WPS_TESTING */
     407             : 
     408          67 :         wpabuf_put_be16(msg, ATTR_OOB_DEVICE_PASSWORD);
     409          67 :         wpabuf_put_be16(msg, WPS_OOB_PUBKEY_HASH_LEN + 2 + dev_pw_len);
     410          67 :         wpa_hexdump(MSG_DEBUG, "WPS: Public Key Hash",
     411             :                     pubkey_hash, WPS_OOB_PUBKEY_HASH_LEN);
     412          67 :         wpabuf_put_data(msg, pubkey_hash, WPS_OOB_PUBKEY_HASH_LEN);
     413          67 :         wpabuf_put_be16(msg, dev_pw_id);
     414          67 :         if (dev_pw) {
     415          24 :                 wpa_hexdump_key(MSG_DEBUG, "WPS: OOB Device Password",
     416             :                                 dev_pw, dev_pw_len);
     417          24 :                 wpabuf_put_data(msg, dev_pw, dev_pw_len);
     418             :         }
     419             : 
     420          67 :         return 0;
     421             : }
     422             : #endif /* CONFIG_WPS_OOB */
     423             : 
     424             : 
     425             : /* Encapsulate WPS IE data with one (or more, if needed) IE headers */
     426        5023 : struct wpabuf * wps_ie_encapsulate(struct wpabuf *data)
     427             : {
     428             :         struct wpabuf *ie;
     429             :         const u8 *pos, *end;
     430             : 
     431        5023 :         ie = wpabuf_alloc(wpabuf_len(data) + 100);
     432        5023 :         if (ie == NULL) {
     433           0 :                 wpabuf_free(data);
     434           0 :                 return NULL;
     435             :         }
     436             : 
     437        5023 :         pos = wpabuf_head(data);
     438        5023 :         end = pos + wpabuf_len(data);
     439             : 
     440       15072 :         while (end > pos) {
     441        5026 :                 size_t frag_len = end - pos;
     442        5026 :                 if (frag_len > 251)
     443           3 :                         frag_len = 251;
     444        5026 :                 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
     445        5026 :                 wpabuf_put_u8(ie, 4 + frag_len);
     446        5026 :                 wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
     447        5026 :                 wpabuf_put_data(ie, pos, frag_len);
     448        5026 :                 pos += frag_len;
     449             :         }
     450             : 
     451        5023 :         wpabuf_free(data);
     452             : 
     453        5023 :         return ie;
     454             : }
     455             : 
     456             : 
     457         575 : int wps_build_mac_addr(struct wpabuf *msg, const u8 *addr)
     458             : {
     459        3450 :         wpa_printf(MSG_DEBUG, "WPS:  * MAC Address (" MACSTR ")",
     460        3450 :                    MAC2STR(addr));
     461         575 :         wpabuf_put_be16(msg, ATTR_MAC_ADDR);
     462         575 :         wpabuf_put_be16(msg, ETH_ALEN);
     463         575 :         wpabuf_put_data(msg, addr, ETH_ALEN);
     464         575 :         return 0;
     465             : }
     466             : 
     467             : 
     468        3513 : int wps_build_rf_bands_attr(struct wpabuf *msg, u8 rf_bands)
     469             : {
     470        3513 :         wpa_printf(MSG_DEBUG, "WPS:  * RF Bands (%x)", rf_bands);
     471        3513 :         wpabuf_put_be16(msg, ATTR_RF_BANDS);
     472        3513 :         wpabuf_put_be16(msg, 1);
     473        3513 :         wpabuf_put_u8(msg, rf_bands);
     474        3513 :         return 0;
     475             : }
     476             : 
     477             : 
     478          12 : int wps_build_ap_channel(struct wpabuf *msg, u16 ap_channel)
     479             : {
     480          12 :         wpa_printf(MSG_DEBUG, "WPS:  * AP Channel (%u)", ap_channel);
     481          12 :         wpabuf_put_be16(msg, ATTR_AP_CHANNEL);
     482          12 :         wpabuf_put_be16(msg, 2);
     483          12 :         wpabuf_put_be16(msg, ap_channel);
     484          12 :         return 0;
     485             : }

Generated by: LCOV version 1.10