/******************************************************************************* Function: UINT16 WF_Disconnect(void) Summary: Commands the MRF24WG to close any open connections and/or to cease attempting to connect. Description: Directs the Connection Manager to close any open connection or connection attempt in progress. No further attempts to connect are taken until WF_Connect() is called. Precondition: Parameters: None. Returns: None Remarks: None. *****************************************************************************/ void WF_Disconnect(void) { uint8_t hdrBuf[2]; uint8_t connectionState; // not used, but required for function call /* WARNING !!! : * Disconnect is allowed only in connected state. * If module FW is in the midst of connection (or reconnection) process, then * disconnect can hammer connection process, and furthermore it may cause * fatal failure in module FW operation. */ // verify it is OK to issue a disconnect command WF_ConnectionStateGet(&connectionState); if ((connectionState != WF_CSTATE_CONNECTED_INFRASTRUCTURE) && (connectionState != WF_CSTATE_CONNECTED_ADHOC)) { EventEnqueue(WF_EVENT_ERROR, UD_ERROR_DISCONNECT_NOT_ALLOWED); return; } hdrBuf[0] = WF_MGMT_REQUEST_TYPE; hdrBuf[1] = WF_CM_DISCONNECT_SUBYTPE; SendMgmtMsg(hdrBuf, sizeof(hdrBuf), NULL, 0); /* wait for mgmt response, free after it comes in, don't need data bytes */ WaitForMgmtResponse(WF_CM_DISCONNECT_SUBYTPE, FREE_MGMT_BUFFER); UdSetConnectionState(CS_NOT_CONNECTED); }
static bool isDisconnectAllowed(void) { uint8_t connectionState; WF_ConnectionStateGet(&connectionState); if (connectionState == WF_CSTATE_CONNECTED_INFRASTRUCTURE || connectionState == WF_CSTATE_CONNECTED_ADHOC) { return true; } return false; }
static void Disconnect(void) { uint8_t connectionState = WF_CSTATE_NOT_CONNECTED; if (!wfmrf24.priv.fMRFBusy) { WF_ConnectionStateGet(&connectionState); switch(connectionState) { // normal case at dropping the AP case WF_CSTATE_CONNECTED_INFRASTRUCTURE: case WF_CSTATE_CONNECTED_ADHOC: WF_Disconnect(); wfmrf24.priv.fMRFBusy = false; break; // this is an ugly case, we could be in the middle of trying // to reconnect and we MUST NOT disconnect or we could // put the firmware into a locked up state // so instead just say we are busy and when the connect attempts // the connect will wait until it is done being busy // however this should never happen as we set the busy state when // we entered either of these states in the event stub case WF_CSTATE_CONNECTION_IN_PROGRESS: case WF_CSTATE_RECONNECTION_IN_PROGRESS: wfmrf24.priv.fMRFBusy = true; break; default: break; } } // in all cases want to pretend at least the we disconnected. wfmrf24.priv.connectionStatus = ForceIPStatus((InitMask | WF_EVENT_INITIALIZATION)); }
static int WFEasyConfigProcess(TCPIP_NET_IF* pNetIf) { #if 0 // should not be needed uint8_t ConnectionState; #endif t_securityContext 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 */ WF_ConnectionStateGet(&ConnectionState); #endif /* Need to disconnect */ WF_Disconnect(); /* Set SSID... */ if (CFGCXT.ssid) { WF_SsidSet(CFGCXT.ssid, strlen((char*)CFGCXT.ssid)); } /* Now deal with security... */ switch ((uint8_t)CFGCXT.security) { case WF_SECURITY_OPEN: /* No security */ WF_SecurityOpenSet(); break; case WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE: if (CFGCXT.key) { securityContext.wpaContext.wpaSecurityType = WF_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); WF_SecurityWpaSet(&securityContext.wpaContext); } break; case WF_SECURITY_WPA_AUTO_WITH_KEY: if (CFGCXT.key) { securityContext.wpaContext.wpaSecurityType = WF_SECURITY_WPA_AUTO_WITH_KEY; securityContext.wpaContext.keyInfo.keyLength = 32; memcpy(securityContext.wpaContext.keyInfo.key, CFGCXT.key, 32); WF_SecurityWpaSet(&securityContext.wpaContext); } break; case WF_SECURITY_WEP_40: if (CFGCXT.key) { securityContext.wepContext.wepSecurityType = WF_SECURITY_WEP_40; securityContext.wepContext.wepKeyLength = WF_WEP40_KEY_LENGTH; memset(CFGCXT.key, 0x00, WF_WEP40_KEY_LENGTH); memset(securityContext.wepContext.wepKey, 0x00, WF_WEP40_KEY_LENGTH); securityContext.wepContext.wepKeyType = WF_SECURITY_WEP_OPENKEY; WF_SecurityWepSet(&securityContext.wepContext); } break; case WF_SECURITY_WEP_104: if (CFGCXT.key) { securityContext.wepContext.wepSecurityType = WF_SECURITY_WEP_104; securityContext.wepContext.wepKeyLength = WF_WEP104_KEY_LENGTH; memset(CFGCXT.key, 0x00, WF_WEP104_KEY_LENGTH); memset(securityContext.wepContext.wepKey, 0x00, WF_WEP104_KEY_LENGTH); securityContext.wepContext.wepKeyType = WF_SECURITY_WEP_OPENKEY; WF_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 WF_ConfigDataSave(); #endif #endif // defined (EZ_CONFIG_STORE) /* Set wlan mode */ WF_NetworkTypeSet(CFGCXT.type); #if defined(DISABLE_MODULE_FW_CONNECT_MANAGER_IN_INFRASTRUCTURE) WF_ReconnectModeSet(0, // report-only when connection lost (no reconnect) WF_DO_NOT_ATTEMPT_TO_RECONNECT, // report-only when deauth received (no reconnect) 40, // set beacon timeout to 40 beacon periods WF_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 == WF_NETWORK_TYPE_INFRASTRUCTURE) { WF_ReconnectModeSet(WF_RETRY_FOREVER, // retry forever to connect to WiFi network WF_ATTEMPT_TO_RECONNECT, // reconnect on deauth from AP 40, // beacon timeout is 40 beacon periods WF_ATTEMPT_TO_RECONNECT); // reconnect on beacon timeout } #if WF_DEFAULT_NETWORK_TYPE == WF_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 = 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 extern bool SoftAP_Redirection_Enable; SoftAP_Redirection_Enable = true; #endif #else /* Kick off connection now... */ WF_Connect(); #if defined(TCPIP_STACK_USE_EVENT_NOTIFICATION) WifiAsyncSetEventPending(ASYNC_DHCP_CONFIG_PENDING); // configure DHCP after init complete #endif #endif /* Change state and return true to show we are done! */ CFGCXT.cfg_state = cfg_stopped; return true; }