Beispiel #1
0
//--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)
    {
        sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,1,0,0,0), 0, 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), (unsigned char *)(policyVal.ucPolicy), sizeof(policyVal));
    if(iRet != 0)
    {
        sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,1,0,0,0), 0, 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);
    sl_WlanPolicySet(SL_POLICY_CONNECTION , SL_CONNECTION_POLICY(1,1,0,0,0), 0, 0);
    
    return network_count;
    
}
Beispiel #2
0
//*****************************************************************************
//
//! \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;
}
Beispiel #3
0
/*!
    \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
        
        

}
Beispiel #4
0
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;

}
Beispiel #5
0
/*!
    \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
        
        

}
Beispiel #6
0
//!!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);
}
Beispiel #8
0
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;
}
Beispiel #9
0
Datei: main.c Projekt: dlugaz/All
//*****************************************************************************
//
//! 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;
}
Beispiel #10
0
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);
}
Beispiel #11
0
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;
}
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);
}
Beispiel #13
0
/*!
    \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;
}
Beispiel #14
0
//*****************************************************************************
//
//!   \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;

}
Beispiel #15
0
//*****************************************************************************
//
//! \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;

}
Beispiel #16
0
//*****************************************************************************
//
//! Task implementing MQTT client communication to other web client through
//!    a broker
//!
//! \param  none
//!
//! This function
//!    1. Initializes network driver and connects to the default AP
//!    2. Initializes the mqtt library and set up MQTT connection configurations
//!    3. set up the button events and their callbacks(for publishing)
//!    4. handles the callback signals
//!
//! \return None
//!
//*****************************************************************************
void MqttClient(void *pvParameters)
{
    
    long lRetVal = -1;
    int iCount = 0;
    int iNumBroker = 0;
    int iConnBroker = 0;
    event_msg RecvQue;
    unsigned char policyVal;
    
    connect_config *local_con_conf = (connect_config *)app_hndl;

    //
    // Configure LED
    //
    GPIO_IF_LedConfigure(LED1|LED2|LED3);

    GPIO_IF_LedOff(MCU_RED_LED_GPIO);
    GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);

    //
    // Reset The state of the machine
    //
    Network_IF_ResetMCUStateMachine();

    //
    // Start the driver
    //
    lRetVal = Network_IF_InitDriver(ROLE_STA);
    if(lRetVal < 0)
    {
       UART_PRINT("Failed to start SimpleLink Device\n\r",lRetVal);
       LOOP_FOREVER();
    }

    // switch on Green LED to indicate Simplelink is properly up
    GPIO_IF_LedOn(MCU_ON_IND);

    // Start Timer to blink Red LED till AP connection
    LedTimerConfigNStart();

    // Initialize AP security params
    SecurityParams.Key = (signed char *)SECURITY_KEY;
    SecurityParams.KeyLen = strlen(SECURITY_KEY);
    SecurityParams.Type = SECURITY_TYPE;

    //
    // Connect to the Access Point
    //
    lRetVal = Network_IF_ConnectAP(SSID_NAME, SecurityParams);
    if(lRetVal < 0)
    {
       UART_PRINT("Connection to an AP failed\n\r");
       LOOP_FOREVER();
    }

    lRetVal = sl_WlanProfileAdd(SSID_NAME,strlen(SSID_NAME),0,&SecurityParams,0,1,0);

    //set AUTO policy
    lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                      SL_CONNECTION_POLICY(1,0,0,0,0),
                      &policyVal, 1 /*PolicyValLen*/);    
    
    //
    // Disable the LED blinking Timer as Device is connected to AP
    //
    LedTimerDeinitStop();

    //
    // Switch ON RED LED to indicate that Device acquired an IP
    //
    GPIO_IF_LedOn(MCU_IP_ALLOC_IND);

    UtilsDelay(20000000);

    GPIO_IF_LedOff(MCU_RED_LED_GPIO);
    GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO);
    GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
   
    //
    // Register Push Button Handlers
    //
    Button_IF_Init(pushButtonInterruptHandler2,pushButtonInterruptHandler3);
    
    //
    // Initialze MQTT client lib
    //
    lRetVal = sl_ExtLib_MqttClientInit(&Mqtt_Client);
    if(lRetVal != 0)
    {
        // lib initialization failed
        UART_PRINT("MQTT Client lib initialization failed\n\r");
        LOOP_FOREVER();
    }
    
    /******************* connection to the broker ***************************/
    iNumBroker = sizeof(usr_connect_config)/sizeof(connect_config);
    if(iNumBroker > MAX_BROKER_CONN)
    {
        UART_PRINT("Num of brokers are more then max num of brokers\n\r");
        LOOP_FOREVER();
    }

