示例#1
0
文件: main.c 项目: dlugaz/All
//****************************************************************************
//
//!  \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;
}
示例#2
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;
}
示例#3
0
    /*!
     * \brief Start the device in STA mode
     *
     * 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
     */
_i32 startAP(void){
      SlPingStartCommand_t PingParams = {0};
    SlPingReport_t Report = {0};
    _u8 SecType = 0;
    _i32 mode = ROLE_STA;
_i32 retVal = configureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            CLI_Write((_u8 *)" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" 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
     */
    mode = sl_Start(0, 0, 0);
    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)) { _SlNonOsMainLoopTask(); }
    }
    else
    {
        /* Configure CC3100 to start in AP mode */
        retVal = sl_WlanSetMode(ROLE_AP);
        if(retVal < 0)
            LOOP_FOREVER();

        /* Configure the SSID of the CC3100 */
        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID,
                pal_Strlen(SSID_AP_MODE), (_u8 *)SSID_AP_MODE);
        if(retVal < 0)
            LOOP_FOREVER();

        SecType = SEC_TYPE_AP_MODE;
        /* Configure the Security parameter the AP mode */
        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1,
                (_u8 *)&SecType);
        if(retVal < 0)
            LOOP_FOREVER();

        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, pal_Strlen(PASSWORD_AP_MODE),
                (_u8 *)PASSWORD_AP_MODE);
        if(retVal < 0)
            LOOP_FOREVER();

        retVal = sl_Stop(SL_STOP_TIMEOUT);
        if(retVal < 0)
            LOOP_FOREVER();

        CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

        mode = sl_Start(0, 0, 0);
        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)) { _SlNonOsMainLoopTask(); }
        }
        else
        {
            CLI_Write((_u8 *)" Device couldn't be configured in AP mode \n\r");
            LOOP_FOREVER();
        }
    }

    CLI_Write((_u8 *)" Device started as Access Point\n\r");

    /* Wait */
    CLI_Write((_u8 *)" Waiting for clients to connect...!\n\r");
    while((!IS_IP_LEASED(g_Status)) || (!IS_STA_CONNECTED(g_Status))) { _SlNonOsMainLoopTask(); }
    CLI_Write((_u8 *)" Client connected to the device \n\r");
    CLI_Write((_u8 *)" Pinging...! \n\r");

    /* Set the ping parameters */
    PingParams.PingIntervalTime = PING_INTERVAL;
    PingParams.PingSize = PING_PKT_SIZE;
    PingParams.PingRequestTimeout = PING_TIMEOUT;
    PingParams.TotalNumberOfAttempts = NO_OF_ATTEMPTS;
    PingParams.Flags = 0;
    PingParams.Ip = g_StationIP; /* Fill the station IP address connected to CC3100 */

    /* Ping client connected to CC3100 */
    retVal = sl_NetAppPingStart((SlPingStartCommand_t*)&PingParams, SL_AF_INET,
                       (SlPingReport_t*)&Report, SimpleLinkPingReport);
    if(retVal < 0)
        LOOP_FOREVER();

    /* Wait */
