⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wps_enrollee.h

📁 WiFi Protected Setup (WPS) 又叫Simple config。 是无线局域网领域推出的新协议
💻 H
字号:
/*
 *  WPS_ENROLLEE.H : WPS ENROLLEE Porcess Module
 * 
 *  ver       date      author     comment
 *  0.0.1     06/08/27  Gao Hua    First
 *  0.0.2     07/09/05  D.W.Yan    Refactor code
 */

#ifndef _WPS_ENROLLEE_H
#define _WPS_ENROLLEE_H

#include "wps_types.h"
#include "wps_lib.h"
#include "wps_data_element.h"
#include "wps_crypto.h"
#include "wps_osfunc.h"


#define ENROLLEE_DEBUG			1
#define ENROLLEE_CHECK_EAP_IDENTIFIER	0
#define ENROLLEE_CHECK_M2D			0
#define ENROLLEE_CHECK_NACK		0


typedef enum _enrollee_state
{
	E_STATE_A0,
	E_STATE_A,
	E_STATE_B,
	E_STATE_C,
	E_STATE_D,
	E_STATE_E,
	E_STATE_F,
	E_STATE_G,
	E_STATE_H,
	E_STATE_I
} E_STATE;

/*
 * Once the Enrollee sends an M3 message, both the Registrar and the Enrollee 
 * must proceed in lock-step fashion until either a failure or until success 
 * occurs (indicated by the Done response message).
 */
typedef enum _enrollee_lock_step
{
	E_LOCK_STEP_NO_LOCKED,
	E_LOCK_STEP_M3_SENT,
	E_LOCK_STEP_M4_RECEIVED,
	E_LOCK_STEP_M5_SENT,
	E_LOCK_STEP_M6_RECEIVED,
	E_LOCK_STEP_M7_SENT,
	E_LOCK_STEP_M8_RECEIVED
} E_LOCK_STEP;

typedef struct _enrollee_credential
{
		WPS_u8 Cre_NetworkIndex;
		WPS_u8 Cre_SSID[E_SSID_MaxLength];
		WPS_u16 Cre_SSID_Length;
		WPS_u16 Cre_AuthenticationType;
		WPS_u16 Cre_EncryptionType;
		WPS_u8 Cre_NetworkKeyIndex;
		WPS_u8 Cre_NetworkKey[E_NetworkKey_MaxLength];
		WPS_u16 Cre_NetworkKey_Length;
		WPS_u8 Cre_MACAddress[E_MACAddress_Length];
} ENROLLEE_CREDENTIAL;

struct enrollee
{
		WPS_u8 initialized;
		WPS_u8 eap_id;
		/* used to correlate Request and Response messages */

		WPS_u8 done;
		WPS_u8 success;
		WPS_u8 MyVersion;
		E_STATE e_state;
		E_LOCK_STEP e_step;
		WPS_DH_P DH_e;

		/* Timeout and re-transmission */
		WPS_TIMER_DESC resend_timer;
		WPS_TIMER_DESC permessage_timer;
		WPS_TIMER_DESC overall_timer;
		WPS_u8 *LastPacket;
		/* Re-send the last packet when timeouts */
		WPS_s32 LastPacketLength;
		WPS_u8 *LastMessage;
		/* points to the same block as LastPacket */
		WPS_s32 LastMessageLength;

		WPS_u8 EnrolleeMAC[E_MACAddress_Length];
		WPS_u16 AuthenticationTypeFlags_E;
		WPS_u16 EncryptionTypeFlags_E;
		WPS_u8 ConnectionTypeFlags_E;
		WPS_u16 ConfigMethods_E;
		WPS_u8 SimpleConfigState_E;
		WPS_u8 Manufacturer_E[E_Manufacturer_MaxLength];
		WPS_u8 ModelName_E[E_ModelName_MaxLength];
		WPS_u8 ModelNumber_E[E_ModelNumber_MaxLength];
		WPS_u8 SerialNumber_E[E_SerialNumber_MaxLength];
		struct primary_device_type primary_device_type_E; /* N/W bytes order */
		WPS_u8 DeviceName_E[E_DeviceName_MaxLength];
		WPS_u8 RFBands_E;
		WPS_u16 AssociationState_E;
		WPS_u16 DevicePasswordID_E;
		WPS_u16 ConfigurationError_E;
		WPS_u32 OSVersion_E;

