コード例 #1
0
ファイル: wlu_server.c プロジェクト: fishbaoz/wiced-emw3165
void start_download( void )
{
    wiced_deinit( );
    currently_downloading = 1;

    host_rtos_init_semaphore( &downloading_semaphore );
    host_rtos_init_semaphore( &download_ready_semaphore );

    wiced_rtos_create_thread( &downloading_thread, WICED_NETWORK_WORKER_PRIORITY, "downloading_init_func", downloading_init_func, 5000, NULL);
    host_rtos_get_semaphore( &download_ready_semaphore, NEVER_TIMEOUT, WICED_FALSE );
    host_rtos_deinit_semaphore( &download_ready_semaphore );
}
コード例 #2
0
ファイル: wwd_thread.c プロジェクト: humminglab/wiced-project
/** Initialises the WWD Thread
 *
 * Initialises the WWD thread, and its flags/semaphores,
 * then starts it running
 *
 * @return    WWD_SUCCESS : if initialisation succeeds
 *            otherwise, a result code
 */
wwd_result_t wwd_thread_init( void ) /*@globals undef wwd_thread, undef wwd_transceive_semaphore@*/ /*@modifies wwd_inited@*/
{
    wwd_result_t retval;

    retval = wwd_sdpcm_init( );

    if ( retval != WWD_SUCCESS )
    {
        WPRINT_WWD_ERROR(("Could not initialize SDPCM codec\n"));
        /*@-unreachable@*/ /*@-globstate@*/ /* Lint: Reachable after hitting assert & globals not defined due to error */
        return retval;
        /*@+unreachable@*/ /*@+globstate@*/
    }

    /* Create the event flag which signals the WWD thread needs to wake up */
    retval = host_rtos_init_semaphore( &wwd_transceive_semaphore );
    if ( retval != WWD_SUCCESS )
    {
        WPRINT_WWD_ERROR(("Could not initialize WWD thread semaphore\n"));
        /*@-unreachable@*/ /*@-globstate@*/ /* Lint: Reachable after hitting assert & globals not defined due to error */
        return retval;
        /*@+unreachable@*/ /*@+globstate@*/
    }

    retval = host_rtos_create_thread( &wwd_thread, wwd_thread_func, "WWD", WWD_THREAD_STACK, (uint32_t) WWD_THREAD_STACK_SIZE, (uint32_t) WWD_THREAD_PRIORITY );
    if ( retval != WWD_SUCCESS )
    {
        /* Could not start WWD main thread */
        WPRINT_WWD_ERROR(("Could not start WWD thread\n"));
        /*@-unreachable@*/ /* Reachable after hitting assert */
        return retval;
        /*@+unreachable@*/
    }

    /* Ready now. Indicate it here and in thread, whatever be executed first. */
    wwd_inited = WICED_TRUE;

    return WWD_SUCCESS;
}
コード例 #3
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;
}
コード例 #4
0
platform_result_t platform_uart_init( platform_uart_driver_t* driver, const platform_uart_t* interface, const platform_uart_config_t* config, wiced_ring_buffer_t* optional_ring_buffer )
{
    uint32_t           uart_number;
    UART_FIFO_CFG_T    UARTFIFOConfigStruct;
    config_uart_data_t config_uart_data;

    wiced_assert( "bad argument", ( driver != NULL ) && ( interface != NULL ) && ( config != NULL ) );
    Chip_Clock_EnablePeriphClock( SYSCTL_CLOCK_UART0 );

    uart_number = platform_uart_get_port_number(interface->uart_base);
    driver->rx_size              = 0;
    driver->tx_size              = 0;
    driver->last_transmit_result = PLATFORM_SUCCESS;
    driver->last_receive_result  = PLATFORM_SUCCESS;
    driver->interface            = (platform_uart_t*)interface;
    host_rtos_init_semaphore( &driver->tx_complete );
    host_rtos_init_semaphore( &driver->rx_complete );

    platform_gpio_set_alternate_function( &driver->interface->tx_pin);
    platform_gpio_set_alternate_function( &driver->interface->rx_pin);

    /* Initialise USART peripheral */
    Chip_UART_FIFOConfigStructInit( driver->interface->uart_base, &UARTFIFOConfigStruct );
    Chip_UART_Init( driver->interface->uart_base );
    Chip_UART_SetBaud( driver->interface->uart_base, config->baud_rate );
    config_uart_data.databits = ( ( config->data_width == DATA_WIDTH_8BIT ) || ( ( config->data_width == DATA_WIDTH_7BIT ) && ( config->parity != NO_PARITY ) ) ) ? UART_DATABIT_8 : UART_DATABIT_7;
    config_uart_data.stopbits = ( config->stop_bits == STOP_BITS_1 ) ? UART_STOPBIT_1 : UART_STOPBIT_2;
    switch ( config->parity )
    {
        case NO_PARITY:
            config_uart_data.parity = UART_PARITY_NONE;
            break;

        case EVEN_PARITY:
            config_uart_data.parity = UART_PARITY_EVEN;
            break;

        case ODD_PARITY:
            config_uart_data.parity = UART_PARITY_ODD;
            break;

        default:
            return WICED_BADARG;
    }

    Chip_UART_ConfigData( driver->interface->uart_base, config_uart_data.databits, config_uart_data.parity, config_uart_data.stopbits );
    Chip_UART_TxCmd( driver->interface->uart_base, ENABLE );
    /* Enable receive data and line status interrupt */
    /* Initialize FIFO for UART0 peripheral */
    Chip_UART_FIFOConfig( driver->interface->uart_base, &UARTFIFOConfigStruct );
    /* Enable UART Rx interrupt */
    Chip_UART_IntConfig( driver->interface->uart_base, UART_INTCFG_RBR, ENABLE );
    /* Enable UART line status interrupt */
    Chip_UART_IntConfig( driver->interface->uart_base, UART_INTCFG_RLS, ENABLE );

    /* Enable Interrupt for UART channel */
    NVIC_DisableIRQ( uart_irq_vectors[ uart_number ] );
    NVIC_ClearPendingIRQ( uart_irq_vectors[ uart_number ] );
    /*Note the LPC uses 5 bits for interrupt priority levels*/
    NVIC_EnableIRQ( uart_irq_vectors[ uart_number ] );
    if ( optional_ring_buffer != NULL )
    {
        /* Note that the ring_buffer should've been initialised first */
        driver->rx_buffer = optional_ring_buffer;
        driver->rx_size = 0;
    }

    return PLATFORM_SUCCESS;
}
コード例 #5
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;
}
コード例 #6
0
wiced_result_t wiced_rtos_init_semaphore( wiced_semaphore_t* semaphore )
{
    return host_rtos_init_semaphore( (host_semaphore_type_t*) semaphore );
}
コード例 #7
0
platform_result_t platform_uart_init( platform_uart_driver_t* driver, const platform_uart_t* peripheral, const platform_uart_config_t* config, wiced_ring_buffer_t* optional_ring_buffer )
{
    sam_usart_opt_t    settings;

    UNUSED_PARAMETER(driver);
    UNUSED_PARAMETER(peripheral);
    UNUSED_PARAMETER(config);
    UNUSED_PARAMETER(optional_ring_buffer);

    pdc_packet_t dma_packet;

    if ( config->flow_control != FLOW_CONTROL_DISABLED )
    {
        return WICED_UNSUPPORTED;
    }

    memset( &settings, 0, sizeof( settings ) );

    switch ( config->data_width )
    {
        case DATA_WIDTH_5BIT:
            settings.char_length = US_MR_CHRL_5_BIT;
            break;
        case DATA_WIDTH_6BIT:
            settings.char_length = US_MR_CHRL_6_BIT;
            break;
        case DATA_WIDTH_7BIT:
            settings.char_length = US_MR_CHRL_7_BIT;
            break;
        case DATA_WIDTH_8BIT:
            settings.char_length = US_MR_CHRL_8_BIT;
            break;
        case DATA_WIDTH_9BIT:
        default:
            return WICED_UNSUPPORTED;
    }

    switch ( config->parity )
    {
        case ODD_PARITY:
            settings.parity_type = US_MR_PAR_ODD;
            break;
        case EVEN_PARITY:
            settings.parity_type = US_MR_PAR_EVEN;
            break;
        case NO_PARITY:
            settings.parity_type = US_MR_PAR_NO;
            break;
        default:
            break;
    }

    switch ( config->stop_bits )
    {
        case STOP_BITS_1:
            settings.stop_bits = US_MR_NBSTOP_1_BIT;
            break;
        case STOP_BITS_2:
            settings.stop_bits = US_MR_NBSTOP_2_BIT;
            break;
        default:
            break;
    }

    settings.baudrate     = config->baud_rate;
    settings.channel_mode = US_MR_CHMODE_NORMAL;


    driver->peripheral = peripheral;

//    /* Initialise TX and RX complete semaphores */
    host_rtos_init_semaphore( &driver->tx_dma_complete );
    host_rtos_init_semaphore( &driver->rx_dma_complete );

    /* Set Tx and Rx pin mode to UART peripheral */
    platform_gpio_peripheral_pin_init( peripheral->tx_pin, ( IOPORT_MODE_MUX_A | IOPORT_MODE_PULLUP ) );
    platform_gpio_peripheral_pin_init( peripheral->rx_pin, ( IOPORT_MODE_MUX_A | IOPORT_MODE_PULLUP ) );

    /* Init CTS and RTS pins (if available) */
    if ( peripheral->cts_pin != NULL )
    {
        platform_gpio_peripheral_pin_init( peripheral->cts_pin, ( IOPORT_MODE_MUX_A | IOPORT_MODE_PULLUP ) );
    }

    if ( peripheral->rts_pin != NULL )
    {
        platform_gpio_peripheral_pin_init( peripheral->rts_pin, ( IOPORT_MODE_MUX_A | IOPORT_MODE_PULLUP ) );
    }

    /* Enable the peripheral clock in the PMC. */
    sysclk_enable_peripheral_clock( peripheral->peripheral_id );

    /* Enable the receiver and transmitter. */
    usart_reset_tx( peripheral->peripheral );
    usart_reset_rx( peripheral->peripheral );

    /* Configure USART in serial mode. */
    usart_init_rs232( peripheral->peripheral, &settings, CPU_CLOCK_HZ );

    /* Disable all the interrupts. */
    usart_disable_interrupt( peripheral->peripheral, 0xffffffff );

    /* Enable uart interrupt */
    NVIC_SetPriority( platform_uarts_irq_numbers[peripheral->uart_id], 0x06 );
    NVIC_EnableIRQ( platform_uarts_irq_numbers[peripheral->uart_id] );

    /* Enable PDC transmit */
    pdc_enable_transfer( usart_get_pdc_base( peripheral->peripheral ), PERIPH_PTCR_TXTEN | PERIPH_PTCR_RXTEN );

    driver->rx_ring_buffer = optional_ring_buffer;

    dma_packet.ul_addr = (uint32_t)driver->rx_ring_buffer->buffer;
    dma_packet.ul_size = (uint32_t)driver->rx_ring_buffer->size;
    pdc_rx_init( usart_get_pdc_base( peripheral->peripheral ), &dma_packet, &dma_packet );


    usart_enable_interrupt( peripheral->peripheral, US_IER_ENDRX | US_IER_RXBUFF | US_IER_RXRDY | US_IER_ENDTX );

    /* Enable the receiver and transmitter. */
    usart_enable_tx( peripheral->peripheral );
    usart_enable_rx( peripheral->peripheral );

    return PLATFORM_SUCCESS;
}