connect_to_broker:
    while(iCount < iNumBroker)
    {
        //create client context
        local_con_conf[iCount].clt_ctx =
        sl_ExtLib_MqttClientCtxCreate(&local_con_conf[iCount].broker_config,
                                      &local_con_conf[iCount].CallBAcks,
                                      &(local_con_conf[iCount]));

        //
        // Set Client ID
        //
        sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
                            SL_MQTT_PARAM_CLIENT_ID,
                            local_con_conf[iCount].client_id,
                            strlen((char*)(local_con_conf[iCount].client_id)));

        //
        // Set will Params
        //
        if(local_con_conf[iCount].will_params.will_topic != NULL)
        {
            sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
                                    SL_MQTT_PARAM_WILL_PARAM,
                                    &(local_con_conf[iCount].will_params),
                                    sizeof(SlMqttWill_t));
        }

        //
        // setting username and password
        //
        if(local_con_conf[iCount].usr_name != NULL)
        {
            sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
                                SL_MQTT_PARAM_USER_NAME,
                                local_con_conf[iCount].usr_name,
                                strlen((char*)local_con_conf[iCount].usr_name));

            if(local_con_conf[iCount].usr_pwd != NULL)
            {
                sl_ExtLib_MqttClientSet((void*)local_con_conf[iCount].clt_ctx,
                                SL_MQTT_PARAM_PASS_WORD,
                                local_con_conf[iCount].usr_pwd,
                                strlen((char*)local_con_conf[iCount].usr_pwd));
            }
        }

        //
        // connectin to the broker
        //
        if((sl_ExtLib_MqttClientConnect((void*)local_con_conf[iCount].clt_ctx,
                            local_con_conf[iCount].is_clean,
                            local_con_conf[iCount].keep_alive_time) & 0xFF) != 0)
        {
            UART_PRINT("\n\rBroker connect fail for conn no. %d \n\r",iCount+1);
            
            //delete the context for this connection
            sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);
            
            break;
        }
        else
        {
            UART_PRINT("\n\rSuccess: conn to Broker no. %d\n\r ", iCount+1);
            local_con_conf[iCount].is_connected = true;
            iConnBroker++;
        }

        //
        // Subscribe to topics
        //

        if(sl_ExtLib_MqttClientSub((void*)local_con_conf[iCount].clt_ctx,
                                   local_con_conf[iCount].topic,
                                   local_con_conf[iCount].qos, TOPIC_COUNT) < 0)
        {
            UART_PRINT("\n\r Subscription Error for conn no. %d\n\r", iCount+1);
            UART_PRINT("Disconnecting from the broker\r\n");
            sl_ExtLib_MqttClientDisconnect(local_con_conf[iCount].clt_ctx);
            local_con_conf[iCount].is_connected = false;
            
            //delete the context for this connection
            sl_ExtLib_MqttClientCtxDelete(local_con_conf[iCount].clt_ctx);
            iConnBroker--;
            break;
        }
        else
        {
            int iSub;
            UART_PRINT("Client subscribed on following topics:\n\r");
            for(iSub = 0; iSub < local_con_conf[iCount].num_topics; iSub++)
            {
                UART_PRINT("%s\n\r", local_con_conf[iCount].topic[iSub]);
            }
        }
        iCount++;
    }

    if(iConnBroker < 1)
    {
        //
        // no succesful connection to broker
        //
        goto end;
    }

    iCount = 0;

    for(;;)
    {
        osi_MsgQRead( &g_PBQueue, &RecvQue, OSI_WAIT_FOREVER);
        
        if(PUSH_BUTTON_SW2_PRESSED == RecvQue.event)
        {
            Button_IF_EnableInterrupt(SW2);
            //
            // send publish message
            //
            sl_ExtLib_MqttClientSend((void*)local_con_conf[iCount].clt_ctx,
                    pub_topic_sw2,data_sw2,strlen((char*)data_sw2),QOS2,RETAIN);
            UART_PRINT("\n\r CC3200 Publishes the following message \n\r");
            UART_PRINT("Topic: %s\n\r",pub_topic_sw2);
            UART_PRINT("Data: %s\n\r",data_sw2);
        }
        else if(PUSH_BUTTON_SW3_PRESSED == RecvQue.event)
        {
            Button_IF_EnableInterrupt(SW3);
            //
            // send publish message
            //
            sl_ExtLib_MqttClientSend((void*)local_con_conf[iCount].clt_ctx,
                    pub_topic_sw3,data_sw3,strlen((char*)data_sw3),QOS2,RETAIN);
            UART_PRINT("\n\r CC3200 Publishes the following message \n\r");
            UART_PRINT("Topic: %s\n\r",pub_topic_sw3);
            UART_PRINT("Data: %s\n\r",data_sw3);
        }
        else if(BROKER_DISCONNECTION == RecvQue.event)
        {
            iConnBroker--;
            /* Derive the value of the local_con_conf or clt_ctx from the message */
			sl_ExtLib_MqttClientCtxDelete(((connect_config*)(RecvQue.hndl))->clt_ctx);
            
            if(!IS_CONNECTED(g_ulStatus))
            {
                UART_PRINT("device has disconnected from AP \n\r");
                
                UART_PRINT("retry connection to the AP\n\r");
                
                while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
                {
                    osi_Sleep(10);
                }
                goto connect_to_broker;
                
            }
            if(iConnBroker < 1)
            {
                //
                // device not connected to any broker
                //
                goto end;
            }
        }
    }
