Exemple #1
0
//****************************************************************************
//
//!  \brief Connecting to a WLAN Accesspoint
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in te form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return       status value
//!
//!   \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    signed long lretVal = 0;

    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lretVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lretVal);

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        // Wait for WLAN Event
#ifndef SL_PLATFORM_MULTI_THREADED
              _SlNonOsMainLoopTask();
#endif

    }

    UNUSED(lretVal);
    return SUCCESS;

}
Exemple #2
0
//*****************************************************************************
//
//! \brief     Starts Smart Configuration
//!
//! \param    none
//!
//! \return void
//! \note
//! \warning
//*****************************************************************************
void SmartConfigTask(void* pValue)
{
    long lRetVal = -1;
    DispatcherUartSendPacket((char*)pucUARTSmartConfigString, 
                             sizeof(pucUARTSmartConfigString));
    
    //Turn off the Network Status LED
    GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
    
    LedTimerConfigNStart();
    
    //Reset the Network Status before Entering Smart Config
    Network_IF_UnsetMCUMachineState(STATUS_BIT_CONNECTION);
    Network_IF_UnsetMCUMachineState(STATUS_BIT_IP_AQUIRED);
    
    lRetVal = SmartConfigConnect();
    if(lRetVal < 0)
    {
        ERR_PRINT(lRetVal);
        LOOP_FOREVER();
    }
    //
    // Wait until IP is acquired
    //
    while (!(IS_CONNECTED(Network_IF_CurrentMCUState())) ||
           !(IS_IP_ACQUIRED(Network_IF_CurrentMCUState())));
    
    LedTimerDeinitStop();
    
    // Red LED on
    GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
    
    //Enable GPIO Interrupt
    Button_IF_EnableInterrupt(SW2);
}
Exemple #3
0
//****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//!
//!  This function connects to the required AP (SSID_NAME) with Security
//!  parameters specified in te form of macros at the top of this file
//!
//! \param  None
//!
//! \return  0 on success else error code 
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
long WlanConnect()
{
   long lRetVal = -1;
   SlSecParams_t secParams;

   secParams.Key = SECURITY_KEY;
   secParams.KeyLen = strlen(SECURITY_KEY);
   secParams.Type = SECURITY_TYPE;

   lRetVal = sl_WlanConnect(SSID_NAME,strlen(SSID_NAME),0,&secParams,0);
   ASSERT_ON_ERROR(lRetVal);
   
   while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
   {
       // Toggle LEDs to Indicate Connection Progress
       GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
       MAP_UtilsDelay(800000);
       GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
       MAP_UtilsDelay(800000);

   }
   //
   // Red LED on to indicate AP connection
   //
   GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
   return SUCCESS;
}
Exemple #4
0
//****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//!
//!  This function connects to the required AP (SSID_NAME) with Security
//!  parameters specified in te form of macros at the top of this file
//!
//! \param  None
//!
//! \return  0 on success else error code
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait for WLAN Event
    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        // Toggle LEDs to Indicate Connection Progress
        _SlNonOsMainLoopTask();
        GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
        MAP_UtilsDelay(800000);
        _SlNonOsMainLoopTask();
        GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
        MAP_UtilsDelay(800000);
    }

    return SUCCESS;

}
static int wlan_connect(const char *ssid, const char *pass, unsigned char sec_type)
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char*)pass;
    secParams.KeyLen = strlen(pass);
    secParams.Type = sec_type;

    lRetVal = sl_WlanConnect((signed char*)ssid, strlen(ssid), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
        _SlNonOsMainLoopTask();   

    SlDateTime_t dateTime= {0};
    dateTime.sl_tm_day =   1;          // Day of month (DD format) range 1-13
    dateTime.sl_tm_mon =   1;          // Month (MM format) in the range of 1-12
    dateTime.sl_tm_year =  1970;       // Year (YYYY format)
    dateTime.sl_tm_hour =  0;          // Hours in the range of 0-23
    dateTime.sl_tm_min =   0;          // Minutes in the range of 0-59
    dateTime.sl_tm_sec =   1;          // Seconds in the range of  0-59

    lRetVal = sl_DevSet(SL_DEVICE_GENERAL_CONFIGURATION, SL_DEVICE_GENERAL_CONFIGURATION_DATE_TIME,
              sizeof(SlDateTime_t),(unsigned char *)(&dateTime));
    ASSERT_ON_ERROR(lRetVal);

    return 0;
}
static int StartSerialSock(unsigned short port, unsigned int slot)
{
    if(!IS_IP_ACQUIRED(wifi_state.status)) {RETURN_ERROR(ERROR_UNKNOWN, "Uninit fail");}
    if(IS_SOCK_STARTED(slot)) {RETURN_ERROR(ERROR_UNKNOWN, "Uninit fail");}

    LOG(LOG_VERBOSE, "Starting socket %d on port %d...", slot, port);

    int retval;

    socket_state[slot].addr_local.sin_family = SL_AF_INET;
    socket_state[slot].addr_local.sin_port = sl_Htons(port);
    socket_state[slot].addr_local.sin_addr.s_addr = 0;

    socket_state[slot].parent_id = sl_Socket(SL_AF_INET, SL_SOCK_STREAM, 0);
    if(socket_state[slot].parent_id < 0) {RETURN_ERROR(socket_state[slot].parent_id, "Socket create fail");}

    retval = sl_Bind(socket_state[slot].parent_id, (SlSockAddr_t*)&(socket_state[slot].addr_local), sizeof(SlSockAddrIn_t));
    if(retval < 0){
        sl_Close(socket_state[slot].parent_id);
        RETURN_ERROR(retval, "Socket bind fail");
    }

    retval = ListenSerialSock(slot);

    LOG(LOG_VERBOSE, "Socket started.");

    socket_state[slot].status = SOCKET_STARTED;
    return RET_SUCCESS;
}
Exemple #7
0
void Task_WifiAP(void* params)
{
    (void)params; //avoid unused warning
    long retval;

    LOG(LOG_IMPORTANT, "Starting WiFi AP Mode.");
    SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_CONNECTING);

    if(WifiDefaultSettings() == RET_FAILURE)  {
        goto error;
    }

    if((retval = sl_Start(0,0,0)) < 0)  {
        goto error;
    }

    if(retval != ROLE_AP) {
        if(WifiSetModeAP() != ROLE_AP) {
            sl_Stop(SL_STOP_TIMEOUT);
            goto error;
        }
    }

    //Wait for an IP address to be acquired
    while(!IS_IP_ACQUIRED(wifi_state.status)) {};

    SetLEDBlink(LED_1, LED_BLINK_PATTERN_WIFI_AP);
    LOG(LOG_IMPORTANT, "AP Started - Ready for client.");