		WPS_u16 AuthenticationTypeFlags_R;
		WPS_u16 EncryptionTypeFlags_R;
		WPS_u8 ConnectionTypeFlags_R;
		WPS_u16 ConfigMethods_R;
		WPS_u8 Manufacturer_R[E_Manufacturer_MaxLength];
		WPS_u8 ModelName_R[E_ModelName_MaxLength];
		WPS_u8 ModelNumber_R[E_ModelNumber_MaxLength];
		WPS_u8 SerialNumber_R[E_SerialNumber_MaxLength];
		struct primary_device_type primary_device_type_R; /* N/W bytes order */
		WPS_u8 DeviceName_R[E_DeviceName_MaxLength];
		WPS_u8 RFBands_R;
		WPS_u16 AssociationState_R;
		WPS_u16 DevicePasswordID_R;
		WPS_u16 ConfigurationError_R;
		WPS_u32 OSVersion_R;

		WPS_u8 UUID_E[E_UUID_E_Length];
		WPS_u8 UUID_R[E_UUID_R_Length];

		WPS_u8 EnrolleeNonce[E_EnrolleeNonce_Length];
		/* 128-bit random number (nonce) specified by the Enrollee. */
		WPS_u8 RegistrarNonce[E_RegistrarNonce_Length];
		/* 128-bit random number (nonce) specified by the Registrar. */

		/*
		 * PK_E and PK_R are Diffie-Hellman public keys of the Enrollee and
		 * Registrar, respectively. If support for other cipher suites (such
		 * as elliptic curve) is added in the future, a different protocol
		 * Version number will be used.
		 */
		WPS_u8 PK_E[E_PublicKey_Length];
		WPS_u8 PK_R[E_PublicKey_Length];

		/* Enrollee's DevicePassword used in the Registration Protocol */
		WPS_u8 DevicePassword[256];
		WPS_s32 DevicePassword_Length;

		/*
		 * PSK1 = first 128 bits of HMAC<AuthKey>(1st half of DevicePassword)
		 * PSK2 = first 128 bits of HMAC<AuthKey>(2nd half of DevicePassword)
		 */
		WPS_u8 PSK1[16];
		WPS_u8 PSK2[16];

		/*
		 * ESNonce1, ESNonce2 are secret 128-bit nonces that, together with
		 * E-Hash1 and E-Hash2, can be used by the Registrar to confirm the 
		 * Enrollee's knowledge of the first and second half of the Enrollee'
		 * device password, respectively.
		 */
		WPS_u8 ESNonce1[E_ESNonce1_Length];
		WPS_u8 ESNonce2[E_ESNonce2_Length];

		/*
		 * EHash1, EHash2 are pre-commitments made by the Enrollee to prove
		 *  knowledge of the
		 * two halves of its own device password.	
		 */
		WPS_u8 EHash1[E_EHash1_Length];
		WPS_u8 EHash2[E_EHash2_Length];

		/*
		 * RSNonce1, RSNonce2 are secret 128-bit nonces that, together with
		 * R-Hash1 and R-Hash2, can be used by the Enrollee to confirm the
		 * Registrar's knowledge of the first and second half of the Enrollee'
		 * device password, respectively.
		 */
		WPS_u8 RSNonce1[E_RSNonce1_Length];
		WPS_u8 RSNonce2[E_RSNonce2_Length];

		/*
		 * RHash1, RHash2 are pre-commitments made by the Registrar to prove
		 * knowledge of the two halves of the Enrollee’s device password.
		 */
		WPS_u8 RHash1[E_RHash1_Length];
		WPS_u8 RHash2[E_RHash2_Length];

		WPS_u8 KDK[32];
		WPS_u8 AuthKey[32];
		/* (256 bits) used to authenticate the Registration Protocol messages */
		WPS_u8 KeyWrapKey[16];
		/* (128 bits) used to encrypt secret nonces and ConfigData */
		WPS_u8 EMSK[32];
		/* (256 bits) an Extended Master Session Key that is used to derive
		 * additional keys used by Wi-Fi Simple Config and possibly other
		 * applications */

		/* WLAN Credential */
		ENROLLEE_CREDENTIAL credential;
		WPS_u8 credential_saved;

		WPS_u8 Current_SSID[E_SSID_MaxLength];
		WPS_u16 Current_SSID_Length;
	};


void enrollee_create_instance(struct enrollee **pp_enrol);
void enrollee_destroy_instance(struct enrollee **pp_enrol);
void enrollee_init(struct enrollee *enrollee, WPS_MODE mode, WPS_char *DevicePassword);
void enrollee_uninit(struct enrollee *enrollee);
WPS_s32 enrollee_recv(struct enrollee *enrollee, WPS_u8 *bp, WPS_u16 pkt_len);
WPS_s32 enrollee_overall_timeout(struct enrollee *enrollee);
WPS_s32 enrollee_permessage_timeout(struct enrollee *enrollee);
WPS_s32 enrollee_resend_last_packet(struct enrollee *enrollee);
WPS_u8 enrollee_is_regprotocol_done(struct enrollee *enrollee);
WPS_u8 enrollee_is_regprotocol_successful(struct enrollee *enrollee);

#endif  //_WPS_ENROLLEE_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -