コード例 #1
0
ファイル: wwd_platform.c プロジェクト: fishbaoz/wiced-emw3165
void host_platform_power_wifi( wiced_bool_t power_enabled )
{
    if ( power_enabled == WICED_FALSE )
    {
        /* Enable WLAN SRAM */
        platform_pmu_wifi_sram_on( );

        platform_pmu_wifi_allowed_to_sleep( );
        platform_pmu_wifi_off( );

        /* delay 100 ms */
        host_rtos_delay_milliseconds( 100 );
    }
    else
    {
        /* Enable WLAN SRAM */
        platform_pmu_wifi_sram_on( );

        /* Power and wake up WLAN core */
        platform_pmu_wifi_on( );
        platform_pmu_wifi_wake_up( );

        /* Disable WLAN SRAM. This is okay because apps core holds WLAN up */
        platform_pmu_wifi_sram_off( );
    }
}
コード例 #2
0
ファイル: NoOS_canned_send.c プロジェクト: 119/bcm-wiced-sdk
int main( void )
{
    wiced_mac_t dest_mac = { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
    char* payload_ptr = 0;
    wwd_result_t result;

    NoOS_setup_timing( );

    WPRINT_APP_INFO(("\nPlatform " PLATFORM " initialised\n"));

    /* Initialise Wiced */
    WPRINT_APP_INFO(("Starting Wiced v" WICED_VERSION "\n"));
    nons_buffer_init_t pkt_buff_init = { pkt_buffer, sizeof( pkt_buffer ) };

    while ( WWD_SUCCESS != ( result = wwd_management_init( COUNTRY, &pkt_buff_init ) ) )
    {
        WPRINT_APP_INFO(("Error %d while starting WICED!\n", result));
    }

    /* Get MAC address - this needs to be done before joining a network, so that */
    /* we can check the address of any incoming packets against our MAC */
    wwd_wifi_get_mac_address( &my_mac, WWD_STA_INTERFACE );

    /* Attempt to join the Wi-Fi network */
    WPRINT_APP_INFO(("Joining : " AP_SSID "\n"));
    while ( wwd_wifi_join( &ap_ssid, AP_SEC, (uint8_t*) AP_PASS, sizeof( AP_PASS ) - 1, NULL ) != WWD_SUCCESS )
    {
        WPRINT_APP_INFO(("Failed to join  : " AP_SSID "   .. retrying\n"));
    }
    WPRINT_APP_INFO(("Successfully joined : " AP_SSID "\n"));

    if ( PKT_TARGET_IP != 0xFFFFFFFF )  /* Check if the target has a broadcast address */
    {
        /* Send an ARP request to resolve the destination IP address into a MAC address */
        resolve_dest_mac( PKT_TARGET_IP, &dest_mac );
    }

    /* Loop forever, repeatedly sending the UDP packet */
    while ( 1 )
    {
        int i;

        /* Setup the packet buffer with the canned packet contents. */
        payload_ptr = setup_canned_packet( pkt_buffer, sizeof( pkt_buffer ), my_ip_addr, &my_mac, PKT_TARGET_IP, &dest_mac, LOCAL_UDP_PORT, PKT_TARGET_UDP_PORT );

        /* Copy the payload into the packet */
        memcpy( payload_ptr, PAYLOAD, sizeof( PAYLOAD ) - 1 );

        WPRINT_APP_INFO(("Sending Hello!\n"));
        send_canned_packet( pkt_buffer, sizeof( PAYLOAD ) - 1 );

        for ( i = 0; i < 10; i++ )
        {
            host_rtos_delay_milliseconds( 100 );
            /* Poll for packets to receive (which will be dropped) - 802.11 device will run out of memory if packets are not read out of it */
            while ( wwd_thread_poll_all( ) != 0 )
            { }
        }
    }
}
コード例 #3
0
ファイル: wwd_SDIO.c プロジェクト: 119/bcm-wiced-sdk
wwd_result_t host_platform_sdio_enumerate( void )
{
    wwd_result_t result;
    uint32_t       loop_count;
    uint32_t       data = 0;

    loop_count = 0;
    do
    {
        /* Send CMD0 to set it to idle state */
        host_platform_sdio_transfer( BUS_WRITE, SDIO_CMD_0, SDIO_BYTE_MODE, SDIO_1B_BLOCK, 0, 0, 0, NO_RESPONSE, NULL );

        /* CMD5. */
        host_platform_sdio_transfer( BUS_READ, SDIO_CMD_5, SDIO_BYTE_MODE, SDIO_1B_BLOCK, 0, 0, 0, NO_RESPONSE, NULL );

        /* Send CMD3 to get RCA. */
        result = host_platform_sdio_transfer( BUS_READ, SDIO_CMD_3, SDIO_BYTE_MODE, SDIO_1B_BLOCK, 0, 0, 0, RESPONSE_NEEDED, &data );
        loop_count++;
        if ( loop_count >= (uint32_t) SDIO_ENUMERATION_TIMEOUT_MS )
        {
            return WICED_TIMEOUT;
        }
    } while ( ( result != WWD_SUCCESS ) && ( host_rtos_delay_milliseconds( (uint32_t) 1 ), ( 1 == 1 ) ) );
    /* If you're stuck here, check the platform matches your hardware */

    /* Send CMD7 with the returned RCA to select the card */
    host_platform_sdio_transfer( BUS_WRITE, SDIO_CMD_7, SDIO_BYTE_MODE, SDIO_1B_BLOCK, data, 0, 0, RESPONSE_NEEDED, NULL );

    return WICED_SUCCESS;
}
コード例 #4
0
ファイル: platform.c プロジェクト: fishbaoz/wiced-emw3165
/* Checks if a factory reset is requested */
wiced_bool_t platform_check_factory_reset( void )
{
    uint32_t factory_reset_counter = 0;
    int led_state = 0;
    while (  ( 0 == platform_gpio_input_get( &platform_gpio_pins[ WICED_BUTTON1 ] ) )
          && ( ( factory_reset_counter += PLATFORM_FACTORY_RESET_CHECK_PERIOD ) <= PLATFORM_FACTORY_RESET_TIMEOUT )
          && ( WICED_SUCCESS == (wiced_result_t)host_rtos_delay_milliseconds( PLATFORM_FACTORY_RESET_CHECK_PERIOD ) )
          )
    {
        /* Factory reset button is being pressed. */
        /* User Must press it for 5 seconds to ensure it was not accidental */
        /* Toggle LED every 100ms */

        if ( led_state == 0 )
        {
            platform_gpio_output_high( &platform_gpio_pins[ WICED_LED1 ] );
            led_state = 1;
        }
        else
        {
            platform_gpio_output_low( &platform_gpio_pins[ WICED_LED1 ] );
            led_state = 0;
        }
        if ( factory_reset_counter == 5000 )
        {
            return WICED_TRUE;
        }
    }
    return WICED_FALSE;
}
コード例 #5
0
ファイル: wwd_rtos.c プロジェクト: 119/bcm-wiced-sdk
/**
 * Blocks the current thread until the indicated thread is complete
 *
 * @param thread         : handle of the thread to terminate
 *
 * @returns WWD_SUCCESS on success, WICED_ERROR otherwise
 */
wwd_result_t host_rtos_join_thread( host_thread_type_t* thread )
{
    while ( ( thread->tx_thread_state != TX_COMPLETED ) && ( thread->tx_thread_state != TX_TERMINATED ) )
    {
        host_rtos_delay_milliseconds( 10 );
    }
    return WWD_SUCCESS;
}
コード例 #6
0
wwd_result_t wwd_ensure_wlan_bus_is_up( void )
{
    /* Ensure HT clock is up */
    if ( bus_is_up == WICED_TRUE )
    {
        return WWD_SUCCESS;
    }

    if ( save_restore_enable == WICED_FALSE )
    {
        uint8_t csr = 0;
        uint32_t attempts = (uint32_t) WLAN_BUS_UP_ATTEMPTS;

        VERIFY_RESULT( wwd_bus_write_register_value( BACKPLANE_FUNCTION, (uint32_t) SDIO_CHIP_CLOCK_CSR, (uint8_t) 1, (uint32_t) SBSDIO_HT_AVAIL_REQ ) );

        do
        {
            VERIFY_RESULT( wwd_bus_read_register_value( BACKPLANE_FUNCTION, (uint32_t) SDIO_CHIP_CLOCK_CSR, (uint8_t) 1, &csr ) );
            --attempts;
        }
        while ( ( ( csr & SBSDIO_HT_AVAIL ) == 0 ) &&
                ( attempts != 0 ) &&
                ( host_rtos_delay_milliseconds( (uint32_t) 1 ), 1==1 ) );

        if (attempts == 0)
        {
            return WWD_SDIO_BUS_UP_FAIL;
        }
        else
        {
            bus_is_up = WICED_TRUE;
            return WWD_SUCCESS;
        }
    }
    else
    {
        if ( wwd_kso_enable( WICED_TRUE ) == WWD_SUCCESS )
        {
            bus_is_up = WICED_TRUE;
            return WWD_SUCCESS;
        }
        else
        {
            return WWD_SDIO_BUS_UP_FAIL;
        }
    }
}
コード例 #7
0
ファイル: platform.c プロジェクト: MXCHIP/MXCHIP-for-WICED
uint32_t  platform_get_factory_reset_button_time ( uint32_t max_time )
{
    uint32_t button_press_timer = 0;
    int led_state = 0;

    /* Initialise input */
     platform_gpio_init( &platform_gpio_pins[ PLATFORM_FACTORY_RESET_BUTTON_GPIO ], INPUT_PULL_UP );

     while ( (PLATFORM_FACTORY_RESET_PRESSED_STATE == platform_gpio_input_get(&platform_gpio_pins[ PLATFORM_FACTORY_RESET_BUTTON_GPIO ])) )
    {
         /* How long is the "Factory Reset" button being pressed. */
         host_rtos_delay_milliseconds( PLATFORM_FACTORY_RESET_CHECK_PERIOD );

         /* Toggle LED every PLATFORM_FACTORY_RESET_CHECK_PERIOD  */
        if ( led_state == 0 )
        {
            platform_gpio_output_high( &platform_gpio_pins[ PLATFORM_FACTORY_RESET_LED_GPIO ] );
            led_state = 1;
        }
        else
        {
            platform_gpio_output_low( &platform_gpio_pins[ PLATFORM_FACTORY_RESET_LED_GPIO ] );
            led_state = 0;
        }

        button_press_timer += PLATFORM_FACTORY_RESET_CHECK_PERIOD;
        if ((max_time > 0) && (button_press_timer >= max_time))
        {
            break;
        }
    }

     /* turn off the LED */
     if (PLATFORM_FACTORY_RESET_LED_ON_STATE == 1)
     {
         platform_gpio_output_low( &platform_gpio_pins[ PLATFORM_FACTORY_RESET_LED_GPIO ] );
     }
     else
     {
         platform_gpio_output_high( &platform_gpio_pins[ PLATFORM_FACTORY_RESET_LED_GPIO ] );
     }

    return button_press_timer;
}
コード例 #8
0
ファイル: wwd_bus_protocol.c プロジェクト: 119/bcm-wiced-sdk
void boot_wlan( void )
{
#ifdef MFG_TEST_ALTERNATE_WLAN_DOWNLOAD
    external_write_wifi_firmware_and_nvram_image( );
#else
    /* Load wlan firmware from sflash */
    wwd_bus_write_wifi_firmware_image();

    /* Load nvram from sflash */
    wwd_bus_write_wifi_nvram_image( );
#endif /* ifdef MFG_TEST_ALTERNATE_WLAN_DOWNLOAD */

    /* init wlan uart */
    init_wlan_uart();

    /* Reset ARM core */
    reset_wlan_core( );

    host_rtos_delay_milliseconds( 200 );
}
コード例 #9
0
ファイル: wlu_server.c プロジェクト: fishbaoz/wiced-emw3165
void
rwl_sleep(int delay)
{
    host_rtos_delay_milliseconds( delay );
}
コード例 #10
0
ファイル: wwd_ap.c プロジェクト: humminglab/wiced-project
static wwd_result_t internal_ap_init( wiced_ssid_t* ssid, wiced_security_t auth_type, const uint8_t* security_key, uint8_t key_length, uint8_t channel )
{
    wiced_bool_t   wait_for_interface = WICED_FALSE;
    wwd_result_t   result;
    wiced_buffer_t response;
    wiced_buffer_t buffer;
    uint32_t*      data;
    uint32_t       bss_index = WWD_AP_INTERFACE;

#ifdef WICED_WIFI_SOFT_AP_WEP_SUPPORT_ENABLED
    uint32_t* auth;
    uint16_t length;
#endif

    if ( ( ( auth_type == WICED_SECURITY_WPA_TKIP_PSK ) || ( auth_type == WICED_SECURITY_WPA2_AES_PSK ) || ( auth_type == WICED_SECURITY_WPA2_MIXED_PSK ) ) &&
         ( ( key_length < (uint8_t) 8 ) || ( key_length > (uint8_t) 64 ) ) )
    {
        WPRINT_APP_INFO(( "Error: WPA security key length must be between 8 and 64\n" ));
        return WWD_WPA_KEYLEN_BAD;
    }

#ifdef WICED_WIFI_SOFT_AP_WEP_SUPPORT_ENABLED
    else if( (( auth_type == WICED_SECURITY_WEP_PSK ) || ( auth_type == WICED_SECURITY_WEP_SHARED )) &&
             (( key_length != FORMATTED_ASCII_WEP40_KEY_LENGTH ) && ( key_length != FORMATTED_ASCII_WEP104_KEY_LENGTH )) )
    {
        WPRINT_APP_INFO(( "Error: WEP security Key length must be either 5 / 13 bytes\n" ));
        return WWD_WEP_KEYLEN_BAD;
    }
#endif

    if ( ( wwd_wifi_p2p_go_is_up == WICED_TRUE ) || ( wwd_wifi_ap_is_up == WICED_TRUE ) )
    {
        WPRINT_APP_INFO(( "Error: Soft AP or Wi-Fi Direct group owner already up\n" ));
        return WWD_AP_ALREADY_UP;
    }

    /* Query bss state (does it exist? if so is it UP?) */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 4, IOVAR_STR_BSS );
    CHECK_IOCTL_BUFFER( data );
    *data = (uint32_t) bss_index;
    if ( wwd_sdpcm_send_iovar( SDPCM_GET, buffer, &response, WWD_STA_INTERFACE ) != WWD_SUCCESS )
    {
        /* Note: We don't need to release the response packet since the iovar failed */
        wait_for_interface = WICED_TRUE;
    }
    else
    {
        /* Check if the BSS is already UP, if so return */
        uint32_t* data2 = (uint32_t*) host_buffer_get_current_piece_data_pointer( response );
        if ( *data2 == (uint32_t) BSS_UP )
        {
            host_buffer_release( response, WWD_NETWORK_RX );
            wwd_wifi_ap_is_up = WICED_TRUE;
            return WWD_SUCCESS;
        }
        else
        {
            host_buffer_release( response, WWD_NETWORK_RX );
        }
    }

    CHECK_RETURN( host_rtos_init_semaphore( &wwd_wifi_sleep_flag ) );

    /* Register for interested events */
    CHECK_RETURN_WITH_SEMAPHORE( wwd_management_set_event_handler( apsta_events, wwd_handle_apsta_event, NULL, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

    /* Check if we need to wait for interface to be created */
    if ( wait_for_interface == WICED_TRUE )
    {
        CHECK_RETURN_WITH_SEMAPHORE( host_rtos_get_semaphore( &wwd_wifi_sleep_flag, (uint32_t) 10000, WICED_FALSE ), &wwd_wifi_sleep_flag );
    }

    if ( wwd_wifi_set_block_ack_window_size( WWD_AP_INTERFACE ) != WWD_SUCCESS )
    {
        return WWD_SET_BLOCK_ACK_WINDOW_FAIL;
    }

    /* Set the SSID */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 40, "bsscfg:" IOVAR_STR_SSID );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    data[0] = bss_index; /* Set the bsscfg index */
    data[1] = ssid->length; /* Set the ssid length */
    memcpy( &data[2], (uint8_t*) ssid->value, ssid->length );
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_STA_INTERFACE ), &wwd_wifi_sleep_flag );

    /* Set the channel */
    data = (uint32_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    *data = channel;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_CHANNEL, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

#ifdef WICED_WIFI_SOFT_AP_WEP_SUPPORT_ENABLED
    if ( ( auth_type == WICED_SECURITY_WEP_PSK ) || ( auth_type == WICED_SECURITY_WEP_SHARED ) )
    {
        for ( length = 0; length < key_length; length = (uint16_t) ( length + 2 + security_key[ 1 ] ) )
        {
            const wiced_wep_key_t* in_key = (const wiced_wep_key_t*) &security_key[ length ];
            wl_wsec_key_t* out_key = (wl_wsec_key_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, sizeof(wl_wsec_key_t) );
            CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( out_key, &wwd_wifi_sleep_flag );
            memset( out_key, 0, sizeof(wl_wsec_key_t) );
            out_key->index = in_key->index;
            out_key->len = in_key->length;
            memcpy( out_key->data, in_key->data, in_key->length );
            switch ( in_key->length )
            {
                case WEP40_KEY_LENGTH:
                    out_key->algo = (uint32_t) CRYPTO_ALGO_WEP1;
                    break;
                case WEP104_KEY_LENGTH:
                    out_key->algo = (uint32_t) CRYPTO_ALGO_WEP128;
                    break;
                default:
                    host_buffer_release( buffer, WWD_NETWORK_TX );
                    return WWD_INVALID_KEY;
            }
            /* Set the first entry as primary key by default */
            if ( length == 0 )
            {
                out_key->flags |= WL_PRIMARY_KEY;
            }
            out_key->index = htod32(out_key->index);
            out_key->len = htod32(out_key->len);
            out_key->algo = htod32(out_key->algo);
            out_key->flags = htod32(out_key->flags);
            CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_KEY, buffer, NULL, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );
        }

        /* Set authentication type */
        auth = (uint32_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
        CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( auth, &wwd_wifi_sleep_flag );
        if ( auth_type == WICED_SECURITY_WEP_SHARED )
        {
            *auth = WEP_SHARED_KEY_AUTHENTICATION; /* 1 = Shared Key authentication */
        }
        else
        {
            *auth = WEP_OPEN_SYSTEM_AUTHENTICATION; /*  0 = Open System authentication */
        }
        CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_AUTH, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );
    }