#ifdef DO_STACK_CHECK
    wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL);
#endif

    //start socket handler.
    xTaskCreate(Task_SocketServer,
                "Socket Server",
                SOCKET_TASK_STACK_SIZE/sizeof(portSTACK_TYPE),
                0,
                SOCKET_TASK_PRIORITY,
                0);

#ifdef DO_STACK_CHECK
    wifi_state.stack_watermark = uxTaskGetStackHighWaterMark(NULL);
#endif

    //exit (delete this task)
    WifiTaskEndCallback(&Task_WifiAP);
    vTaskDelete(NULL);

error:
    SetLED(LED_1, LED_BLINK_PATTERN_WIFI_FAILED);
    TASK_RETURN_ERROR(ERROR_UNKNOWN, "WIFI AP fail");
    return;

    return;
}
Exemple #8
0
static int WifiConnectSTA()
{
    LOG(LOG_IMPORTANT ,"Waiting for auto connect...");

    while((!IS_CONNECTED(wifi_state.status)) || (!IS_IP_ACQUIRED(wifi_state.status))) {
#ifndef SL_PLATFORM_MULTI_THREADED
        _SlNonOsMainLoopTask();
#endif
    }

    return RET_SUCCESS;
}
Exemple #9
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;
}
Exemple #10
0
/*!
    \brief Connecting to a WLAN Access point

    This function connects to the required AP (SSID_NAME).
    The function will return once we are connected and have acquired IP address

    \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 establishConnectionWithAP()
{
    SlSecParams_t secParams = {0};
    _i32 retVal = 0;

    secParams.Key = "";
    secParams.KeyLen = 0;
    secParams.Type = SL_SEC_TYPE_OPEN;

    retVal = sl_WlanConnect(UNSEC_SSID_NAME, pal_Strlen(UNSEC_SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(retVal);

    /* Wait */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    return SUCCESS;
}
Exemple #11
0
/*!
    \brief Connecting to a WLAN Access point

    This function connects to the required AP (SSID_NAME).
    The function will return once we are connected and have acquired IP address

    \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.
*/
_i32 establishConnectionWithAP()
{

  _i32 retVal = 0;
    SlSecParams_t secParams = {0};

    secParams.Key = (_i8 *)PASSKEY;
    secParams.KeyLen = pal_Strlen(PASSKEY);
    secParams.Type = SEC_TYPE;

    retVal = sl_WlanConnect((_i8 *)SSID_NAME, pal_Strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(retVal);

    /* Wait */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    return SUCCESS;
}
Exemple #12
0
//*****************************************************************************
//
//!    \brief Connecting to a WLAN Accesspoint
//!    This function connects to the required AP (SSID_NAME).
//!    This code example assumes the AP doesn't use WIFI security.
//!    The function will return only once we are connected 
//!    and have acquired IP address
//!
//!    \param[in] None
//!
//!    \return None
//!
//!    \note 0 on success else error code
//!
//!    \warning    If the WLAN connection fails or we don't aquire an IP address,
//!                We will be stuck in this function forever.
//
//*****************************************************************************
long 
WpsConnectPinCode()
{
    SlSecParams_t secParams;
    long lRetVal = -1;

    secParams.Key = WPS_PIN_CODE;
    secParams.KeyLen = strlen(WPS_PIN_CODE);
    secParams.Type = SL_SEC_TYPE_WPS_PIN;

    lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }
    return SUCCESS;
}
Exemple #13
0
//****************************************************************************
//
//!  \brief Connecting to a WLAN Access point
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in the form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return                 None
//!
//!   \warning    If the WLAN connection fails or we don't acquire an IP 
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = (signed char *)P2P_SECURITY_KEY;
    secParams.KeyLen = strlen(P2P_SECURITY_KEY);
    secParams.Type = P2P_SECURITY_TYPE;

    lRetVal = sl_WlanConnect((signed char *)P2P_REMOTE_DEVICE,
                            strlen((const char *)P2P_REMOTE_DEVICE), 0,
                            &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait till Device acquired an IP in P2P mode
    while(! IS_P2P_REQ_RCVD(g_ulStatus))
    { 
        _SlNonOsMainLoopTask();
    }

    // Connect with the device requesting the connection
    lRetVal = sl_WlanConnect((signed char *)g_p2p_dev,
                           strlen((const char *)g_p2p_dev),
                           0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);
    
#ifdef P2P_ROLE_TYPE_NEGOTIATE
    while(! IS_IP_ACQUIRED(g_ulStatus))
#else
    while(! IS_IP_LEASED(g_ulStatus))
#endif
    {
        _SlNonOsMainLoopTask();
        if(IS_CONNECT_FAILED(g_ulStatus))
        {
            // Error, connection is failed
            ASSERT_ON_ERROR(NETWORK_CONNECTION_FAILED);
        }
    }

    return SUCCESS;
}
Exemple #14
0
//****************************************************************************
//
//! \brief Connecting to a WLAN Accesspoint
//!
//!  This function connects to the required AP (SSID_NAME) with Security
//!  parameters specified in te form of macros at the top of this file
//!
//! \param  None
//!
//! \return  None
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long lRetVal = 0;

    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
    ASSERT_ON_ERROR(lRetVal);

    // Wait for WLAN Event
    while((!IS_CONNECTED(g_ulStatus))|| (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        _SlNonOsMainLoopTask();
    }

    return SUCCESS;
}
Exemple #15
0
//****************************************************************************
//
//!  \brief Connecting to a WLAN Access point
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in the form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return                 None
//!
//!   \warning    If the WLAN connection fails or we don't acquire an IP 
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
static long WlanConnect()
{
    SlSecParams_t secParams = {0};
    long retVal = 0;

    secParams.Key = SECURITY_KEY;
    secParams.KeyLen = strlen(SECURITY_KEY);
    secParams.Type = SECURITY_TYPE;

    retVal = sl_WlanConnect(P2P_REMOTE_DEVICE, strlen(P2P_REMOTE_DEVICE), 0,
                            &secParams, 0);
    ASSERT_ON_ERROR(__LINE__, retVal);

    // Wait till Device acquired an IP in P2P mode
    while(! IS_P2P_REQ_RCVD(g_ulStatus))
    { 
        _SlNonOsMainLoopTask();
    }

    // Connect with the device requesting the connection
    retVal = sl_WlanConnect(g_p2p_dev, strlen(g_p2p_dev), 0, &secParams, 0);
    ASSERT_ON_ERROR(__LINE__, retVal);
    
#ifdef P2P_ROLE_TYPE_NEGOTIATE
    while(! IS_IP_ACQUIRED(g_ulStatus))
#else
    while(! IS_IP_LEASED(g_ulStatus))
#endif
    {
        _SlNonOsMainLoopTask();
        if(IS_CONNECT_FAILED(g_ulStatus))
        {
            // Error, connection is failed
            UART_PRINT("Connection Failed\r\n");
            return -1;
        }
    }

    return SUCCESS;
}
Exemple #16
0
//****************************************************************************
//
//!  \brief Connecting to a WLAN Accesspoint
//!
//!   This function connects to the required AP (SSID_NAME) with Security
//!   parameters specified in te form of macros at the top of this file
//!
//!   \param[in]              None
//!
//!   \return       status value
//!
//!   \warning    If the WLAN connection fails or we don't aquire an IP
//!            address, It will be stuck in this function forever.
//
//****************************************************************************
long NetWlanConnect(const char *cssid, SlSecParams_t *secParams)
{
    long lRetVal = 0;

    lRetVal = sl_WlanConnect((signed char *)cssid, strlen(cssid), 0, secParams, 0);
    if( lRetVal != 0)
    {
      return lRetVal;
    }

    while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
    {
        // Wait for WLAN Event
#ifndef SL_PLATFORM_MULTI_THREADED
              _SlNonOsMainLoopTask();
#endif

    }

    return SUCCESS;

}
Exemple #17
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;
}
Exemple #18
0
/*!
    \brief Connecting to a WLAN Access point

    This function connects to the required AP (ENT_SSID_NAME).
    The function will return once we are connected and have acquired IP address

    \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 establishConnectionWithAP()
{
    SlSecParams_t secParams = {0};
    SlSecParamsExt_t eapParams = {0};

    _i32 retVal = -1;

    secParams.Key = ENT_PASS_KEY;
    secParams.KeyLen = pal_Strlen(ENT_PASS_KEY);
    secParams.Type = ENT_SEC_TYPE;

    eapParams.EapMethod = ENT_SEC_METHOD;
    eapParams.User = ENT_USER_NAME;
    eapParams.UserLen = pal_Strlen(ENT_USER_NAME);
    eapParams.AnonUserLen = 0;

    retVal = sl_WlanConnect(ENT_SSID_NAME, pal_Strlen(ENT_SSID_NAME), NULL, &secParams, &eapParams);
    ASSERT_ON_ERROR(retVal);

    /* Wait */
    while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

    return SUCCESS;
}
Exemple #19
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 */
}
Exemple #20
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
}
Exemple #21
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;
}
void Microphone( void *pvParameters )
{
    long lRetVal = -1;

#ifdef MULTICAST
    //Wait for Network Connection
    while((!IS_IP_ACQUIRED(g_ulStatus)))
    {

    }
#endif //MULTICAST

    while(1)
    {     
        while(g_ucMicStartFlag || g_loopback)
        {
            int iBufferFilled = 0;
            iBufferFilled = GetBufferSize(pRecordBuffer);
            if(iBufferFilled >= (2*PACKET_SIZE))
            { 
                if(!g_loopback)
                {

#ifndef MULTICAST          
                    lRetVal = sendto(g_UdpSock.iSockDesc, \
                                       (char*)(pRecordBuffer->pucReadPtr),PACKET_SIZE,\
                                       0,(struct sockaddr*)&(g_UdpSock.Client),\
                                       sizeof(g_UdpSock.Client));
                    if(lRetVal < 0)
                    {
                        UART_PRINT("Unable to send data\n\r");
                        LOOP_FOREVER();
                    }

#else	//MULTICAST
                    lRetVal = SendMulticastPacket();
                    if(lRetVal < 0)
                    {
                        UART_PRINT("Unable to send data\n\r");
                        LOOP_FOREVER();
                    }

#endif     //MULTICAST      
                }
                else
                {
                    lRetVal = FillBuffer(pPlayBuffer,\
                                          (unsigned char*)(pRecordBuffer->pucReadPtr), \
                                          PACKET_SIZE);
                    if(lRetVal < 0)
                    {
                        UART_PRINT("Unable to fill buffer\n\r");
                    }
                    g_iReceiveCount++;
                }
                UpdateReadPtr(pRecordBuffer, PACKET_SIZE);
                g_iSentCount++;
            }
        }      
        MAP_UtilsDelay(1000);
    }
}
//*****************************************************************************
//
//! Network_IF_ConnectAP  Connect to an Access Point using the specified SSID
//!
//! \param[in]  pcSsid is a string of the AP's SSID
//! \param[in]  SecurityParams is Security parameter for AP
//!
//! \return On success, zero is returned. On error, -ve value is returned
//
//*****************************************************************************
long
Network_IF_ConnectAP(char *pcSsid, SlSecParams_t SecurityParams)
{
#ifndef NOTERM  
    char acCmdStore[128];
    unsigned short usConnTimeout;
    unsigned char ucRecvdAPDetails;
#endif
    long lRetVal;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefGateway = 0;
    unsigned long ulDns = 0;

    //
    // Disconnect from the AP
    //
    Network_IF_DisconnectFromAP();
    
    //
    // This triggers the CC3200 to connect to specific AP
    //
    lRetVal = sl_WlanConnect((signed char *)pcSsid, strlen((const char *)pcSsid),
                        NULL, &SecurityParams, NULL);
    ASSERT_ON_ERROR(lRetVal);

    //
    // Wait for ~10 sec to check if connection to desire AP succeeds
    //
    while(g_usConnectIndex < 15)
    {
#ifndef SL_PLATFORM_MULTI_THREADED
        _SlNonOsMainLoopTask();
#else
              osi_Sleep(1);
#endif
        MAP_UtilsDelay(8000000);
        if(IS_CONNECTED(g_ulStatus) && IS_IP_ACQUIRED(g_ulStatus))
        {
            break;
        }
        g_usConnectIndex++;
    }

#ifndef NOTERM
    //
    // Check and loop until AP connection successful, else ask new AP SSID name
    //
    while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
    {
        //
        // Disconnect the previous attempt
        //
        Network_IF_DisconnectFromAP();

        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        UART_PRINT("Device could not connect to %s\n\r",pcSsid);

        do
        {
            ucRecvdAPDetails = 0;

            UART_PRINT("\n\r\n\rPlease enter the AP(open) SSID name # ");

            //
            // Get the AP name to connect over the UART
            //
            lRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
            if(lRetVal > 0)
            {
                // remove start/end spaces if any
                lRetVal = TrimSpace(acCmdStore);

                //
                // Parse the AP name
                //
                strncpy(pcSsid, acCmdStore, lRetVal);
                if(pcSsid != NULL)
                {
                    ucRecvdAPDetails = 1;
                    pcSsid[lRetVal] = '\0';

                }
            }
        }while(ucRecvdAPDetails == 0);

        //
        // Reset Security Parameters to OPEN security type
        //
        SecurityParams.Key = (signed char *)"";
        SecurityParams.KeyLen = 0;
        SecurityParams.Type = SL_SEC_TYPE_OPEN;

        UART_PRINT("\n\rTrying to connect to AP: %s ...\n\r",pcSsid);

        //
        // Get the current timer tick and setup the timeout accordingly
        //
        usConnTimeout = g_usConnectIndex + 15;

        //
        // This triggers the CC3200 to connect to specific AP
        //
        lRetVal = sl_WlanConnect((signed char *)pcSsid,
                                  strlen((const char *)pcSsid), NULL,
                                  &SecurityParams, NULL);
        ASSERT_ON_ERROR(lRetVal);

        //
        // Wait ~10 sec to check if connection to specifed AP succeeds
        //
        while(!(IS_CONNECTED(g_ulStatus)) || !(IS_IP_ACQUIRED(g_ulStatus)))
        {
#ifndef SL_PLATFORM_MULTI_THREADED
            _SlNonOsMainLoopTask();
#else
              osi_Sleep(1);
#endif
            MAP_UtilsDelay(8000000);
            if(g_usConnectIndex >= usConnTimeout)
            {
                break;
            }
            g_usConnectIndex++;
        }

    }
#endif
    //
    // Put message on UART
    //
    UART_PRINT("\n\rDevice has connected to %s\n\r",pcSsid);

    //
    // Get IP address
    //
    lRetVal = Network_IF_IpConfigGet(&ulIP,&ulSubMask,&ulDefGateway,&ulDns);
    ASSERT_ON_ERROR(lRetVal);

    //
    // Send the information
    //
    UART_PRINT("Device IP Address is %d.%d.%d.%d \n\r\n\r",
            SL_IPV4_BYTE(ulIP, 3),SL_IPV4_BYTE(ulIP, 2),
            SL_IPV4_BYTE(ulIP, 1),SL_IPV4_BYTE(ulIP, 0));
    return 0;
}
//*****************************************************************************
//
//! Network_IF_InitDriver
//! The function initializes a CC3200 device and triggers it to start operation
//!  
//! \param  uiMode (device mode in which device will be configured)
//!  
//! \return 0 : sucess, -ve : failure
//
//*****************************************************************************
long
Network_IF_InitDriver(unsigned int uiMode)
{
    long lRetVal = -1;
    // Reset CC3200 Network State Machine
    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 application
    //
    // 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(NULL,NULL,NULL);

    if (lRetVal < 0 || lRetVal != ROLE_STA)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Started SimpleLink Device: STA Mode\n\r");

    if(uiMode == ROLE_AP)
    {
        UART_PRINT("Switching to AP mode on application request\n\r");
        // Switch to AP role and restart
        lRetVal = sl_WlanSetMode(uiMode);
        ASSERT_ON_ERROR(lRetVal);

        lRetVal = sl_Stop(0xFF);

        lRetVal = sl_Start(0, 0, 0);
        ASSERT_ON_ERROR(lRetVal);

        // Check if the device is up in AP Mode
        if (ROLE_AP == lRetVal)
        {
            // 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();
#else
              osi_Sleep(1);
#endif
            }
        }
        else
        {
            // We don't want to proceed if the device is not coming up in AP-mode
            ASSERT_ON_ERROR(DEVICE_NOT_IN_AP_MODE);
        }

        UART_PRINT("Re-started SimpleLink Device: AP Mode\n\r");
    }
    else if(uiMode == ROLE_P2P)
    {
        UART_PRINT("Switching to P2P mode on application request\n\r");
        // Switch to AP role and restart
        lRetVal = sl_WlanSetMode(uiMode);
        ASSERT_ON_ERROR(lRetVal);

        lRetVal = sl_Stop(0xFF);

        lRetVal = sl_Start(0, 0, 0);
        ASSERT_ON_ERROR(lRetVal);

        // Check if the device is in station again
        if (ROLE_P2P != lRetVal)
        {
            // We don't want to proceed if the device is not coming up in P2P-mode
            ASSERT_ON_ERROR(DEVICE_NOT_IN_P2P_MODE);
        }

        UART_PRINT("Re-started SimpleLink Device: P2P Mode\n\r");
    }
    else
    {
        // Device already started in STA-Mode
    }
    return 0;
}
//*****************************************************************************
//
//! Network_IF_ConnectAP  Connect to an Access Point using the specified SSID
//!
//! \param  pcSsid is a string of the AP's SSID
//!
//! \return none
//
//*****************************************************************************
int
Network_IF_ConnectAP(char *pcSsid, SlSecParams_t SecurityParams)
{
    char acCmdStore[128];
    unsigned short usConnTimeout;
    int iRetVal;
    unsigned long ulIP = 0;
    unsigned long ulSubMask = 0;
    unsigned long ulDefGateway = 0;
    unsigned long ulDns = 0;
    unsigned char ucRecvdAPDetails;

    Network_IF_DisconnectFromAP();

    //
    // This triggers the CC3200 to connect to specific AP
    //
    sl_WlanConnect(pcSsid, strlen(pcSsid), NULL, &SecurityParams, NULL);

    //
    // Wait to check if connection to DIAGNOSTIC_AP succeeds
    //
    while(g_usConnectIndex < 10)
    {
        MAP_UtilsDelay(8000000);
        g_usConnectIndex++;
        if(IS_CONNECTED(g_ulStatus))
        {
            break;
        }
    }

    //
    // Check and loop until async event from network processor indicating Wlan
    // Connect success was received
    //
    while(!(IS_CONNECTED(g_ulStatus)))
    {
        //
        // Disconnect the previous attempt
        //
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
        UART_PRINT("Device could not connect to %s\n\r",pcSsid);

        do
        {
            ucRecvdAPDetails = 0;

            UART_PRINT("\n\r\n\rPlease enter the AP(open) SSID name # ");

            //
            // Get the AP name to connect over the UART
            //
            iRetVal = GetCmd(acCmdStore, sizeof(acCmdStore));
            if(iRetVal > 0)
            {
                //
                // Parse the AP name
                //
                pcSsid = strtok(acCmdStore, ":");
                if(pcSsid != NULL)
                {

                    ucRecvdAPDetails = 1;

                }
            }
        } while(ucRecvdAPDetails == 0);

        UART_PRINT("\n\rTrying to connect to AP: %s ...\n\r",pcSsid);
        /*UART_PRINT("Key: %s, Len: %d, KeyID: %d, Type: %d\n\r",
                    SecurityParams.Key, SecurityParams.KeyLen
                      , SecurityParams.Type);
        */

        //
        // Get the current timer tick and setup the timeout accordingly
        //
        usConnTimeout = g_usConnectIndex + 10;

        //
        // This triggers the CC3200 to connect to specific AP
        //
        sl_WlanConnect(pcSsid, strlen(pcSsid), NULL, &SecurityParams, NULL);

        //
        // Wait to check if connection to specifed AP succeeds
        //
        while(!(IS_CONNECTED(g_ulStatus)))
        {
            if(g_usConnectIndex >= usConnTimeout)
            {
                break;
            }
            MAP_UtilsDelay(8000000);
            g_usConnectIndex++;
        }
    }

    //
    // Wait until IP is acquired
    //
    while(!(IS_IP_ACQUIRED(g_ulStatus)));

    //
    // Put message on UART
    //
    UART_PRINT("\n\rDevice has connected to %s\n\r",pcSsid);

    //
    // Get IP address
    //
    Network_IF_IpConfigGet(&ulIP,&ulSubMask,&ulDefGateway,&ulDns);

    //
    // Send the information
    //
    UART_PRINT("Device IP Address is %d.%d.%d.%d \n\r\n\r",
               SL_IPV4_BYTE(ulIP, 3),SL_IPV4_BYTE(ulIP, 2),
               SL_IPV4_BYTE(ulIP, 1),SL_IPV4_BYTE(ulIP, 0));
    return 0;
}
Exemple #26
0
long ConnectToNetwork()
{
    long lRetVal = -1;
    unsigned int uiConnectTimeoutCnt =0;
    
    //Start Simplelink Device 
    lRetVal =  sl_Start(NULL,NULL,NULL);
    ASSERT_ON_ERROR(lRetVal);

    if(lRetVal != ROLE_STA)
    {
        if (ROLE_AP == lRetVal)
        {
            // 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
            }
        }
        //
        // Configure to STA Mode
        //
        lRetVal = ConfigureMode(ROLE_STA);
        if(lRetVal !=ROLE_STA)
        {
            UART_PRINT("Unable to set STA mode...\n\r");
            lRetVal = sl_Stop(SL_STOP_TIMEOUT);
            CLR_STATUS_BIT_ALL(g_ulStatus);
            return DEVICE_NOT_IN_STATION_MODE;
        }
    }

    //waiting for the device to Auto Connect
    while(uiConnectTimeoutCnt<AUTO_CONNECTION_TIMEOUT_COUNT &&
        ((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))) 
    {
        //Turn Green LED On       
        GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);            
        osi_Sleep(50);            
        //Turn Green LED Off
        GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);            
        osi_Sleep(50);
        
        uiConnectTimeoutCnt++;
    }
    //Couldn't connect Using Auto Profile
    if(uiConnectTimeoutCnt==AUTO_CONNECTION_TIMEOUT_COUNT)
    {
        CLR_STATUS_BIT_ALL(g_ulStatus);
        
        //Turn Green LED On       
        GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);  
        
        //Connect Using Smart Config
        lRetVal = SmartConfigConnect();
        ASSERT_ON_ERROR(lRetVal);

        //Waiting for the device to Auto Connect
        while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
        {
            MAP_UtilsDelay(500);              
        }
         
        //Turn Green LED Off      
        GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);    
    }

    return SUCCESS;
    
}
Exemple #27
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;
}
Exemple #28
0
//****************************************************************************
//
//!    \brief Connects to the Network in AP or STA Mode - If ForceAP Jumper is
//!                                             Placed, Force it to AP mode
//!
//! \return  0 - Success
//!            -1 - Failure
//
//****************************************************************************
long ConnectToNetwork()
{
    long lRetVal = -1;
    unsigned int uiConnectTimeoutCnt =0;

    // staring simplelink
    lRetVal =  sl_Start(NULL,NULL,NULL);
    ASSERT_ON_ERROR( lRetVal);

    // Device is in AP Mode and Force AP Jumper is not Connected
    if(ROLE_STA != lRetVal && g_uiDeviceModeConfig == ROLE_STA )
    {
        if (ROLE_AP == lRetVal)
        {
            // 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 Mode
        lRetVal = ConfigureMode(ROLE_STA);
        ASSERT_ON_ERROR( lRetVal);
    }

    //Device is in STA Mode and Force AP Jumper is Connected
    if(ROLE_AP != lRetVal && g_uiDeviceModeConfig == ROLE_AP )
    {
         //Switch to AP Mode
         lRetVal = ConfigureMode(ROLE_AP);
         ASSERT_ON_ERROR( lRetVal);

    }

    //No Mode Change Required
    if(lRetVal == ROLE_AP)
    {
        //waiting for the AP to acquire IP address from Internal DHCP Server
        // 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
        }
        //Stop Internal HTTP Server
        lRetVal = sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
        ASSERT_ON_ERROR( lRetVal);

        //Start Internal HTTP Server
        lRetVal = sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID);
        ASSERT_ON_ERROR( lRetVal);

       char cCount=0;
       
       //Blink LED 3 times to Indicate AP Mode
       for(cCount=0;cCount<3;cCount++)
       {
           //Turn RED LED On
           GPIO_IF_LedOn(MCU_RED_LED_GPIO);
           osi_Sleep(400);
           
           //Turn RED LED Off
           GPIO_IF_LedOff(MCU_RED_LED_GPIO);
           osi_Sleep(400);
       }

       char ssid[32];
	   unsigned short len = 32;
	   unsigned short config_opt = WLAN_AP_OPT_SSID;
	   sl_WlanGet(SL_WLAN_CFG_AP_ID, &config_opt , &len, (unsigned char* )ssid);
	   UART_PRINT("\n\r Connect to : \'%s\'\n\r\n\r",ssid);
    }
    else
    {
        //Stop Internal HTTP Server
        lRetVal = sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
        ASSERT_ON_ERROR( lRetVal);

        //Start Internal HTTP Server
        lRetVal = sl_NetAppStart(SL_NET_APP_HTTP_SERVER_ID);
        ASSERT_ON_ERROR( lRetVal);

    	//waiting for the device to Auto Connect
        while(uiConnectTimeoutCnt<AUTO_CONNECTION_TIMEOUT_COUNT &&
            ((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))) 
        {
            //Turn RED LED On
            GPIO_IF_LedOn(MCU_RED_LED_GPIO);
            osi_Sleep(50);
            
            //Turn RED LED Off
            GPIO_IF_LedOff(MCU_RED_LED_GPIO);
            osi_Sleep(50);
            
            uiConnectTimeoutCnt++;
        }
        //Couldn't connect Using Auto Profile
        if(uiConnectTimeoutCnt == AUTO_CONNECTION_TIMEOUT_COUNT)
        {
            //Blink Red LED to Indicate Connection Error
            GPIO_IF_LedOn(MCU_RED_LED_GPIO);
            
            CLR_STATUS_BIT_ALL(g_ulStatus);

            //Connect Using Smart Config
            lRetVal = SmartConfigConnect();
            ASSERT_ON_ERROR(lRetVal);

            //Waiting for the device to Auto Connect
            while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
            {
                MAP_UtilsDelay(500);              
            }
    }
    //Turn RED LED Off
    GPIO_IF_LedOff(MCU_RED_LED_GPIO);

    g_iInternetAccess = ConnectionTest();

    }
    return SUCCESS;
}
Exemple #29
0
//*****************************************************************************
//
//! UARTCommandHandler
//!
//!     @brief  The function handles commands arrived from CLI
//!
//!     @param  usBuffer is the receive buffer from the UART interface to PC
//!
//!     @return 0 on success or error code on failure
//!
//
//*****************************************************************************
long UARTCommandHandler(char *usBuffer)
{
    int iIndex = 0;
    int iParamcount = 0;
    long lRetVal = -1;
    signed char cStatus1 = 0;
    signed char cStatus2 = 0;

    if(usBuffer == NULL)
    {
        UART_PRINT("Null pointer\r\n");
        return -1;
    }

    switch(usBuffer[1])
    {
        //**********************************************
        // Case 01: Connect to default AP
        //**********************************************
        case UART_COMMAND_SIMPLE_CONFIG_START:

            if(!IS_CONNECTED(Network_IF_CurrentMCUState()))
            {
                LedTimerConfigNStart();

                // Setting Acess Point's security parameters
                SecurityParams.Key = (signed char *)SECURITY_KEY;
                SecurityParams.KeyLen = strlen(SECURITY_KEY);
                SecurityParams.Type = SECURITY_TYPE;

                lRetVal = Network_IF_ConnectAP(SSID_NAME,SecurityParams);
                if(lRetVal < 0)
                {
                    UART_PRINT("Error: %d Connecting to an AP.", lRetVal);
                    return lRetVal;
                }
            }

            //
            // 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);
            DispatcherUartSendPacket((char*)pucUARTOKString, 
                                     sizeof(pucUARTOKString));
            break;
                
    //**********************************************
    // Case 02: Configure sender (source) email
    //**********************************************
        // TODO Phase 2: Include
        /*
    case UART_COMMAND_EMAIL_SOURCE:
          
        memset(serveruser,0,sizeof(serveruser));
                memset(pcServerpass,0,sizeof(pcServerpass));
        pcOfserveruser = &serveruser[0];
                ofpcServerpass = &pcServerpass[0];
                // '<' To maintain RFC 2821 format
                *pcOfserveruser++= '<';
                
        iIndex = 2;
        while ((int)usBuffer[iIndex] != 0x0D)
        {

            //look for comma ',' for separation of params
            if((int)usBuffer[iIndex] == 44)
                        {
                iParamcount++;
            }
            else
                        {
                if(iParamcount==1)
                                {
                                    //Enter smtp server username (email address)
                                    *pcOfserveruser++ = usBuffer[iIndex];

                }
                if(iParamcount==2)
                                {
                                    //Enter username's password
                                    *ofpcServerpass++ = usBuffer[iIndex];
                                }
                        }
            iIndex++;
        }
                // '>' To maintain RFC 2821 format
                *pcOfserveruser++= '>';
        *pcOfserveruser++= '\0';
        *ofpcServerpass++= '\0';
        
        //Set variables in smtp.c
        cStatus1 = smtpSetVariable(serveruser, USERNAME_VAR);
        cStatus2 = smtpSetVariable(pcServerpass, PASSWORD_VAR);
                //If error in return
        if(cStatus1 == 0 && cStatus2 == 0)
        {
                    DispatcherUartSendPacket((char*)pucUARTOKString, sizeof(pucUARTOKString));
        }
                else
                {
                    DispatcherUartSendPacket((char*)putUARTErrorInputString, \
                                        sizeof(putUARTErrorInputString));  
                }
        break;
                */
    //**********************************************
    // Case 03: Configure sender (source) email
    //**********************************************
        case UART_COMMAND_EMAIL_HEADER:
          
            memset(pcEmailto,0,sizeof(pcEmailto));
            pcOfemailto = &pcEmailto[0];
            pcOfemailsubject = &pcEmailsubject[0];
            // '<' To maintain RFC 2821 format
            *pcOfemailto++= '<';
            iIndex = 2;
            while ((int)usBuffer[iIndex] != 0x0D && usBuffer[iIndex] != '\0')
            {
                //look for comma ',' for separation of params
                if((int)usBuffer[iIndex] == 44)
                {
                    iParamcount++;
                }
                else
                {
                    if(iParamcount==1)
                    {
                        //Enter destination email address
                        *pcOfemailto++ = usBuffer[iIndex];

                    }
                    if(iParamcount==2)
                    {
                        //Enter email subject
                        *pcOfemailsubject++ = usBuffer[iIndex];
                    }
                }
                iIndex++;
            }
            
            // '>' To maintain RFC 2821 format
            *pcOfemailto++= '>';
            *pcOfemailto++= '\0';
            *pcOfemailsubject= '\0';

            SlNetAppDestination_t destEmailAdd;
            memcpy(destEmailAdd.Email,pcEmailto,strlen(pcEmailto)+1);
            cStatus1 = sl_NetAppEmailSet(SL_NET_APP_EMAIL_ID,NETAPP_DEST_EMAIL, \
                                         strlen(pcEmailto)+1, \
                                         (unsigned char *)&destEmailAdd);

            SlNetAppEmailSubject_t emailSubject;
            memcpy(emailSubject.Value,pcEmailsubject,strlen(pcEmailsubject)+1);
            cStatus2 = sl_NetAppEmailSet(SL_NET_APP_EMAIL_ID,NETAPP_SUBJECT, \
                                         strlen(pcEmailsubject)+1, \
                                         (unsigned char *)&emailSubject);
            
            // Check for Error in setting the variables
            if(cStatus1 == 0 && cStatus2 == 0)
            {
                DispatcherUartSendPacket((char*)pucUARTOKString, \
                                         sizeof(pucUARTOKString));
            }
            else
            {
                DispatcherUartSendPacket((char*)putUARTErrorInputString, \
                                         sizeof(putUARTErrorInputString));  
            }
            break;
                
        //**********************************************
        // Case 04: Record email message
        //**********************************************
        case UART_COMMAND_EMAIL_MESSAGE:

            pcOfemailmessage = &pcEmailmessage[0];

            //Enter "Message"
            iIndex =3;
            while ((int)usBuffer[iIndex] != 0x0D && usBuffer[iIndex] != '\0')
            {
                if((int)usBuffer[iIndex] == 62)
                {
                    iParamcount++;
                }
                else
                {
                    if(iParamcount==0)
                    {
                        *pcOfemailmessage++ = usBuffer[iIndex];
                    }
                }
                iIndex++;
            }
            *pcOfemailmessage= '\0';
            /* TODO here unsigned char is converting to char */
            DispatcherUartSendPacket((char*)pucUARTOKString, \
                                     sizeof(pucUARTOKString));

            break; 
        //**********************************************
        // Case 05: Send email message using configurations
        //**********************************************
        case UART_COMMAND_EMAIL_SEND:
        {

            // reset Orange LED state
            GPIO_IF_LedOff(MCU_SENDING_DATA_IND);
            // TODO: If no destination email given, default to hardcoded value
            SlNetAppEmailOpt_t eMailServerSetting;

            lRetVal = Network_IF_GetHostIP(GMAIL_HOST_NAME, &eMailServerSetting.Ip);
            if(lRetVal >= 0)
            {
                eMailServerSetting.Family = AF_INET;
                eMailServerSetting.Port = GMAIL_HOST_PORT;
                eMailServerSetting.SecurityMethod = SL_SO_SEC_METHOD_SSLV3;
                eMailServerSetting.SecurityCypher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5;
                lRetVal = sl_NetAppEmailSet(SL_NET_APP_EMAIL_ID, \
                                        NETAPP_ADVANCED_OPT, \
                                        sizeof(SlNetAppEmailOpt_t), \
                                        (unsigned char*)&eMailServerSetting);
                ASSERT_ON_ERROR(lRetVal);
            }
            else
            {
                UART_PRINT("Error:%d GetHostIP.", lRetVal);
                return -1;
            }
            g_cConnectStatus = sl_NetAppEmailConnect();
            // If return -1, throw connect error
            if(g_cConnectStatus == -1)
            {
                DispatcherUartSendPacket((char*)pucUARTErrorSocketCreateString, \
                                         sizeof(pucUARTErrorSocketCreateString));
            }
            // If return -2, throw socket option error
            if(g_cConnectStatus == -2)
            {
                DispatcherUartSendPacket((char*)pucUARTErrorSocketOptionString, \
                                         sizeof(pucUARTErrorSocketOptionString));
            }

            if(g_cConnectStatus == 0)
            {
                SlNetAppServerError_t sEmailErrorInfo;
                long lRetCode = SL_EMAIL_ERROR_FAILED;
                if((lRetCode = sl_NetAppEmailSend(pcEmailto,pcEmailsubject, \
                                      pcEmailmessage, \
                                      &sEmailErrorInfo)) == SL_EMAIL_ERROR_NONE)
                {
                    // Blink LED7 to indicate email has been sent
                    for(iIndex=0 ;iIndex<5 ;iIndex++)
                    {
                          MAP_UtilsDelay(6000000);
                          GPIO_IF_LedOff(MCU_SENDING_DATA_IND);
                          MAP_UtilsDelay(6000000);
                          GPIO_IF_LedOn(MCU_SENDING_DATA_IND);

                    }
                    DispatcherUartSendPacket((char*)putUARTFinishString, \
                                             sizeof(putUARTFinishString));
                }
                else
                {
                    lRetVal = EmailHandleERROR(lRetCode,(char*)sEmailErrorInfo.Value);
                    ASSERT_ON_ERROR(lRetVal);
                }
            }
        }
        break;

        case UART_COMMAND_SMART_CONFIG:
            GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
            DispatcherUartSendPacket((char*)pucUARTSmartConfigString, \
                                     sizeof(pucUARTSmartConfigString));
              
            // Start LED blinking Timer
            LedTimerConfigNStart();
            
            //Reset the Network Status before Entering Smart Config
            Network_IF_UnsetMCUMachineState(STATUS_BIT_CONNECTION);
            Network_IF_UnsetMCUMachineState(STATUS_BIT_IP_AQUIRED);
            
            // start smart config process
            lRetVal = SmartConfigConnect();
            ASSERT_ON_ERROR(lRetVal);
            while (!(IS_CONNECTED(Network_IF_CurrentMCUState())) || \
                   !(IS_IP_ACQUIRED(Network_IF_CurrentMCUState())))
            {
                MAP_UtilsDelay(100);
            }
            LedTimerDeinitStop();
            GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
            break;
                      
        default:
            DispatcherUartSendPacket((char*)pucUARTErrorString, \
                                     sizeof(pucUARTErrorString));
            break;
  }

 return SUCCESS;
}
Exemple #30
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;

}