/* ****************************************************************************** * INTERPEAK INTERNAL API HEADER FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ip8021x_h.h,v $ $Revision: 1.27 $ * $Source: /home/interpeak/CVSRoot/ip8021x/src/ip8021x_h.h,v $ * $Author: krosenfe $ $Date: 2010-04-01 20:49:57 $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Roger Boden ****************************************************************************** */ #ifndef IP8021X_H_H #define IP8021X_H_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ #include "ip8021x_config.h" /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #include #include #include #include #ifdef IPMCRYPTO #include #include #else #include #include #endif #include "ip8021x.h" #include "ip8021x_wpa_ie.h" #include "ip8021x_state_machine.h" #include "ipwlan_wlan.h" #ifdef __cplusplus extern "C" { #endif /* **************************************************************************** * 4 DEFINES **************************************************************************** */ #define IP8021X_ETH_P_EAPOL 0x888e #define IP8021X_EAPOL_KEY_INFO_KEY_VER 1 #define IP8021X_EAPOL_KEY_INFO_KEY_TYPE 2 #define IP8021X_EAPOL_KEY_INFO_KEY_INDEX 3 #define IP8021X_EAPOL_KEY_INFO_INSTALL 4 #define IP8021X_EAPOL_KEY_INFO_KEY_ACK 5 #define IP8021X_EAPOL_KEY_INFO_KEY_MIC 6 #define IP8021X_EAPOL_KEY_INFO_SECURE 7 #define IP8021X_EAPOL_KEY_INFO_ERROR 8 #define IP8021X_EAPOL_KEY_INFO_REQUEST 9 #define IP8021X_EAPOL_KEY_INFO_ENCR_KEY 10 #define IP8021X_EAPOL_TYPE_PACKET 0 #define IP8021X_EAPOL_TYPE_START 1 #define IP8021X_EAPOL_TYPE_LOGOFF 2 #define IP8021X_EAPOL_TYPE_KEY 3 #define IP8021X_EAPOL_MODE_WIRED 1 #define IP8021X_EAPOL_MODE_WPA (1<<1) #define IP8021X_EAPOL_MODE_WPA2 (1<<2) #define IP8021X_EAPOL_MODE_WPA_PSK (1<<3) #define IP8021X_EAPOL_MODE_WPA2_PSK (1<<4) #define IP8021X_EAPOL_MODE_WPS (1<<5) #define IP8021X_PORT_STATUS_AUTHORIZED 100 #define IP8021X_PORT_STATUS_UNAUTHORIZED 101 /* These MUST match values defines in "dot1xCommonIoctls.h" */ #define IP8021X_PHY_PORT_EVENT_INVALID 0 #define IP8021X_PHY_PORT_EVENT_ASSOCIATION 1 #define IP8021X_PHY_PORT_EVENT_DISASSOCIATION 2 #define IP8021X_MIC_ERROR_EVENT_PAIRWISE 3 #define IP8021X_MIC_ERROR_EVENT_GROUPWISE 4 #define IP8021X_PHY_PORT_STATUS_UNKNOWN 0 #define IP8021X_PHY_PORT_STATUS_UP 1 #define IP8021X_PHY_PORT_STATUS_DOWN 2 #define IP8021X_STATE_STA_UNINITIALIZED 0 #define IP8021X_STATE_STA_WAITING_KEY_MSG1 1 #define IP8021X_STATE_STA_WAITING_KEY_MSG3 2 #define IP8021X_STATE_STA_WAITING_KEY_MSG5 3 #define IP8021X_STATE_STA_FINISHED 4 #define IP8021X_STATE_STA_EAPOL_START_SENT 5 #define IP8021X_STATE_STA_EAP_HANDSHAKE 6 #define IP8021X_HMAC_SHA1 1 #define IP8021X_HMAC_MD5 2 #define IP8021X_DESCRIPTOR_TYPE_WPA 254 #define IP8021X_DESCRIPTOR_TYPE_WPA2 2 #define IP8021X_FLAG_PORT_OPENED 0x00000001 #define IP8021X_FLAG_PMK_ESTABLISHED 0x00000002 #define IP8021X_FLAG_PTK_INSTALLED 0x00000004 #define IP8021X_FLAG_GTK_INSTALLED 0x00000008 #if 0 #define IP8021X_GET_KEY_INFO_BITS(ptr, index, startbit, bits) ((ptr[index]>> startbit) & (0xff >> (8-bits))); #define IP8021X_SET_KEY_INFO_BITS(ptr, index, startbit, bits, value) do { \ int mask; \ int i; \ ip_assert(index < 2); \ ip_assert(bits <= 3); \ ip_assert(startbit + bits <= 8); \ /* Clear bits to be set */ \ for(i=startbit; i-loopback[-port]" \ " or " IP8021X_SIMTEST_IFNAME "--[-]" #define IP8021X_SIMTEST_DEFAULT_PORT 31334 /* El3ET port, used if no custom port is specified */ #endif /* **************************************************************************** * 5 TYPES **************************************************************************** */ IP_GLOBAL void ip8021x_eapol_set_key_info(Ip_u8* key_info, int field_id, int value); IP_GLOBAL int ip8021x_eapol_get_key_info(Ip_u8* key_info, int field_id); struct Ip8021x_hmac_ctx_st { union { SHA_CTX sha; MD5_CTX md5; } hash_ctx; int hash_id; int key_len; Ip_u8 k_ipad[64]; Ip_u8 k_opad[64]; }; typedef struct Ip8021x_hmac_ctx_st Ip8021x_hmac_ctx; union ip8021x_temporal_key { Ip_u8 tkip[32]; Ip_u8 ccmp[16]; }; struct Ip8021x_ptk_keys_st { Ip_u8 key_conf_key[16]; Ip_u8 key_enc_key[16]; union ip8021x_temporal_key temp_key; }; typedef struct Ip8021x_ptk_keys_st Ip8021x_ptk_keys; /* Pairwise Transient Key */ union Ip8021x_ptk_key { Ip_u8 ptk[64]; Ip8021x_ptk_keys keys; }; struct Ip8021x_eapol_hdr_st { Ip_u8 version; Ip_u8 type; Ip_u16 len; }; typedef struct Ip8021x_eapol_hdr_st Ip8021x_eapol_hdr; typedef struct Ip8021x_eapol_key_msg_st { /* Generic EAPOL field */ Ip_u8 version; Ip_u8 type; Ip_u16 len; /* EAPOL key fields */ Ip_u8 descriptor_type; Ip_u8 key_info[2]; Ip_u8 key_len[2]; Ip_u8 replay_counter[8]; Ip_u8 key_nonce[32]; Ip_u8 key_iv[16]; Ip_u8 key_rsc[8]; Ip_u8 reserved[8]; Ip_u8 key_mic[16]; Ip_u8 key_data_len[2]; Ip_u8 key_data[1]; } Ip8021x_eapol_key_msg; #ifdef IP8021X_USE_STATS #define IP8021X_STATS(xctx, xvar) xctx->stats.xvar #define IP8021X_STAT_LINE(xline) xline #else #define IP8021X_STATS(xctx, xvar) IP_NOOP #define IP8021X_STAT_LINE(xline) IP_NOOP #endif /* Configuration entries for each supplicant instance */ typedef struct ip8021x_config_st { Ip_bool valid; /* set after the supplicant instance is created */ char if_name[IP8021X_IFNAMSIZ]; char encr_type[32]; char auth_type[32]; Ip_u8 psk[IP_IW_KEY_PMK_LEN+3]; /* enough to fit 63 char passphrase, or 32 octet hex key (0xaabb....) plus null terminating char */ char ssid[32+1]; } ip8021x_config; /* Supplicant Context (supp instance specific */ typedef struct Ip8021x_ctx_st { Ip_u32 init; /* Indicates a properly initialized instance (1st supp needs to have been created/configured) */ Ip_u32 instance; /* supplicant instance # corresponding to this context */ ip8021x_config *config; /* ptr to corresponding config entry */ char if_name[IP8021X_IFNAMSIZ]; Ip8021x_state_machine sm; Ip_u8 aa[6]; /* Authenticator MAC address */ Ip_u8 spa[6]; /* Supplicant MAC address */ Ipcom_mutex mutex; Ipcom_tmo tmo; /* IP8021x State Machine Timer onject */ Ipcom_tmo tkip_cm_tmo; /* TKIP CounterMeasures Timer object */ Ipcom_tmo eapol_msg1_tmo; /* Eapol Msg 1 Timer object */ Ipcom_tmo auth_req_tmo; /* Auth request Timer */ Ip_u32 tkip_mic_errors_in_last_minute; Ip_u64 rx_key_replay_counter; /* Last received key replay counter */ Ip_u64 tx_key_replay_counter; /* Last sent key replay counter (used in key request eapol msgs) */ Ip_u8 ANonce[32]; Ip_u8 SNonce[32]; Ip_u8 pmk[32]; /* Pair-wise master key */ Ip_u8 ptk[64]; /* Pair-wise temporal key */ Ip_u8 gtk[32]; /* Group-wise temporal key */ int gtk_len; int ptk_index; /* Key index of pairwise key */ int gtk_index; /* Key index of groupwise key */ int gtk_tx_flag; /* tx flag, used in WPA2 only */ Ip8021x_funcs* cb; Ip_fd sock; #ifdef IP8021X_USE_STATS Ip8021x_stats stats; #endif int encr_type; int multicast_encr_type; int auth_type; Ip_u16 rsn_cap; Ip8021x_wpa_ie wpa_ie; Ip_u8 last_ie[64]; Ip_u16 last_ie_size; int eapol_key_descr_type; Ip_u32 state; /* TODO: can this member be removed? */ Ip_u32 port_status; Ip_u32 phy_layer_status; /* Physical layer status as reported by driver */ Ip_u32 mode; Ip_u32 flags; Ip_u32 enforce_rfc4017; #ifdef IP8021X_SIM_SUPPORT Ip_bool simtest; /* true if simtest enabled */ char simif[IP_IFNAMSIZ]; struct Ip_in_addr simaddr; /* Ipv4 address */ Ip_u16 simport; Ip_fd simsock; #endif #ifdef IPEAP struct Ipeap_ctx_st *eap_ctx; #ifdef IP8021X_AUTH_SUPPORT char peer_identity[IPEAP_IDENTITY_MAX_LEN]; Ip_u8 req_retry_count; #endif #endif #ifdef IPWPS Ip_bool wps_enabled; char wsc_eap_id[128]; #endif void* extra; #ifdef IP8021X_AUTH_SUPPORT void* authAssocCallback; /* callback for external authenticator */ void* authAssocCallbackParm; void* authPacketCallback; void* authPacketCallbackParm; #endif } Ip8021x_ctx; typedef enum { IP8021X_UITYPE_EAP_CHALLENGE_RESP = 0 } Ip8021x_user_input_type; /* **************************************************************************** * 6 DATA **************************************************************************** */ IP_EXTERN Ip_u8 ip8021x_pae_grp_addr[6]; /* **************************************************************************** * 7 FUNCTIONS **************************************************************************** */ IP_GLOBAL void ip8021x_generate_ptk(Ip_u8* pmk, int pmk_len, Ip_u8* auth_addr, int auth_addr_len, Ip_u8* sta_addr, int sta_addr_len, Ip_u8* auth_nonce, int auth_nonce_len, Ip_u8* sta_nonce, int sta_nonce_len, Ip_u8* ptk, int req_bits); IP_GLOBAL void ip8021x_hmac_init(Ip8021x_hmac_ctx* ctx, Ip_u8* key, int key_len, int hash_id); IP_GLOBAL void ip8021x_hmac_update(Ip8021x_hmac_ctx* ctx, Ip_u8* data, int data_len); IP_GLOBAL void ip8021x_hmac_final(Ip8021x_hmac_ctx* ctx, Ip_u8* digest, int digest_len); IP_GLOBAL void ip8021x_hmac(Ip_u8* key, int key_len, Ip_u8* data, int data_len, Ip_u8* digest, int digest_len, int hash_id); IP_GLOBAL void ip8021x_rc4_skip(Ip_u8 *key, Ip_size_t keylen, Ip_size_t skip, Ip_u8 *data, Ip_size_t data_len); IP_GLOBAL void ip8021x_rc4(Ip_u8 *key, Ip_size_t key_len, Ip_u8 *buf, Ip_size_t len); IP_GLOBAL Ip_err ip8021x_aes_key_unwrap(const Ip_u8 *K, int n, const Ip_u8 *C, Ip_u8 *P); IP_PUBLIC Ip_err ip8021x_wpa_psk_set_pmk(Ip8021x_ctx* ctx, const char* ascii_psk); IP_GLOBAL Ip_err ip8021x_F(const char *password, unsigned char *ssid, int ssidlength, int iterations, int count, unsigned char *output); IP_GLOBAL Ip_err ip8021x_wpa_psk_pw_hash(const char *password, unsigned char *ssid, int ssidlength, unsigned char *output); IP_GLOBAL Ip_err ip8021x_prf(Ip_u8* pmk, int pmk_len, const char* label, Ip_u8* data, int data_len, int req_bits, Ip_u8* out_buf); IP_GLOBAL Ip_err ip8021x_send_eapol_msg(Ip8021x_ctx* ctx, Ip8021x_pkt* pkt, Ip_u8 version, Ip_u8 pkt_type); IP_GLOBAL Ip_err ip8021x_send_msg(Ip8021x_ctx* ctx, Ip8021x_pkt* pkt); IP_GLOBAL Ip_err ip8021x_send_key_msg2(Ip8021x_ctx* ctx, Ip8021x_eapol_key_msg* key_msg1); IP_GLOBAL Ip_err ip8021x_send_key_msg4(Ip8021x_ctx* ctx, Ip8021x_eapol_key_msg* key_msg3); IP_GLOBAL Ip_err ip8021x_send_key_msg6(Ip8021x_ctx* ctx, Ip8021x_eapol_key_msg* key_msg5); IP_GLOBAL Ip_err ip8021x_send_eapol_key_msg(Ip8021x_ctx* ctx, Ip8021x_pkt* pkt); IP_GLOBAL void ip8021x_calculate_mic(Ip8021x_ctx* ctx, Ip8021x_eapol_key_msg* msg, Ip_u8* mic); IP_GLOBAL const char* ip8021x_eapol_key_get_state_str(Ip_u32 state); IP_GLOBAL const char* ip8021x_eapol_get_msg_type_str(Ip_u8 pkt_type); IP_GLOBAL const char* ip8021x_encr_type_str(int encr_type); IP_GLOBAL const char* ip8021x_auth_type_str(int auth_type); IP_GLOBAL const char* ip8021x_mode_str(int mode); IP_GLOBAL const char* ip8021x_eapol_key_descr_type_str(int eapol_key_descr_type); IP_GLOBAL const char* ip8021x_flags_str(Ip_u32 eapol_key_descr_type); IP_GLOBAL Ip_err ip8021x_tx_eapol_start(Ip8021x_ctx* ctx); IP_GLOBAL Ip_err ip8021x_tx_eapol_logoff(Ip8021x_ctx* ctx); IP_GLOBAL Ip8021x_pkt* ip8021x_pkt_new(int len, int offset, Ip_u8 version, Ip_u8 type); IP_GLOBAL void ip8021x_pkt_free(Ip8021x_pkt*); IP_GLOBAL Ip_err ip8021x_eapol_msg_input(Ip8021x_ctx* ctx, Ip8021x_pkt* in_pkt); IP_GLOBAL Ip_err ip8021x_eapol_key_msg_input(Ip8021x_ctx* ctx, Ip8021x_pkt* pkt); #ifdef IPEAP IP_GLOBAL void ip8021x_pkt_map_to_eap(Ip8021x_pkt* pkt, Ipeap_pkt* eap_pkt); #endif #ifdef __cplusplus } #endif #endif /* **************************************************************************** * END OF FILE **************************************************************************** */