/** * @brief This function cleans module * * @return n/a */ static void wlan_cleanup_module(void) { wlan_private *priv = wlanpriv; wlan_adapter *Adapter = NULL; ENTER(); if (OS_ACQ_SEMAPHORE_BLOCK(&AddRemoveCardSem)) goto exit_sem_err; if (!priv || !priv->adapter) goto exit; Adapter = priv->adapter; /* Exit deep sleep */ wlan_exit_deep_sleep_timeout(priv); if (Adapter->MediaConnectStatus == WlanMediaStateConnected) wlan_disconnect(priv); wlan_prepare_cmd(priv, HostCmd_CMD_FUNC_SHUTDOWN, 0, HostCmd_OPTION_WAITFORRSP | HostCmd_OPTION_TIMEOUT, 0, NULL); /* Disable interrupts on the card */ sbi_disable_host_int(priv); exit: OS_REL_SEMAPHORE(&AddRemoveCardSem); exit_sem_err: sbi_unregister(); LEAVE(); }
//***************************************************************************** // Crasons First FUnction //! DefaultWifiConnection //! //! \param none //! //! \return none //! //! \brief Connect to an Access Point using the default values "demo_config.h" // //***************************************************************************** int DefaultWifiConnection(void) { unsetCC3000MachineState(CC3000_ASSOC); // Disable Profiles and Fast Connect wlan_ioctl_set_connection_policy(0, 0, 0); wlan_disconnect(); __delay_cycles(10000); wlan_connect(DEFAULT_AP_SECURITY, DEFAULT_OUT_OF_BOX_SSID, strlen(DEFAULT_OUT_OF_BOX_SSID), NULL, DFAULT_AP_SECURITY_KEY, strlen(DFAULT_AP_SECURITY_KEY)); return 0; }
/** * @brief Disconnects from the AP * * @return True if disconnected successfully. False otherwise. */ bool SFE_CC3000::disconnect() { /* If CC3000 is not initialized, return false. */ if (!getInitStatus()) { return false; } /* Attempt to disconnect from the network */ if (wlan_disconnect() == CC3000_SUCCESS) { return true; } else { return false; } }
/*------------------------------------------------------------------------ Spider_Disconnect Dissconnect SpiderL3 from a exist AP. return 0, Connect success. return -1, Hardware uninitialized. -----------------------------------------------------------------------*/ int Spider_Disconnect(void){ long ret; if(HW_Initialed != 1) return -1; ret = wlan_disconnect(); // Check connection failed. if(ret != 0){ return -2; } return 0; }
int hw_net_disconnect (void) { CC3000_START; int disconnect = wlan_disconnect(); memset(hw_wifi_ip, 0, sizeof hw_wifi_ip); memset(hw_wifi_ip, 0, sizeof hw_cc_ver); // reset connection ulCC3000Connected = 0; ulCC3000DHCP = 0; CC3000_END; return disconnect; }
/*************************************************** * * FUNCTION : Into EasyLink mode * ****************************************************/ void IntoEasyLink() { int ledflag=0; #if (GAGENT_FEATURE_WXCHIP_EASYLINK == 1) wlan_disconnect(); OpenEasylink2(60); while( g_Xpg_GlobalVar.AirLinkFlag==0) { msleep(100); DRV_Led_Red(ledflag); DRV_Led_Green(1); ledflag=!ledflag; } #endif return; }
static clarityError clarityMgmtAttemptPowerDown(void) { clarityMgmtMtxLock(); if (mgmtData.active == true) { if (mgmtData.activeProcesses == 0) { clarityCC3000ApiLock(); wlan_disconnect(); wlan_stop(); clarityCC3000ApiUnlock(); mgmtData.active = false; /* TODO what can we do about asyncdata shutdown ok??? */ } } clarityMgmtMtxUnlock(); return CLARITY_SUCCESS; }
//***************************************************************************** // //! ConnectUsingSSID //! //! \param ssidName is a string of the AP's SSID //! //! \return none //! //! \brief Connect to an Access Point using the specified SSID // //***************************************************************************** int ConnectUsingSSID(char * ssidName) { unsetCC3000MachineState(CC3000_ASSOC); // Disable Profiles and Fast Connect wlan_ioctl_set_connection_policy(0, 0, 0); wlan_disconnect(); __delay_cycles(10000); // This triggers the CC3000 to connect to specific AP with certain parameters //sends a request to connect (does not necessarily connect - callback checks that for me) #ifndef CC3000_TINY_DRIVER wlan_connect(0, ssidName, strlen(ssidName), NULL, NULL, 0); #else wlan_connect(ssidName, strlen(ssidName)); #endif // We don't wait for connection. This is handled somewhere else (in the main // loop for example). return 0; }
//***************************************************************************** // //! DemoHandleUartCommand //! //! @param buffer //! //! @return none //! //! @brief The function handles commands arrived from CLI // //***************************************************************************** void DemoHandleUartCommand(unsigned char *usBuffer) { char *pcSsid, *pcData, *pcSockAddrAscii; unsigned long ulSsidLen, ulDataLength; volatile signed long iReturnValue; sockaddr tSocketAddr; socklen_t tRxPacketLength; unsigned char pucIP_Addr[4]; unsigned char pucIP_DefaultGWAddr[4]; unsigned char pucSubnetMask[4]; unsigned char pucDNS[4]; // usBuffer[0] contains always 0 // usBuffer[1] maps the command // usBuffer[2..end] optional parameters switch(usBuffer[1]) { // Start a smart configuration process case UART_COMMAND_CC3000_SIMPLE_CONFIG_START: StartSmartConfig(); break; // Start a WLAN Connect process case UART_COMMAND_CC3000_CONNECT: { ulSsidLen = atoc(usBuffer[2]); pcSsid = (char *)&usBuffer[3]; #ifndef CC3000_TINY_DRIVER wlan_connect(WLAN_SEC_UNSEC, pcSsid, ulSsidLen,NULL, NULL, 0); #else wlan_connect(pcSsid,ulSsidLen); #endif } break; // Handle open socket command case UART_COMMAND_SOCKET_OPEN: // wait for DHCP process to finish. if you are using a static IP address // please delete the wait for DHCP event - ulCC3000DHCP while ((ulCC3000DHCP == 0) || (ulCC3000Connected == 0)) { hci_unsolicited_event_handler(); SysCtlDelay(1000); } ulSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); break; // Handle close socket command case UART_COMMAND_SOCKET_CLOSE: closesocket(ulSocket); ulSocket = 0xFFFFFFFF; break; // Handle receive data command case UART_COMMAND_RCV_DATA: iReturnValue = recvfrom(ulSocket, pucCC3000_Rx_Buffer, CC3000_APP_BUFFER_SIZE, 0, &tSocketAddr, &tRxPacketLength); if (iReturnValue <= 0) { // No data received by device DispatcherUartSendPacket((unsigned char*)pucUARTNoDataString, sizeof(pucUARTNoDataString)); } else { // Send data to UART... DispatcherUartSendPacket(pucCC3000_Rx_Buffer, CC3000_APP_BUFFER_SIZE); } break; // Handle send data command case UART_COMMAND_SEND_DATA: // data pointer pcData = (char *)&usBuffer[4]; // data length to send ulDataLength = atoshort(usBuffer[2], usBuffer[3]); pcSockAddrAscii = (pcData + ulDataLength); // the family is always AF_INET tSocketAddr.sa_family = atoshort(pcSockAddrAscii[0], pcSockAddrAscii[1]); // the destination port tSocketAddr.sa_data[0] = ascii_to_char(pcSockAddrAscii[2], pcSockAddrAscii[3]); tSocketAddr.sa_data[1] = ascii_to_char(pcSockAddrAscii[4], pcSockAddrAscii[5]); // the destination IP address tSocketAddr.sa_data[2] = ascii_to_char(pcSockAddrAscii[6], pcSockAddrAscii[7]); tSocketAddr.sa_data[3] = ascii_to_char(pcSockAddrAscii[8], pcSockAddrAscii[9]); tSocketAddr.sa_data[4] = ascii_to_char(pcSockAddrAscii[10], pcSockAddrAscii[11]); tSocketAddr.sa_data[5] = ascii_to_char(pcSockAddrAscii[12], pcSockAddrAscii[13]); sendto(ulSocket, pcData, ulDataLength, 0, &tSocketAddr, sizeof(sockaddr)); break; // Handle bind command case UART_COMMAND_BSD_BIND: tSocketAddr.sa_family = AF_INET; // the source port tSocketAddr.sa_data[0] = ascii_to_char(usBuffer[2], usBuffer[3]); tSocketAddr.sa_data[1] = ascii_to_char(usBuffer[4], usBuffer[5]); // all 0 IP address memset (&tSocketAddr.sa_data[2], 0, 4); bind(ulSocket, &tSocketAddr, sizeof(sockaddr)); break; // Handle IP configuration command case UART_COMMAND_IP_CONFIG: // Network mask is assumed to be 255.255.255.0 pucSubnetMask[0] = 0xFF; pucSubnetMask[1] = 0xFF; pucSubnetMask[2] = 0xFF; pucSubnetMask[3] = 0x0; pucIP_Addr[0] = ascii_to_char(usBuffer[2], usBuffer[3]); pucIP_Addr[1] = ascii_to_char(usBuffer[4], usBuffer[5]); pucIP_Addr[2] = ascii_to_char(usBuffer[6], usBuffer[7]); pucIP_Addr[3] = ascii_to_char(usBuffer[8], usBuffer[9]); pucIP_DefaultGWAddr[0] = ascii_to_char(usBuffer[10], usBuffer[11]); pucIP_DefaultGWAddr[1] = ascii_to_char(usBuffer[12], usBuffer[13]); pucIP_DefaultGWAddr[2] = ascii_to_char(usBuffer[14], usBuffer[15]); pucIP_DefaultGWAddr[3] = ascii_to_char(usBuffer[16], usBuffer[17]); pucDNS[0] = 0; pucDNS[1] = 0; pucDNS[2] = 0; pucDNS[3] = 0; netapp_dhcp((unsigned long *)pucIP_Addr, (unsigned long *)pucSubnetMask, (unsigned long *)pucIP_DefaultGWAddr, (unsigned long *)pucDNS); break; // Handle WLAN disconnect command case UART_COMMAND_CC3000_DISCONNECT: wlan_disconnect(); break; // Handle erase policy command case UART_COMMAND_CC3000_DEL_POLICY: wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE); break; // Handle send DNS Discovery command case UART_COMMAND_SEND_DNS_ADVERTIZE: if(ulCC3000DHCP) { mdnsAdvertiser(1,device_name,strlen(device_name)); } break; default: DispatcherUartSendPacket((unsigned char*)pucUARTIllegalCommandString, sizeof(pucUARTIllegalCommandString)); break; } // Send a response - the command handling has finished DispatcherUartSendPacket((unsigned char *)(pucUARTCommandDoneString), sizeof(pucUARTCommandDoneString)); }
static void cmd_smart_cc3000(BaseSequentialStream *chp, int argc, char *argv[]) { long rval; (void)argv; if(argc > 0) { chprintf(chp, "Usage: setup\r\n"); return; } chprintf(chp, "Disconnecting "); wlan_disconnect(); while(cc3000AsyncData.connected == 1) { chprintf(chp, "."); } chprintf(chp, "done!\r\n"); chprintf(chp, "Disabling auto connect policy ...\r\n"); /* Set connection policy to disable */ if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE)) != 0) { chprintf(chp, "Error disabling auto connect policy ...\r\n"); return; } /* Delete all profiles */ chprintf(chp, "Deleting all profiles ...\r\n"); if ((rval = wlan_ioctl_del_profile(255)) != 0) { chprintf(chp, "Error deleting profiles ...\r\n"); return; } chprintf(chp, "Creating AES keys ...\r\n"); nvmem_create_entry(NVMEM_AES128_KEY_FILEID, AES128_KEY_SIZE); aes_write_key((UINT8 *) AES_KEY); // Set the smart config prefix chprintf(chp, "Setting smart config prefix ...\r\n"); if((rval = wlan_smart_config_set_prefix(smartConfigPrefix)) != 0) { chprintf(chp, "Error setting smart config prefix ... \r\n"); return; } chprintf(chp, "Starting CC3000 SmartConfig ...\r\n"); if((rval = wlan_smart_config_start(0)) != 0) { chprintf(chp, "Error starting smart config ...\r\n"); return; } chprintf(chp, "Waiting for SmartConfig to finish ...\r\n"); /* Wait until smart config is finished */ while(cc3000AsyncData.smartConfigFinished == 0) { // We blink the led here .. the thread process // will set this to PAL_LOW (since we are disconnected) palWritePad(CON_LED_PORT, CON_LED_PIN, PAL_HIGH); chThdSleep(MS2ST(200)); } chprintf(chp, "Smart config packet received ...\r\n"); /* Re enable auto connect policy */ if ((rval = wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE)) != 0) { chprintf(chp, "Error setting auto connect policy ...\r\n"); return; } /* Restart wlan */ wlan_stop(); chprintf(chp, "Reconnecting ...\r\n"); chThdSleep(MS2ST(2000)); wlan_start(0); /* No need to call connect, hopefully auto connect policy * can connect to our AP now **/ chprintf(chp, "Waiting for connection to AP ...\r\n"); while (cc3000AsyncData.dhcp.present != 1) { chThdSleep(MS2ST(5)); } show_cc3_dhcp_info(chp); mdnsAdvertiser(1, deviceName, strlen(deviceName)); }
/* mgmt mutex MUST be locked by caller */ static clarityError clarityMgmtAttemptActivate_mtxext(void) { clarityError rtn = CLARITY_SUCCESS; #if 0 uint32_t ip = 0; uint32_t subnet = 0; uint32_t gateway = 0; uint32_t dns = 0; #endif if (mgmtData.active == true) { return CLARITY_SUCCESS; } #if 0 if (mgmtData.ap->deviceIp.isStatic == true) { ip = htonl(mgmtData.ap->deviceIp.ip); subnet = htonl(mgmtData.ap->deviceIp.subnet); gateway = htonl(mgmtData.ap->deviceIp.gateway); dns = htonl(mgmtData.ap->deviceIp.dns); } #endif clarityCC3000ApiLock(); wlan_start(0); mgmtData.active = true; #if 0 if (netapp_dhcp(&ip, &subnet, &gateway, &dns) != 0) { CLAR_PRINT_ERROR(); rtn = CLARITY_ERROR_CC3000_NETAPP; } wlan_disconnect(); wlan_stop(); chThdSleep(MS2ST(200)); wlan_start(0); #endif clarityCC3000ApiUnlock(); if ((rtn = connectToWifi_mtxext()) != CLARITY_SUCCESS) { CLAR_PRINT_ERROR(); } if (rtn != CLARITY_SUCCESS) { clarityCC3000ApiLock(); wlan_disconnect(); wlan_stop(); clarityCC3000ApiUnlock(); mgmtData.active = false; } return rtn; }
/* * @brief Initialization is used to configure all of the registers of the microcontroller * Steps: * 1) Initialize CC3000 * 2) Set MUX Select_A to LOW, so we can send the Kill command from Atmega TX line * (C0 input on MUX) * 3) Set Mode to Safety Mode * 4) Set MUX Select A to HIGH, so we get into Autonomous mode by default * (C1 input on MUX) */ inline void Initialization (void) { #ifdef WATCHDOG_ENABLED wdt_enable(WDTO_8S); // WDTO_8S means set the watchdog to 8 seconds. #endif //Turn on the Power LED to identify that the device is on. // [UNUSED] DDRC |= (1 << DDC7); //STATUS LED //Set up the LEDs for WLAN_ON and DHCP: DDRC |= (1 << DDC6); //WLAN_INIT LED DDRC |= (1 << DDC7); //DHCP_Complete LED. This will turn on and very slowly blink DDRB |= (1 << DDB7); // MUX Select line, setting as output. DDRE |= (1 << DDE2); // DDRF set outbound for Safe Mode LED DDRD |= (1 << DDD6); // DDRF set outbound for Manual Mode LED DDRD |= (1 << DDD4); // DDRF set outbound for Auto Mode LED PORTF |= (1 << PF0); // Extra GPIO Pin PORTF |= (1 << PF1); // Extra GPIO Pin #ifndef SKIP_BOOT DDRB |= (1 << DDB4); DDRD |= (1 << DDD7); DDRD |= (1 << DDD6); PORTB |= (1 << PB4); _delay_ms(200); PORTD |= (1 << PD7); _delay_ms(200); PORTD |= (1 << PD6); _delay_ms(200); PORTB &= ~(1 << PB4); _delay_ms(200); PORTD &= ~(1 << PD7); _delay_ms(200); PORTD &= ~(1 << PD6); #endif _delay_ms(500); PORTF &= ~(1 << PF0); PORTF &= ~(1 << PF1); // #ifdef ENERGY_ANALYSIS_ENABLED // //Enable Timer/Counter0 Interrupt on compare match of OCR0A: // TIMSK0 = (1 << OCIE0A); // //Set the Output Compare Register for the timer to compare against: // OCR0A = Energy_Analysis_Interval; // //Configure the ADC to have the reference pin be AREF on pin 21, and make sure everything is set to defaults: // ADMUX = 0x00; // //Enable the Analog to Digital Conversion (ADC): // ADCSRA = (1 << ADEN); //25 Clock cycles to initialize. // #endif #ifdef CC3000_ENABLED //Enable the CC3000, and setup the SPI configurations. init_spi(); //Set up the CC3000 API for communication. wlan_init(CC3000_Unsynch_Call_Back, Send_WLFW_Patch, Send_Driver_Patch, Send_Boot_Loader_Patch, Read_WLAN_Interrupt_Pin, WLAN_Interrupt_Enable, WLAN_Interrupt_Disable, Write_WLAN_Pin); PORTB |= (1 << PB6); //Set the WLAN_INIT LED on. sei(); //Enable the CC3000, and wait for initialization process to finish. wlan_start(0); wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT); //Make sure we disconnect from any previous routers before we connect to a new one to prevent confusion on the device. wlan_disconnect(); wlan_connect(WLAN_SEC_UNSEC, ROUTER_SSID, SSID_LENGTH, NULL, NULL, 0); while(!DHCP_Complete) { _delay_ms(1000); } #ifdef WATCHDOG_ENABLED wdt_reset(); #endif //Bind a socket to receive data: //sockaddr Mission_Control_Address; memset((char *) &Mission_Control_Address, 0, sizeof(Mission_Control_Address)); Mission_Control_Address.sa_family = AF_INET; //The Source Port: Mission_Control_Address.sa_data[0] = (char)HEX_PORT_1; //(char)0x09; Mission_Control_Address.sa_data[1] = (char)HEX_PORT_2; //(char)0x56; //Configure the socket to not time out to keep the connection active. //-------------------------------------------------------------------- unsigned long aucDHCP = 14400; unsigned long aucARP = 3600; unsigned long aucKeepalive = 10; unsigned long aucInactivity = 0; netapp_timeout_values(&aucDHCP, &aucARP, &aucKeepalive, &aucInactivity); //TODO: //Should check the CC3000's profiles. In the case that there are no profiles found, then //inform the PC system, or use an LED. //Open a UDP socket that grabs datagram: Socket_Handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); switch(Socket_Handle) { case -1: //Error //Flag somehow. break; default: //Success //Set the socket configuration for blocking (since it is the only thing that is allowed). switch( bind(Socket_Handle, &Mission_Control_Address, sizeof(sockaddr))) { case -1: //Flag as ERROR. break; default: //Flag as good. break; } break; } #endif // NEED TO SETUP A QUICK REMOVAL FLAG FOR THIS CODE TO TEST THE CC3000. // #ifdef MOTOR_CONTROL_FLAG // Set up our Motor Controller Selection lines and the output for the RS232 lines: // DDRD |= (1 << DDD3) | (1 << DDD4) | (1 << DDD5); DDRD |= (1 << DDD3) | (1 << DDD5); // Initialize the UART (RS-232 communications) for the motor controller interface: // Set the Baud rate to 115200 bits/s. ((System Oscillator clock frequency / (2 * BAUD) ) - 1) // NOTE: The value may not be correct, according to the data sheet (pg. 213). // With the value 16, the error is 2.1% (lower than 8, being -3.5%). // This comes from util/setbaud.h UBRR1H = UBRRH_VALUE; /*Set baud rate*/ UBRR1L = UBRRL_VALUE; /*Set baud rate*/ //Defined in util/setbaud.h: #if USE_2X UCSR1A |= (1 << U2X1); //Double the baud rate for asynchronous communication. #else UCSR1A &= ~(1 << U2X1); #endif // Set to no parity and in Asynchronous mode. // 1 Stop bit. // 1 Start bit. // Set to 8-bit data. UCSR1C |= (1 << UCSZ11) | (1 << UCSZ10); //Enable the Rx and Tx lines. UCSR1B |= (1 << TXEN1); #ifdef TWI_ENABLED //Set the SCL frequency to 200 KHz. From the equation: f(SCL) = F_CPU/(16 + (2*TWBR) * (4^TWPS)) TWBR = 12; DDRB |= (1 << DDB4); //Setup PortB4 as the TWI error LED. #endif //End TWI_ENABLED _delay_ms(1000); //Wait for one second for the RoboteQs to finish booting. Set_Mode(SAFETY_MODE); // Set to Safe Mode to send Kill Command to Roboteq's Set_Mode(AUTONOMOUS_MODE); #ifdef ROUTER_WATCHDOG_ENABLED Count = 0; //Clear the Count variable out. TCNT1 = 0; //Clear the TCNT register. TCCR1B = (1 << CS12) | (1 << CS10); //Set the prescaler for 1024. TIMSK1 = (1 << OCIE1A); //Enable output compare for 1A. OCR1A = 39063; //Set the system to interrupt every 5 seconds. //OCR1A = (Multiplier) * (F_CPU) / (Prescaler) //39063 = (5) * (8000000) / (1024) #endif }
void test_wlan_disconnect(int argc, char **argv) { if (wlan_disconnect() != WLAN_ERROR_NONE) wmprintf("Error: unable to disconnect\r\n"); }
wlan_result_t wlan_disconnect_now() { wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);//Disable auto connect return wlan_disconnect(); }