static int WFEasyConfigProcess(void) { UINT8 ConnectionProfileID; UINT8 ConnectionState; #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 = TickGet(); return 0; } /* Wait for stall time to expire */ if (CFGCXT.cfg_state == cfg_stalled) { UINT32 time = TickGet(); if ((time - CFGCXT.timeStart) < WF_STALL_TIME_MS) return 0; } #endif //EZ_CONFIG_STALL /* We will re-use the current profile */ WF_CMGetConnectionState(&ConnectionState, &ConnectionProfileID); /* Need to disconnect */ WF_CMDisconnect(); /* Delete profile */ WF_CPDelete(ConnectionProfileID); /* Create and prepare new profile */ WF_CPCreate(&ConnectionProfileID); /* Now set the various connection profile parameters */ /* Set SSID... */ if (CFGCXT.ssid) #if defined(__18CXX) WF_CPSetSsid(ConnectionProfileID, (ROM char *)CFGCXT.ssid, strlen(CFGCXT.ssid)); #else WF_CPSetSsid(ConnectionProfileID, CFGCXT.ssid, strlen((char*)CFGCXT.ssid)); #endif /* Now deal with security... */ switch ((BYTE)CFGCXT.security) { case WF_SECURITY_OPEN: /* No security */ WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_OPEN, 0, 0, 0); break; case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: if (CFGCXT.key) { WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE, 0, CFGCXT.key, strlen((char *)CFGCXT.key)); } break; case WF_SECURITY_WPA_AUTO_WITH_KEY: if (CFGCXT.key) { WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_KEY, 0, CFGCXT.key, 32); } break; case WF_SECURITY_WEP_40: { BYTE keys[20]; int i; if (CFGCXT.key) { /* Clear key */ for (i = 0; i < 20; i++) keys[i] = 0; memcpy(keys, CFGCXT.key, 20); WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_40, CFGCXT.defaultWepKey, keys, 20); } } break; case WF_SECURITY_WEP_104: { BYTE keys[52]; int i; if (CFGCXT.key) { /* Clear key */ for (i = 0; i < 52; i++) keys[i] = 0; memcpy(keys, CFGCXT.key, 52); WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_104, CFGCXT.defaultWepKey, keys, 52); } } break; } #if defined (EZ_CONFIG_STORE) SaveWifiConfig(); #endif /* Set wlan mode */ WF_CPSetNetworkType(ConnectionProfileID, CFGCXT.type); /* Kick off connection now... */ WF_CMConnect(ConnectionProfileID); /* Change state and return TRUE to show we are done! */ CFGCXT.cfg_state = cfg_stopped; return 1; }
/******************************************************************************* Function: BOOL iwconfigSetCb(void) Summary: Set the iwconfigCb structure Description: Set the iwconfigCb structure Parameters: None. Returns: TRUE or FALSE Remarks: None. *****************************************************************************/ BOOL iwconfigSetCb(void) { UINT8 cpId; if ( !iwconfigCbInitialized ) // first time call of iwconfigSetCb { memset(&iwconfigCb, 0, sizeof(iwconfigCb)); iwconfigCbInitialized = TRUE; } #if defined(WF_USE_POWER_SAVE_FUNCTIONS) WF_GetPowerSaveState(&iwconfigCb.powerSaveState); #endif if (iwconfigCb.powerSaveState == WF_PS_HIBERNATE) { WFConsolePrintRomStr("WF device hibernated", TRUE); return FALSE; } WF_CMGetConnectionState(&iwconfigCb.connState, &cpId); if ( iwconfigCb.cpId == WF_CURRENT_CPID_NONE ) { if ( cpId == WF_CURRENT_CPID_NONE ) { iwconfigCb.cpId = 1; // console demo only supports 1 CPID; don't create a new one here } else if ( cpId == WF_CURRENT_CPID_LIST ) { WFConsolePrintRomStr("Connection profile list not supported", TRUE); return FALSE; } else { iwconfigCb.cpId = cpId; // use the application-created profile } } else // WF_MIN_NUM_CPID <= iwconfigCb.cpId && iwconfigCb.cpId <= WF_MAX_NUM_CPID { if ( cpId == WF_CURRENT_CPID_NONE ) { // continue to use iwconfigCb.cpId } else if ( cpId == WF_CURRENT_CPID_LIST ) { WFConsolePrintRomStr("Conection profile list not supported", TRUE); WF_CPDelete(iwconfigCb.cpId); iwconfigCb.cpId = WF_CURRENT_CPID_NONE; return FALSE; } else if ( cpId != iwconfigCb.cpId ) { WF_CPDelete(iwconfigCb.cpId); iwconfigCb.cpId = cpId; // use the application-created profile } else // cpId == iwconfigCb.cpId { // contine to use iwconfigCb.cpId } } if ((iwconfigCb.connState == WF_CSTATE_NOT_CONNECTED) || (iwconfigCb.connState == WF_CSTATE_CONNECTION_PERMANENTLY_LOST)) { iwconfigCb.isIdle = TRUE; } else { iwconfigCb.isIdle = FALSE; } return TRUE; }
static int WFEasyConfigProcess(void) { uint8_t ConnectionProfileID; uint8_t ConnectionState; #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 = TickGet(); return 0; } /* Wait for stall time to expire */ if (CFGCXT.cfg_state == cfg_stalled) { uint32_t time = TickGet(); if ((time - CFGCXT.timeStart) < WF_STALL_TIME_MS) return 0; } #endif //EZ_CONFIG_STALL /* We will re-use the current profile */ WF_CMGetConnectionState(&ConnectionState, &ConnectionProfileID); /* Need to disconnect */ WF_CMDisconnect(); /* Delete profile */ WF_CPDelete(ConnectionProfileID); /* Create and prepare new profile */ WF_CPCreate(&ConnectionProfileID); AppConfig.passPhraseToKeyFlag = 0; /* Now set the various connection profile parameters */ /* Set SSID... */ if (CFGCXT.ssid) #if defined(__XC8) WF_CPSetSsid(ConnectionProfileID, //(ROM char *)CFGCXT.ssid, Note (VMH): fixed compile warning - not sure why this is necessary. CFGCXT.ssid, strlen(CFGCXT.ssid)); #else WF_CPSetSsid(ConnectionProfileID, CFGCXT.ssid, strlen((char*)CFGCXT.ssid)); #endif #if defined(DERIVE_KEY_FROM_PASSPHRASE_IN_HOST) if ((uint8_t)CFGCXT.security == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE) { WF_ConvPassphrase2Key(strlen((char *)CFGCXT.key), CFGCXT.key, strlen((char*)CFGCXT.ssid), CFGCXT.ssid); CFGCXT.security--; #if MY_DEFAULT_NETWORK_TYPE == WF_ADHOC if (AppConfig.SecurityMode == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE) { WF_ConvPassphrase2Key(AppConfig.SecurityKeyLength, AppConfig.SecurityKey, AppConfig.SsidLength, AppConfig.MySSID); AppConfig.SecurityMode--; AppConfig.SecurityKeyLength = 32; AppConfig.passPhraseToKeyFlag = 1; } #endif /* MY_DEFAULT_NETWORK_TYPE == WF_ADHOC */ } #endif /* defined(DERIVE_KEY_FROM_PASSPHRASE_IN_HOST) */ /* Now deal with security... */ switch ((uint8_t)CFGCXT.security) { case WF_SECURITY_OPEN: /* No security */ WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_OPEN, 0, 0, 0); break; case WF_SECURITY_WEP_40: { uint8_t keys[20]; int i; if (CFGCXT.key) { /* Clear key */ for (i = 0; i < 20; i++) keys[i] = 0; memcpy(keys, (void*)CFGCXT.key, 20); WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_40, CFGCXT.defaultWepKey, keys, 20); } } break; case WF_SECURITY_WEP_104: { uint8_t keys[52]; int i; if (CFGCXT.key) { /* Clear key */ for (i = 0; i < 52; i++) keys[i] = 0; memcpy(keys, (void*)CFGCXT.key, 52); WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_104, CFGCXT.defaultWepKey, keys, 52); } } break; case WF_SECURITY_WPA_AUTO_WITH_KEY: if (CFGCXT.key) { WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_KEY, 0, CFGCXT.key, 32); } break; case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: if (CFGCXT.key) { WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE, 0, CFGCXT.key, strlen((char *)CFGCXT.key)); } break; } #if defined (EZ_CONFIG_STORE) SaveAppConfig(&AppConfig); #endif /* Set wlan mode */ WF_CPSetNetworkType(ConnectionProfileID, CFGCXT.type); if (AppConfig.networkType == WF_INFRASTRUCTURE) WF_CASetListRetryCount(MY_DEFAULT_LIST_RETRY_COUNT_INFRASTRUCTURE); #if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE) WF_DisableModuleConnectionManager(); #endif #if MY_DEFAULT_NETWORK_TYPE == WF_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. // Operation of hibernate mode // Turned off LDO of the MRF24W module, which is turning off the power completely. Has same effect of resetting the module. // // FW flow of hibernate mode: // Ensure WF_USE_POWER_SAVE_FUNCTIONS is enabled. // In main() loop, StackTask() -> MACProcess() will be called. It will invoke CheckHibernate(), which executes/handles // hibernate mode based on WF_hibernate.state and WF_hibernate.wakeup_notice. WF_hibernate.state = WF_HB_ENTER_SLEEP; WF_hibernate.wakeup_notice = false; //WFConsolePrintRomStr("SoftAP redirection: Put Wi-Fi module into hibernate mode.", true); DelayMs(50); // SOFTAP_ZEROCONF_SUPPORT. Timing reduced from 200 to 50. WF_hibernate.wakeup_notice = true; //WFConsolePrintRomStr("Wakeup Wi-Fi module.", true); #else /* Kick off connection now... */ WF_CMConnect(ConnectionProfileID); #endif /* Change state and return true to show we are done! */ CFGCXT.cfg_state = cfg_stopped; return 1; }
static int WFEasyConfigProcess(void) { UINT8 ConnectionProfileID; UINT8 ConnectionState; #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 = TickGet(); return 0; } /* Wait for stall time to expire */ if (CFGCXT.cfg_state == cfg_stalled) { UINT32 time = TickGet(); if ((time - CFGCXT.timeStart) < WF_STALL_TIME_MS) return 0; } #endif //EZ_CONFIG_STALL /* We will re-use the current profile */ WF_CMGetConnectionState(&ConnectionState, &ConnectionProfileID); /* Need to disconnect */ WF_CMDisconnect(); /* Delete profile */ WF_CPDelete(ConnectionProfileID); /* Create and prepare new profile */ WF_CPCreate(&ConnectionProfileID); /* Now set the various connection profile parameters */ /* Set SSID... */ if (CFGCXT.ssid) #if defined(__18CXX) WF_CPSetSsid(ConnectionProfileID, //(ROM char *)CFGCXT.ssid, Note (VMH): fixed compile warning - not sure why this is necessary. CFGCXT.ssid, strlen(CFGCXT.ssid)); #else WF_CPSetSsid(ConnectionProfileID, CFGCXT.ssid, strlen((char*)CFGCXT.ssid)); #endif #if defined(DERIVE_KEY_FROM_PASSPHRASE_IN_HOST) if ((BYTE)CFGCXT.security == WF_SECURITY_WPA_WITH_PASS_PHRASE || (BYTE)CFGCXT.security == WF_SECURITY_WPA2_WITH_PASS_PHRASE || (BYTE)CFGCXT.security == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE) { WF_ConvPassphrase2Key(strlen((char *)CFGCXT.key), CFGCXT.key, strlen((char*)CFGCXT.ssid), CFGCXT.ssid); CFGCXT.security--; } #endif /* defined(DERIVE_KEY_FROM_PASSPHRASE_IN_HOST) */ /* Now deal with security... */ switch ((BYTE)CFGCXT.security) { case WF_SECURITY_OPEN: /* No security */ WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_OPEN, 0, 0, 0); break; case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: if (CFGCXT.key) { WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE, 0, CFGCXT.key, strlen((char *)CFGCXT.key)); } break; case WF_SECURITY_WPA_AUTO_WITH_KEY: if (CFGCXT.key) { WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WPA_AUTO_WITH_KEY, 0, CFGCXT.key, 32); } break; case WF_SECURITY_WEP_40: { BYTE keys[20]; int i; if (CFGCXT.key) { /* Clear key */ for (i = 0; i < 20; i++) keys[i] = 0; memcpy(keys, (void*)CFGCXT.key, 20); WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_40, CFGCXT.defaultWepKey, keys, 20); } } break; case WF_SECURITY_WEP_104: { BYTE keys[52]; int i; if (CFGCXT.key) { /* Clear key */ for (i = 0; i < 52; i++) keys[i] = 0; memcpy(keys, (void*)CFGCXT.key, 52); WF_CPSetSecurity(ConnectionProfileID, WF_SECURITY_WEP_104, CFGCXT.defaultWepKey, keys, 52); } } break; } #if defined (EZ_CONFIG_STORE) SaveAppConfig(&AppConfig); #endif /* Set wlan mode */ WF_CPSetNetworkType(ConnectionProfileID, CFGCXT.type); #if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE) WF_DisableModuleConnectionManager(); #endif if (AppConfig.networkType == WF_INFRASTRUCTURE) WF_CASetListRetryCount(MY_DEFAULT_LIST_RETRY_COUNT_INFRASTRUCTURE); #if MY_DEFAULT_NETWORK_TYPE == WF_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. WF_hibernate.state = WF_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 /* Kick off connection now... */ WF_CMConnect(ConnectionProfileID); #endif /* Change state and return TRUE to show we are done! */ CFGCXT.cfg_state = cfg_stopped; return 1; }