end:
    //
    // Deinitializating the client library
    //
    sl_ExtLib_MqttClientExit();
    UART_PRINT("\n\r Exiting the Application\n\r");
    
    LOOP_FOREVER();
}
Beispiel #17
0
void initNetwork(signed char *ssid, SlSecParams_t *keyParams) {
    memset(g_ConnectionSSID, 0, sizeof(g_ConnectionSSID));
    memset(g_ConnectionBSSID, 0, sizeof(g_ConnectionBSSID));

    short status = sl_Start(0, 0, 0);
    if (status >= 0) {
        printVersionInfo();

        // disable scan
        unsigned char configOpt = SL_SCAN_POLICY(0);
        sl_WlanPolicySet(SL_POLICY_SCAN, configOpt, NULL, 0);

        // set tx power to maximum
        unsigned char txPower = 0;
        sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&txPower);

        // set power policy to normal
        sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0);

        // remove all rx filters
        _WlanRxFilterOperationCommandBuff_t rxFilterIdMask;
        memset(rxFilterIdMask.FilterIdMask, 0xFF, 8);
        sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (unsigned char *)&rxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t));

        status = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 0), NULL, 0);
    }

    if (status < 0) {
        sl_Stop(SL_STOP_TIMEOUT);
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    if (status < 0) {
        sl_Stop(SL_STOP_TIMEOUT);
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    sl_WlanDisconnect();

    status = sl_WlanSetMode(ROLE_STA);
    if (status < 0) {
        sl_Stop(SL_STOP_TIMEOUT);
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    UART_PRINT("\r\n");
    UART_PRINT("[QuickStart] Network init\r\n");

    status = sl_WlanConnect(ssid, strlen((char *)ssid), NULL, keyParams, NULL);
    if (status < 0) {
        sl_Stop(SL_STOP_TIMEOUT);
        ERR_PRINT(status);
        LOOP_FOREVER();
    }

    while (!IS_IP_ACQUIRED(g_Status)) {
#ifndef SL_PLATFORM_MULTI_THREADED
        _SlNonOsMainLoopTask();
#else
        osi_Sleep(100);
#endif
    }

    sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
}
void wlan_sl_init (int8_t mode, const char *ssid, uint8_t ssid_len, uint8_t auth, const char *key, uint8_t key_len,
                   uint8_t channel, uint8_t antenna, bool add_mac) {

    // stop the servers
    wlan_servers_stop();

    // do a basic start
    wlan_first_start();

    // close any active connections
    wlan_sl_disconnect();

    // Remove all profiles
    ASSERT_ON_ERROR(sl_WlanProfileDel(0xFF));

    // Enable the DHCP client
    uint8_t value = 1;
    ASSERT_ON_ERROR(sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE, 1, 1, &value));

    // Set PM policy to normal
    ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0));

    // Unregister mDNS services
    ASSERT_ON_ERROR(sl_NetAppMDNSUnRegisterService(0, 0));

    // Stop the internal HTTP server
    sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);

    // Remove all 64 filters (8 * 8)
    _WlanRxFilterOperationCommandBuff_t  RxFilterIdMask;
    memset ((void *)&RxFilterIdMask, 0 ,sizeof(RxFilterIdMask));
    memset(RxFilterIdMask.FilterIdMask, 0xFF, 8);
    ASSERT_ON_ERROR(sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask, sizeof(_WlanRxFilterOperationCommandBuff_t)));

#if MICROPY_HW_ANTENNA_DIVERSITY
    // set the antenna type
    wlan_set_antenna (antenna);