//    while(!IS_PING_DONE(g_Status)) { _SlNonOsMainLoopTask(); }
//
//    if (0 == g_PingPacketsRecv)
//    {
//        CLI_Write((_u8 *)" A STATION couldn't connect to the device \n\r");
//        ASSERT_ON_ERROR(LAN_CONNECTION_FAILED);
//    }

    CLI_Write((_u8 *)" Device and the station are successfully connected \n\r");
    return SUCCESS;

}
示例#4
0
//****************************************************************************
//
//!    \brief start simplelink, wait for the sta to connect to the device and 
//!        run the ping test for that sta
//!
//!    \param  pvparameters is the pointer to the list of parameters that can be
//!         passed to the task while creating it
//!
//!    \return None
//
//****************************************************************************
void WlanAPMode( void *pvParameters )
{   
    int iTestResult = 0;
    unsigned char ucDHCP;
    long retVal = -1;

    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
    //
    retVal = ConfigureSimpleLinkToDefaultState();
    if(retVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == retVal)
            UART_PRINT("Failed to configure the device in its default state \n\r");

        LOOP_FOREVER(__LINE__);
    }

    UART_PRINT("Device is configured in default state \n\r");

    //
    // Asumption is that the device is configured in station mode already
    // and it is in its default state
    //
    retVal = sl_Start(NULL,NULL,NULL);

    if (retVal < 0)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER(__LINE__);
    }

    UART_PRINT("Device started as STATION \n\r");
    
    //
    // Configure the networking mode and ssid name(for AP mode)
    //
    if(retVal != ROLE_AP)
    {
        if(ConfigureMode(retVal) !=ROLE_AP)
        {
            UART_PRINT("Unable to set AP mode, exiting Application...\n\r");
            sl_Stop(SL_STOP_TIMEOUT);
            return;
        }
    }

    while(!IS_IP_ACQUIRED(g_ulStatus))
    {
      //looping till ip is acquired
    }

    unsigned char len = sizeof(_NetCfgIpV4Args_t);
    _NetCfgIpV4Args_t ipV4 = {0};

    retVal = sl_NetCfgGet(SL_IPV4_STA_P2P_CL_GET_INFO,&ucDHCP,&len,
                            (unsigned char *)&ipV4);
    if (retVal < 0)
    {
        UART_PRINT("Failed to get network configuration \n\r");
        LOOP_FOREVER(__LINE__);
    }
    
    UART_PRINT("Connect a client to Device\n\r");
    while(!IS_IP_LEASED(g_ulStatus))
    {
      //wating for the client to connect
    }
    UART_PRINT("Client is connected to Device\n\r");

    iTestResult = PingTest(g_ulStaIp);
    UNUSED(ucDHCP);
    UNUSED(iTestResult);
    sl_WlanSetMode(ROLE_STA);

    /* Switch off Network processor */
    sl_Stop(SL_STOP_TIMEOUT);
    UART_PRINT("Application exits\n\r");
    while(1);
}
示例#5
0
文件: main.c 项目: callalilychen/TIOT
/*
 * Application's entry point
 */
int main(int argc, char** argv)
{
    SlPingStartCommand_t PingParams = {0};
    SlPingReport_t Report = {0};

    _u8 SecType = 0;
    _i32 mode = ROLE_STA;
    _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();

    CLR_STATUS_BIT(g_Status, STATUS_BIT_PING_DONE);
    g_PingPacketsRecv = 0;

    /*
     * 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((_u8 *)" Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

    CLI_Write((_u8 *)" 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
     */
    mode = sl_Start(0, 0, 0);
    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)) { _SlNonOsMainLoopTask(); }
    }
    else
    {
        /* Configure CC3100 to start in AP mode */
        retVal = sl_WlanSetMode(ROLE_AP);
        if(retVal < 0)
            LOOP_FOREVER();

        /* Configure the SSID of the CC3100 */
        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID,
                pal_Strlen(SSID_AP_MODE), (_u8 *)SSID_AP_MODE);
        if(retVal < 0)
            LOOP_FOREVER();

        SecType = SEC_TYPE_AP_MODE;
        /* Configure the Security parameter the AP mode */
        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1,
                (_u8 *)&SecType);
        if(retVal < 0)
            LOOP_FOREVER();

        retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, pal_Strlen(PASSWORD_AP_MODE),
                (_u8 *)PASSWORD_AP_MODE);
        if(retVal < 0)
            LOOP_FOREVER();

        retVal = sl_Stop(SL_STOP_TIMEOUT);
        if(retVal < 0)
            LOOP_FOREVER();

        CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

        mode = sl_Start(0, 0, 0);
        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)) { _SlNonOsMainLoopTask(); }
        }
        else
        {
            CLI_Write((_u8 *)" Device couldn't be configured in AP mode \n\r");
            LOOP_FOREVER();
        }
    }

    CLI_Write((_u8 *)" Device started as Access Point\n\r");
