int32_t ResetSimpleLink() { int32_t i32Mode = -1, i32RetVal = -1; uint8_t ui8Val = 1; i32Mode = sl_Start(0, 0, 0); i32RetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); if (i32RetVal != 0) { return -1; } i32RetVal = sl_WlanProfileDel(0xFF); if (i32RetVal != 0) { return -1; } if (ROLE_STA != i32Mode) { if (ROLE_AP == i32Mode) { while (!STATUS_GET(g_sSLCon.Status, STATUS_BIT_IP_ACQUIRED)) { } } sl_WlanSetMode(ROLE_STA); sl_Stop(0); g_sSLCon.Status = 0; i32RetVal = sl_Start(0, 0, 0); if (ROLE_STA != i32RetVal) { return -1; } } i32RetVal = sl_WlanDisconnect(); if (i32RetVal == 0) { while (STATUS_GET(g_sSLCon.Status, STATUS_BIT_CONNECTED)) { } } sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE, 1, 1, &ui8Val); sl_WlanPolicySet(SL_POLICY_SCAN, SL_SCAN_POLICY(0), NULL, NULL); ui8Val = 0; sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *) &ui8Val); sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0); sl_NetAppMDNSUnRegisterService(0, 0); sl_Stop(0); InitVariables(); return 0; }
//***************************************************************************** // //! Set all P2P Configuration to device //! //! \param None //! //! \return status code - Success:0, Failure:-ve // //***************************************************************************** long P2PConfiguration() { unsigned char ucP2PParam[4]; long lRetVal = -1; // Set any p2p option (SL_CONNECTION_POLICY(0,0,0,any_p2p,0)) to connect to // first available p2p device lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0); ASSERT_ON_ERROR(lRetVal); // 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 lRetVal = sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE, SL_P2P_NEG_INITIATOR_ACTIVE),NULL,0); ASSERT_ON_ERROR(lRetVal); // Set P2P Device name lRetVal = 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); ASSERT_ON_ERROR(lRetVal); // Set P2P device type lRetVal = sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_DEV_TYPE, strlen(P2P_CONFIG_VALUE), (unsigned char*)P2P_CONFIG_VALUE); ASSERT_ON_ERROR(lRetVal); // 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 lRetVal = sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_CHANNEL_N_REGS, sizeof(ucP2PParam), ucP2PParam); ASSERT_ON_ERROR(lRetVal); // Restart as P2P device lRetVal = sl_Stop(SL_STOP_TIMEOUT); lRetVal = sl_Start(NULL,NULL,NULL); if(lRetVal < 0 || lRetVal != ROLE_P2P) { ASSERT_ON_ERROR(P2P_CONFIG_FAILED); } else { UART_PRINT("Connect to %s \n\r",P2P_DEVICE_NAME); } return SUCCESS; }
//--tested, working--// int8_t WiFiClass::scanNetworks() { if (!_initialized) { init(); } const int WLAN_SCAN_COUNT = 20; int iRet; unsigned char ucpolicyOpt; union { unsigned char ucPolicy[4]; unsigned int uiPolicyLen; }policyVal; // // make sure the connection policy is not set (so no scan is run in the background) // ucpolicyOpt = SL_CONNECTION_POLICY(0, 0, 0, 0, 0); iRet = sl_WlanPolicySet(SL_POLICY_CONNECTION , ucpolicyOpt, NULL, 0); if(iRet != 0) { return 0; } // // set the scan policy for ten seconds. This starts the scan. // policyVal.uiPolicyLen = 10; iRet = sl_WlanPolicySet(SL_POLICY_SCAN , SL_SCAN_POLICY(1), (UINT8*)(policyVal.ucPolicy), sizeof(policyVal)); if(iRet != 0) { return 0; } delay(300); // // get scan results - all 20 entries in one transaction // this array isn't actually used, but you have to do this to get the count // Sl_WlanNetworkEntry_t found_networks[WLAN_SCAN_COUNT]; network_count = sl_WlanGetNetworkList(0, (unsigned char)WLAN_SCAN_COUNT, found_networks); // // disable scan // ucpolicyOpt = SL_SCAN_POLICY(0); sl_WlanPolicySet(SL_POLICY_SCAN , ucpolicyOpt, NULL, 0); return network_count; }
//***************************************************************************** // //! \brief Connecting to a WLAN Accesspoint using SmartConfig provisioning //! //! Enables SmartConfig provisioning for adding a new connection profile //! to CC3200. Since we have set the connection policy to Auto, once //! SmartConfig is complete, CC3200 will connect automatically to the new //! connection profile added by smartConfig. //! //! \param[in] None //! //! \return None //! //! \note //! //! \warning If the WLAN connection fails or we don't //! acquire an IP address, We will be stuck in this //! function forever. // //***************************************************************************** int SmartConfigConnect() { unsigned char policyVal; long lRetVal = -1; // Clear all profiles // This is of course not a must, it is used in this example to make sure // we will connect to the new profile added by SmartConfig // lRetVal = sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES); ASSERT_ON_ERROR(lRetVal); //set AUTO policy lRetVal = sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,1), &policyVal, 1 /*PolicyValLen*/); ASSERT_ON_ERROR(lRetVal); // Start SmartConfig // This example uses the unsecured SmartConfig method // lRetVal = sl_WlanSmartConfigStart(0, /*groupIdBitmask*/ SMART_CONFIG_CIPHER_NONE, /*cipher*/ 0, /*publicKeyLen*/ 0, /*group1KeyLen*/ 0, /*group2KeyLen */ NULL, /*publicKey */ NULL, /*group1Key */ NULL); /*group2Key*/ ASSERT_ON_ERROR(lRetVal); // Wait for WLAN Event while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { _SlNonOsMainLoopTask(); } // // Turn ON the RED LED to indicate connection success // GPIO_IF_LedOn(MCU_RED_LED_GPIO); //wait for few moments MAP_UtilsDelay(80000000); //reset to default AUTO policy lRetVal = sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); ASSERT_ON_ERROR(lRetVal); return SUCCESS; }
/*! \brief Connecting to a WLAN Accesspoint using SmartConfig provisioning This function enables SmartConfig provisioning for adding a new connection profile to CC3100. Since we have set the connection policy to Auto, once SmartConfig is complete, CC3100 will connect automatically to the new connection profile added by smartConfig. \param[in] None \return None \note \warning If the WLAN connection fails or we don't acquire an IP address, We will be stuck in this function forever. */ void SmartConfigConnect() { unsigned char policyVal; /* Clear all profiles */ /* This is of course not a must, it is used in this example to make sure * we will connect to the new profile added by SmartConfig */ sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES); //set AUTO policy sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); /* Start SmartConfig * This example uses the unsecured SmartConfig method */ sl_WlanSmartConfigStart(0, //groupIdBitmask SMART_CONFIG_CIPHER_NONE, //cipher 0, //publicKeyLen 0, //group1KeyLen 0, //group2KeyLen NULL, //publicKey NULL, //group1Key NULL); //group2Key }
int WiFiClass::begin() { int8_t name[32]; int16_t NameLen; if(_connecting) { delay(500); return status(); } bool init_success = init(); if (!init_success) { return WL_CONNECT_FAILED; } int16_t ret = sl_WlanProfileGet(0, name, (short int*)&NameLen, NULL, NULL, NULL, NULL); if(ret < 0) { return WL_CONNECT_FAILED; } sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,1,0,0,0), 0, 0); _connecting = true; return WL_IDLE_STATUS; }
/*! \brief Connecting to a WLAN Accesspoint using SmartConfig provisioning This function enables SmartConfig provisioning for adding a new connection profile to CC3100. Since we have set the connection policy to Auto, once SmartConfig is complete, CC3100 will connect automatically to the new connection profile added by smartConfig. \param[in] None \return None \note \warning If the WLAN connection fails or we don't acquire an IP address, We will be stuck in this function forever. */ void SmartConfigConnect() { unsigned char policyVal; //set AUTO policy sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); /* Start SmartConfig * This example uses the unsecured SmartConfig method */ sl_WlanSmartConfigStart(0, //groupIdBitmask SMART_CONFIG_CIPHER_NONE, //cipher 0, //publicKeyLen 0, //group1KeyLen 0, //group2KeyLen NULL, //publicKey NULL, //group1Key NULL); //group2Key }
//!!Ignore key index!!// int WiFiClass::begin(char* ssid, uint8_t key_idx, char* key) { // // If we already called begin and are already connecting // then return the status. This prevents sl_WlanConnect() // from being called repeatedly. // if(_connecting) { delay(500); return status(); } // //initialize the simplelink driver and make sure it was a success // bool init_success = WiFiClass::init(); if (!init_success) { return WL_CONNECT_FAILED; } sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES); // // Set IP address configuration to DHCP if needed // setIpDefaults(); sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,1,0,0,0), 0, 0); // //get name length and set security type to WEP //add key and keylength to security parameters // int NameLen = strlen(ssid); SlSecParams_t SecParams = {0}; SecParams.Type = SL_SEC_TYPE_WEP; SecParams.Key = (signed char *)key; SecParams.KeyLen = strlen(key); // //Connect to the access point (non enterprise, so 5th argument is NULL); //also mac address parameter set as null (3rd argument) // int iRet = sl_WlanConnect((signed char*)ssid, NameLen, NULL, &SecParams, NULL); // //return appropriate status as described by arduino wifi library //the WiFiClass:WiFi_status is handled by the WlanEvenHandler //in SimpleLinkCallbacks.cpp. However, if iRet < 0, there was an error // if (iRet == 0) { sl_WlanProfileAdd((signed char*)ssid, NameLen, 0, &SecParams, 0, 6, 0); _connecting = true; return status(); } else { return WL_CONNECT_FAILED; } }
void wlan_configure() { sl_Start(NULL, NULL, NULL); // // reset all network policies // unsigned char ucpolicyVal; int ret; ret = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), &ucpolicyVal, 1 /*PolicyValLen*/); if(ret < 0) { LOOP_FOREVER(); } sl_WlanSetMode(ROLE_STA); sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); sl_WlanProfileDel(0xFF); sl_WlanDisconnect(); _WlanRxFilterOperationCommandBuff_t RxFilterIdMask;// = {0}; memset(&RxFilterIdMask, 0, sizeof(RxFilterIdMask)); unsigned char ucVal = 0; unsigned char ucConfigOpt = 0; // Enable DHCP client sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal); // Disable scan ucConfigOpt = SL_SCAN_POLICY(0); sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0); // Set Tx power level for station mode // Number between 0-15, as dB offset from max power - 0 will set max power unsigned char ucPower = 0; sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower); // Set PM policy to normal sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); // Unregister mDNS services sl_NetAppMDNSUnRegisterService(0, 0); // Remove all 64 filters (8*8) memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); sl_Stop(SL_STOP_TIMEOUT); }
static int ensure_role_sta() { if (s_current_role == ROLE_STA) return 1; if (sl_WlanSetMode(ROLE_STA) != 0) return 0; if (!restart_nwp()) return 0; _u32 scan_interval = WIFI_SCAN_INTERVAL_SECONDS; sl_WlanPolicySet(SL_POLICY_SCAN, 1 /* enable */, (_u8 *) &scan_interval, sizeof(scan_interval)); return 1; }
int WiFiClass::startSmartConfig() { unsigned char policyVal; if (!_initialized) { init(); } if (sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,1), &policyVal, 1 /*PolicyValLen*/) < 0) { return -1; } if (sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES) < 0) { return -1; } sl_WlanSmartConfigStart(0, //groupIdBitmask SMART_CONFIG_CIPHER_NONE, //cipher 0, //publicKeyLen 0, //group1KeyLen 0, //group2KeyLen NULL, //publicKey NULL, //group1Key NULL); //group2Key /* Block until connected */ while (WiFi.status() != WL_CONNECTED) { #ifndef SL_PLATFORM_MULTI_THREADED // TODO: this call appears unnecessary: status() already calls sl_Task sl_Task(); #else // TODO: is 10 appropriate? to save power, shouldn't we always delay? delay(10); #endif } if (sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/) < 0) { return -1; } return (0); }
static void wlan_scan() { unsigned char ucpolicyOpt; union { unsigned char ucPolicy[4]; unsigned int uiPolicyLen; } policyVal; ucpolicyOpt = SL_CONNECTION_POLICY(0, 0, 0, 0,0); sl_WlanPolicySet(SL_POLICY_CONNECTION , ucpolicyOpt, NULL, 0); ucpolicyOpt = SL_SCAN_POLICY(1); policyVal.uiPolicyLen = 10; sl_WlanPolicySet(SL_POLICY_SCAN , ucpolicyOpt, (unsigned char*)(policyVal.ucPolicy), sizeof(policyVal)); MAP_UtilsDelay(8000000); Sl_WlanNetworkEntry_t netEntries[10]; _i16 resultsCount = sl_WlanGetNetworkList(0,10,&netEntries[0]); for (int i=0; i< resultsCount; i++) UART_PRINT("ssid: %s\trssi: %d\tsec-t: %u\r\n",netEntries[i].ssid, netEntries[i].rssi, netEntries[i].sec_type); }
//***************************************************************************** // //! \brief This function Get the Scan Result //! //! \param[in] none //! //! \return Size of Scan Result Array //! //! \note //! // //***************************************************************************** int GetScanResult(Sl_WlanNetworkEntry_t* netEntries ) { UINT8 policyOpt; UINT32 IntervalVal = 60; int retVal; policyOpt = SL_CONNECTION_POLICY(0, 0, 0, 0, 0); retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , policyOpt, NULL, 0); if(retVal < 0) { /* Error */ } // enable scan policyOpt = SL_SCAN_POLICY(1); // set scan policy - this starts the scan retVal = sl_WlanPolicySet(SL_POLICY_SCAN , policyOpt, (UINT8 *)(IntervalVal), sizeof(IntervalVal)); // delay 1 second to verify scan is started osi_Sleep(1000); // retVal indicates the valid number of entries // The scan results are occupied in netEntries[] retVal = sl_WlanGetNetworkList(0, SCAN_TABLE_SIZE, netEntries); // Disable scan policyOpt = SL_SCAN_POLICY(0); // set scan policy - this stops the scan sl_WlanPolicySet(SL_POLICY_SCAN , policyOpt, (UINT8 *)(IntervalVal), sizeof(IntervalVal)); return retVal; }
STATIC mp_obj_t wlan_scan(mp_obj_t self_in) { STATIC const qstr wlan_scan_info_fields[] = { MP_QSTR_ssid, MP_QSTR_bssid, MP_QSTR_sec, MP_QSTR_channel, MP_QSTR_rssi }; // check for correct wlan mode if (wlan_obj.mode == ROLE_AP) { mp_raise_OSError(MP_EPERM); } Sl_WlanNetworkEntry_t wlanEntry; mp_obj_t nets = mp_obj_new_list(0, NULL); uint8_t _index = 0; // trigger a new network scan uint32_t scanSeconds = MODWLAN_SCAN_PERIOD_S; ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_SCAN , MODWLAN_SL_SCAN_ENABLE, (_u8 *)&scanSeconds, sizeof(scanSeconds))); // wait for the scan to complete mp_hal_delay_ms(MODWLAN_WAIT_FOR_SCAN_MS); do { if (sl_WlanGetNetworkList(_index++, 1, &wlanEntry) <= 0) { break; } // we must skip any duplicated results if (!wlan_scan_result_is_unique(nets, wlanEntry.bssid)) { continue; } mp_obj_t tuple[5]; tuple[0] = mp_obj_new_str((const char *)wlanEntry.ssid, wlanEntry.ssid_len, false); tuple[1] = mp_obj_new_bytes((const byte *)wlanEntry.bssid, SL_BSSID_LENGTH); // 'normalize' the security type if (wlanEntry.sec_type > 2) { wlanEntry.sec_type = 2; } tuple[2] = mp_obj_new_int(wlanEntry.sec_type); tuple[3] = mp_const_none; tuple[4] = mp_obj_new_int(wlanEntry.rssi); // add the network to the list mp_obj_list_append(nets, mp_obj_new_attrtuple(wlan_scan_info_fields, 5, tuple)); } while (_index < MODWLAN_SL_MAX_NETWORKS); return nets; }
int WiFiClass::startSmartConfig() { unsigned char policyVal; if (!_initialized) { init(); } if(sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,1), &policyVal, 1 /*PolicyValLen*/) < 0) return -1; if(sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES) < 0) return -1; sl_WlanSmartConfigStart(0, //groupIdBitmask SMART_CONFIG_CIPHER_NONE, //cipher 0, //publicKeyLen 0, //group1KeyLen 0, //group2KeyLen NULL, //publicKey NULL, //group1Key NULL); //group2Key /* Block until connected */ uint8_t iCount; while(WiFi.status() != WL_CONNECTED) { _SlNonOsMainLoopTask(); } if(sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/) < 0) return -1; }
//***************************************************************************** // //! \brief Connecting to a WLAN Accesspoint using SmartConfig provisioning //! //! This function enables SmartConfig provisioning for adding a new //! connection profile to CC3200. Since we have set the connection policy //! to Auto, once SmartConfig is complete,CC3200 will connect //! automatically to the new connection profile added by smartConfig. //! //! \param[in] None //! //! \return 0 - Success //! -1 - Failure //! //! \warning If the WLAN connection fails or we don't acquire an //! IP address,We will be stuck in this function forever. //! //***************************************************************************** long SmartConfigConnect() { unsigned char policyVal; long lRetVal = -1; // // Clear all profiles // This is of course not a must, it is used in this example to make sure // we will connect to the new profile added by SmartConfig // lRetVal = sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES); ASSERT_ON_ERROR(lRetVal); //set AUTO policy lRetVal = sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); ASSERT_ON_ERROR(lRetVal); // // Start SmartConfig // This example uses the unsecured SmartConfig method // lRetVal = sl_WlanSmartConfigStart(0, /*groupIdBitmask*/ SMART_CONFIG_CIPHER_NONE, /*cipher*/ 0, /*publicKeyLen*/ 0, /*group1KeyLen*/ 0, /*group2KeyLen */ NULL, /*publicKey */ NULL, /*group1Key */ NULL); /*group2Key*/ ASSERT_ON_ERROR(lRetVal); return SUCCESS; }
/*! \brief Connecting to a WLAN Access point using SmartConfig provisioning This function enables SmartConfig provisioning for adding a new connection profile to CC3100. Since we have set the connection policy to Auto, once SmartConfig is complete, CC3100 will connect automatically to the new connection profile added by smartConfig. \param[in] None \return 0 on success, negative error-code on error \note \warning If the WLAN connection fails or we don't acquire an IP address, We will be stuck in this function forever. */ static _i32 SmartConfigConnect() { _u8 policyVal = 0; _i32 retVal = -1; /* Clear all profiles */ /* This is of course not a must, it is used in this example to make sure * we will connect to the new profile added by SmartConfig */ retVal = sl_WlanProfileDel(WLAN_DEL_ALL_PROFILES); ASSERT_ON_ERROR(retVal); /* set AUTO policy */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 0), &policyVal, 1); /*PolicyValLen*/ ASSERT_ON_ERROR(retVal); /* Start SmartConfig * This example uses the unsecured SmartConfig method */ retVal = sl_WlanSmartConfigStart(0, /* groupIdBitmask */ SMART_CONFIG_CIPHER_NONE, /* cipher */ 0, /* publicKeyLen */ 0, /* group1KeyLen */ 0, /* group2KeyLen */ (const _u8 *)"", /* publicKey */ (const _u8 *)"", /* group1Key */ (const _u8 *)""); /* group2Key */ ASSERT_ON_ERROR(retVal); /* Wait */ while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } return SUCCESS; }
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(); } }
//***************************************************************************** //! \brief This function puts the device in its default state. It: //! - Set the mode to STATION //! - Configures connection policy to Auto and AutoSmartConfig //! - Deletes all the stored profiles //! - Enables DHCP //! - Disables Scan policy //! - Sets Tx power to maximum //! - Sets power policy to normal //! - Unregister mDNS services //! - Remove all filters //! //! \param none //! \return On success, zero is returned. On error, negative is returned //***************************************************************************** static long ConfigureSimpleLinkToDefaultState() { SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; unsigned char ucVal = 1; unsigned char ucConfigOpt = 0; unsigned char ucConfigLen = 0; unsigned char ucPower = 0; long lRetVal = -1; long lMode = -1; lMode = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lMode); // If the device is not in station-mode, try configuring it in station-mode if (ROLE_STA != lMode) { if (ROLE_AP == lMode) { // If the device is in AP mode, we need to wait for this event // before doing anything while(!IS_IP_ACQUIRED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // Switch to STA role and restart lRetVal = sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Start(0, 0, 0); ASSERT_ON_ERROR(lRetVal); // Check if the device is in station again if (ROLE_STA != lRetVal) { // We don't want to proceed if the device is not coming up in STA-mode return DEVICE_NOT_IN_STATION_MODE; } } // Get the device's version-information ucConfigOpt = SL_DEVICE_GENERAL_VERSION; ucConfigLen = sizeof(ver); lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt, &ucConfigLen, (unsigned char *)(&ver)); ASSERT_ON_ERROR(lRetVal); UART_PRINT("Host Driver Version: %s\n\r",SL_DRIVER_VERSION); UART_PRINT("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n\r", ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3], ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1], ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3], ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1], ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]); // Set connection policy to Auto + SmartConfig // (Device's default connection policy) lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); ASSERT_ON_ERROR(lRetVal); // Remove all profiles lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); // // Device in station-mode. Disconnect previous connection if any // The function returns 0 if 'Disconnected done', negative number if already // disconnected Wait for 'disconnection' event if 0 is returned, Ignore // other return-codes // lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { // Wait while(IS_CONNECTED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } // Enable DHCP client lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal); ASSERT_ON_ERROR(lRetVal); // Disable scan ucConfigOpt = SL_SCAN_POLICY(0); lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0); ASSERT_ON_ERROR(lRetVal); // Set Tx power level for station mode // Number between 0-15, as dB offset from max power - 0 will set max power ucPower = 0; lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower); ASSERT_ON_ERROR(lRetVal); // Set PM policy to normal lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); ASSERT_ON_ERROR(lRetVal); // Unregister mDNS services lRetVal = sl_NetAppMDNSUnRegisterService(0, 0); ASSERT_ON_ERROR(lRetVal); // Remove all 64 filters (8*8) memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); lRetVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(lRetVal); InitializeAppVariables(); return lRetVal; // Success }
/* * Application's entry point */ int main(int argc, char** argv) { SlSecParams_t secParams = {0}; _i32 retVal = -1; retVal = initializeAppVariables(); ASSERT_ON_ERROR(retVal); /* Stop WDT and initialize the system-clock of the MCU */ stopWDT(); initClk(); /* Configure command line interface */ CLI_Configure(); displayBanner(); /* * Following function configures 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 application * * Note that all profiles and persistent settings that were done on the * device will be lost */ retVal = configureSimpleLinkToDefaultState(); if(retVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == retVal) CLI_Write(" Failed to configure the device in its default state \n\r"); LOOP_FOREVER(); } CLI_Write(" Device is configured in default state \n\r"); /* * Initializing the CC3100 device * Assumption is that the device is configured in station mode already * and it is in its default state */ retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } CLI_Write(" Device started as STATION \n\r"); /* Delete all profiles (0xFF) stored and reset policy settings */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(0, 0, 0, 0, 0), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Add unsecured AP profile with priority 6 (7 is highest) */ retVal = sl_WlanProfileAdd((_i8 *)UNSEC_SSID_NAME, pal_Strlen(UNSEC_SSID_NAME), g_BSSID, 0, 0, 6, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Add WPA2 secured AP profile with priority 7 (highest) */ secParams.Type = SL_SEC_TYPE_WPA; secParams.Key = SEC_SSID_KEY; secParams.KeyLen = pal_Strlen(SEC_SSID_KEY); retVal = sl_WlanProfileAdd((_i8 *)SEC_SSID_NAME, pal_Strlen(SEC_SSID_NAME), g_BSSID, &secParams, 0, 7, 0); if(retVal < 0) { LOOP_FOREVER(); } /* * Enable auto connect (connection to stored profiles according to priority) * Connection should first be established to higher (secured) profile as in * this example */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,0,0,0,0), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Wait for the connection to be established */ while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } CLI_Write(" Device connected to the AP using 'auto' connection policy\n\r"); /* Delete all profiles (0xFF) stored */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } g_Status = 0; /* Restart the device */ retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } /* * Set connection policy to Fast - Device will connect to the last connected AP. * This feature can be used to reconnect to AP */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 1, 0, 0, 0), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Connect to the open AP */ retVal = establishConnectionWithAP(); if(retVal < 0) { CLI_Write(" Failed to establish connection w/ an AP \n\r"); LOOP_FOREVER(); } CLI_Write(" Device was connected to the AP using host-driver API \n\r"); g_Status = 0; /* Status variable */ /* Restart the Device */ retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } /* Wait for the connection to be established */ while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } CLI_Write(" Device connected to the AP using 'fast' connection policy\n\r"); /* Delete all profiles (0xFF) stored */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } /* Set Auto SmartConfig policy */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,0,0,0,1), 0, 0); if(retVal < 0) { LOOP_FOREVER(); } /* Restart the Device */ g_Status = 0; retVal = sl_Stop(SL_STOP_TIMEOUT); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_Start(0, 0, 0); if ((retVal < 0) || (ROLE_STA != retVal) ) { CLI_Write(" Failed to start the device \n\r"); LOOP_FOREVER(); } /* * After restarting , device will wait for a command for 2 second and start * the SmartConfig process if no command is received */ CLI_Write(" Device waiting to be connected using SmartConfig technology \n\r"); while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); } CLI_Write(" Device connected to the AP \n\r"); /* * Cleaning all profiles and setting the default connection policy before exiting the application * Set connection policy to Auto + SmartConfig (Device's default connection policy) */ retVal = sl_WlanProfileDel(0xFF); if(retVal < 0) { LOOP_FOREVER(); } retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); if(retVal < 0) { LOOP_FOREVER(); } return 0; }
void sj_wifi_hal_init(struct v7 *v7) { _u32 scan_interval = WIFI_SCAN_INTERVAL_SECONDS; sl_WlanPolicySet(SL_POLICY_SCAN, 1 /* enable */, (_u8 *) &scan_interval, sizeof(scan_interval)); }
//***************************************************************************** // //! \brief the aim of this example code is to demonstrate File-system //! capabilities of the device. //! For simplicity, the serial flash is used as the device under test. //! //! \param None //! //! \return none //! //! \note Green LED is turned solid in case of success //! Red LED is turned solid in case of failure // //***************************************************************************** void main() { long lRetVal; unsigned char policyVal; long lFileHandle; unsigned long ulToken; // // Initialize Board configurations // BoardInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configure LEDs // GPIO_IF_LedConfigure(LED1|LED3); GPIO_IF_LedOff(MCU_RED_LED_GPIO); GPIO_IF_LedOff(MCU_GREEN_LED_GPIO); // // Initializing the CC3200 networking layers // lRetVal = sl_Start(NULL, NULL, NULL); if(lRetVal < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } // // reset all network policies // lRetVal = sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); if(lRetVal < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } if(WriteFileToDevice(&ulToken, &lFileHandle) < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } if(ReadFileFromDevice(ulToken, lFileHandle) < 0) { GPIO_IF_LedOn(MCU_RED_LED_GPIO); LOOP_FOREVER(); } // // turn ON the green LED indicating success // GPIO_IF_LedOn(MCU_GREEN_LED_GPIO); lRetVal = sl_Stop(SL_STOP_TIMEOUT); LOOP_FOREVER(); }
//***************************************************************************** // //! \brief Task Created by main fucntion.This task starts simpleink, set NWP //! power policy, connects to an AP. Give Signal to the other task about //! the connection.wait for the message form the interrupt handlers and //! the other task. Accordingly print the wake up cause from the low //! power modes. //! //! \param pvParameters is a general void pointer (not used here). //! //! \return none // //***************************************************************************** void TimerGPIOTask(void *pvParameters) { cc_hndl tTimerHndl = NULL; cc_hndl tGPIOHndl = NULL; unsigned char ucQueueMsg = 0; unsigned char ucSyncMsg = 0; int iRetVal = 0; // // Displays the Application Banner // DisplayBanner(); // // creating the queue for signalling about connection events // iRetVal = osi_MsgQCreate(&g_tConnection, NULL, sizeof( unsigned char ), 3); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } // // starting the simplelink // iRetVal = sl_Start(NULL, NULL, NULL); if (iRetVal < 0) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(); } // // Swtich to STA mode if device is not // SwitchToStaMode(iRetVal); // // Set the power management policy of NWP // iRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0); if (iRetVal < 0) { UART_PRINT("unable to configure network power policy\n\r"); LOOP_FOREVER(); } // // connecting to the Access Point // if(-1 == WlanConnect()) { sl_Stop(SL_STOP_TIMEOUT); UART_PRINT("Connection to AP failed\n\r"); } else { UART_PRINT("Connected to AP\n\r"); // //signal the other task about the sl start and connection to the AP // iRetVal = osi_MsgQWrite(&g_tConnectionFlag, &ucSyncMsg, OSI_WAIT_FOREVER); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } } // // Queue management related configurations // iRetVal = osi_MsgQCreate(&g_tWkupSignalQueue, NULL, sizeof( unsigned char ), 10); if (iRetVal < 0) { UART_PRINT("unable to create the msg queue\n\r"); LOOP_FOREVER(); } // // setting Timer as one of the wakeup source // tTimerHndl = SetTimerAsWkUp(); // // setting some GPIO as one of the wakeup source // tGPIOHndl = SetGPIOAsWkUp(); /* handles, if required, can be used to stop the timer, but not used here*/ UNUSED(tTimerHndl); UNUSED(tGPIOHndl); // // setting Apps power policy // lp3p0_setup_power_policy(POWER_POLICY_STANDBY); while(FOREVER) { // // waits for the message from the various interrupt handlers(GPIO, // Timer) and the UDPServerTask. // osi_MsgQRead(&g_tWkupSignalQueue, &ucQueueMsg, OSI_WAIT_FOREVER); switch(ucQueueMsg){ case 1: UART_PRINT("timer\n\r"); break; case 2: UART_PRINT("GPIO\n\r"); break; case 3: UART_PRINT("host irq\n\r"); break; default: UART_PRINT("invalid msg\n\r"); break; } } }
//***************************************************************************** // //! 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 This function puts the device in its default state. It: - Set the mode to STATION - Configures connection policy to Auto and AutoSmartConfig - Deletes all the stored profiles - Enables DHCP - Disables Scan policy - Sets Tx power to maximum - Sets power policy to normal - Unregister mDNS services \param[in] none \return On success, zero is returned. On error, negative is returned */ static int32_t configureSimpleLinkToDefaultState(char *pConfig){ SlVersionFull ver = {0}; UINT8 val = 1; UINT8 configOpt = 0; UINT8 configLen = 0; UINT8 power = 0; INT32 retVal = -1; INT32 mode = -1; mode = sl_Start(0, pConfig, 0); /* If the device is not in station-mode, try putting it in station-mode */ if (ROLE_STA != mode){ if (ROLE_AP == mode){ /* If the device is in AP mode, we need to wait for this event before doing anything */ while(!IS_IP_AQUIRED(g_Status)); } /* Switch to STA role and restart */ retVal = sl_WlanSetMode(ROLE_STA); retVal = sl_Stop(0xFF); retVal = sl_Start(0, pConfig, 0); /* Check if the device is in station again */ if (ROLE_STA != retVal){ /* We don't want to proceed if the device is not coming up in station-mode */ return DEVICE_NOT_IN_STATION_MODE; } } /* Get the device's version-information */ configOpt = SL_DEVICE_GENERAL_VERSION; configLen = sizeof(ver); retVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &configOpt, &configLen, (unsigned char *)(&ver)); /* Set connection policy to Auto + SmartConfig (Device's default connection policy) */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); /* Remove all profiles */ retVal = sl_WlanProfileDel(0xFF); /* * Device in station-mode. Disconnect previous connection if any * The function returns 0 if 'Disconnected done', negative number if already disconnected * Wait for 'disconnection' event if 0 is returned, Ignore other return-codes */ retVal = sl_WlanDisconnect(); if(0 == retVal){ /* Wait */ while(IS_CONNECTED(g_Status)); } /* Enable DHCP client*/ retVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&val); /* Disable scan */ configOpt = SL_SCAN_POLICY(0); retVal = sl_WlanPolicySet(SL_POLICY_SCAN , configOpt, NULL, 0); /* Set Tx power level for station mode Number between 0-15, as dB offset from max power - 0 will set maximum power */ power = 0; retVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&power); /* Set PM policy to normal */ retVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); /* TBD - Unregister mDNS services */ retVal = sl_NetAppMDNSUnRegisterService(0, 0); retVal = sl_Stop(0xFF); g_Status = 0; memset(&Recvbuff,0,MAX_RECV_BUFF_SIZE); memset(&SendBuff,0,MAX_SEND_BUFF_SIZE); memset(&HostName,0,MAX_HOSTNAME_SIZE); DestinationIP = 0;; SockID = 0; return retVal; /* Success */ }
//**************************************************************************** // //! \brief Configuring the Connection Policy //! //! This function configures different Connection Policy such as FAST,AUTO,OPEN //! //! \param[in] None //! //! \return 0 on success else error code //! //! \note // //**************************************************************************** static long SetConnectionPolicy() { unsigned char policyVal; long lRetVal = -1; /* Clear all stored profiles and reset the policies */ lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), 0, 0); ASSERT_ON_ERROR(lRetVal); //Add Profile /* user needs to change SSID_NAME = "<Secured AP>" SECURITY_TYPE = SL_SEC_TYPE_WPA SECURITY_KEY = "<password>" and set the priority as per requirement to connect with a secured AP */ SlSecParams_t secParams; secParams.Key = SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanProfileAdd(SSID_NAME,strlen(SSID_NAME),0,&secParams,0,1,0); ASSERT_ON_ERROR(lRetVal); //set AUTO policy lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); ASSERT_ON_ERROR(lRetVal); //wait until IP is acquired while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { _SlNonOsMainLoopTask(); } CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); // // ****** Put breakpoint here ****** // If control comes here- means device connected to AP in auto mode // // Disconnect from AP lRetVal = sl_WlanDisconnect(); if(0 == lRetVal) { // Wait while(IS_CONNECTED(g_ulStatus)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } //delete profiles lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); //set Auto SmartConfig policy lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1,0,0,0,1), &policyVal,0); ASSERT_ON_ERROR(lRetVal); // reset the NWP lRetVal = ResetNwp(); ASSERT_ON_ERROR(lRetVal); // wait for smart config to complete and device to connect to an AP //wait until IP is acquired while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { _SlNonOsMainLoopTask(); } CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); // // ****** Put breakpoint here ****** // If control comes here- means device connected to AP in smartconfig mode // /* Delete all profiles (0xFF) stored */ lRetVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(lRetVal); // reset the NWP lRetVal = ResetNwp(); ASSERT_ON_ERROR(lRetVal); /* Set connection policy to Fast, Device will connect to last connected AP. * This feature can be used to reconnect to AP */ lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION , \ SL_CONNECTION_POLICY(1,1,0,0,0), 0, 0); ASSERT_ON_ERROR(lRetVal); /* Connect to the open AP */ lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, 0, 0); ASSERT_ON_ERROR(lRetVal); //wait until IP is acquired while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { _SlNonOsMainLoopTask(); } CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION); CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED); // Add unsecured AP profile with priority 6 (7 is highest) // Because of a limitation in SDK-0.5 which prevents the automatic addition // of the profile (fast), the application is required to explicitly add it. // The limitation shall be addressed in subsequent SDK release, and the below // lines for adding the profile can be removed then...! secParams.Key = ""; secParams.KeyLen = 0; secParams.Type = SL_SEC_TYPE_OPEN; lRetVal = sl_WlanProfileAdd((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0, 6, 0); ASSERT_ON_ERROR(lRetVal); // reset the NWP lRetVal = ResetNwp(); ASSERT_ON_ERROR(lRetVal); /* Wait for the connection to be established */ while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) { _SlNonOsMainLoopTask(); } // // ****** Put breakpoint here ****** // If control comes here- means device connected to AP in FAST mode // //remove all policies lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), &policyVal,0); ASSERT_ON_ERROR(lRetVal); return SUCCESS; }
void Task_WifiScan(void* params) { (void)params; //avoid unused error long retval; unsigned char policy; unsigned int policy_len; LOG(LOG_VERBOSE, "Starting WiFi network scan..."); SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_SCANNING); if(WifiDefaultSettings() == RET_FAILURE) { goto error; } retval = sl_Start(0,0,0); if(retval<0) { goto error; } //first, delete current connection policy policy = SL_CONNECTION_POLICY(0,0,0,0,0); retval = sl_WlanPolicySet(SL_POLICY_CONNECTION, policy, NULL, 0); if(retval<0) { goto error; } //make scan policy policy = SL_SCAN_POLICY(1); policy_len = WIFI_SCAN_TIME_S; retval = sl_WlanPolicySet(SL_POLICY_SCAN, policy, (unsigned char*)&policy_len, sizeof(policy_len)); if(retval<0) { goto error; } //wait for the scan to complete const TickType_t delay = (1100*WIFI_SCAN_TIME_S) / portTICK_PERIOD_MS; vTaskDelay(delay); //get the results back unsigned char index = 0; retval = sl_WlanGetNetworkList(index, (unsigned char)WIFI_NUM_NETWORKS, &(wifi_state.networks[index])); //retval holds the number of networks now, and they are saved in the state. //disable the scan policy = SL_SCAN_POLICY(0); retval = sl_WlanPolicySet(SL_POLICY_SCAN, policy, NULL, 0); if(retval<0) { goto error; } //disable SimpleLink altogether retval = sl_Stop(SL_STOP_TIMEOUT); if(retval<0) { goto error; } LOG(LOG_VERBOSE, "WiFi network scan complete."); ClearLED(LED_1); #ifdef DO_STACK_CHECK wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL); #endif //exit (delete this task) WifiTaskEndCallback(&Task_WifiScan); vTaskDelete(NULL); return; error: SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_FAILED); TASK_RETURN_ERROR(ERROR_UNKNOWN, "WIFI scan fail"); return; }
static int WifiDefaultSettings(void) { long retval = -1; unsigned char val = 1; unsigned char config, config_len; //filters _WlanRxFilterOperationCommandBuff_t filter_mask = { .Padding = {0} }; //initialize the SimpleLink API retval = sl_Start(0,0,0); if(retval < 0) { RETURN_ERROR(ERROR_UNKNOWN, "SL start fail"); } //set device in station mode if(retval != ROLE_STA) { if(retval == ROLE_AP) { //we need to wait for an event before doing anything while(!IS_IP_ACQUIRED(wifi_state.status)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } //change mode to Station retval = sl_WlanSetMode(ROLE_STA); if(retval < 0) { RETURN_ERROR(ERROR_UNKNOWN, "WLAN mode fail"); } //restart retval = sl_Stop(0xFF); if(retval < 0) { RETURN_ERROR(ERROR_UNKNOWN, "SL stop fail"); } retval = sl_Start(0,0,0); if(retval < 0) { RETURN_ERROR(ERROR_UNKNOWN, "SL start fail"); } if(retval != ROLE_STA) { RETURN_ERROR(ERROR_UNKNOWN, "WLAN mode fail"); } } //get SimpleLink version config = SL_DEVICE_GENERAL_VERSION; config_len = sizeof(SlVersionFull); retval = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &config, &config_len, (unsigned char*)&wifi_state.version); if(retval<0) { RETURN_ERROR(retval, "WIFI conf fail"); } //default connection policy retval = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 0), NULL, 0); if(retval<0) { RETURN_ERROR(retval, "WIFI policy fail"); } //disconnect retval = sl_WlanDisconnect(); if(retval == 0) { //not yet disconnected while(IS_CONNECTED(wifi_state.status)) { #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif } } //Enable DHCP client retval = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&val); if(retval<0) { RETURN_ERROR(retval, "WIFI conf fail"); } //Disable scan policy config = SL_SCAN_POLICY(0); retval = sl_WlanPolicySet(SL_POLICY_SCAN, config, NULL, 0); if(retval<0) { RETURN_ERROR(retval, "WIFI policy fail"); } //Set Tx power level for station mode //Number between 0-15, as dB offset from max power - 0 will set max power val = 0; retval = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&val); if(retval<0) { RETURN_ERROR(retval, "WIFI set fail"); } // Set PM policy to normal retval = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); if(retval<0) { RETURN_ERROR(retval, "WIFI policy fail"); } // Unregister mDNS services retval = sl_NetAppMDNSUnRegisterService(0, 0); if(retval<0) { RETURN_ERROR(retval, "mDNS fail"); } //Set mDNS device hostname char hostname[64]; char macstring[20]; unsigned char maclen = SL_MAC_ADDR_LEN; retval = sl_NetCfgGet(SL_MAC_ADDRESS_GET, NULL, &maclen, wifi_state.mac); if(retval < 0) { RETURN_ERROR(retval, "WIFI conf fail"); } snprintf(macstring, 20, "%02X%02X%02X%02X%02X%02X", wifi_state.mac[0], wifi_state.mac[1], wifi_state.mac[2], wifi_state.mac[3], wifi_state.mac[4], wifi_state.mac[5]); snprintf(hostname, 64, "LeashDebugger%s", macstring); retval = sl_NetAppSet (SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, strlen((const char *)hostname), (unsigned char *) hostname); // Remove all 64 filters (8*8) memset(filter_mask.FilterIdMask, 0xFF, 8); retval = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (uint8_t*)&filter_mask, sizeof(_WlanRxFilterOperationCommandBuff_t)); if(retval<0) { RETURN_ERROR(retval, "WIFI filter fail"); } retval = sl_Stop(SL_STOP_TIMEOUT); if(retval < 0) { RETURN_ERROR(ERROR_UNKNOWN, "SL stop fail"); } wifi_state.status = 0; return RET_SUCCESS; }
/*! \brief This function puts the device in its default state. It: - Set the mode to STATION - Configures connection policy to Auto and AutoSmartConfig - Deletes all the stored profiles - Enables DHCP - Disables Scan policy - Sets Tx power to maximum - Sets power policy to normal - Unregister mDNS services - Remove all filters \param[in] none \return On success, zero is returned. On error, negative is returned */ static _i32 configureSimpleLinkToDefaultState(_i8 *pConfig) { SlVersionFull ver = {0}; _WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0}; _u8 val = 1; _u8 configOpt = 0; _u8 configLen = 0; _u8 power = 0; _i32 retVal = -1; _i32 mode = -1; mode = sl_Start(0, pConfig, 0); ASSERT_ON_ERROR(mode); /* If the device is not in station-mode, try configuring it in station-mode */ if (ROLE_STA != mode) { if (ROLE_AP == mode) { /* If the device is in AP mode, we need to wait for this event before doing anything */ while(!IS_IP_ACQUIRED(g_Status)); } /* Switch to STA role and restart */ retVal = sl_WlanSetMode(ROLE_STA); ASSERT_ON_ERROR(retVal); retVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(retVal); retVal = sl_Start(0, pConfig, 0); ASSERT_ON_ERROR(retVal); /* Check if the device is in station again */ if (ROLE_STA != retVal) { /* We don't want to proceed if the device is not coming up in station-mode */ ASSERT_ON_ERROR(DEVICE_NOT_IN_STATION_MODE); } } /* Get the device's version-information */ configOpt = SL_DEVICE_GENERAL_VERSION; configLen = sizeof(ver); retVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &configOpt, &configLen, (_u8 *)(&ver)); ASSERT_ON_ERROR(retVal); printf("Host Driver Version: %s\n",SL_DRIVER_VERSION); printf("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n", ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3], ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1], ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3], ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1], ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]); /* Set connection policy to Auto + SmartConfig (Device's default connection policy) */ retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0); ASSERT_ON_ERROR(retVal); /* Remove all profiles */ retVal = sl_WlanProfileDel(0xFF); ASSERT_ON_ERROR(retVal); /* * Device in station-mode. Disconnect previous connection if any * The function returns 0 if 'Disconnected done', negative number if already disconnected * Wait for 'disconnection' event if 0 is returned, Ignore other return-codes */ retVal = sl_WlanDisconnect(); if(0 == retVal) { /* Wait */ while(IS_CONNECTED(g_Status)); } /* Enable DHCP client*/ retVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&val); ASSERT_ON_ERROR(retVal); /* Disable scan */ configOpt = SL_SCAN_POLICY(0); retVal = sl_WlanPolicySet(SL_POLICY_SCAN , configOpt, NULL, 0); ASSERT_ON_ERROR(retVal); /* Set Tx power level for station mode Number between 0-15, as dB offset from max power - 0 will set maximum power */ power = 0; retVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (_u8 *)&power); ASSERT_ON_ERROR(retVal); /* Set PM policy to normal */ retVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0); ASSERT_ON_ERROR(retVal); /* Unregister mDNS services */ retVal = sl_NetAppMDNSUnRegisterService(0, 0); ASSERT_ON_ERROR(retVal); /* Remove all 64 filters (8*8) */ memset(RxFilterIdMask.FilterIdMask, 0xFF, 8); retVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)); ASSERT_ON_ERROR(retVal); retVal = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(retVal); retVal = initializeAppVariables(); ASSERT_ON_ERROR(retVal); return retVal; /* Success */ }
int main() { UserIn User; int iFlag = 1; long lRetVal = -1; char cChar; unsigned char policyVal; // // Initialize Board configuration // BoardInit(); // // //Pin muxing // PinMuxConfig(); // Configuring UART // InitTerm(); DisplayBanner(APPLICATION_NAME); 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"); CLR_STATUS_BIT_ALL(g_ulStatus); // // 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 all network policies // lRetVal = sl_WlanPolicySet( SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(0,0,0,0,0), &policyVal, 1 /*PolicyValLen*/); if (lRetVal < 0) { UART_PRINT("Failed to set policy \n\r"); LOOP_FOREVER(); } while (iFlag) { User = UserInput(); switch(User.choice) { case(1): /*******An example of Tx continuous on user selected channel, rate 11, * user selected number of packets, minimal delay between packets*******/ lRetVal = Tx_continuous(User.channel,User.rate,User.packets, \ User.Txpower,0); if(lRetVal < 0) { UART_PRINT("Error during transmission of raw data\n\r"); LOOP_FOREVER(); } break; case(2): /******An example of Rx statistics using user selected channel *******/ lRetVal = RxStatisticsCollect(); if(lRetVal < 0) { UART_PRINT("Error while collecting statistics data\n\r"); LOOP_FOREVER(); } break; } UART_PRINT("\n\rEnter \"1\" to restart or \"0\" to quit: "); // // Wait to receive a character over UART // cChar = MAP_UARTCharGet(CONSOLE); // // Echo the received character // MAP_UARTCharPut(CONSOLE, cChar); UART_PRINT("\n\r"); iFlag = atoi(&cChar); } UART_PRINT("\r\nEnding the application...."); // // power off network processor // lRetVal = sl_Stop(SL_STOP_TIMEOUT); LOOP_FOREVER(); }