static UINT8 SetMode_idle(void) { UINT8 networkType; WF_CPGetNetworkType(iwconfigCb.cpId, &networkType); if (FALSE == iwconfigCb.isIdle ) { if (WF_CMDisconnect() != WF_SUCCESS) { putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n"); } WF_PsPollDisable(); #ifdef STACK_USE_CERTIFICATE_DEBUG DelayMs(100); #endif } return networkType; }
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; }
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; }
/******************************************************************************* Function: BOOL iwconfigSetMode(void) Summary: Set the mode to idle, managed or adhoc. Description: Idle mode - Force MRF24W module to disconnect from any currently connected network Managed mode - MRF24W module will connect to SSID in infrastructure mode. Ensure all network parameters are correct before this command is invoked. Adhoc mode - MRF24W module will connect to SSID in adhoc mode. Ensure all network parameters are correct before this command is invoked. Parameters: Mode - idle / managed /adhoc Returns: TRUE or FALSE Remarks: None. *****************************************************************************/ static BOOL iwconfigSetMode(void) { UINT8 networkType; WF_CPGetNetworkType(iwconfigCb.cpId, &networkType); if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "idle") == 0) ) { if ( iwconfigCb.isIdle ) { WFConsolePrintRomStr("Already in the idle mode", TRUE); } else { if (WF_CMDisconnect() != WF_SUCCESS) { #if defined(STACK_USE_UART) putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n"); #endif } WF_PsPollDisable(); } } else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "managed") == 0) ) { if ( iwconfigCb.isIdle ) { WF_CPSetNetworkType(iwconfigCb.cpId, WF_INFRASTRUCTURE); WF_CMConnect(iwconfigCb.cpId); } else { WF_CPGetNetworkType(iwconfigCb.cpId, &networkType); if (networkType == WF_INFRASTRUCTURE) { WFConsolePrintRomStr("Already in the managed mode", TRUE); } else { if (WF_CMDisconnect() != WF_SUCCESS) { #if defined(STACK_USE_UART) putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n"); #endif } WF_CPSetNetworkType(iwconfigCb.cpId, WF_INFRASTRUCTURE); WF_CMConnect(iwconfigCb.cpId); } } } else if ( (3u <= ARGC) && (strcmppgm2ram((char*)ARGV[2], "adhoc") == 0) ) { if ( iwconfigCb.isIdle ) { WF_CASetListRetryCount(ADHOC_RETRY_COUNT); WF_CPSetNetworkType(iwconfigCb.cpId, WF_ADHOC); WF_CPSetAdHocBehavior(iwconfigCb.cpId, WF_ADHOC_CONNECT_THEN_START); WF_CMConnect(iwconfigCb.cpId); } else { WF_CPGetNetworkType(iwconfigCb.cpId, &networkType); if (networkType == WF_ADHOC) { WFConsolePrintRomStr("Already in the adhoc mode", TRUE); } else { if (WF_CMDisconnect() != WF_SUCCESS) { #if defined(STACK_USE_UART) putsUART("Disconnect failed. Disconnect is allowed only when module is in connected state\r\n"); #endif } WF_CPSetNetworkType(iwconfigCb.cpId, WF_ADHOC); WF_CMConnect(iwconfigCb.cpId); } } } else { WFConsolePrintRomStr("Unknown parameter", TRUE); return FALSE; } return TRUE; }
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; }