#endif

    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, "bsscfg:" IOVAR_STR_WSEC );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    data[0] = bss_index;
    if ((auth_type & WPS_ENABLED) != 0)
    {
        data[1] = (uint32_t) ( ( auth_type & ( ~WPS_ENABLED ) ) | SES_OW_ENABLED );
    }
    else
    {
        data[1] = (uint32_t) auth_type;
    }
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_STA_INTERFACE ), &wwd_wifi_sleep_flag );

    if ( ( auth_type != WICED_SECURITY_OPEN ) && ( auth_type != WICED_SECURITY_WEP_PSK ) && ( auth_type != WICED_SECURITY_WEP_SHARED ) )
    {
        wsec_pmk_t* psk;

        /* Set the wpa auth */
        data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, "bsscfg:" IOVAR_STR_WPA_AUTH );
        CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
        data[0] = bss_index;
        data[1] = (uint32_t) (auth_type == WICED_SECURITY_WPA_TKIP_PSK) ? ( WPA_AUTH_PSK ) : ( WPA2_AUTH_PSK | WPA_AUTH_PSK );
        CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_STA_INTERFACE ), &wwd_wifi_sleep_flag );

        /* Set the passphrase */
        psk = (wsec_pmk_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, sizeof(wsec_pmk_t) );
        CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( psk, &wwd_wifi_sleep_flag );
        memcpy( psk->key, security_key, key_length );
        psk->key_len = key_length;
        psk->flags   = (uint16_t) WSEC_PASSPHRASE;
        host_rtos_delay_milliseconds( 1 ); /* Delay required to allow radio firmware to be ready to receive PMK and avoid intermittent failure */
        CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_WSEC_PMK, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );
    }

    /* Set the GMode */
    data = (uint32_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    *data = (uint32_t) GMODE_AUTO;

    result =  wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_GMODE, buffer, 0, WWD_AP_INTERFACE );
    if ( ( result != WWD_SUCCESS ) && ( result != WWD_WLAN_ASSOCIATED ) )
    {
        wiced_assert("start_ap: Failed to set GMode\n", 0 == 1 );

        (void) host_rtos_deinit_semaphore( &wwd_wifi_sleep_flag );
        return result;
    }

    /* Set the multicast transmission rate to 11 Mbps rather than the default 1 Mbps */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 4, IOVAR_STR_2G_MULTICAST_RATE );
    CHECK_IOCTL_BUFFER( data );
    *data = (uint32_t) RATE_SETTING_11_MBPS;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

    /* Set DTIM period */
    data = (uint32_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    *data = (uint32_t) WICED_DEFAULT_SOFT_AP_DTIM_PERIOD;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_DTIMPRD, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

#ifdef WICED_DISABLE_SSID_BROADCAST
    /* Make the AP "hidden" */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 4, IOVAR_STR_CLOSEDNET );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    data[0] = (uint32_t) 1;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );
#endif

#ifdef WICED_WIFI_ISOLATE_AP_CLIENTS
    result = wwd_wifi_enable_ap_isolate( WWD_AP_INTERFACE, WICED_TRUE );
    wiced_assert("start_ap: Failed to disable intra BSS routing\r\n", result == WWD_SUCCESS );
#endif /* WICED_WIFI_ISOLATE_AP_CLIENTS */

    return WWD_SUCCESS;
}
コード例 #11
0
static wwd_result_t wwd_kso_enable (wiced_bool_t enable)
{
    uint8_t write_value = 0;
    uint8_t read_value = 0;
    uint8_t compare_value;
    uint8_t bmask;
    uint32_t attempts = ( uint32_t ) MAX_KSO_ATTEMPTS;
    wwd_result_t result;

    if ( enable == WICED_TRUE )
    {
        write_value |= SBSDIO_SLPCSR_KEEP_SDIO_ON;
    }

    /* 1st KSO write goes to AOS wake up core if device is asleep  */
    /* Possibly device might not respond to this cmd. So, don't check return value here */
    /* 2 Sequential writes to KSO bit are required for SR module to wakeup */
    wwd_bus_write_register_value( BACKPLANE_FUNCTION, (uint32_t) SDIO_SLEEP_CSR, (uint8_t) 1, write_value );
    wwd_bus_write_register_value( BACKPLANE_FUNCTION, (uint32_t) SDIO_SLEEP_CSR, (uint8_t) 1, write_value );

    if ( enable == WICED_TRUE )
    {
        /* device WAKEUP through KSO:
         * write bit 0 & read back until
         * both bits 0(kso bit) & 1 (dev on status) are set
         */
        compare_value = SBSDIO_SLPCSR_KEEP_SDIO_ON | SBSDIO_SLPCSR_DEVICE_ON;
        bmask = compare_value;
    }
    else
    {
        /* Put device to sleep, turn off  KSO  */
        compare_value = 0;
        /* Check for bit0 only, bit1(devon status) may not get cleared right away */
        bmask = SBSDIO_SLPCSR_KEEP_SDIO_ON;
    }

    do
    {
        /* Reliable KSO bit set/clr:
         * Sdiod sleep write access appears to be in sync with PMU 32khz clk
         * just one write attempt may fail,(same is with read ?)
         * in any case, read it back until it matches written value
         */
        result = wwd_bus_read_register_value( BACKPLANE_FUNCTION, (uint32_t) SDIO_SLEEP_CSR, (uint8_t) 1, &read_value );
        if ( ( ( read_value & bmask ) == compare_value ) && ( result == WWD_SUCCESS ) )
        {
            break;
        }

        host_rtos_delay_milliseconds( (uint32_t) KSO_WAIT_MS );

        wwd_bus_write_register_value( BACKPLANE_FUNCTION, (uint32_t) SDIO_SLEEP_CSR, (uint8_t) 1, write_value );
        attempts--;
    } while ( attempts != 0 );

    if ( attempts == 0 )
    {
        return WWD_SDIO_BUS_UP_FAIL;
    }
    else
    {
        return WWD_SUCCESS;
    }
}
コード例 #12
0
ファイル: gpio_trace.c プロジェクト: 119/bcm-wiced-sdk
/**
 * Start tracing scheduler activity.
 */