while(1){
    /* Wait */
    CLI_Write((_u8 *)" Waiting for clients to connect...!\n\r");
    while((!IS_IP_LEASED(g_Status)) || (!IS_STA_CONNECTED(g_Status))) { _SlNonOsMainLoopTask(); }
    CLI_Write((_u8 *)" Client connected to the device \n\r");
    CLI_Write((_u8 *)" Pinging...! \n\r");

    /* Set the ping parameters */
    PingParams.PingIntervalTime = PING_INTERVAL;
    PingParams.PingSize = PING_SIZE;
    PingParams.PingRequestTimeout = PING_REQUEST_TIMEOUT;
    PingParams.TotalNumberOfAttempts = PING_ATTEMPT;
    PingParams.Flags = 0;
    PingParams.Ip = g_StationIP; /* Fill the station IP address connected to CC3100 */

    /* Ping client connected to CC3100 */
    retVal = sl_NetAppPingStart((SlPingStartCommand_t*)&PingParams, SL_AF_INET,
                       (SlPingReport_t*)&Report, SimpleLinkPingReport);
    if(retVal < 0)
        LOOP_FOREVER();

    /* Wait */
    while(!IS_PING_DONE(g_Status)) { _SlNonOsMainLoopTask(); }

    if (0 == g_PingPacketsRecv)
    {
        CLI_Write((_u8 *)" A STATION couldn't connect to the device \n\r");
        ASSERT_ON_ERROR(LAN_CONNECTION_FAILED);
    }

    CLI_Write((_u8 *)" Device and the station are successfully connected \n\r");
}
    return SUCCESS;
}
void HttpServer(){
	 _u8   SecType = 0;
	    _i32   retVal = -1;
	    _i32   mode = ROLE_STA;
	   /*
	     * 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");

	    /*
	     * Assumption is that the device is configured in station mode already
	     * and it is in its default state
	     */
	    mode = sl_Start(0, 0, 0);
	    if(mode < 0)
	    {
	        LOOP_FOREVER();
	    }
	    else
	    {
	        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)) { _SlNonOsMainLoopTask(); }
	        }
	        else
	        {
	            /* Configure CC3100 to start in AP mode */
	            retVal = sl_WlanSetMode(ROLE_AP);
	            if(retVal < 0)
	                LOOP_FOREVER();
	        }
	    }

	    /* Configure AP mode without security */
	    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID,
	               pal_Strlen(SSID_AP_MODE), (_u8 *)SSID_AP_MODE);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    SecType = SEC_TYPE_AP_MODE;
	    /* Configure the Security parameter in the AP mode */
	    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1,
	            (_u8 *)&SecType);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    retVal = sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, pal_Strlen(PASSWORD_AP_MODE),
	            (_u8 *)PASSWORD_AP_MODE);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    /* Restart the CC3100 */
	    retVal = sl_Stop(SL_STOP_TIMEOUT);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    g_Status = 0;

	    mode = sl_Start(0, 0, 0);
	    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)) { _SlNonOsMainLoopTask(); }
	    }
	    else
	    {
	        CLI_Write(" Device couldn't come in AP mode \n\r");
	        LOOP_FOREVER();
	    }

	    CLI_Write(" \r\n Device is configured in AP mode \n\r");

	    CLI_Write(" Waiting for client to connect\n\r");
	    /* wait for client to connect */
	    while((!IS_IP_LEASED(g_Status)) || (!IS_STA_CONNECTED(g_Status))) { _SlNonOsMainLoopTask(); }

	    CLI_Write(" Client connected\n\r");

	    /* Enable the HTTP Authentication */
	    retVal = set_authentication_check(TRUE);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    /* Get authentication parameters */
	    retVal = get_auth_name(g_auth_name);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    retVal = get_auth_password(g_auth_password);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    retVal = get_auth_realm(g_auth_realm);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    CLI_Write((_u8 *)"\r\n Authentication parameters: ");
	    CLI_Write((_u8 *)"\r\n Name = ");
	    CLI_Write(g_auth_name);
	    CLI_Write((_u8 *)"\r\n Password = "******"\r\n Realm = ");
	    CLI_Write(g_auth_realm);

	    /* Get the domain name */
	    retVal = get_domain_name(g_domain_name);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    CLI_Write((_u8 *)"\r\n\r\n Domain name = ");
	    CLI_Write(g_domain_name);

	    /* Get URN */
	    retVal = get_device_urn(g_device_urn);
	    if(retVal < 0)
	        LOOP_FOREVER();

	    CLI_Write((_u8 *)"\r\n Device URN = ");
	    CLI_Write(g_device_urn);
	    CLI_Write((_u8 *)"\r\n");

	    /* Process the async events from the NWP */
	    while(1)
	    {
	        Semaphore_pend(Semaphore_CC3100_Req, BIOS_WAIT_FOREVER);
	        _SlNonOsMainLoopTask();
	    }

}