Esempio n. 1
0
File: main.c Progetto: 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;
}
Esempio n. 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;
}
Esempio n. 3
0
int main()
{

    unsigned char ucP2PParam[4];
    long lRetVal = -1;

    //
    // Initialize Board configurations
    //
    BoardInit();
    
    //
    // Pinmuxing for GPIO, UART
    //
    PinMuxConfig();
    
    //
    // configure LEDs
    //
    GPIO_IF_LedConfigure(LED1|LED2|LED3);
    
    // off all LEDs
    GPIO_IF_LedOff(MCU_ALL_LED_IND);
    
#ifndef NOTERM
    //
    // Configuring UART
    //
    InitTerm();
#endif

    
    //
    // Display the Application Banner
    //
    DisplayBanner(APP_NAME);

    UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r");

    // Initializing the CC3200 device
    lRetVal = StartDeviceInP2P();
    if(lRetVal < 0)
    {
    	LOOP_FOREVER(__LINE__);
    }

    // Set any p2p option (SL_CONNECTION_POLICY(0,0,0,any_p2p,0)) to connect to
    // first available p2p device
    sl_WlanPolicySet(SL_POLICY_CONNECTION,SL_CONNECTION_POLICY(1,0,0,0,0),NULL,0);

    // Set the negotiation role (SL_P2P_ROLE_NEGOTIATE).
    // CC3200 will negotiate with remote device GO/client mode.
    // Other valid options are:
    //             - SL_P2P_ROLE_GROUP_OWNER
    //             - SL_P2P_ROLE_CLIENT
    sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE,
            SL_P2P_NEG_INITIATOR_ACTIVE),NULL,0);


    // Set P2P Device name
    sl_NetAppSet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN,
            strlen(P2P_DEVICE_NAME), (unsigned char *)P2P_DEVICE_NAME);

    // Set P2P device type
    sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_DEV_TYPE,
            strlen(P2P_CONFIG_VALUE), (unsigned char*)P2P_CONFIG_VALUE);

    // setting P2P channel parameters
    ucP2PParam[0] = LISENING_CHANNEL;
    ucP2PParam[1] = REGULATORY_CLASS;
    ucP2PParam[2] = OPERATING_CHANNEL;
    ucP2PParam[3] = REGULATORY_CLASS;

    // Set P2P Device listen and open channel valid channels are 1/6/11
    sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, WLAN_P2P_OPT_CHANNEL_N_REGS,
                sizeof(ucP2PParam), ucP2PParam);

    // Restart as P2P device
    sl_Stop(SL_STOP_TIMEOUT);
    lRetVal = sl_Start(NULL,NULL,NULL);

    if(lRetVal < 0 || lRetVal != ROLE_P2P)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER(__LINE__);
    }
    else
    {
        UART_PRINT("Connect to %s \n\r",P2P_DEVICE_NAME);
    }
    
    /* Connect to configure P2P device */
    lRetVal = WlanConnect();

    if(lRetVal == 0)
    {
        GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
    }
    else
    {
        UART_PRINT("Reset the device and try again\n\r");
        LOOP_FOREVER(__LINE__);
    }

    DisplayIP();
    UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r");
    
    /*After calling this function, you can start sending data to CC3200 IP
    * address on PORT_NUM */
    if(!(IS_CONNECT_FAILED(g_ulStatus)))
        BsdTcpServer(PORT_NUM);

    UART_PRINT("Received TCP packets successfully \n\r");
    
    // revert Device into STA mode and power off Network Processor
    sl_WlanSetMode(ROLE_STA);
    sl_Stop(SL_STOP_TIMEOUT);
    UART_PRINT("Test passed, exiting application... \n\r");
    while(1)
    {
        _SlNonOsMainLoopTask();
    }
}
Esempio n. 4
0
File: main.c Progetto: dlugaz/All
int main()
{
    long lRetVal = -1;

    //
    // Initialize Board configurations
    //
    BoardInit();
    
    //
    // Pinmuxing for GPIO, UART
    //
    PinMuxConfig();
    
    //
    // configure LEDs
    //
    GPIO_IF_LedConfigure(LED1|LED2|LED3);
    
    // off all LEDs
    GPIO_IF_LedOff(MCU_ALL_LED_IND);
    
#ifndef NOTERM
    //
    // Configuring UART
    //
    InitTerm();
#endif

    
    //
    // Display the Application Banner
    //
    DisplayBanner(APP_NAME);

    UART_PRINT("Scan Wi-FI direct device in your handheld device\n\r");

    // Initializing the CC3200 device
    lRetVal = StartDeviceInP2P();
    if(lRetVal < 0)
    {
        UART_PRINT("Start Device in P2P mode failed \n\r");
        LOOP_FOREVER();
    }
    
    lRetVal = P2PConfiguration();
    if(lRetVal < 0)
    {
        UART_PRINT("Setting P2P configuration failed\n\r");
        LOOP_FOREVER();
    }
    /* Connect to configure P2P device */
    lRetVal = WlanConnect();

    if(lRetVal == 0)
    {
        GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
    }
    else
    {
        UART_PRINT("Reset the device and try again\n\r");
        LOOP_FOREVER();
    }

    if(DisplayIP() < 0)
    {
        UART_PRINT("Get IP address failed \n\r");
        LOOP_FOREVER();
    }
    UART_PRINT("Send TCP packets from your handheld device to CC3200's IP\n\r");
    
    /*After calling this function, you can start sending data to CC3200 IP
    * address on PORT_NUM */
    if(!(IS_CONNECT_FAILED(g_ulStatus)))
    {
        lRetVal = BsdTcpServer(PORT_NUM);
        if(lRetVal >= 0)
        {
            UART_PRINT("Received TCP packets successfully \n\r");
        }
        else if(lRetVal == CLIENT_DISCONNECTED)
        {
            UART_PRINT("P2P Client disconnected \n\r");
        }
        else
        {
            UART_PRINT("TCP packets receive failed \n\r");
        }

    }

    if(lRetVal >=0)
    {
    	UART_PRINT("Test passed, exiting application... \n\r");
    }
    else
    {
    	UART_PRINT("Test failed, exiting application... \n\r");
    }

    // revert Device into STA mode and power off Network Processor
    lRetVal = sl_WlanSetMode(ROLE_STA);
    if(lRetVal < 0)
    {
         ERR_PRINT(lRetVal);
         LOOP_FOREVER();
    }

    lRetVal = sl_Stop(SL_STOP_TIMEOUT);

    GPIO_IF_LedOff(MCU_IP_ALLOC_IND);


    while(1)
    {
        _SlNonOsMainLoopTask();
    }
}