void gpio_trace_start_trace( trace_flush_function_t flush_f )
{
    /* We don't need a flush function because GPIO tracing does not use "any" memory */
    UNUSED_PARAMETER( flush_f );

    /* Setup the GPIO pins and construct the bit list. */
    gpio_trace_init( );

    /* Print out the GPIO->Bit mapping. */
    Bit_List *curr = least_significant_bit;
    unsigned int i = 0;
    while ( curr != NULL )
    {
#if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED
    #define _GPIO_TRACE_START_TRACE_TEXT    "Bit"
#elif TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ONEBIT
    #define _GPIO_TRACE_START_TRACE_TEXT    "Task"
#endif /* #if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED */
        printf( _GPIO_TRACE_START_TRACE_TEXT " %d => Pin %d\r\n", i, breakout_pins_get_pin_number( curr->settings ) );
        curr = curr->next;
        i++;
    }

    printf( "\r\n" );
    print_tasks( );

#if 0 /* TEST SEQUENCE */
    /* Count the number of GPIO pins available */
    int num_pins = 0;
    curr = least_significant_bit;
    while ( curr != NULL )
    {
        num_pins++;
        curr = curr->next;
    }

    printf( "\r\n" );
    printf( "Testing in 3 seconds..." );

    host_rtos_delay_milliseconds( 1000 );
    printf( "\rTesting in 2 seconds..." );

    host_rtos_delay_milliseconds( 1000 );
    printf( "\rTesting in 1 second... " );

    host_rtos_delay_milliseconds( 1000 );
    printf( "\rTesting...             " );

#if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED
#include <math.h>
    const int max_value = (int) pow( (double) 2, (double) num_pins );
#elif TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ONEBIT
    const int max_value = num_pins;
#endif /* #if TRACE_OUTPUT_TYPE == TRACE_OUTPUT_TYPE_ENCODED */
    for ( i = 0; i < max_value; i++ )
    {
        gpio_encode_value( i );
        host_rtos_delay_milliseconds( 1 );
    }

    gpio_encode_value( all_off );
    printf( "\rTesting... DONE!       \r\n" );
#endif /* 0 */

    /* Flash GPIO pins to indicate start of trace */
    TRACE_START_SEQUENCE( );
} /* gpio_trace_start_trace */
コード例 #13
0
ファイル: wiced_tls.c プロジェクト: fishbaoz/wiced-emw3165
wiced_result_t wiced_supplicant_start_tls( supplicant_workspace_t* supplicant, wiced_tls_endpoint_type_t type, wiced_tls_certificate_verification_t verification )
{
    host_rtos_delay_milliseconds( 10 );
    return wiced_generic_start_tls_with_ciphers( (wiced_tls_simple_context_t*)supplicant->tls_context, supplicant, type, verification, my_ciphers, TLS_EAP_TRANSPORT );
}
コード例 #14
0
wiced_result_t wiced_rtos_delay_milliseconds( uint32_t milliseconds )
{
    return host_rtos_delay_milliseconds( milliseconds );
}
コード例 #15
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
void besl_p2p_test( p2p_workspace_t* workspace )
{
    wiced_buffer_t buffer;
    wiced_result_t result;
    uint32_t* data;
    wiced_mac_t my_mac;

    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    wiced_wifi_get_mac_address( &my_mac );
    my_mac.octet[0] |= 0x2;

    wl_p2p_if_t* p2p_if = wwd_sdpcm_get_iovar_buffer( &buffer, sizeof(wl_p2p_if_t), IOVAR_STR_P2P_IFADD );
    p2p_if->interface_type = P2P_GROUP_OWNER_MODE;
    memcpy( &p2p_if->mac_address, &my_mac, sizeof(besl_mac_t) );
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    /*  Enable discovery */
    data = wwd_sdpcm_get_iovar_buffer( &buffer, 4, IOVAR_STR_P2P_DISC );
    *data = 1;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    wiced_buffer_t response;
    wwd_sdpcm_get_iovar_buffer( &buffer, 4, IOVAR_STR_P2P_DEV );
    result = wwd_sdpcm_send_iovar( SDPCM_GET, buffer, &response, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);
    workspace->p2p_interface = BESL_READ_32(host_buffer_get_current_piece_data_pointer(response));
    host_buffer_release( response, WICED_NETWORK_RX );
    BESL_DEBUG( ("interface = %lu\n", workspace->p2p_interface) );

    data = wiced_get_ioctl_buffer( &buffer, 4 );
    *data = 1;
    result = wiced_send_ioctl( SDPCM_SET, WLC_SET_CHANNEL, buffer, NULL, workspace->p2p_interface );
    wiced_assert("", result == WICED_SUCCESS);

    /*  Set WSEC */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, IOVAR_STR_BSSCFG_WSEC );
    data[0] = (uint32_t) workspace->p2p_interface;
    data[1] = WICED_SECURITY_WPA2_AES_PSK;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, SDPCM_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    wsec_pmk_t* psk;

    /* Set the wpa auth */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, IOVAR_STR_BSSCFG_WPA_AUTH );
    data[0] = (uint32_t) workspace->p2p_interface;
    data[1] = (uint32_t) WPA2_AUTH_PSK;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, SDPCM_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS );

    /* Set the passphrase */
    psk = (wsec_pmk_t*) wiced_get_ioctl_buffer( &buffer, sizeof(wsec_pmk_t) );
    memcpy( psk->key, "YOUR_AP_PASSPHRASE", 18 );
    psk->key_len = 18;
    psk->flags = (uint16_t) WSEC_PASSPHRASE;
    host_rtos_delay_milliseconds( 1 ); /*  Delay required to allow radio firmware to be ready to receive PMK and avoid intermittent failure */
    result = wiced_send_ioctl( SDPCM_SET, WLC_SET_WSEC_PMK, buffer, 0, workspace->p2p_interface );
    wiced_assert("", result == WICED_SUCCESS );

    wlc_ssid_t* p2p_ssid = wwd_sdpcm_get_iovar_buffer( &buffer, sizeof(wl_p2p_if_t), IOVAR_STR_P2P_SSID );
    p2p_ssid->SSID_len = 9;
    memcpy( p2p_ssid->SSID, "DIRECT-ww", 9 );
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WICED_SUCCESS);

    /* Bring up P2P interface */
    wiced_get_ioctl_buffer( &buffer, 0 );
    result = wiced_send_ioctl( SDPCM_SET, WLC_UP, buffer, NULL, workspace->p2p_interface );
    wiced_assert("", result == WICED_SUCCESS);

    p2p_set_discovery_state( P2P_DISCOVERY_STATE_LISTEN );
}
コード例 #16
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
static besl_result_t p2p_run_as_go( p2p_workspace_t* workspace, wps_agent_t* wps_registrar )
{
    uint32_t*             data;
    wwd_result_t          result;
    besl_wps_credential_t credential;
    wiced_buffer_t        buffer;
    uint8_t               passphrase_buffer[32];
    uint8_t               a;

    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    host_rtos_delay_milliseconds( 500 );

    /* Limit the rates used on the P2P soft AP */
    data    = wwd_sdpcm_get_iovar_buffer( &buffer, 4, IOVAR_STR_BSS_RATESET );
    data[0] = 1;
    result  = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_AP_INTERFACE );
    wiced_assert("", result == WWD_SUCCESS);

    /* Prepare the AP credentials */
    credential.security = WICED_SECURITY_WPA2_AES_PSK;
    credential.ssid.length = workspace->group_candidate.ssid.length;
    memcpy( credential.ssid.value, workspace->group_candidate.ssid.value, credential.ssid.length );
    credential.passphrase_length = 64;
    besl_host_random_bytes(passphrase_buffer, 32);
    for ( a = 0; a < 32; ++a )
    {
        credential.passphrase[2*a]     = nibble_to_hexchar(passphrase_buffer[a] >> 4);
        credential.passphrase[2*a + 1] = nibble_to_hexchar(passphrase_buffer[a] & 0x0F);
    }

    /* Start the AP */
    wwd_wifi_start_ap( &workspace->group_candidate.ssid, WICED_SECURITY_WPA2_AES_PSK | WPS_ENABLED, credential.passphrase, credential.passphrase_length, 1 );

    workspace->p2p_interface = WICED_AP_INTERFACE;
    memcpy( &workspace->device_info.mac_address, &workspace->intended_mac_address, sizeof(besl_mac_t) );

    wl_p2p_if_t* p2p_if = wwd_sdpcm_get_iovar_buffer( &buffer, sizeof(wl_p2p_if_t), IOVAR_STR_P2P_IFUPD );
    p2p_if->interface_type = P2P_GROUP_OWNER_MODE;
    memcpy( &p2p_if->mac_address, &workspace->intended_mac_address, sizeof(besl_mac_t) );
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE );
    wiced_assert("", result == WWD_SUCCESS);

    p2p_write_probe_response_ie( workspace );
    p2p_write_beacon_ie( workspace );

    /* Bring up IP layer on AP interface */
    wiced_ip_up( WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &p2p_ip_settings );

    besl_wps_init( wps_registrar, workspace->wps_device_details, WPS_REGISTRAR_AGENT, WICED_AP_INTERFACE );

    /* Init WPS */
    wps_internal_init( wps_registrar, WICED_AP_INTERFACE, WPS_PBC_MODE, "00000000", &credential, 1 );

    /* Run WPS state machine in P2P thread */
    wiced_wps_thread_main( (uint32_t) wps_registrar );

    if ( wps_registrar->wps_result == WPS_COMPLETE )
    {
        workspace->p2p_result = BESL_SUCCESS;
    }
    else
    {
        workspace->p2p_result = wps_registrar->wps_result;
    }

    return BESL_SUCCESS;
}
コード例 #17
0
ファイル: wiced_p2p.c プロジェクト: 119/bcm-wiced-sdk
static besl_result_t p2p_run_as_client( p2p_workspace_t* workspace, wps_agent_t* wps_enrollee )
{
    wwd_result_t        result;
    wl_escan_result_t     p2p_group_ap;
    besl_wps_credential_t credential;
    uint8_t               a;

    /* Start WPS */
    memset( &p2p_group_ap, 0, sizeof(p2p_group_ap) );

    /* Add the P2P association request IE to the STA interface */
    workspace->p2p_interface = WICED_STA_INTERFACE;
    memcpy(&workspace->device_info.mac_address, &workspace->intended_mac_address, sizeof(besl_mac_t));
    p2p_write_association_request_ie( workspace );

    host_rtos_delay_milliseconds(1500);

    besl_wps_init( wps_enrollee, workspace->wps_device_details, WPS_ENROLLEE_AGENT, WICED_STA_INTERFACE);

    /* NOTE: For some reason packet being received on the P2P interface are sent up with an interface of 0 (WICED_STA_INTERFACE) */
    wps_internal_init(wps_enrollee, WICED_STA_INTERFACE, WPS_PBC_MODE, "00000000", &credential, 1);

    /*  Create the AP details */
    p2p_group_ap.bss_info[0].chanspec = WL_CHANSPEC_BAND_2G | workspace->group_candidate.channel;
    p2p_group_ap.bss_info[0].SSID_len = (uint8_t)workspace->group_candidate.ssid.length;
    memcpy(&p2p_group_ap.bss_info[0].BSSID, &workspace->group_candidate.bssid, sizeof(besl_mac_t));
    memcpy(p2p_group_ap.bss_info[0].SSID,    workspace->group_candidate.ssid.value,  p2p_group_ap.bss_info[0].SSID_len);

    /* Add a few copies to the WPS workspace so it will automatically join the designated AP */
    wps_host_store_ap(wps_enrollee->wps_host_workspace, &p2p_group_ap );
    wps_host_store_ap(wps_enrollee->wps_host_workspace, &p2p_group_ap );
    wps_host_store_ap(wps_enrollee->wps_host_workspace, &p2p_group_ap );
    wps_host_store_ap(wps_enrollee->wps_host_workspace, &p2p_group_ap );

    /* Run the WPS state machine in the P2P thread */
    wiced_wps_thread_main((uint32_t)wps_enrollee);

    /* Clean up WPS objects*/
    BESL_INFO( ("WPS complete\n") );
    besl_wps_deinit( wps_enrollee );

    wiced_scan_result_t wps_ap;
    wps_ap.channel  = workspace->group_candidate.channel;
    wps_ap.SSID.length = (uint8_t)workspace->group_candidate.ssid.length;
    wps_ap.security = credential.security;
    wps_ap.band     = WICED_802_11_BAND_2_4GHZ;
    wps_ap.bss_type = WICED_BSS_TYPE_INFRASTRUCTURE;
    memcpy(&wps_ap.BSSID,  &workspace->group_candidate.bssid, sizeof(besl_mac_t));
    memcpy(wps_ap.SSID.value, workspace->group_candidate.ssid.value,  wps_ap.SSID.length);

    /* Try a few times to join the AP with the credentials we've just received */
    result = WWD_PENDING;
    for ( a = 0; a < 3 && result != WWD_SUCCESS; ++a )
    {
        result = wwd_wifi_join_specific( &wps_ap, credential.passphrase, credential.passphrase_length, NULL, WWD_STA_INTERFACE );
    }

    if ( result == WWD_SUCCESS )
    {
        BESL_INFO( ("P2P complete\n") );
        wiced_ip_up(workspace->p2p_interface, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);
        workspace->p2p_result = BESL_SUCCESS;
        return BESL_SUCCESS;
    }
    else
    {
        BESL_INFO( ("P2P couldn't join AP\n") );
        workspace->p2p_result = BESL_ERROR_JOIN_FAILED;
        return BESL_ERROR_JOIN_FAILED;
    }
}
コード例 #18
0
ファイル: usleep.c プロジェクト: 119/bcm-wiced-sdk
int usleep(useconds_t usec) {
    return host_rtos_delay_milliseconds( usec / 1000 );
}
コード例 #19
0
ファイル: wiced_tls.c プロジェクト: fishbaoz/wiced-emw3165
wiced_result_t wiced_generic_start_tls_with_ciphers( wiced_tls_simple_context_t* tls_context, void* referee, wiced_tls_endpoint_type_t type, wiced_tls_certificate_verification_t verification, const cipher_suite_t* cipher_list[], tls_transport_protocol_t transport_protocol )
{
    microrng_state              rngstate;
    int                         prev_state;
    uint64_t                    start_time;
    tls_result_t                result;

    /* Initialize the session data */
    if ( transport_protocol != TLS_EAP_TRANSPORT )
    {
        memset( &tls_context->session, 0, sizeof(wiced_tls_session_t) );
    }
    memset( &tls_context->context, 0, sizeof(wiced_tls_context_t) );

    /* Prepare session and entropy */
    tls_context->session.age = MAX_TLS_SESSION_AGE;
    wwd_wifi_get_random( &rngstate.entropy, 4 );

    /* Initialize session context */ /* TODO: Ideally this should be done once for a socket */
    if ( ssl_init( &tls_context->context ) != 0 )
    {
        wiced_assert("Error initialising SSL", 0!=0 );
        return WICED_TLS_INIT_FAIL;
    }

    tls_context->context.transport_protocol = transport_protocol;

    microrng_init( &rngstate );

    ssl_set_endpoint( &tls_context->context, type );
    ssl_set_rng     ( &tls_context->context, microrng_rand, &rngstate );
    tls_context->context.receive_context = referee;
    tls_context->context.send_context    = referee;
    tls_context->context.get_session     = tls_get_session;
    tls_context->context.set_session     = tls_set_session;
    tls_context->context.ciphers         = cipher_list;
    ssl_set_session ( &tls_context->context, SESSION_CAN_BE_RESUMED, 1000000, &tls_context->session );

    /* Assert if user has not created correct TLS context for the TLS endpoint type */
    wiced_assert("TLS servers must have an advanced TLS context", !((type == WICED_TLS_AS_SERVER) && (tls_context->context_type != WICED_TLS_ADVANCED_CONTEXT)));

    if ( root_ca_certificates != NULL )
    {
        ssl_set_ca_chain( &tls_context->context, root_ca_certificates, tls_context->context.peer_cn );
        ssl_set_authmode( &tls_context->context, verification );
    }
    else
    {
        ssl_set_authmode( &tls_context->context, SSL_VERIFY_NONE );
    }

    if ( tls_context->context_type == WICED_TLS_ADVANCED_CONTEXT )
    {
        wiced_tls_advanced_context_t* advanced_context = (wiced_tls_advanced_context_t*)tls_context;
        ssl_set_own_cert( &advanced_context->context, &advanced_context->certificate, &advanced_context->key );

        ssl_set_dh_param( &tls_context->context, diffie_hellman_prime_P, sizeof( diffie_hellman_prime_P ), diffie_hellman_prime_G, sizeof( diffie_hellman_prime_G ) );
    }

    prev_state = 0;
    start_time = tls_host_get_time_ms();
    do
    {
        uint64_t curr_time;
        if (type == WICED_TLS_AS_SERVER)
        {
            result = ssl_handshake_server_async( &tls_context->context );
            if ( result != TLS_SUCCESS )
            {
                WPRINT_SECURITY_INFO(( "Error with TLS server handshake\n" ));
                goto exit_with_inited_context;
            }
        }
        else
        {
            result = ssl_handshake_client_async( &tls_context->context );
            if ( result != TLS_SUCCESS )
            {
                WPRINT_SECURITY_INFO(( "Error with TLS client handshake %u\n", (unsigned int)result ));
                goto exit_with_inited_context;
            }
        }

        /* break out if stuck */
        curr_time = tls_host_get_time_ms();
        if ( curr_time - start_time > MAX_HANDSHAKE_WAIT )
        {
            WPRINT_SECURITY_INFO(( "Timeout in SSL handshake\n" ));
            result = TLS_HANDSHAKE_TIMEOUT;
            goto exit_with_inited_context;
        }

        /* if no state change then wait on client */
        if ( prev_state == tls_context->context.state )
        {
            host_rtos_delay_milliseconds( 10 );
        }
        else /* otherwise process next state with no delay */
        {
            prev_state = tls_context->context.state;
        }
    } while ( tls_context->context.state != SSL_HANDSHAKE_OVER );

    return WICED_SUCCESS;

exit_with_inited_context:
    ssl_close_notify( &tls_context->context );
    ssl_free(&tls_context->context);
    return (wiced_result_t) result;
}
コード例 #20
0
ファイル: wwd_ap.c プロジェクト: 119/bcm-wiced-sdk
static wwd_result_t internal_ap_init( wiced_ssid_t* ssid, wiced_security_t auth_type, const uint8_t* security_key, uint8_t key_length, uint8_t channel )
{
    wiced_bool_t   wait_for_interface = WICED_FALSE;
    wwd_result_t   result;
    wiced_buffer_t response;
    wiced_buffer_t buffer;
    uint32_t*      data;

    if ( auth_type == WICED_SECURITY_WEP_PSK )
    {
        return WWD_WEP_NOT_ALLOWED;
    }
    if ( ( ( auth_type == WICED_SECURITY_WPA_TKIP_PSK ) || ( auth_type == WICED_SECURITY_WPA2_AES_PSK ) || ( auth_type == WICED_SECURITY_WPA2_MIXED_PSK ) ) &&
         ( ( key_length < (uint8_t) 8 ) || ( key_length > (uint8_t) 64 ) ) )
    {
        return WWD_WPA_KEYLEN_BAD;
    }

    if ( wwd_wifi_set_block_ack_window_size( WWD_AP_INTERFACE ) != WWD_SUCCESS )
    {
        return WWD_SET_BLOCK_ACK_WINDOW_FAIL;
    }

    /* Query bss state (does it exist? if so is it UP?) */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 4, IOVAR_STR_BSS );
    CHECK_IOCTL_BUFFER( data );
    *data = (uint32_t) CHIP_AP_INTERFACE;
    if ( wwd_sdpcm_send_iovar( SDPCM_GET, buffer, &response, WWD_STA_INTERFACE ) != WWD_SUCCESS )
    {
        /* Note: We don't need to release the response packet since the iovar failed */
        wait_for_interface = WICED_TRUE;
    }
    else
    {
        /* Check if the BSS is already UP, if so return */
        uint32_t* data2 = (uint32_t*) host_buffer_get_current_piece_data_pointer( response );
        if ( *data2 == (uint32_t) BSS_UP )
        {
            host_buffer_release( response, WWD_NETWORK_RX );
            wwd_wifi_ap_is_up = WICED_TRUE;
            return WWD_SUCCESS;
        }
        else
        {
            host_buffer_release( response, WWD_NETWORK_RX );
        }
    }

    CHECK_RETURN( host_rtos_init_semaphore( &wwd_wifi_sleep_flag ) );

    /* Register for interested events */
    CHECK_RETURN_WITH_SEMAPHORE( wwd_management_set_event_handler( apsta_events, wwd_handle_apsta_event, NULL, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

    /* Set the SSID */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 40, IOVAR_STR_BSSCFG_SSID );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    data[0] = (uint32_t) CHIP_AP_INTERFACE; /* Set the bsscfg index */
    data[1] = ssid->length; /* Set the ssid length */
    memcpy( &data[2], (uint8_t*) ssid->value, ssid->length );
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_STA_INTERFACE ), &wwd_wifi_sleep_flag );

    /* Check if we need to wait for interface to be created */
    if ( wait_for_interface == WICED_TRUE )
    {
        CHECK_RETURN_WITH_SEMAPHORE( host_rtos_get_semaphore( &wwd_wifi_sleep_flag, (uint32_t) 10000, WICED_FALSE ), &wwd_wifi_sleep_flag );
    }

    /* Set the channel */
    data = (uint32_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    *data = channel;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_CHANNEL, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, IOVAR_STR_BSSCFG_WSEC );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    data[0] = (uint32_t) CHIP_AP_INTERFACE;
    if ((auth_type & WPS_ENABLED) != 0)
    {
        data[1] = (uint32_t) ( ( auth_type & ( ~WPS_ENABLED ) ) | SES_OW_ENABLED );
    }
    else
    {
        data[1] = (uint32_t) auth_type;
    }
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_STA_INTERFACE ), &wwd_wifi_sleep_flag );

    if ( auth_type != WICED_SECURITY_OPEN )
    {
        wsec_pmk_t* psk;

        /* Set the wpa auth */
        data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 8, IOVAR_STR_BSSCFG_WPA_AUTH );
        CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
        data[0] = (uint32_t) CHIP_AP_INTERFACE;
        data[1] = (uint32_t) (auth_type == WICED_SECURITY_WPA_TKIP_PSK) ? ( WPA_AUTH_PSK ) : ( WPA2_AUTH_PSK | WPA_AUTH_PSK );
        CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_STA_INTERFACE ), &wwd_wifi_sleep_flag );

        /* Set the passphrase */
        psk = (wsec_pmk_t*) wwd_sdpcm_get_ioctl_buffer( &buffer, sizeof(wsec_pmk_t) );
        CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( psk, &wwd_wifi_sleep_flag );
        memcpy( psk->key, security_key, key_length );
        psk->key_len = key_length;
        psk->flags   = (uint16_t) WSEC_PASSPHRASE;
        host_rtos_delay_milliseconds( 1 ); /* Delay required to allow radio firmware to be ready to receive PMK and avoid intermittent failure */
        CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_WSEC_PMK, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );
    }

    /* Set the GMode */
    data = wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    *data = (uint32_t) GMODE_AUTO;

    result =  wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_GMODE, buffer, 0, WWD_AP_INTERFACE );
    if ( ( result != WWD_SUCCESS ) && ( result != WWD_WLAN_ASSOCIATED ) )
    {
        wiced_assert("start_ap: Failed to set GMode\n", 0 == 1 );

        (void) host_rtos_deinit_semaphore( &wwd_wifi_sleep_flag );
        return result;
    }

    /* Set the multicast transmission rate to 11 Mbps rather than the default 1 Mbps */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 4, IOVAR_STR_2G_MULTICAST_RATE );
    CHECK_IOCTL_BUFFER( data );
    *data = (uint32_t) RATE_SETTING_11_MBPS;
    result = wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WWD_AP_INTERFACE );
    wiced_assert("start_ap: Failed to set multicast transmission rate\r\n", result == WWD_SUCCESS );

    /* Set DTIM period */
    data = wwd_sdpcm_get_ioctl_buffer( &buffer, (uint16_t) 4 );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    *data = (uint32_t) WICED_DEFAULT_SOFT_AP_DTIM_PERIOD;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_SET_DTIMPRD, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );

#ifdef WICED_DISABLE_SSID_BROADCAST
    /* Make the AP "hidden" */
    data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 4, IOVAR_STR_CLOSEDNET );
    CHECK_IOCTL_BUFFER_WITH_SEMAPHORE( data, &wwd_wifi_sleep_flag );
    data[0] = (uint32_t) 1;
    CHECK_RETURN_WITH_SEMAPHORE( wwd_sdpcm_send_iovar( SDPCM_SET, buffer, 0, WWD_AP_INTERFACE ), &wwd_wifi_sleep_flag );
#endif

    return WWD_SUCCESS;
}