示例#1
0
文件: wlanapi.c 项目: reactos/reactos
static void WlanDisconnect_test(void)
{
    DWORD ret;
    
    /* invalid pReserved */
    ret = WlanDisconnect((HANDLE) -1, &InterfaceGuid, (PVOID) 1);
    ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n");
    
    /* invalid InterfaceGuid */
    ret = WlanDisconnect((HANDLE) -1, NULL, NULL);
    ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n");

    /* invalid hClientHandle */
    ret = WlanDisconnect(NULL, &InterfaceGuid, NULL);
    ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n");
}
示例#2
0
void		wififriend_disconnect_user(GtkWidget* Widget, gpointer Data)
{
	t_wifi	Disconnect;

	Disconnect = wififriend_create_handle();
	Disconnect = wififriend_retrieve_config(Disconnect);
	if ((WlanDisconnect(Disconnect.MyHandle, &Disconnect.MyGuid, NULL)!= ERROR_SUCCESS))
		error_cannot_disconnect(0);
	else
		error_disconnect_success(0);
	WlanCloseHandle(Disconnect.MyHandle, NULL);
}
示例#3
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 0 means success, -1 means failure
//!
//! \note
//!
//! \warning    If the WLAN connection fails or we don't aquire an IP address,
//!             We will be stuck in this function forever.
//
//*****************************************************************************
int WlanConnect()
{
    int iRetCode = 0;
    int iRetVal = 0;
    int iConnect = 0;
    unsigned char ucQueueMsg = 0;
    SlSecParams_t secParams;

    secParams.Key = (signed char *)SECURITY_KEY;
    secParams.KeyLen = strlen((const char *)secParams.Key);
    secParams.Type = SECURITY_TYPE;

    //
    // Set up the watchdog interrupt handler.
    //
    WDT_IF_Init(WatchdogIntHandler, MILLISECONDS_TO_TICKS(WD_PERIOD_MS));
    /* Enabling the Sleep clock for the Watch Dog Timer*/
    MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_SLP_MODE_CLK);
    
    g_ucFeedWatchdog = 1;
    g_ucWdogCount = 0;
    while(!(ucQueueMsg & (EVENT_IP_ACQUIRED|CONNECTION_FAILED)))
    {
        UART_PRINT("Trying to connect to AP: ");
        UART_PRINT(SSID_NAME);
        UART_PRINT("\n\r");
        sl_WlanConnect((signed char *)SSID_NAME,
                        strlen((const char *)SSID_NAME), 0, &secParams, 0);
        iConnect = 0;
        do{
            osi_MsgQRead(&g_tConnection, &ucQueueMsg, OSI_WAIT_FOREVER);

            switch(ucQueueMsg)
            {
                case EVENT_CONNECTION:
                    iConnect = 1;
                    break;

                case EVENT_IP_ACQUIRED:
                    iRetVal = 0;
                    break;

                case WDOG_EXPIRED:

                    //
                    // disconnect from the Access Point
                    //
                    if(iConnect)
                    {
                        WlanDisconnect();
                    }

                    //
                    // stop the simplelink with reqd. timeout value (30 ms)
                    //
                    sl_Stop(SL_STOP_TIMEOUT);

                    UART_PRINT("sl stop\n\r");

                    MAP_UtilsDelay(8000);

                    //
                    // starting the simplelink
                    //
                    sl_Start(NULL, NULL, NULL);

                    UART_PRINT("sl start\n\r");
                    break;

                case EVENT_DISCONNECTION:
                    iConnect = 0;
                    break;

                case CONNECTION_FAILED:
                    iRetVal = -1;
                    break;

                default:
                    UART_PRINT("unexpected event\n\r");
                    break;
            }
        }while(ucQueueMsg == (unsigned char)EVENT_CONNECTION);
    }
    iRetCode = MAP_WatchdogRunning(WDT_BASE);
    if(iRetCode)
    {
       WDT_IF_DeInit();
       MAP_PRCMPeripheralClkDisable(PRCM_WDT, PRCM_RUN_MODE_CLK);
    }
    ASSERT_ON_ERROR(iRetVal);
    return(iRetVal);
}
示例#4
0
//*****************************************************************************
//
//! Main which invokes the WPS provisioning APIs
//!
//! \param  none
//!
//! \return 0
//
//*****************************************************************************
void
main()
{
    long lRetVal = -1;
    //
    // Initialize board configurations
    BoardInit();
    //
    // Configure the pinmux settings for the peripherals exercised
    //
    PinMuxConfig();

#ifndef NOTERM
    //
    // Configuring UART
    //
    InitTerm();
#endif
   
    // configure RED LED
    GPIO_IF_LedConfigure(LED1);

    GPIO_IF_LedOff(MCU_RED_LED_GPIO);

    InitializeAppVariables();

    //
    // Following function configure the device to default state by cleaning
    // the persistent settings stored in NVMEM (viz. connection profiles &
    // policies, power policy etc)
    //
    // Applications may choose to skip this step if the developer is sure
    // that the device is in its default state at start of applicaton
    //
    // Note that all profiles and persistent settings that were done on the
    // device will be lost
    //
    lRetVal = ConfigureSimpleLinkToDefaultState();
    if(lRetVal < 0)
    {
        if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
            UART_PRINT("Failed to configure the device in its default state \n\r");

        LOOP_FOREVER();
    }

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

    //
    // Initialzing the CC3200 networking layers
    //
    lRetVal = sl_Start(NULL, NULL, NULL);
    if (lRetVal < 0 || ROLE_STA != lRetVal)
    {
        UART_PRINT("Failed to start the device \n\r");
        LOOP_FOREVER();
    }

    UART_PRINT("Device started as STATION \n\r");

    //
    // Connecting to WLAN AP with WPS security, using Push Button method.
    // The AP parameters are set with static values defined at the top.
    // After this function call we will be connected and have IP address.
    //
    lRetVal = WpsConnectPushButton();
    if(lRetVal < 0)
    {
        ERR_PRINT("Connect through push button failed\n\r");
        LOOP_FOREVER();
    }

    //
    // Turn ON the RED LED to indicate connection success
    //
    GPIO_IF_LedOn(MCU_RED_LED_GPIO);

    //
    // Wait for a while
    //
    MAP_UtilsDelay(80000000);

    //
    // Disconnect from the WLAN AP.
    // After this function call we will be disconnected
    //
    lRetVal = WlanDisconnect();
    if(lRetVal < 0)
    {
        ERR_PRINT("Disconect failed\n\r");
        LOOP_FOREVER();
    }

    MAP_UtilsDelay(8000000);

    //
    // Turn OFF the RED LED to indicate connection disconnected
    //
    GPIO_IF_LedOff(MCU_RED_LED_GPIO);

    //
    // Connecting to WLAN AP with WPS security, using Pin Code method.
    // The default pin code is as specified in WPS_PIN_CODE.
    // The AP parameters are set with static values defined at the top.
    // After this function call we will be connected and have IP address.
    //
    lRetVal = WpsConnectPinCode();
    if(lRetVal < 0)
    {
        ERR_PRINT("Connect through pin code failed\n\r");
        LOOP_FOREVER();
    }

    //
    // Turn ON the RED LED to indicate connection success
    //
    GPIO_IF_LedOn(MCU_RED_LED_GPIO);

    //
    // Wait for a while
    //
    MAP_UtilsDelay(80000000);

    //
    // Disconnect from the WLAN AP.
    // After this function call we will be disconnected
    //
    lRetVal = WlanDisconnect();
    if(lRetVal < 0)
    {
        ERR_PRINT("Disconnect failed\n\r");
        LOOP_FOREVER();
    }

    //
    // Turn OFF the RED LED to indicate connection disconnected
    //
    GPIO_IF_LedOff(MCU_RED_LED_GPIO);
    lRetVal = sl_Stop(SL_STOP_TIMEOUT);

    while (1)
    {
        _SlNonOsMainLoopTask();
    }

}
示例#5
0
//*****************************************************************************
//
//! \brief Task Created by main fucntion. This task prints the wake up reason
//!        (from hibernate or from restart). start simplelink, set NWP power
//!        policy and connects to an AP. Creates UDP client and send UDP
//!        packets at around 1Mbit/sec for certain time. Disconnect form AP
//!        and stops the simplelink.Setup GPIO and Timer as wakeup source from
//!        low power modes. Go into HIBernate.
//!
//! \param pvParameters is a general void pointer (not used here).
//!
//! \return none
//
//*****************************************************************************
void TimerGPIOTask(void *pvParameters)
{
    cc_hndl tTimerHndl;
    cc_hndl tGPIOHndl;
    int iSockDesc = 0;
    int iRetVal = 0;
    int iCounter = 0;
    sockaddr_in sServerAddr;
    unsigned char *pcSendBuff;
    unsigned char cSyncMsg;

    //
    // creating the queue for signalling about connection events
    //
    iRetVal = osi_MsgQCreate(&g_tConnection, NULL, sizeof( unsigned char ), 3);
    if (iRetVal < 0)
    {
        UART_PRINT("unable to create the msg queue\n\r");
        LOOP_FOREVER();
    }
    
    // filling the buffer
    for (iCounter=0 ; iCounter<BUFF_SIZE ; iCounter++)
    {
        g_cBsdBuf[iCounter] = (char)(iCounter % 10);
    }
    pcSendBuff = g_cBsdBuf;

    if(MAP_PRCMSysResetCauseGet() == PRCM_POWER_ON)
    {
        //
        // Displays the Application Banner
        //
        DisplayBanner();
        
        //
        // starting the simplelink
        //
        iRetVal = sl_Start(NULL, NULL, NULL);
        if (iRetVal < 0)
        {
            UART_PRINT("Failed to start the device \n\r");
            LOOP_FOREVER();
        }

        //
        // Switch to STA mode if device is not in this mode
        //
        SwitchToStaMode(iRetVal);

        //
        // Set the power management policy of NWP
        //
        iRetVal = sl_WlanPolicySet(SL_POLICY_PM, SL_NORMAL_POLICY, NULL, 0);
        if (iRetVal < 0)
        {
            UART_PRINT("unable to configure network power policy\n\r");
            LOOP_FOREVER();
        }
    }
    else if(MAP_PRCMSysResetCauseGet() == PRCM_HIB_EXIT)
    {
        UART_PRINT("woken from hib\n\r");
        //
        // starting the simplelink
        //
        iRetVal = sl_Start(NULL, NULL, NULL);
        if (iRetVal < 0)
        {
            UART_PRINT("Failed to start the device \n\r");
            LOOP_FOREVER();
        }
    }
    else if(MAP_PRCMSysResetCauseGet() == PRCM_WDT_RESET)
    {
        UART_PRINT("woken from WDT Reset\n\r");
        //
        // starting the simplelink
        //
        iRetVal = sl_Start(NULL, NULL, NULL);
        if (iRetVal < 0)
        {
            UART_PRINT("Failed to start the device \n\r");
            LOOP_FOREVER();
        }
    }
    else
    {
        UART_PRINT("woken cause unknown\n\r");
    }
    
    //
    // connecting to the Access Point
    //
    if(-1 == WlanConnect())
    {
        UART_PRINT("Connection to AP failed\n\r");
        goto no_network_connection;
    }else{
        UART_PRINT("Connected to AP\n\r");
    }
    
    //
    // creating a UDP socket
    //
    iSockDesc = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);

    if(iSockDesc < 0)
    {
        UART_PRINT("sock error\n\r");
        LOOP_FOREVER();
    }

    //
    // configure the UDP Server address
    //
    sServerAddr.sin_family = SL_AF_INET;
    sServerAddr.sin_port = sl_Htons(APP_UDP_PORT);
    sServerAddr.sin_addr.s_addr = sl_Htonl(SERVER_IP_ADDRESS);

    //
    // Set 5 sec timer allowing 5 sec of UDP Tx.
    //
    tTimerHndl = SetTimer();

    g_ucTrafficEnable = 1;
    while(g_ucTrafficEnable == 1)
    {
        //
        // sending message
        //
        iRetVal = sendto(iSockDesc, pcSendBuff,BUFF_SIZE, 0,
                        (struct sockaddr *)&sServerAddr,sizeof(sServerAddr));
        if(iRetVal < 0)
        {
            UART_PRINT("send error\n\r");
            LOOP_FOREVER();
        }
        ManageDelay(128,BUFF_SIZE);
    }
    UART_PRINT("sent\n\r");

    //
    // stop and delete the timer
    //
    cc_timer_stop(tTimerHndl);
    cc_timer_delete(tTimerHndl);

    //
    //close the socket
    //
    close(iSockDesc);

    if(iRetVal < 0)
    {
        UART_PRINT("could not close the socket\n\r");
    }
    
    //
    // disconnect from the Access Point
    //
    WlanDisconnect();

no_network_connection:
    //
    // stop the simplelink with reqd. timeout value (30 ms)
    //
    sl_Stop(SL_STOP_TIMEOUT);

    //
    // setting Timer as one of the wakeup source
    //
    tTimerHndl = SetTimerAsWkUp();

    //
    // setting some GPIO as one of the wakeup source
    //
    tGPIOHndl = SetGPIOAsWkUp();

    /* handles, if required, can be used to stop the timer, but not used here*/
    UNUSED(tTimerHndl);
    UNUSED(tGPIOHndl);

    //
    // Setting up HIBERNATE as the lowest power mode for the system.
    //
    lp3p0_setup_power_policy(POWER_POLICY_HIBERNATE);

    //
    // idle wait will push the system into the lowest power mode(HIBERNATE).
    //
    iRetVal = osi_MsgQCreate(&g_tWaitForHib, NULL, sizeof( unsigned char ), 1);
    if (iRetVal < 0)
    {
           UART_PRINT("unable to create the msg queue\n\r");
           LOOP_FOREVER();
    }
    osi_MsgQRead(&g_tWaitForHib, &cSyncMsg, OSI_WAIT_FOREVER);

    //
    // infinite loop (must not reach here)
    //
    LOOP_FOREVER();

}