void TcpServerHandler_test(void *param) { unsigned short port = 5555; vTaskDelay(10000); printf("\n\rTCP: Start tcp Server!"); g_start_server = 1; if(g_start_server) BsdTcpServer(port); #if defined(INCLUDE_uxTaskGetStackHighWaterMark) && (INCLUDE_uxTaskGetStackHighWaterMark == 1) printf("\n\rMin available stack size of %s = %d * %d bytes\n\r", __FUNCTION__, uxTaskGetStackHighWaterMark(NULL), sizeof(portBASE_TYPE)); #endif printf("\n\rTCP: Tcp server stopped!"); g_server_task = NULL; vTaskDelete(NULL); }
int main() { unsigned char ucP2PParam[4]; long lRetVal = -1; // // Initialize Board configurations // BoardInit(); // // Pinmuxing for GPIO, UART // PinMuxConfig(); // // configure LEDs // GPIO_IF_LedConfigure(LED1|LED2|LED3); // off all LEDs GPIO_IF_LedOff(MCU_ALL_LED_IND); #ifndef NOTERM // // Configuring UART // InitTerm(); #endif // // Display the Application Banner // DisplayBanner(APP_NAME); UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r"); // Initializing the CC3200 device lRetVal = StartDeviceInP2P(); if(lRetVal < 0) { LOOP_FOREVER(__LINE__); } // Set any p2p option (SL_CONNECTION_POLICY(0,0,0,any_p2p,0)) to connect to // first available p2p device sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0); // Set the negotiation role (SL_P2P_ROLE_NEGOTIATE). // CC3200 will negotiate with remote device GO/client mode. // Other valid options are: // - SL_P2P_ROLE_GROUP_OWNER // - SL_P2P_ROLE_CLIENT sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE, SL_P2P_NEG_INITIATOR_ACTIVE),NULL,0); // Set P2P Device name sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen(P2P_DEVICE_NAME), (unsigned char *)P2P_DEVICE_NAME); // Set P2P device type sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_DEV_TYPE, strlen(P2P_CONFIG_VALUE), (unsigned char*)P2P_CONFIG_VALUE); // setting P2P channel parameters ucP2PParam[0] = LISENING_CHANNEL; ucP2PParam[1] = REGULATORY_CLASS; ucP2PParam[2] = OPERATING_CHANNEL; ucP2PParam[3] = REGULATORY_CLASS; // Set P2P Device listen and open channel valid channels are 1/6/11 sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_CHANNEL_N_REGS, sizeof(ucP2PParam), ucP2PParam); // Restart as P2P device sl_Stop(SL_STOP_TIMEOUT); lRetVal = sl_Start(NULL,NULL,NULL); if(lRetVal < 0 || lRetVal != ROLE_P2P) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(__LINE__); } else { UART_PRINT("Connect to %s \n\r",P2P_DEVICE_NAME); } /* Connect to configure P2P device */ lRetVal = WlanConnect(); if(lRetVal == 0) { GPIO_IF_LedOn(MCU_IP_ALLOC_IND); } else { UART_PRINT("Reset the device and try again\n\r"); LOOP_FOREVER(__LINE__); } DisplayIP(); UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r"); /*After calling this function, you can start sending data to CC3200 IP * address on PORT_NUM */ if(!(IS_CONNECT_FAILED(g_ulStatus))) BsdTcpServer(PORT_NUM); UART_PRINT("Received TCP packets successfully \n\r"); // revert Device into STA mode and power off Network Processor sl_WlanSetMode(ROLE_STA); sl_Stop(SL_STOP_TIMEOUT); UART_PRINT("Test passed, exiting application... \n\r"); while(1) { _SlNonOsMainLoopTask(); } }
void taskServer( void *pvParameters ){ BsdTcpServer(PORT_NUM); UART_PRINT("taskServer over\r\n"); vTaskDelete(NULL); }
int main() { long lRetVal = -1; // // Initialize Board configurations // BoardInit(); // // Pinmuxing for GPIO, UART // PinMuxConfig(); // // configure LEDs // GPIO_IF_LedConfigure(LED1|LED2|LED3); // off all LEDs GPIO_IF_LedOff(MCU_ALL_LED_IND); #ifndef NOTERM // // Configuring UART // InitTerm(); #endif // // Display the Application Banner // DisplayBanner(APP_NAME); UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r"); // Initializing the CC3200 device lRetVal = StartDeviceInP2P(); if(lRetVal < 0) { UART_PRINT("Start Device in P2P mode failed \n\r"); LOOP_FOREVER(); } lRetVal = P2PConfiguration(); if(lRetVal < 0) { UART_PRINT("Setting P2P configuration failed\n\r"); LOOP_FOREVER(); } /* Connect to configure P2P device */ lRetVal = WlanConnect(); if(lRetVal == 0) { GPIO_IF_LedOn(MCU_IP_ALLOC_IND); } else { UART_PRINT("Reset the device and try again\n\r"); LOOP_FOREVER(); } if(DisplayIP() < 0) { UART_PRINT("Get IP address failed \n\r"); LOOP_FOREVER(); } UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r"); /*After calling this function, you can start sending data to CC3200 IP * address on PORT_NUM */ if(!(IS_CONNECT_FAILED(g_ulStatus))) { lRetVal = BsdTcpServer(PORT_NUM); if(lRetVal >= 0) { UART_PRINT("Received TCP packets successfully \n\r"); } else if(lRetVal == CLIENT_DISCONNECTED) { UART_PRINT("P2P Client disconnected \n\r"); } else { UART_PRINT("TCP packets receive failed \n\r"); } } if(lRetVal >=0) { UART_PRINT("Test passed, exiting application... \n\r"); } else { UART_PRINT("Test failed, exiting application... \n\r"); } // revert Device into STA mode and power off Network Processor lRetVal = sl_WlanSetMode(ROLE_STA); if(lRetVal < 0) { ERR_PRINT(lRetVal); LOOP_FOREVER(); } lRetVal = sl_Stop(SL_STOP_TIMEOUT); GPIO_IF_LedOff(MCU_IP_ALLOC_IND); while(1) { _SlNonOsMainLoopTask(); } }
//***************************************************************************** // //! NwpFilter - Function which Creates and Enables the Filter //! //! \param pvParameters //! //! \return 0 //! //***************************************************************************** static int NwpFilter(void *pvParameters) { long lRetVal = 0; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } UART_PRINT("Device started as STATION \n\r"); // // Reset policy settings // lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, \ SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0); // // This function creates two different filters: // (1) Filter packets according to remote MAC // (2) Filter packets according to remote IP address // lRetVal=CreateFilters(); if (lRetVal < 0) { UART_PRINT("Filter creation failed\n\r"); LOOP_FOREVER(); } // // Activate pre-defined filters - The filters will be deleted upon reset // if(EnableAllFilters() < 0) { UART_PRINT("Unable to enable filter \n\r"); LOOP_FOREVER(); } // //Connecting to WLAN AP // lRetVal = WlanConnect(); if(lRetVal < 0) { UART_PRINT("Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } UART_PRINT("Connection established w/ AP and IP is aquired \n\r"); // // After calling this function, you can start sending data to CC3200 IP // address on PORT_NUM TCP connection will be refused if remote MAC/IP is of // the filtered. It's also possible to enable the filters after TCP // connection, resulting in TCP packets to not being received // lRetVal = BsdTcpServer(PORT_NUM); if(lRetVal < 0) { UART_PRINT("Failure in TCP server\n\r"); LOOP_FOREVER(); } // // Power off Network processor // lRetVal = sl_Stop(SL_STOP_TIMEOUT); return 0; }
//**************************************************************************** // //! \brief start simplelink, connect to the ap and run the ping test //! //! This function starts the simplelink, connect to the ap and start the ping //! test on the default gateway for the ap //! //! \param pvparameters is the pointer to the list of parameters that can be //! passed to the task while creating it //! //! \return None // //**************************************************************************** void WlanStationMode( void *pvParameters ) { int iTestResult = 0; unsigned long ulIP = 0; unsigned long ulSubMask = 0; unsigned long ulDefaultGateway = 0; unsigned long ulDNSServer = 0; unsigned char ucDHCP = 0; char cMode; char* buff="hhhhhh\n\r"; unsigned char currentMacAddress[SL_MAC_ADDR_LEN]; UART_PRINT(" in WlanStationMode \n\r"); /* for(int a = 0; a<5; ++a){ Z_DelayS(30); *buff=a+'0'; UART_PRINT(buff); } */ sl_Start(NULL,NULL,InitCallback); /* if((cMode = sl_Start(NULL,NULL,NULL)) != ROLE_STA){ UART_PRINT("hellow \n\r"); *buff=cMode+'0'; UART_PRINT(buff); *buff=ROLE_STA+'0'; UART_PRINT(buff); // SL_WLAN_SET_MODE_STA(); } UART_PRINT("hellow i am in station mode now \n\r"); */ while(!g_uiSimplelinkstarted) { //looping till simplelink starts Z_DelayS(1); UART_PRINT("i am starting now \n\r"); } UART_PRINT("i am started \n\r"); // Connecting to WLAN AP - Set with static parameters defined at the top // After this call we will be connected and have IP address */ WlanConnect(); UART_PRINT("i'm connected! \n\r"); //get mac addr from s-flash SL_MAC_ADDR_GET(currentMacAddress); Z_MACDispaly(currentMacAddress); SL_STA_IPV4_ADDR_GET(&ulIP,&ulSubMask,&ulDefaultGateway,&ulDNSServer, &ucDHCP); Z_IPDispaly(&ulIP); Z_IPDispaly(&ulSubMask); Z_IPDispaly(&ulDefaultGateway); /* UNUSED(ulIP); UNUSED(ulSubMask); UNUSED(ulDNSServer); UNUSED(ucDHCP); */ iTestResult = PingTest(ulDefaultGateway); // UNUSED(iTestResult); if(0 <= BsdTcpServer(PORT_NUM)) UART_PRINT("ok! \n\r"); }