LCOV - code coverage report
Current view: top level - src/wps - wps_attr_build.c (source / functions) Hit Total Coverage
Test: hostapd/hlr_auc_gw (AS) hwsim test run 1388338050 Lines: 0 247 0.0 %
Date: 2013-12-29 Functions: 0 22 0.0 %
Branches: 0 62 0.0 %

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

Generated by: LCOV version 1.9