/* ipwps_protocol.h - IPWPS Protocol Handler header file */ /* * Copyright (c) 2009 Wind River Systems, Inc. * * The right to copy, distribute, modify, or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. * */ /* modification history -------------------- 01b,13feb09,dwb Adding fake attribute define 01a,16Jan09,mry Created */ #ifndef IPWPS_PROTOCOL_H #define IPWPS_PROTOCOL_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #include #include #include #include "ipwps_common.h" #include "ipwps_debug.h" #ifdef __cplusplus extern "C" { #endif #undef IPWPS_DEBUG_FAKE_ATTRIBUTE /* **************************************************************************** * 4 DEFINES **************************************************************************** */ #ifdef IPWPS_DEBUG_PROTO_CRYPTO_DATA #warning *** Defining IPWPS_DEBUG_PROTO_CRYPTO_DATA exposes sensitive cryptographic information. DO NOT SHIP CODE WITH THIS ON *** #define IPWPS_PROTO_CRYPTO_DUMPHEX(prefix,key) { \ if ((key).data) \ ipwps_dump_data((prefix), (key).data, (key).len); \ else \ IPCOM_LOG1(DEBUG2, "%s : Empty Key", (prefix)); \ } #define IPWPS_PROTO_CRYPTO_DUMPASCII(prefix,ptr,len) { \ if (ptr) \ ipwps_dump_ascii((prefix), (ptr), len); \ else \ IPCOM_LOG1(DEBUG2, "%s : null)", (prefix)); \ } #else #define IPWPS_PROTO_CRYPTO_DUMPHEX(...) {} #define IPWPS_PROTO_CRYPTO_DUMPASCII(...) {} #endif #define IWPPS_PROTO_ATTR_SIZE(attr_len) ((attr_len)+4) #define IPWPS_PROTO_SM_STATE_ERROR(_proto_ctx_) ((_proto_ctx_)->sm_error && ((_proto_ctx_)->sm_state < 0)) /* WPS Attribute ID values */ #define IPWPS_ATTR_1ST_AVAILABLE 0x1000 /* Not a valid Attribute type */ #define IPWPS_ATTR_AP_CHANNEL 0x1001 #define IPWPS_ATTR_ASSOCIATION_STATE 0x1002 #define IPWPS_ATTR_AUTHENTICATION_TYPE 0x1003 #define IPWPS_ATTR_AUTHENTICATION_TYPE_FLAGS 0x1004 #define IPWPS_ATTR_AUTHENTICATOR 0x1005 #define IPWPS_ATTR_FAKE 0x1006 #define IPWPS_ATTR_CONFIG_METHODS 0x1008 #define IPWPS_ATTR_CONFIGURATION_ERROR 0x1009 #define IPWPS_ATTR_CONFIRMATION_URL4 0x100A #define IPWPS_ATTR_CONFIRMATION_URL6 0x100B #define IPWPS_ATTR_CONNECTION_TYPE 0x100C #define IPWPS_ATTR_CONNECTION_TYPE_FLAGS 0x100D #define IPWPS_ATTR_CREDENTIAL 0x100E #define IPWPS_ATTR_DEVICE_NAME 0x1011 #define IPWPS_ATTR_DEVICE_PASSWORD_ID 0x1012 #define IPWPS_ATTR_E_HASH1 0x1014 #define IPWPS_ATTR_E_HASH2 0x1015 #define IPWPS_ATTR_E_SNONCE1 0x1016 #define IPWPS_ATTR_E_SNONCE2 0x1017 #define IPWPS_ATTR_ENCRYPTED_SETTINGS 0x1018 #define IPWPS_ATTR_ENCRYPTION_TYPE 0x100F #define IPWPS_ATTR_ENCRYPTION_TYPE_FLAGS 0x1010 #define IPWPS_ATTR_ENROLLEE_NONCE 0x101A #define IPWPS_ATTR_FEATURE_ID 0x101B #define IPWPS_ATTR_IDENTITY 0x101C #define IPWPS_ATTR_IDENTITY_PROOF 0x101D #define IPWPS_ATTR_KEY_WRAP_AUTHENTICATOR 0x101E #define IPWPS_ATTR_KEY_IDENTIFIER 0x101F #define IPWPS_ATTR_MAC_ADDRESS 0x1020 #define IPWPS_ATTR_MANUFACTURER 0x1021 #define IPWPS_ATTR_MESSAGE_TYPE 0x1022 #define IPWPS_ATTR_MODEL_NAME 0x1023 #define IPWPS_ATTR_MODEL_NUMBER 0x1024 #define IPWPS_ATTR_NETWORK_INDEX 0x1026 #define IPWPS_ATTR_NETWORK_KEY 0x1027 #define IPWPS_ATTR_NETWORK_KEY_INDEX 0x1028 #define IPWPS_ATTR_NEW_DEVICE_NAME 0x1029 #define IPWPS_ATTR_NEW_PASSWORD 0x102A #define IPWPS_ATTR_OOB_DEVICE_PASSWORD 0x102C #define IPWPS_ATTR_OS_VERSION 0x102D #define IPWPS_ATTR_POWER_LEVEL 0x102F #define IPWPS_ATTR_PSK_CURRENT 0x1030 #define IPWPS_ATTR_PSK_MAX 0x1031 #define IPWPS_ATTR_PUBLIC_KEY 0x1032 #define IPWPS_ATTR_RADIO_ENABLED 0x1033 #define IPWPS_ATTR_REBOOT 0x1034 #define IPWPS_ATTR_REGISTRAR_CURRENT 0x1035 #define IPWPS_ATTR_REGISTRAR_ESTABLISHED 0x1036 #define IPWPS_ATTR_REGISTRAR_LIST 0x1037 #define IPWPS_ATTR_REGISTRAR_MAX 0x1038 #define IPWPS_ATTR_REGISTRAR_NONCE 0x1039 #define IPWPS_ATTR_REQUEST_TYPE 0x103A #define IPWPS_ATTR_RESPONSE_TYPE 0x103B #define IPWPS_ATTR_RF_BANDS 0x103C #define IPWPS_ATTR_R_HASH1 0x103D #define IPWPS_ATTR_R_HASH2 0x103E #define IPWPS_ATTR_R_SNONCE1 0x103F #define IPWPS_ATTR_R_SNONCE2 0x1040 #define IPWPS_ATTR_SELECTED_REGISTRAR 0x1041 #define IPWPS_ATTR_SERIAL_NUMBER 0x1042 #define IPWPS_ATTR_WI_FI_PROTECTED_SETUP_STATE 0x1044 #define IPWPS_ATTR_SSID 0x1045 #define IPWPS_ATTR_TOTAL_NETWORKS 0x1046 #define IPWPS_ATTR_UUID_E 0x1047 #define IPWPS_ATTR_UUID_R 0x1048 #define IPWPS_ATTR_VENDOR_EXTENSION 0x1049 #define IPWPS_ATTR_VERSION 0x104A #define IPWPS_ATTR_X509_CERTIFICATE_REQUEST 0x104B #define IPWPS_ATTR_X509_CERTIFICATE 0x104C #define IPWPS_ATTR_EAP_IDENTITY 0x104D #define IPWPS_ATTR_MESSAGE_COUNTER 0x104E #define IPWPS_ATTR_PUBLIC_KEY_HASH 0x104F #define IPWPS_ATTR_REKEY_KEY 0x1050 #define IPWPS_ATTR_KEY_LIFETIME 0x1051 #define IPWPS_ATTR_PERMITTED_CONFIG_METHODS 0x1052 #define IPWPS_ATTR_SELECTED_REGISTRAR_CONFIG_METHODS 0x1053 #define IPWPS_ATTR_PRIMARY_DEVICE_TYPE 0x1054 #define IPWPS_ATTR_SECONDARY_DEVICE_TYPE_LIST 0x1055 #define IPWPS_ATTR_PORTABLE_DEVICE 0x1056 #define IPWPS_ATTR_AP_SETUP_LOCKED 0x1057 #define IPWPS_ATTR_APPLICATION_EXTENSION 0x1058 #define IPWPS_ATTR_EAP_TYPE 0x1059 #define IPWPS_ATTR_INITIALIZATION_VECTOR 0x1060 #define IPWPS_ATTR_KEY_PROVIDED_AUTOMATICALLY 0x1061 #define IPWPS_ATTR_8021X_ENABLED 0x1062 #define IPWPS_ATTR_APPSESSIONKEY 0x1063 #define IPWPS_ATTR_WEPTRANSMITKEY 0x1064 /* Attributes beyond this value are not supported */ #define IPWPS_ATTR_RESERVED_FOR_WFA_1ST 0x1065 #define IPWPS_ATTR_RESERVED_FOR_WFA_LAST 0x1FFF #define IPWPS_ATTR_LAST_AVAILABLE IPWPS_ATTR_RESERVED_FOR_WFA_LAST #define IPWPS_ATTR_OTHER 0xFFFF /* Catch all for any other attributes */ /* Currently supported WPS Protocol version (format as per WPS spec: 0x:4:4*/ #define IPWPS_PROTO_VER_CURRENT 0x10 /* Version 1.0 */ /* WPS Protocol Message Type values */ #define IPWPS_PROTO_MSGTYPE_BEACON 0x01 #define IPWPS_PROTO_MSGTYPE_PROBE_REQ 0x02 #define IPWPS_PROTO_MSGTYPE_PREOBE_RESP 0x03 #define IPWPS_PROTO_MSGTYPE_M1 0x04 #define IPWPS_PROTO_MSGTYPE_M2 0x05 #define IPWPS_PROTO_MSGTYPE_M2D 0x06 #define IPWPS_PROTO_MSGTYPE_M3 0x07 #define IPWPS_PROTO_MSGTYPE_M4 0x08 #define IPWPS_PROTO_MSGTYPE_M5 0x09 #define IPWPS_PROTO_MSGTYPE_M6 0x0A #define IPWPS_PROTO_MSGTYPE_M7 0x0B #define IPWPS_PROTO_MSGTYPE_M8 0x0C #define IPWPS_PROTO_MSGTYPE_ACK 0x0D #define IPWPS_PROTO_MSGTYPE_NACK 0x0E #define IPWPS_PROTO_MSGTYPE_DONE 0x0F /* WPS "DEVICE PASSWORD ID" ATTRIBUTE VALUES */ #define IPWPS_ATTRVAL_DEVPWDID_DEFAULT_PIN 0x0000 #define IPWPS_ATTRVAL_DEVPWDID_USER_SPECIFIED 0x0001 #define IPWPS_ATTRVAL_DEVPWDID_MACHINE_SPECIFIED 0x0002 #define IPWPS_ATTRVAL_DEVPWDID_REKEY 0x0003 #define IPWPS_ATTRVAL_DEVPWDID_PUSHBUTTON 0x0004 #define IPWPS_ATTRVAL_DEVPWDID_REGISTRAR_SPECIFIED 0x0005 #define IPWPS_ATTRVAL_DEVPWDID_RESERVED_START 0x0006 #define IPWPS_ATTRVAL_DEVPWDID_RESERVED_END 0x000F /* WPS "REQUEST TYPE" ATTRIBUTE VALUES */ #define IPWPS_ATTRVAL_REQTYPE_ENROLEE_INFO 0x00 #define IPWPS_ATTRVAL_REQTYPE_ENROLEE_OPEN8021X 0x01 #define IPWPS_ATTRVAL_REQTYPE_REGISTRAR 0x02 #define IPWPS_ATTRVAL_REQTYPE_WLANMGR_REGISTRAR 0x03 /* WPS "RESPONSE TYPE" ATTRIBUTE VALUES */ #define IPWPS_ATTRVAL_RESPTYPE_ENROLEE_INFO 0x00 #define IPWPS_ATTRVAL_RESPTYPE_ENROLEE_OPEN8021X 0x01 #define IPWPS_ATTRVAL_RESPTYPE_REGISTRAR 0x02 #define IPWPS_ATTRVAL_RESPTYPE_AP 0x03 /* WPS "WPS STATE" ATTRIBUTE VALUES */ #define IPWPS_ATTRVAL_WPSSTATE_RESERVED 0x00 #define IPWPS_ATTRVAL_WPSSTATE_NOTCONFIG 0x01 #define IPWPS_ATTRVAL_WPSSTATE_CONFIGURED 0x02 #define IPWPS_ATTRVAL_WPSSTATE_RESERVED_START 0x03 #define IPWPS_ATTRVAL_WPSSTATE_RESERVED_END 0xFF #define IPWPS_PROTO_MAX_ATTR_SIZE 0xFFFF #define IPWPS_PROTO_ATTR_LEN_DEVICE_TYPE 8 #define IPWPS_PROTO_ATTR_LEN_AUTHENTICATOR 8 #define IPWPS_PROTO_ATTR_LEN_NETWORK_KEY IPWPS_PROTO_NETWORK_KEY_MAXLEN #define IPWPS_PROTO_ATTR_LEN_ENCRSET_MAX 1024 #define IPWPS_PROTO_ATTR_LEN_CREDENTIAL_MAX 256 #define IPWPS_PROTO_ATTR_LEN_PASSWORD_MAX IPWPS_PROTO_PASSWORD_MAXLEN #define IPWPS_PROTO_NONCE_SIZE 16 #define IPWPS_PROTO_UUID_SIZE IPWPS_UUID_SIZE #define IPWPS_PROTO_HASH_SIZE 32 #define IPWPS_PROTO_IV_SIZE 16 #define IPWPS_PROTO_AUTHENTICATOR_SIZE 8 #define IPWPS_PROTO_PUBLIC_KEY_SIZE 192 #define IPWPS_PROTO_PUBLIC_KEY_HASH_SIZE 20 /* WPS Protocol Key validity check */ #define IPWPS_PROTO_CONTAINER_ISVALID(_container_) \ ((_container_).data && (_container_).len \ && (((_container_).alloc_len == 0) || ((_container_).len <= (_container_).alloc_len)) \ ) #define IPWPS_PROTO_CONTAINER_INIT(_container_) {ipcom_memset(&(_container_), 0, sizeof(_container_));} #define IPWPS_PROTO_KEY_ISVALID IPWPS_PROTO_CONTAINER_ISVALID #define IPWPS_PROTO_KEY_INIT IPWPS_PROTO_CONTAINER_INIT #define IPWPS_PROTO_NONCE_ISVALID IPWPS_PROTO_CONTAINER_ISVALID #define IPWPS_PROTO_NONCE_INIT IPWPS_PROTO_CONTAINER_INIT #define IPWPS_PROTO_HASH_ISVALID IPWPS_PROTO_CONTAINER_ISVALID #define IPWPS_PROTO_HASH_INIT IPWPS_PROTO_CONTAINER_INIT /* WPS Protocol Key Lengths (in bytes) */ #define IPWPS_PROTO_KEYLEN_AUTHKEY (256/8) #define IPWPS_PROTO_KEYLEN_KEYWRAPKEY (128/8) #define IPWPS_PROTO_KEYLEN_EMSK (256/8) #define IPWPS_PROTO_KEYLEN_SESSIONKEYS_TOTAL \ (IPWPS_PROTO_KEYLEN_AUTHKEY + IPWPS_PROTO_KEYLEN_KEYWRAPKEY + IPWPS_PROTO_KEYLEN_EMSK) #define IPWPS_PROTO_LEN_KEYWRAPAUTH (64/8) /* **************************************************************************** * 5 TYPES **************************************************************************** */ typedef enum { IPWPS_IETYPE_BEACON, IPWPS_IETYPE_PROBE_REQUEST, IPWPS_IETYPE_PROBE_RESPONSE, IPWPS_IETYPE_ASSOC_REQUEST, IPWPS_IETYPE_ASSOC_RESPONSE } Ipwps_ie_type; typedef enum { IPWPS_ENCRSET_M4, IPWPS_ENCRSET_M5, IPWPS_ENCRSET_M6, IPWPS_ENCRSET_M7_ENR, IPWPS_ENCRSET_M7_AP, IPWPS_ENCRSET_M2_8_AP, IPWPS_ENCRSET_M2_8_STA } Ipwps_encrypted_settings_specifier; typedef Ip_u16 Ipwps_attribute_type; /* All of the Ipwps_protomsg_xxx structures are stored in host endian format */ /* WPS Attribute TLV overlay struct */ typedef struct Ipwps_attribute_tlv_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 data[1]; Ip_u8 pad[3]; } Ipwps_attribute_tlv; /* WPS Attribute TLV struct definitions */ typedef struct Ipwps_attribute_uint8_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 val; Ip_u8 pad[3]; } Ipwps_attribute_uint8; typedef struct Ipwps_attribute_uint16_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u16 val; Ip_u8 pad[2]; } Ipwps_attribute_uint16; typedef struct Ipwps_attribute_uint32_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u32 val; } Ipwps_attribute_uint32; typedef struct Ipwps_attribute_uint8_st Ipwps_attribute_bool; typedef struct Ipwps_attribute_uint8_st Ipwps_attribute_version; typedef struct Ipwps_attribute_uint8_st Ipwps_attribute_msgtype; typedef struct Ipwps_attribute_uint8_st Ipwps_attribute_reqtype; typedef struct Ipwps_attribute_uint8_st Ipwps_attribute_resptype; typedef struct Ipwps_attribute_uint8_st Ipwps_attribute_rfbands; typedef struct Ipwps_attribute_ascii_name_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 name[65]; /* includes space for null terminating character which is not sent */ Ip_u8 pad[3]; } Ipwps_attribute_ascii_name; typedef struct Ipwps_attribute_ascii_number32B_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 byte[33]; /* includes space for null terminating character which is not sent */ Ip_u8 pad[3]; } Ipwps_attribute_ascii_number32B; typedef struct Ipwps_attribute_primary_dev_type_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ipwps_device_type dev_type[1]; } Ipwps_attribute_primary_dev_type; typedef struct Ipwps_attribute_uuid_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_UUID_SIZE]; } Ipwps_attribute_uuid; typedef struct Ipwps_attribute_nonce_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_NONCE_SIZE]; } Ipwps_attribute_nonce; typedef struct Ipwps_attribute_hash_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_HASH_SIZE]; } Ipwps_attribute_hash; typedef struct Ipwps_attribute_public_key_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_PUBLIC_KEY_SIZE]; } Ipwps_attribute_public_key; typedef struct Ipwps_attribute_authenticator_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_AUTHENTICATOR_SIZE]; } Ipwps_attribute_authenticator; typedef struct Ipwps_attribute_mac_addr_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[6]; Ip_u8 pad[2]; } Ipwps_attribute_mac_addr; typedef struct Ipwps_attribute_encr_settings_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_ATTR_LEN_ENCRSET_MAX]; } Ipwps_attribute_encr_settings; typedef struct Ipwps_attribute_keywrap_auth_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_LEN_KEYWRAPAUTH]; } Ipwps_attribute_keywrap_auth; typedef struct Ipwps_attribute_credential_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_ATTR_LEN_CREDENTIAL_MAX]; } Ipwps_attribute_credential; typedef struct Ipwps_attribute_dev_pwd_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_ATTR_LEN_PASSWORD_MAX]; }Ipwps_attribute_dev_pwd; typedef struct Ipwps_attribute_network_key_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[IPWPS_PROTO_ATTR_LEN_NETWORK_KEY]; } Ipwps_attribute_network_key; typedef struct Ipwps_attribute_eap_type_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u8 octet[8]; } Ipwps_attribute_eap_type; typedef struct Ipwps_attribute_ap_settings_st { Ipwps_attribute_ascii_name ssid; Ipwps_attribute_mac_addr mac_addr; Ipwps_attribute_uint16 auth_type; Ipwps_attribute_uint16 encr_type; Ipwps_attribute_uint8 network_idx; Ipwps_attribute_uint8 netkey_idx; Ipwps_attribute_network_key netkey; Ipwps_attribute_eap_type eap_type; Ipwps_attribute_ascii_name eap_id; Ipwps_attribute_bool key_auto; Ipwps_attribute_bool enabled_8021x; } Ipwps_attribute_credential_settings; /* Contains all possible decrypted settings */ typedef struct Ipwps_decrypted_settings_st { Ipwps_encrypted_settings_specifier which_encr_set; Ipwps_attribute_nonce e_snonce1; Ipwps_attribute_nonce e_snonce2; Ipwps_attribute_nonce r_snonce1; Ipwps_attribute_nonce r_snonce2; /* TBD */ Ipwps_attribute_credential_settings ap_settings; Ip_u16 num_wlan_creds; Ip_u16 pad; Ipwps_attribute_credential_settings wlan_credentials[IPWPS_NUM_CEDENTIALS_MAX]; Ipwps_attribute_dev_pwd new_password; Ipwps_attribute_uint16 dev_pwd_id; Ipwps_attribute_credential credential[IPWPS_NUM_CEDENTIALS_MAX]; Ipwps_attribute_keywrap_auth kwa; } Ipwps_decrypted_settings; /* WPS Protocol Message common struct definitions */ typedef struct Ipwps_protomsg_common_header_st { Ipwps_attribute_version version; Ipwps_attribute_msgtype msg_type; } Ipwps_protomsg_common_header; typedef struct Ipwps_protomsg_common_device_info_st { Ipwps_attribute_ascii_name manufacturer; Ipwps_attribute_ascii_name model_name; Ipwps_attribute_ascii_number32B model_number; Ipwps_attribute_ascii_number32B serial_number; Ipwps_attribute_primary_dev_type primary_dev_type; Ipwps_attribute_ascii_name dev_name; Ipwps_attribute_uint32 os_ver; } Ipwps_protomsg_common_device_info; #ifdef IPWPS_DEBUG_FAKE_ATTRIBUTE typedef struct Ipwps_attribute_fake_st { Ipwps_attribute_type attr_type; Ip_u16 len; Ip_u16 pad; Ip_u8 octet[4000]; } Ipwps_attribute_fake; #endif /* WPS Protocol Message TLV struct definitions */ typedef struct Ipwps_protomsg_M1_st { Ipwps_protomsg_common_header common_hdr; Ipwps_protomsg_common_device_info common_dev_info; Ipwps_attribute_uuid uuid_e; Ipwps_attribute_mac_addr mac_addr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_public_key public_key; Ipwps_attribute_uint16 auth_type_flags; Ipwps_attribute_uint16 encr_type_flags; Ipwps_attribute_uint8 conn_type_flags; Ipwps_attribute_uint16 config_methods; Ipwps_attribute_uint8 wps_state; Ipwps_attribute_rfbands rf_bands; Ipwps_attribute_uint16 assoc_state; Ipwps_attribute_uint16 dev_pwd_id; Ipwps_attribute_uint16 config_err; #ifdef IPWPS_DEBUG_FAKE_ATTRIBUTE Ipwps_attribute_fake fake; #endif } Ipwps_protomsg_M1; typedef struct Ipwps_protomsg_M2_st { Ipwps_protomsg_common_header common_hdr; Ipwps_protomsg_common_device_info common_dev_info; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_nonce r_nonce; Ipwps_attribute_uuid uuid_r; Ipwps_attribute_public_key public_key; Ipwps_attribute_uint16 auth_type_flags; Ipwps_attribute_uint16 encr_type_flags; Ipwps_attribute_uint8 conn_type_flags; Ipwps_attribute_uint16 config_methods; Ipwps_attribute_rfbands rf_bands; Ipwps_attribute_uint16 assoc_state; Ipwps_attribute_uint16 dev_pwd_id; Ipwps_attribute_uint16 config_err; Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M2; typedef struct Ipwps_protomsg_M2D_st { Ipwps_protomsg_common_header common_hdr; Ipwps_protomsg_common_device_info common_dev_info; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_nonce r_nonce; Ipwps_attribute_uuid uuid_r; Ipwps_attribute_uint16 auth_type_flags; Ipwps_attribute_uint16 encr_type_flags; Ipwps_attribute_uint8 conn_type_flags; Ipwps_attribute_uint16 config_methods; Ipwps_attribute_rfbands rf_bands; Ipwps_attribute_uint16 assoc_state; Ipwps_attribute_uint16 config_err; } Ipwps_protomsg_M2D; typedef struct Ipwps_protomsg_M3_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_hash e_hash1; Ipwps_attribute_hash e_hash2; Ipwps_attribute_nonce r_nonce; Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M3; typedef struct Ipwps_protomsg_M4_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_hash r_hash1; Ipwps_attribute_hash r_hash2; Ipwps_attribute_encr_settings encr_set; Ipwps_decrypted_settings decr_set; /* Not part of a WPS message, but contains decrypted values of the encrypted settings attribute */ Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M4; typedef struct Ipwps_protomsg_M5_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce r_nonce; Ipwps_attribute_encr_settings encr_set; Ipwps_decrypted_settings decr_set; /* Not part of a WPS message, but contains decrypted values of the encrypted settings attribute */ Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M5; typedef struct Ipwps_protomsg_M6_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_encr_settings encr_set; Ipwps_decrypted_settings decr_set; /* Not part of a WPS message, but contains decrypted values of the encrypted settings attribute */ Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M6; typedef struct Ipwps_protomsg_M7_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce r_nonce; Ipwps_attribute_encr_settings encr_set; Ipwps_decrypted_settings decr_set; /* Not part of a WPS message, but contains decrypted values of the encrypted settings attribute */ Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M7; typedef struct Ipwps_protomsg_M8_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_encr_settings encr_set; Ipwps_decrypted_settings decr_set; /* Not part of a WPS message, but contains decrypted values of the encrypted settings attribute */ Ipwps_attribute_authenticator authenticator; } Ipwps_protomsg_M8; typedef struct Ipwps_protomsg_ACK_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_nonce r_nonce; } Ipwps_protomsg_ACK; typedef struct Ipwps_protomsg_NACK_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_nonce r_nonce; Ipwps_attribute_uint16 config_err; } Ipwps_protomsg_NACK; typedef struct Ipwps_protomsg_DONE_st { Ipwps_protomsg_common_header common_hdr; Ipwps_attribute_nonce e_nonce; Ipwps_attribute_nonce r_nonce; } Ipwps_protomsg_DONE; typedef struct Ipwps_protomsg_overlay_st { Ipwps_protomsg_common_header common_hdr; Ip_u8 data[4]; } Ipwps_protomsg_overlay; /* WPS IE TLV struct definitions */ typedef struct Ipwps_iedata_beacon_st { Ipwps_ie_type ie_type; Ipwps_attribute_version version; Ipwps_attribute_uint8 wps_state; Ipwps_attribute_bool ap_locked; Ipwps_attribute_bool selreg; /* Selected Registrar */ Ipwps_attribute_uint16 dev_pwd_id; Ipwps_attribute_uint16 selreg_config_methods; Ipwps_attribute_uuid uuid_e; Ipwps_attribute_rfbands rf_bands; } Ipwps_iedata_beacon; typedef struct Ipwps_iedata_probe_req_st { Ipwps_ie_type ie_type; Ipwps_attribute_version version; Ipwps_attribute_reqtype request_type; Ipwps_attribute_uint16 config_methods; Ipwps_attribute_uuid uuid_e; Ipwps_attribute_uuid uuid_r; Ipwps_attribute_primary_dev_type primary_dev_type; Ipwps_attribute_rfbands rf_bands; Ipwps_attribute_uint16 assoc_state; Ipwps_attribute_uint16 dev_pwd_id; Ipwps_attribute_uint16 config_err; } Ipwps_iedata_probe_req; typedef struct Ipwps_iedata_probe_resp_st { Ipwps_ie_type ie_type; Ipwps_attribute_version version; Ipwps_attribute_uint8 wps_state; Ipwps_attribute_bool ap_locked; Ipwps_attribute_bool selreg; /* Selected Registrar */ Ipwps_attribute_uint16 dev_pwd_id; Ipwps_attribute_uint16 selreg_config_methods; Ipwps_attribute_resptype response_type; Ipwps_attribute_uuid uuid_e; Ipwps_protomsg_common_device_info common_dev_info; Ipwps_attribute_uint16 config_methods; Ipwps_attribute_rfbands rf_bands; } Ipwps_iedata_probe_resp; typedef struct Ipwps_iedata_assoc_req_st { Ipwps_ie_type ie_type; Ipwps_attribute_version version; Ipwps_attribute_reqtype request_type; } Ipwps_iedata_assoc_req; typedef struct Ipwps_iedata_assoc_resp_st { Ipwps_ie_type ie_type; Ipwps_attribute_version version; Ipwps_attribute_resptype response_type; } Ipwps_iedata_assoc_resp; typedef struct Ipwps_iedata_overlay_st { Ipwps_ie_type ie_type; Ipwps_attribute_version version; } Ipwps_iedata_overlay; /* WPS Protocol generic data container structure * This is mainly used to store cryptographically * sensitive data. */ typedef struct Ipwps_proto_container_st { Ip_u8 *data; Ip_u16 len; Ip_u16 alloc_len; /* Max Length if container has allocated data, 0 otherwise */ } Ipwps_proto_container; /* WPS Protocol Key structure */ typedef Ipwps_proto_container Ipwps_proto_key; /* WPS Protocol Nonce structure */ typedef Ipwps_proto_container Ipwps_proto_nonce; /* WPS Protocol Hash structure */ typedef Ipwps_proto_container Ipwps_proto_hash; /* WPS Protocol state machine states */ typedef enum { IPWPS_PROTOSM_STATE_INVALID = 0, IPWPS_PROTOSM_STATE_IDLE, IPWPS_PROTOSM_STATE_START_RCVD, IPWPS_PROTOSM_STATE_M1_RCVD, IPWPS_PROTOSM_STATE_M2_RCVD, IPWPS_PROTOSM_STATE_M2D_RCVD, IPWPS_PROTOSM_STATE_M3_RCVD, IPWPS_PROTOSM_STATE_M4_RCVD, IPWPS_PROTOSM_STATE_M5_RCVD, IPWPS_PROTOSM_STATE_M6_RCVD, IPWPS_PROTOSM_STATE_M7_RCVD, IPWPS_PROTOSM_STATE_M8_RCVD, IPWPS_PROTOSM_STATE_DONE_RCVD, IPWPS_PROTOSM_STATE_ACK_RCVD, IPWPS_PROTOSM_STATE_NACK_RCVD, IPWPS_PROTOSM_STATE_START_SENT, IPWPS_PROTOSM_STATE_M1_SENT, IPWPS_PROTOSM_STATE_M2_SENT, IPWPS_PROTOSM_STATE_M2D_SENT, IPWPS_PROTOSM_STATE_M3_SENT, IPWPS_PROTOSM_STATE_M4_SENT, IPWPS_PROTOSM_STATE_M5_SENT, IPWPS_PROTOSM_STATE_M6_SENT, IPWPS_PROTOSM_STATE_M7_SENT, IPWPS_PROTOSM_STATE_M8_SENT, IPWPS_PROTOSM_STATE_DONE_SENT, IPWPS_PROTOSM_STATE_ACK_SENT, IPWPS_PROTOSM_STATE_NACK_SENT, IPWPS_PROTOSM_STATE_FINISHED, /* WPS Protocol exchange completed properly */ /* Make sure Error states are ngative */ IPWPS_PROTOSM_STATE_SEND_ERROR = -1, IPWPS_PROTOSM_STATE_RCV_ERROR = -2, IPWPS_PROTOSM_STATE_LOCAL_ERROR = -3, IPWPS_PROTOSM_STATE_SESSION_PROTO_ERROR = -4, IPWPS_PROTOSM_STATE_SESSION_CRYPTO_ERROR = -5, IPWPS_PROTOSM_STATE_INVALID_PEER_ERROR = -6 } Ipwps_protocol_sm_state; /* WPS Protocol context structure definitions */ struct dh_st; typedef struct Ipwps_proto_ctx_st { /* State members */ Ip_u8 version; /* protocol version */ Ip_u8 pad1[3]; Ipwps_protocol_sm_state sm_state; /* current state */ Ip_bool sm_error; /* True if a state machine error occurred */ Ipwps_protocol_sm_state sm_prev_state; /* previous state */ Ipwps_proto_data *last_rcvd_proto_msg; /* ptr to latest received protocol msg for wps msg authenticator validation purposes */ Ipwps_proto_data *last_sent_proto_msg; /* ptr to last sent protocol msg for wps msg authenticator validation purposes */ /* Crypto members */ Ip_bool crypto_init; Ip_u8 enrollee_mac[6]; Ip_u8 pad2[2]; struct dh_st *dh; /* Diffie-Hellman structure use for publick/private key derivation */ Ipwps_proto_key local_pub_key; Ipwps_proto_key peer_pub_key; Ipwps_proto_nonce nonce1; /* Enrollee nonce */ Ipwps_proto_nonce nonce2; /* Registrar nonce */ Ipwps_proto_key auth_key; Ipwps_proto_key key_wrap_key; Ipwps_proto_key emsk; Ipwps_proto_container dev_pwd; /* Device password as set by WPS app */ Ipwps_proto_key psk1; Ipwps_proto_key psk2; Ipwps_proto_nonce e_snonce1; Ipwps_proto_nonce e_snonce2; Ipwps_proto_nonce r_snonce1; Ipwps_proto_nonce r_snonce2; Ipwps_proto_hash e_hash1; Ipwps_proto_hash e_hash2; Ipwps_proto_hash r_hash1; Ipwps_proto_hash r_hash2; } Ipwps_proto_ctx; /* **************************************************************************** * 6 FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipwps_protocol_format_message *=========================================================================== * Description: * Format a WPS protocol message given the corresponding message structure. * This format function will also do the appropriate endian translations. * Parameters: * Ipwps_protomsg_overlay *msg - A valid WPS protocol message structure * with type, length and any corrsponding data set. * Ip_u8 *buf - pointer to buffer in which to format the protocol message * Ip_u16 *len - max size of buffer. Will be set to the actual size of the protoco message upon success. * Returns: * IPCOM_SUCCESS if format is successful, otherwise an error indication */ IP_GLOBAL Ip_err ipwps_protocol_format_message ( Ipwps_protomsg_overlay *msg, Ip_u8 *buf, Ip_u16 *len ); /* *=========================================================================== * ipwps_protocol_decode_message *=========================================================================== * Description: * Decode a WPS protocol message into the corresponding message structure. * This decode function will also do the appropriate endian translations. * Parameters: * Ip_u8 *buf - pointer to buffer containing the protocol message to be decoded * Ip_u16 len - size of the protocol message to be decoded. * Returns: * Ipwps_protomsg_overlay *msg - * A non-NULL pointer to a valid WPS protocol message * overlay structure where the decoder set the type, length and any corrsponding * data (if any. The type is used to decide the exact type of the allocated * WPS protocol message structure. * IP_NULL if decoding fails or any other errors occur. * */ IP_GLOBAL Ipwps_protomsg_overlay *ipwps_protocol_decode_message ( Ip_u8 *buf, Ip_u16 len ); /* *=========================================================================== * ipwps_protocol_format_encrypted_settings *=========================================================================== * Description: * Format a "yet to be encrypted" WPS Encrypted Settings given the corresponding * structure. set->which_encr_set specifies which exact encrypted settings * blueprint to use. * This format function will also do the appropriate endian translations. * Parameters: * Ipwps_decrypted_settings *set - A valid pointer to a structure containing * the fields to encode. Only relevant tlvs will be queried. * set->which_encr_set should also specify the exact encrypted settings * blueprint to use when this function is called. * Ipwps_proto_container *dtf - container for the encoded * WPS Encrypted Settings fields. This function updates the container length * with the size of the data that was encoded. Length field must contain the * max length of the buffer when this function is called. * Returns: * IPCOM_SUCCESS if format is successful, otherwise an error indication */ IP_GLOBAL Ip_err ipwps_protocol_format_encrypted_settings ( Ipwps_decrypted_settings *set, Ipwps_proto_container *dtf ); /* *=========================================================================== * ipwps_protocol_decode_encrypted_settings *=========================================================================== * Description: * Decode an "already decrypted" WPS Encrypted Settings field into the provided * Ipwps_decrypted_settings structure. set->which_encr_set specifies which * exact encrypted settings blueprint to use. * This decode function will also do the appropriate endian translations. * Parameters: * Ipwps_proto_container *dtd - container of the already decrypted * WPS Encrypted Settings field to be decoded * Ipwps_decrypted_settings *set - A valid pointer to a structure to contain * the decoded results. Only relevant decoded tlvs will be updated. * set->which_encr_set should also specify the exact encrypted settings * blueprint to use when this function is called. * Returns: * an error code if decoding fails or any other errors occur, * otherwise IPCOM_SUCCESS upon successful decode. * */ IP_GLOBAL Ip_err ipwps_protocol_decode_encrypted_settings ( Ipwps_decrypted_settings *set, Ipwps_proto_container *dtd ); /* *=========================================================================== * ipwps_protocol_format_credentials *=========================================================================== * Description: * Format a WPS Crdentials data given the corresponding credentials structure. * This format function will also do the appropriate endian translations. * Parameters: * Ipwps_attribute_credential_settings *cred - A valid pointer to a structure * containing the fields to encode. Only relevant tlvs will be queried. * Ipwps_proto_container *ctf - container for the encoded * WPS Credentials. This function updates the container length * with the size of the data that was encoded. Length field must contain the * max length of the buffer when this function is called. * Returns: * IPCOM_SUCCESS if format is successful, otherwise an error indication */ IP_GLOBAL Ip_err ipwps_protocol_format_credentials ( Ipwps_attribute_credential_settings *cred, Ipwps_proto_container *ctf ); /* *=========================================================================== * ipwps_protocol_decode_credentials *=========================================================================== * Description: * Decode WPS Crdentials data field into the provided * Ipwps_attribute_credential_settings structure. * This decode function will also do the appropriate endian translations. * Parameters: * Ipwps_proto_container *ctd - container of WPS Crdentials data to be decoded * Ipwps_attribute_credential_settings *cred - A valid pointer to a structure * to contain the decoded results. Only relevant decoded tlvs will be updated. * Returns: * an error code if decoding fails or any other errors occur, * otherwise IPCOM_SUCCESS upon successful decode. */ IP_GLOBAL Ip_err ipwps_protocol_decode_credentials ( Ipwps_attribute_credential_settings *cred, Ipwps_proto_container *ctd ); /* *=========================================================================== * ipwps_protocol_format_iedata *=========================================================================== * Description: * Format the contents of a WPS IE given the corresponding structure. * This format function will also do the appropriate endian translations. * Parameters: * Ipwps_iedata_overlay *iedata - A valid WPS iedata structure * with ie_type set, and all relevant tlvs length and any corrsponding data set. * Ip_u8 *buf - pointer to buffer in which to format the ie data * Ip_u16 *len - max size of buffer. Will be set to the actual size of the protoco message upon success. * Returns: * IPCOM_SUCCESS if format is successful, otherwise an error indication */ IP_GLOBAL Ip_err ipwps_protocol_format_iedata ( Ipwps_iedata_overlay *iedata, Ip_u8 *buf, Ip_u16 *len ); /* *=========================================================================== * ipwps_protocol_decode_iedata *=========================================================================== * Description: * Decode a WPS IE data content into the corresponding structure. * This decode function will also do the appropriate endian translations. * Parameters: * Ipwps_ie_type ie_type - Type of IE to decode. * Ip_u8 *buf - pointer to buffer containing the IE data to be decoded * Ip_u16 len - size of the IE data to be decoded. * Returns: * Ipwps_iedata_overlay *iedata - * A non-NULL pointer to a valid WPS iedata * overlay structure where the decoder set the type, length and any corrsponding * data (if any. The type is used to decide the exact type of the allocated * WPS protocol message structure. * IP_NULL if decoding fails or any other errors occur. * */ IP_GLOBAL Ipwps_iedata_overlay *ipwps_protocol_decode_iedata ( Ipwps_ie_type ie_type, Ip_u8 *buf, Ip_u16 len ); /* *=========================================================================== * ipwps_protocol_msgtype_name *=========================================================================== * Description: * Retrieve the name of a WPS message. * Parameters: * Ip_u8 msg_type - A valid message type * Returns: * A pointer to a string containing the name of the message. */ IP_GLOBAL IP_CONST char *ipwps_protocol_msgtype_name ( Ip_u8 msg_type ); /* *=========================================================================== * ipwps_protocol_ietype_name *=========================================================================== * Description: * Retrieve the name of a WPS IE. * Parameters: * Ip_u8 ie_type - A valid ie type * Returns: * A pointer to a string containing the name of the ie. */ IP_GLOBAL IP_CONST char *ipwps_protocol_ietype_name ( Ip_u8 ie_type ); /* *=========================================================================== * ipwps_protocol_attribute_name *=========================================================================== * Description: * Retrieve the name of an attribute. * Parameters: * Ipwps_attribute_type attr_type - A valid attribute type * Returns: * A pointer to a string containing the name of the attribute if recognized, * IP_NULL otherwise */ IP_GLOBAL char *ipwps_protocol_attribute_name ( Ipwps_attribute_type attr_type ); /* *=========================================================================== * ipwps_protocol_display_msg *=========================================================================== * Description: * Display the contents of a WPS Protocol Message. * Parameters: * char *heading - A string containing a short description. * Ipwps_protomsg_overlay *msg - Pointer to a valid WPS Protocol message struct * Returns: * None */ IP_GLOBAL void ipwps_protocol_display_msg ( char *heading, Ipwps_protomsg_overlay *msg ); /* *=========================================================================== * ipwps_protocol_display_decrypted_settings *=========================================================================== * Description: * Display the contents of a the decrypted and decoded WPS encrypted settings. * Parameters: * char *heading - A string containing a short description. * Ipwps_decrypted_settings *set - settings to display * Returns: * None */ IP_GLOBAL void ipwps_protocol_display_decrypted_settings ( char *heading, Ipwps_decrypted_settings *set ); /* *=========================================================================== * ipwps_protocol_display_iedata *=========================================================================== * Description: * Display the WPS IE data. * Parameters: * char *heading - A string containing a short description. * Ipwps_iedata_overlay *iedata - IE data to display * Returns: * None */ IP_GLOBAL void ipwps_protocol_display_iedata ( char *heading, Ipwps_iedata_overlay *iedata ); /* *=========================================================================== * ipwps_proto_crypto_delete_all *=========================================================================== * Description: * Deletes all protocol keys from the provided protocol context. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context. * Returns: * IPSUCCESS if successful, error otherwise */ IP_GLOBAL void ipwps_proto_crypto_delete_all ( struct Ipwps_proto_ctx_st *proto_ctx ); /* *=========================================================================== * ipwps_proto_crypto_init *=========================================================================== * Description: * Initialize the IPWPS Protocol Crypto module. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context. * Returns: * IPSUCCESS if successful, error otherwise */ IP_GLOBAL Ip_err ipwps_proto_crypto_init ( struct Ipwps_proto_ctx_st *proto_ctx ); /* *=========================================================================== * ipwps_proto_alloc_data *=========================================================================== * Description: * Allocate container data of length "len". * Parameters: * Returns: */ IP_GLOBAL Ip_err ipwps_proto_alloc_data ( Ipwps_proto_container *container, Ip_u16 len ); /* *=========================================================================== * ipwps_proto_alloc_and_copy_data *=========================================================================== * Description: * Allocate container data of length "len" and copy "data" into it. * Parameters: * Returns: */ IP_GLOBAL Ip_err ipwps_proto_alloc_and_copy_data ( Ipwps_proto_container *container, Ip_u8 *data, Ip_u16 len ); /* *=========================================================================== * ipwps_proto_duplicate_data *=========================================================================== * Description: * Duplicate container "from" into "to. * Parameters: * Ipwps_proto_container *to - Container to create duplicate in Ipwps_proto_container *from - Container to duplicate * Returns: */ IP_GLOBAL Ip_err ipwps_proto_duplicate_data ( Ipwps_proto_container *to, Ipwps_proto_container *from ); /* *=========================================================================== * ipwps_proto_copy_data *=========================================================================== * Description: * Copy "copy_len" bytes from "src" container's data starting at offset * "src_offset" into a new buffer allocated for "dest". * Parameters: * Ipwps_proto_container *dest - Destination container which will have a newly * allocated data buffer to copy data into. * Ipwps_proto_container *src - source container to copy from * Ip_u16 src_offset - offset from start of src container buffer to start copying from * Ip_u16 copy_len - number of bytes to copy * Returns: */ IP_GLOBAL Ip_err ipwps_proto_copy_data ( Ipwps_proto_container *dest, Ipwps_proto_container *src, Ip_u16 src_offset, Ip_u16 copy_len ); /* *=========================================================================== * ipwps_proto_compare_data *=========================================================================== * Description: * Compare 2 daat containers * Parameters: * Ipwps_proto_container *c1, *c2 - data to compare * Returns: * IP_TRUE if matching, IP_FALSE otherwise. */ IP_GLOBAL Ip_bool ipwps_proto_compare_data ( Ipwps_proto_container *c1, Ipwps_proto_container *c2 ); /* *=========================================================================== * ipwps_proto_container_delete *=========================================================================== * Description: Delete a data container after clearing its buffer. * Used to erase the contents of sensitive crypto data before deallocating. * Parameters: * Returns: */ IP_GLOBAL void ipwps_proto_container_delete ( Ipwps_proto_container *container ); /* *=========================================================================== * ipwps_proto_crypto_randdata *=========================================================================== * Description: Fill a container with a Cryptographically Random stream of * data according to data len. * (NOTE: Overwrites any exisiting data) * Parameters: * Ipwps_proto_container *container: A valid container * (with allocated data and non zero len) * Returns: */ IP_GLOBAL Ip_err ipwps_proto_crypto_randdata ( Ipwps_proto_container *container ); /* *=========================================================================== * ipwps_proto_set_device_password *=========================================================================== * Description: Set the device password associated with the protocol handler * context specified. * Called by WPS applications. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid IPWPS Protocol Handler context * Ip_u8 *buf - Pointer to device password. * Ip_u16 len - Length of device password * (for PIN, it doesn't include the NULL terminating character) * Returns: * */ IP_GLOBAL Ip_err ipwps_proto_set_device_password ( struct Ipwps_proto_ctx_st *proto_ctx, Ip_u8 *buf, Ip_u16 len ); /* *=========================================================================== * ipwps_proto_generate_local_keys *=========================================================================== * Description: * Generate our local Private/Public key pair and store the public * key in the "local_pub_key" member of the protocol context. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context. * Returns: * IPSUCCESS if successful, error otherwise */ IP_GLOBAL Ip_err ipwps_proto_generate_local_keys ( struct Ipwps_proto_ctx_st *proto_ctx ); /* *=========================================================================== * ipwps_proto_derive_session_keys *=========================================================================== * Description: * Derive the WPS session keys after receiving the peer info. * The results are stored in the corresponding members of the protocol context. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context. * Returns: * IPCOM_SUCCESS if successful, error otherwise */ IP_GLOBAL Ip_err ipwps_proto_derive_session_keys ( struct Ipwps_proto_ctx_st *proto_ctx ); /* *=========================================================================== * ipwps_proto_derive_psks *=========================================================================== * Description: * Derive PSK1 and PSK2 values for the specified protocol handler context. * Requires the "dev_pwd" to be set. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context. * Returns: * IPCOM_SUCCESS if successful, error otherwise */ IP_GLOBAL Ip_err ipwps_proto_derive_psks ( Ipwps_proto_ctx *proto_ctx ); /* *=========================================================================== * ipwps_proto_derive_devpwd_proof_hash *=========================================================================== * Description: * Derive the hashes used to prove possession of the device password. * The hash is HMAC_AuthKey(snonce || psk || PKe || PKr) * specifically they are: * HMAC_AuthKey(E-snonce1 || psk1 || PKe || PKr) * HMAC_AuthKey(E-snonce2 || psk2 || PKe || PKr) * HMAC_AuthKey(R-snonce1 || psk1 || PKe || PKr) * HMAC_AuthKey(R-snonce2 || psk2 || PKe || PKr) * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context. * Ipwps_proto_nonce *snonce - Snonce to use * Ipwps_proto_key *psk - psk to use * Ipwps_proto_hash *hash - Hash to store result in. * Ipwps_proto_key *pk_e - Enolleee Public key * Ipwps_proto_key *pk_r - Registrar Public key ) * Returns: * IPCOM_SUCCESS if successful, error otherwise */ IP_GLOBAL Ip_err ipwps_proto_derive_devpwd_proof_hash ( Ipwps_proto_ctx *proto_ctx, Ipwps_proto_nonce *snonce, Ipwps_proto_key *psk, Ipwps_proto_key *pk_e, Ipwps_proto_key *pk_r, Ipwps_proto_hash *hash ); /* *=========================================================================== * ipwps_proto_calc_msgauth *=========================================================================== * Description: * Calculate the Message authenticatorfor msg2: HMAC_AuthKey(msg1 || msg2*) * excluding the last authenticator portion of msg2 and storing the result in * the excluded section of msg2. * HMAC_AuthKey() is the keyed hash function HMAC-SHA-256 using the AuthKey * as a key with the result trauncated to 64 bit (8 bytes). * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context with appropriately * initialized members (e.g. keys, nonces, etc). * struct Ipwps_proto_data_st *msg1 - Pointer to 1st msg to use in the HMAC. * struct Ipwps_proto_data_st *msg2 - Pointer to 2nd msg to use in the HMAC. * msg2 length is that of the full message including the last * IPWPS_PROTO_ATTR_LEN_AUTHENTICATOR bytes of the msg that will be skipped * during HMAC_AuthKey() calculation so their content is irrelevant when * this function is called, but they will contain the authenticator value * when this function returns. * Returns: * IPCOM_SUCCESS upon successfully computing the authenticator value and copying * it to the end of msg2 * an error indication otherwise. */ IP_GLOBAL Ip_err ipwps_proto_calc_msgauth ( struct Ipwps_proto_ctx_st *proto_ctx, struct Ipwps_proto_data_st *msg1, struct Ipwps_proto_data_st *msg2 ); /* *=========================================================================== * ipwps_proto_verify_msgauth *=========================================================================== * Description: * Verify the Message authenticator contained the last authenticator portion * of msg2 to match the value: HMAC_AuthKey(msg1 || msg2*), exluding the last * uthenticator portion of msg2 from the calculation * HMAC_AuthKey() is the keyed hash function HMAC-SHA-256 using the AuthKey * as a key with the result trauncated to 64 bit (8 bytes). * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context with appropriately * initialized members (e.g. keys, nonces, etc). * struct Ipwps_proto_data_st *msg1 - Pointer to 1st msg to use in the HMAC. * struct Ipwps_proto_data_st *msg2 - Pointer to 2nd msg to use in the HMAC. * msg2 length is that of the full message including the last * IPWPS_PROTO_ATTR_LEN_AUTHENTICATOR bytes of the msg that will be skipped * during HMAC_AuthKey() calculation but their content is very relevant when * this function is called, since they contain the authenticator value to * compare the HMAC result to. * Returns: * IPCOM_SUCCESS upon successfully verification of the msg authenticator * an error indication otherwise. */ IP_GLOBAL Ip_err ipwps_proto_verify_msgauth ( struct Ipwps_proto_ctx_st *proto_ctx, struct Ipwps_proto_data_st *msg1, struct Ipwps_proto_data_st *msg2 ); /* *=========================================================================== * ipwps_proto_calc_kwa *=========================================================================== * Description: * Calculate the Key Wrap Authenticatorfor msg: 1st 64 bits of HMAC_AuthKey(data*) * excluding the last kwa portion of data and storing the result in * the excluded section of data. * HMAC_AuthKey() is the keyed hash function HMAC-SHA-256 using the AuthKey * as a key with the result trauncated to 64 bit (8 bytes). * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context with appropriately * initialized authKey. * Ipwps_proto_container *data - container of data to use in the HMAC calculation. * length is that of the full message including the last * IPWPS_PROTO_LEN_KEYWRAPAUTH bytes of the data that will be skipped * during HMAC_AuthKey() calculation so their content is irrelevant when * this function is called, but they will contain the kwa value * when this function returns. * Returns: * IPCOM_SUCCESS upon successfully computing the authenticator value and copying * it to the end of data * an error indication otherwise. */ IP_GLOBAL Ip_err ipwps_proto_calc_kwa ( Ipwps_proto_ctx *proto_ctx, Ipwps_proto_container *data ); /* *=========================================================================== * ipwps_proto_verify_kwa *=========================================================================== * Description: * Verify the Key Wrap Authenticator contained the last kwa portion * of the data to match the value: HMAC_AuthKey(data*), exluding the last * kwa portion of data* from the calculation * HMAC_AuthKey() is the keyed hash function HMAC-SHA-256 using the authKey * as a key with the result trauncated to 64 bit (8 bytes). * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context with appropriately * Ipwps_proto_container *data - container of data to use in the HMAC. * length of data to use in the HMAC verification is that of the full * message including the last IPWPS_PROTO_LEN_KEYWRAPAUTH bytes of the * data that will be skipped during HMAC_AuthKey() calculation * but their content is very relevant when this function is called, * since they contain the kwa value to compare the HMAC result to. * Returns: * IPCOM_SUCCESS upon successfully verification of the msg authenticator * an error indication otherwise. */ IP_GLOBAL Ip_err ipwps_proto_verify_kwa ( Ipwps_proto_ctx *proto_ctx, Ipwps_proto_container *data ); /* *=========================================================================== * ipwps_proto_kwf_encrypt_data *=========================================================================== * Description: * Encrypt the WPS data using the Key Wrap Algorithm. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context with appropriately * initialized keyWrapKey. * Ipwps_proto_container *data_to_encrypt - data to encrypt. * Ipwps_proto_container *encrypted_data - container of the encrypted data. * length of the data is initialized to max buffer size when this function * is called and will contain the actual size of the encrypted data upon * successful completion of this fn. * Returns: * IPCOM_SUCCESS upon successfully encrypting the data, * an error indication otherwise. */ IP_GLOBAL Ip_err ipwps_proto_kwf_encrypt_data ( Ipwps_proto_ctx *proto_ctx, Ipwps_proto_container *data_to_encrypt, Ipwps_proto_container *encrypted_data ); /* *=========================================================================== * ipwps_proto_kwf_decrypt_data *=========================================================================== * Description: * Decrypt the WPS data using the Key Wrap Algorithm. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid protocol context with appropriately * initialized KeyWrapKey. * Ipwps_proto_container *data_to_decrypt - container of data to decrypt. * Ipwps_proto_container *decrypted_data - container which will contain the decrypted data. * container length should be initialized to max buffer size when this function * is called and will contain the actual size of the decrypted data * upon successful completion of this fn. * Returns: * IPCOM_SUCCESS upon successfully decrypting the data, * an error indication otherwise. */ IP_GLOBAL Ip_err ipwps_proto_kwf_decrypt_data ( Ipwps_proto_ctx *proto_ctx, Ipwps_proto_container *data_to_dencrypt, Ipwps_proto_container *decrypted_data ); /* *=========================================================================== * ipwps_proto_set_beacon_ie *=========================================================================== * Description: * Set the Beacon WPS IE attribute tlvs * Parameters: * Ipwps_ctx* ctx - A valid wps context * Ipwps_iedata_beacon *probe_req - A valid pointer to an allocated * Ipwps_iedata_beacon struct. * Ipwps_device_pwdid dev_pwdid - Device Password Id of the Selected * Registrar if ctx->public.ap_info.sel_reg_set is true. * Returns: * */ IP_GLOBAL Ip_err ipwps_proto_set_beacon_ie ( struct Ipwps_ctx_st* ctx, Ipwps_iedata_beacon *beacon, Ipwps_device_pwdid dev_pwdid ); /* *=========================================================================== * ipwps_proto_set_probe_req_ie *=========================================================================== * Description: * Set the Probe Request WPS IE attribute tlvs * Parameters: * Ipwps_ctx* ctx - A valid wps context * Ipwps_iedata_probe_req *probe_req - A valid pointer to an allocated * Ipwps_iedata_probe_req struct. * Ip_u16 request_type - A valid request type to set in the WPS IE * Ipwps_uuid_specifier which_uuid - Which UUID to set (UUID-E or UUID-R) * Returns: * */ IP_GLOBAL Ip_err ipwps_proto_set_probe_req_ie ( struct Ipwps_ctx_st* ctx, Ipwps_iedata_probe_req *probe_req, Ip_u16 request_type, Ipwps_uuid_specifier which_uuid ); /* *=========================================================================== * ipwps_proto_set_probe_resp_ie *=========================================================================== * Description: * Set the Probe Response WPS IE attribute tlvs * Parameters: * Ipwps_ctx* ctx - A valid wps context * Ipwps_iedata_probe_resp *probe_resp - A valid pointer to an allocated * Ipwps_iedata_probe_resp struct. * Ip_u16 response_type - A valid Response type to set in the WPS IE * Ipwps_device_pwdid dev_pwdid - Device Password Id of the Selected * Registrar if ctx->public.ap_info.sel_reg_set is true. * Returns: * */ IP_GLOBAL Ip_err ipwps_proto_set_probe_resp_ie ( struct Ipwps_ctx_st* ctx, Ipwps_iedata_probe_resp *probe_resp, Ip_u16 response_type, Ipwps_device_pwdid dev_pwdid ); /* *=========================================================================== * ipwps_proto_get_common_devinfo *=========================================================================== * Description: Retrieve the Peer's WPS Common Device Info from a message. * Parameters: * Ipwps_ctx* ctx - A valid Ready wps context. * Ipwps_protomsg_common_device_info *dev_info - Pointer to a Device Info attributes structure * Returns: * */ IP_GLOBAL Ip_err ipwps_proto_get_common_devinfo ( struct Ipwps_ctx_st* ctx, Ipwps_protomsg_common_device_info *dev_info ); /* *=========================================================================== * ipwps_proto_get_capability_info *=========================================================================== * Description: Retrieve the device Capability info from an M1 message * Parameters: * Ipwps_ctx* ctx - A valid wps context * Ipwps_protomsg_overlay *msg - A valid M1, M2 or M2D message * Ipwps_capability_info *cap_info - Pointer to Capability info structure * in which the retrieved values will be stored. * Returns: * */ IP_GLOBAL Ip_err ipwps_proto_get_capability_info ( struct Ipwps_ctx_st* ctx, Ipwps_protomsg_overlay *msg, Ipwps_capability_info *cap_info ); /* *=========================================================================== * ipwps_proto_sm_state_name *=========================================================================== * Description: Retrieve the state name of the current state for the provided * protocol context. * Parameters: * Ipwps_protocol_sm_state state - A valid IPWPS Protocol Handler state * Returns: * A pointer to the string containing the state name. */ IP_GLOBAL IP_CONST char *ipwps_proto_sm_state_name ( Ipwps_protocol_sm_state state ); /* *=========================================================================== * ipwps_proto_log_sm_state_info *=========================================================================== * Description: Log the state information for the provided protocol context. * Parameters: * Ipwps_proto_ctx *proto_ctx - A valid IPWPS Protocol Handler context * char *prefix - Prefix string to use in the logs * Returns: * None */ IP_GLOBAL void ipwps_proto_log_sm_state_info ( Ipwps_proto_ctx *proto_ctx, char *prefix ); /* *=========================================================================== * ipwps_protocol_decode_attrval_dev_pwdid *=========================================================================== * Description: * Translate a dev_pwd_id attribute value to the corresponding * Ipwps_device_pwdid enum * Parameters: * Ipwps_attribute_uint16 dev_pwd_id - dev_pwd_id attribute * Returns: * Ipwps_device_pwdid enum corresponding to the attribute value * or IPWPS_DEVPWDID_INVALID if the attribute is invalid. */ IP_GLOBAL Ipwps_device_pwdid ipwps_protocol_decode_attr_dev_pwdid ( Ipwps_attribute_uint16 dev_pwd_id ); #ifdef __cplusplus } #endif #endif /* **************************************************************************** * END OF FILE **************************************************************************** */