static void EasyConfigSetSecurity(void) { DRV_WIFI_SECURITY_CONTEXT securityContext; switch ((uint8_t)CFGCXT.security) { case DRV_WIFI_SECURITY_OPEN: /* No security */ DRV_WIFI_SecurityOpenSet(); break; case DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: if (CFGCXT.key) { securityContext.wpaContext.wpaSecurityType = DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE; securityContext.wpaContext.keyInfo.keyLength = strlen((char *)CFGCXT.key); memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, securityContext.wpaContext.keyInfo.keyLength); DRV_WIFI_SecurityWpaSet(&securityContext.wpaContext); } break; case DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY: if (CFGCXT.key) { securityContext.wpaContext.wpaSecurityType = DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY; securityContext.wpaContext.keyInfo.keyLength = 32; memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, 32); DRV_WIFI_SecurityWpaSet(&securityContext.wpaContext); } break; case DRV_WIFI_SECURITY_WEP_40: if (CFGCXT.key) { securityContext.wepContext.wepSecurityType = DRV_WIFI_SECURITY_WEP_40; securityContext.wepContext.wepKeyLength = DRV_WIFI_WEP40_KEY_LENGTH; memset(CFGCXT.key, 0x00, DRV_WIFI_WEP40_KEY_LENGTH); memset(securityContext.wepContext.wepKey, 0x00, DRV_WIFI_WEP40_KEY_LENGTH); securityContext.wepContext.wepKeyType = DRV_WIFI_DEFAULT_WEP_KEY_TYPE;; DRV_WIFI_SecurityWepSet(&securityContext.wepContext); } break; case DRV_WIFI_SECURITY_WEP_104: if (CFGCXT.key) { securityContext.wepContext.wepSecurityType = DRV_WIFI_SECURITY_WEP_104; securityContext.wepContext.wepKeyLength = DRV_WIFI_WEP104_KEY_LENGTH; memset(CFGCXT.key, 0x00, DRV_WIFI_WEP104_KEY_LENGTH); memset(securityContext.wepContext.wepKey, 0x00, DRV_WIFI_WEP104_KEY_LENGTH); securityContext.wepContext.wepKeyType = DRV_WIFI_DEFAULT_WEP_KEY_TYPE;; DRV_WIFI_SecurityWepSet(&securityContext.wepContext); } break; } // end switch }
static uint8_t SetWEPKey(const char *password) { int keyLength = strlen(password); DRV_WIFI_WEP_CONTEXT context; if (keyLength == WEP104_KEY_LENGTH) { context.wepSecurityType = DRV_WIFI_SECURITY_WEP_104; context.wepKeyLength = 13; } else { context.wepSecurityType = DRV_WIFI_SECURITY_WEP_40; context.wepKeyLength = 5; } int wepKeyIndex = 0; int keyCharIndex = 0; for (keyCharIndex = 0; keyCharIndex < keyLength; keyCharIndex += 2, wepKeyIndex++) { uint8_t byteValue = ((GetHexValue(password[keyCharIndex]) << 4) + GetHexValue(password[keyCharIndex + 1])); context.wepKey[wepKeyIndex] = byteValue; // it contains 4 keys make all the same context.wepKey[wepKeyIndex + context.wepKeyLength] = byteValue; context.wepKey[wepKeyIndex + (context.wepKeyLength * 2)] = byteValue; context.wepKey[wepKeyIndex + (context.wepKeyLength * 3)] = byteValue; } context.wepKeyType = DRV_WIFI_SECURITY_WEP_OPENKEY; DRV_WIFI_SecurityWepSet(&context); return context.wepSecurityType; }
static void SetWepSecurity(void) { DRV_WIFI_WEP_CONTEXT wepContext; wepContext.wepSecurityType = p_wifi_ConfigData->SecurityMode; wepContext.wepKeyLength = p_wifi_ConfigData->SecurityKeyLength; memcpy(wepContext.wepKey, p_wifi_ConfigData->SecurityKey, wepContext.wepKeyLength); wepContext.wepKeyType = DRV_WIFI_DEFAULT_WEP_KEY_TYPE; DRV_WIFI_SecurityWepSet(&wepContext); }
static int WFEasyConfigProcess(TCPIP_NET_IF* pNetIf) { #if 0 // should not be needed uint8_t ConnectionState; #endif DRV_WIFI_SECURITY_CONTEXT securityContext; #if defined (EZ_CONFIG_STALL) if (CFGCXT.cfg_state == cfg_stopped) { /* State machine just started get current time stamp */ CFGCXT.cfg_state = cfg_stalled; CFGCXT.timeStart = SYS_TICK_Get(); return false; } /* Wait for stall time to expire */ if (CFGCXT.cfg_state == cfg_stalled) { SYS_TICK time = SYS_TICK_Get(); if ((time - CFGCXT.timeStart) < (WF_EASY_CONFIG_DELAY_TIME * SYS_TICK_TicksPerSecondGet())) { return false; } } #endif //EZ_CONFIG_STALL #if 0 // should not be needed /* We will re-use the current profile */ DRV_WIFI_ConnectionStateGet(&ConnectionState); #endif /* Need to disconnect */ DRV_WIFI_Disconnect(); /* Set SSID... */ if (CFGCXT.ssid) { DRV_WIFI_SsidSet(CFGCXT.ssid, strlen((char*)CFGCXT.ssid)); } /* Now deal with security... */ switch ((uint8_t)CFGCXT.security) { case DRV_WIFI_SECURITY_OPEN: /* No security */ DRV_WIFI_SecurityOpenSet(); break; case DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: if (CFGCXT.key) { securityContext.wpaContext.wpaSecurityType = DRV_WIFI_SECURITY_WPA_AUTO_WITH_PASS_PHRASE; securityContext.wpaContext.keyInfo.keyLength = strlen((char *)CFGCXT.key); memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, securityContext.wpaContext.keyInfo.keyLength); DRV_WIFI_SecurityWpaSet(&securityContext.wpaContext); } break; case DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY: if (CFGCXT.key) { securityContext.wpaContext.wpaSecurityType = DRV_WIFI_SECURITY_WPA_AUTO_WITH_KEY; securityContext.wpaContext.keyInfo.keyLength = 32; memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, 32); DRV_WIFI_SecurityWpaSet(&securityContext.wpaContext); } break; case DRV_WIFI_SECURITY_WEP_40: if (CFGCXT.key) { securityContext.wepContext.wepSecurityType = DRV_WIFI_SECURITY_WEP_40; securityContext.wepContext.wepKeyLength = DRV_WIFI_WEP40_KEY_LENGTH; memset(CFGCXT.key, 0x00, DRV_WIFI_WEP40_KEY_LENGTH); memset(securityContext.wepContext.wepKey, 0x00, DRV_WIFI_WEP40_KEY_LENGTH); securityContext.wepContext.wepKeyType = DRV_WIFI_DEFAULT_WEP_KEY_TYPE; DRV_WIFI_SecurityWepSet(&securityContext.wepContext); } break; case DRV_WIFI_SECURITY_WEP_104: if (CFGCXT.key) { securityContext.wepContext.wepSecurityType = DRV_WIFI_SECURITY_WEP_104; securityContext.wepContext.wepKeyLength = DRV_WIFI_WEP104_KEY_LENGTH; memset(CFGCXT.key, 0x00, DRV_WIFI_WEP104_KEY_LENGTH); memset(securityContext.wepContext.wepKey, 0x00, DRV_WIFI_WEP104_KEY_LENGTH); securityContext.wepContext.wepKeyType = DRV_WIFI_DEFAULT_WEP_KEY_TYPE; DRV_WIFI_SecurityWepSet(&securityContext.wepContext); } break; } #if defined (EZ_CONFIG_STORE) && defined(TCPIP_STACK_USE_STORAGE) #if 0 TCPIP_STORAGE_HANDLE hS; hS = TCPIPStorageOpen(0, 1); TCPIPStorageSaveIfConfig(hS, "MRF24W", true); TCPIPStorageClose(hS); #else DRV_WIFI_ConfigDataSave(); #endif #endif // defined (EZ_CONFIG_STORE) /* Set wlan mode */ DRV_WIFI_NetworkTypeSet(CFGCXT.type); #if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE) DRV_WIFI_ReconnectModeSet(0, // report-only when connection lost (no reconnect) DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT, // report-only when deauth received (no reconnect) 40, // set beacon timeout to 40 beacon periods DRV_WIFI_DO_NOT_ATTEMPT_TO_RECONNECT); // report only when beacon timeout occurs #endif //TCPIP_NET_IF* p_config= (TCPIP_NET_IF*)GetNetworkConfig(); if (p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_INFRASTRUCTURE) { DRV_WIFI_ReconnectModeSet(DRV_WIFI_RETRY_FOREVER, // retry forever to connect to WiFi network DRV_WIFI_ATTEMPT_TO_RECONNECT, // reconnect on deauth from AP 40, // beacon timeout is 40 beacon periods DRV_WIFI_ATTEMPT_TO_RECONNECT); // reconnect on beacon timeout } #if WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP // SoftAP: To allow redirection, need to hibernate before changing network type. Module // FW has SoftAP flag and therefore hibernate mode is needed to clear this // indication and allow proper network change. This should work for non-SoftAP, // but these have not been tested yet. #if 0 WF_hibernate.state = DRV_WIFI_HB_ENTER_SLEEP; WF_hibernate.wakeup_notice = false; //WFConsolePrintRomStr("SoftAP redirection: Put Wi-Fi module into hibernate mode.", true); DelayMs(200); WF_hibernate.wakeup_notice = true; //WFConsolePrintRomStr("Wakeup Wi-Fi module.", true); #else //extern bool SoftAP_Redirection_Enable; //SoftAP_Redirection_Enable = true; int ret_init; WF_InitForSoftApReDirection_enable(); do { ret_init = WF_InitForSoftApReDirection(); }while(ret_init == TCPIP_MAC_RES_PENDING); #endif #else /* Kick off connection now... */ DRV_WIFI_Connect(); #endif /* Change state and return true to show we are done! */ CFGCXT.cfg_state = cfg_stopped; return true; }