#endif

    // switch to the requested mode
    wlan_set_mode(mode);

    // stop and start again (we need to in the propper mode from now on)
    wlan_reenable(mode);

    // Set Tx power level for station or AP mode
    // Number between 0-15, as dB offset from max power - 0 will set max power
    uint8_t ucPower = 0;
    if (mode == ROLE_AP) {
        ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_AP_TX_POWER, sizeof(ucPower),
                                   (unsigned char *)&ucPower));

        // configure all parameters
        wlan_set_ssid (ssid, ssid_len, add_mac);
        wlan_set_security (auth, key, key_len);
        wlan_set_channel (channel);

        // set the country
        _u8*  country = (_u8*)"EU";
        ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_COUNTRY_CODE, 2, country));

        SlNetCfgIpV4Args_t ipV4;
        ipV4.ipV4          = (_u32)SL_IPV4_VAL(192,168,1,1);            // _u32 IP address
        ipV4.ipV4Mask      = (_u32)SL_IPV4_VAL(255,255,255,0);          // _u32 Subnet mask for this AP
        ipV4.ipV4Gateway   = (_u32)SL_IPV4_VAL(192,168,1,1);            // _u32 Default gateway address
        ipV4.ipV4DnsServer = (_u32)SL_IPV4_VAL(192,168,1,1);            // _u32 DNS server address
        ASSERT_ON_ERROR(sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE, IPCONFIG_MODE_ENABLE_IPV4,
                                     sizeof(SlNetCfgIpV4Args_t), (_u8 *)&ipV4));

        SlNetAppDhcpServerBasicOpt_t dhcpParams;
        dhcpParams.lease_time      =  4096;                             // lease time (in seconds) of the IP Address
        dhcpParams.ipv4_addr_start =  SL_IPV4_VAL(192,168,1,2);         // first IP Address for allocation.
        dhcpParams.ipv4_addr_last  =  SL_IPV4_VAL(192,168,1,254);       // last IP Address for allocation.
        ASSERT_ON_ERROR(sl_NetAppStop(SL_NET_APP_DHCP_SERVER_ID));      // Stop DHCP server before settings
        ASSERT_ON_ERROR(sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT,
                                     sizeof(SlNetAppDhcpServerBasicOpt_t), (_u8* )&dhcpParams));  // set parameters
        ASSERT_ON_ERROR(sl_NetAppStart(SL_NET_APP_DHCP_SERVER_ID));     // Start DHCP server with new settings

        // stop and start again
        wlan_reenable(mode);
    } else { // STA and P2P modes
        ASSERT_ON_ERROR(sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER,
                                   sizeof(ucPower), (unsigned char *)&ucPower));
        // set connection policy to Auto + Fast (tries to connect to the last connected AP)
        ASSERT_ON_ERROR(sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 1, 0, 0, 0), NULL, 0));
    }

    // set current time and date (needed to validate certificates)
    wlan_set_current_time (pyb_rtc_get_seconds());

    // start the servers before returning
    wlan_servers_start();
}
Beispiel #19
0
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();
    }
}
Beispiel #20
0
//*****************************************************************************
//
//! 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;
}
Beispiel #21
0
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();

}
Beispiel #22
0
//****************************************************************************
//
//! \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;

}
Beispiel #23
0
//*****************************************************************************
//
//! \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();

}
Beispiel #24
0
/*
 * 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;
}
Beispiel #25
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 */
}
Beispiel #26
0
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;
}
Beispiel #27
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
//!           - 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
}
Beispiel #28
0
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;
}
Beispiel #29
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
           - 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 */
}
Beispiel #30
0
//****************************************************************************
//                            MAIN FUNCTION
//****************************************************************************
int main(void)
{
    long lRetVal;
	char cCmdBuff[20];
	signed char cCmd = APP_SLEEP;

    SlSockAddrIn_t  sAddr;
    SlSockAddrIn_t  sLocalAddr;
    SlSockAddrIn_t  sBrdAddr;
    int             iCounter;
    int             iAddrSize;
    int             iSockID;
    int             iStatus;
    long            lLoopCount = 0;
    short           sTestBufLen;
    struct SlTimeval_t timeVal;

    //
    // Board Initialization
    //
    BoardInit();
    
    //
	// uDMA Initialization
	//
	UDMAInit();
    
    //
    // Configure the pinmux settings for the peripherals exercised
    // Note: pinmux has been modified after the output from pin mux tools
    // to enable sleep clk for the peripherals exercised
    //
    PinMuxConfig();

    //
	// Initialize the platform
	//
	platform_init();

    //
    // Initialise the UART terminal
    //
    InitTerm();

    //
	// Display banner
	//
    DisplayBanner();
    
	//
    // starting the simplelink
    //
	lRetVal = sl_Start(NULL, NULL, NULL);
	if (lRetVal < 0)
	{
		UART_PRINT("Failed to start the device \n\r");
		LOOP_FOREVER();
	}

    //
    // Swtich to STA mode if device is not
    //
    SwitchToStaMode(lRetVal);
    
    //
    // set connection policy
    //
    sl_WlanPolicySet(SL_POLICY_CONNECTION, 
                                SL_CONNECTION_POLICY(0, 0, 0, 0, 0), NULL, 0);
	//
	// Set the power management policy of NWP
	//
	lRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0);

    UART_PRINT("Trying to Connect to AP: %s ...\r\n",SSID_NAME);

    //
    //Connecting to WLAN AP
    //
    lRetVal = WlanConnect();
    if(lRetVal < 0)
    {
        UART_PRINT("Failed to establish connection w/ an AP \n\r");
        LOOP_FOREVER();
    }

    // filling the buffer
    for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++)
    {
        g_cBsdBuf[iCounter] = (char)(iCounter % 10);
    }
    
	sTestBufLen  = BUF_SIZE;
	//filling the UDP server socket address
	sLocalAddr.sin_family = SL_AF_INET;
	sLocalAddr.sin_port = sl_Htons((unsigned short)PORT_NUM);
	sLocalAddr.sin_addr.s_addr = 0;

	//filling the UDP server socket address
	sBrdAddr.sin_family = SL_AF_INET;
	sBrdAddr.sin_port = sl_Htons((unsigned short)PORT_NUM);
	sBrdAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp);

	iAddrSize = sizeof(SlSockAddrIn_t);

	// creating a UDP socket
	iSockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);

    /* setting time out for socket recv */
    timeVal.tv_sec =  5;             // Seconds
    timeVal.tv_usec = 0;             // Microseconds. 10000 microseconds resolution
    sl_SetSockOpt(iSockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal));

    // binding the UDP socket to the UDP server address
    iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize);
    if( iStatus < 0 )
    {
        // error
        sl_Close(iSockID);
        ASSERT_ON_ERROR(iStatus);
    }

	//
	// setting Apps power policy
	//
	lp3p0_setup_power_policy(POWER_POLICY_STANDBY);
    
    UART_PRINT("enter one of the following command:\n\r");
    UART_PRINT("sleep - for putting the system into LPDS mode\n\r");
    UART_PRINT("        GPIO 13 and timer(5 sec) are the wk source configured\n\r");
    UART_PRINT("recv  - for receiving 1000 UDP packets\n\r");
    UART_PRINT("send  - for broadcasting 1000 UDP packets\n\r");
	
    do{
        
		UART_PRINT("cmd#");
		//
		// get cmd over UART
		//
		GetCmd(cCmdBuff, 20);

		//
		// parse the command
		//
		ParseCmd(cCmdBuff, &cCmd);

		if(cCmd == APP_SLEEP)
		{
			//
			// set timer and gpio as wake src
			//
			set_rtc_as_wk_src(WK_LPDS, LPDS_DUR_SEC, false);
			set_gpio_as_wk_src(WK_LPDS, GPIO_SRC_WKUP, PRCM_LPDS_FALL_EDGE);
			cc_idle_task_pm();
		}
		else if(cCmd == APP_RECV)
		{
			lLoopCount = 0;
		    /// waits for 1000 packets from a UDP client
		    while (lLoopCount < g_ulPacketCount)
		    {
		        iStatus = sl_RecvFrom(iSockID, g_cBsdBuf, sTestBufLen, 0,
		                     ( SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize );

				if( iStatus < 0 )
				{
					//error
					break;
				}
				lLoopCount++;
		    }
		    UART_PRINT("Recieved %u packets successfully \n\r",lLoopCount);
		    if(lLoopCount != g_ulPacketCount)
		    {
                if(iStatus == SL_EAGAIN)
                {
                    UART_PRINT("timed out\n\r");
                }
                else
                {
                    UART_PRINT("recv error: %d\n\r", iStatus);
                }
		    }
		}
		else if(cCmd == APP_SEND)
		{
			lLoopCount = 0;
		    // sending 1000 packets to the UDP server
		    while (lLoopCount < g_ulPacketCount)
		    {
		        // sending packet
		        iStatus = sl_SendTo(iSockID, g_cBsdBuf, sTestBufLen, 0,
		                                (SlSockAddr_t *)&sBrdAddr, iAddrSize);
		        if( iStatus <= 0 )
		        {
		            // error
		            UART_PRINT("send error\n\r");
                    break;
		        }
		        lLoopCount++;
		    }
		    UART_PRINT("Sent %u packets successfully\n\r",lLoopCount);
		}
	}while(FOREVER);
}