Esempio n. 1
0
/**
 * Initializes the DCT area if required.
 * @return
 */
wiced_result_t wlan_initialize_dct()
{
    // find the next available slot, or use the first
    platform_dct_wifi_config_t* wifi_config = NULL;
    wiced_result_t result = wiced_dct_read_lock( (void**) &wifi_config, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof(*wifi_config));
    if (result==WICED_SUCCESS) {
        // the storage may not have been initialized, so device_configured will be 0xFF
        if (initialize_dct(wifi_config))
            result = wiced_dct_write( (const void*) wifi_config, DCT_WIFI_CONFIG_SECTION, 0, sizeof(*wifi_config) );
        wiced_dct_read_unlock(wifi_config, WICED_TRUE);
    }
    return result;
}
Esempio n. 2
0
/**
 * Clears the WLAN credentials by erasing the DCT data and taking down the STA
 * network interface.
 * @return
 */
int wlan_clear_credentials()
{
    // write to DCT credentials
    // clear current IP
    platform_dct_wifi_config_t* wifi_config = NULL;
    wiced_result_t result = wiced_dct_read_lock( (void**) &wifi_config, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof(*wifi_config));
    if (!result) {
        memset(wifi_config->stored_ap_list, 0, sizeof(wifi_config->stored_ap_list));
        result = wiced_dct_write( (const void*) wifi_config, DCT_WIFI_CONFIG_SECTION, 0, sizeof(*wifi_config) );
        wiced_dct_read_unlock(wifi_config, WICED_TRUE);
    }
    return result;
}
/******************************************************
 *               Function Definitions
 ******************************************************/
wiced_result_t aws_app_init( aws_app_info_t *app_info )
{
    wiced_result_t ret = WICED_SUCCESS;
    aws_config_dct_t *aws_app_dct = NULL;

    aws_app_info = app_info;

    wiced_init( );

    /* Disable roaming to other access points */
    wiced_wifi_set_roam_trigger( -99 ); /* -99dBm ie. extremely low signal level */

    WPRINT_APP_INFO((" Please wait, connecting to network...\n"));
    WPRINT_APP_INFO(("(To return to SSID console screen, hold USER switch for 5 seconds during RESET to clear DCT configuration)\n"));
    wiced_rtos_delay_milliseconds( 1000 );

    for ( int i = 0; i < 25; i++ )
    {
        wiced_gpio_output_high( WICED_LED2 );
        wiced_rtos_delay_milliseconds( 100 );
        wiced_gpio_output_low( WICED_LED2 );
        wiced_rtos_delay_milliseconds( 100 );

        if ( !wiced_gpio_input_get( WICED_BUTTON1 ) )
        {
            wiced_rtos_delay_milliseconds( 5000 );

            if ( !wiced_gpio_input_get( WICED_BUTTON1 ) )
            {
                aws_config_dct_t aws_dct =
                {
                    .is_configured = WICED_FALSE,
                    .thing_name = AWS_DEFAULT_THING_NAME
                };

                wiced_gpio_output_high( WICED_LED1 );
                WPRINT_APP_INFO(( "DCT clearing start\n" ));
                wiced_dct_write( &aws_dct, DCT_APP_SECTION, 0, sizeof( aws_config_dct_t ) );
                wiced_rtos_delay_milliseconds( 1000 );
                wiced_gpio_output_low( WICED_LED1 );
                WPRINT_APP_INFO(( "DCT clearing end\n" ));

                break;
            }
        }
Esempio n. 4
0
wiced_result_t add_wiced_wifi_credentials(const char *ssid, uint16_t ssidLen, const char *password,
    uint16_t passwordLen, wiced_security_t security, unsigned channel)
{
    platform_dct_wifi_config_t* wifi_config = NULL;
    wiced_result_t result = wiced_dct_read_lock( (void**) &wifi_config, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof(*wifi_config));
    if (!result) {
        // the storage may not have been initialized, so device_configured will be 0xFF
        initialize_dct(wifi_config);

        // shuffle all slots along
        memmove(wifi_config->stored_ap_list+1, wifi_config->stored_ap_list, sizeof(wiced_config_ap_entry_t)*(CONFIG_AP_LIST_SIZE-1));

        const int empty = 0;
        wiced_config_ap_entry_t& entry = wifi_config->stored_ap_list[empty];
        memset(&entry, 0, sizeof(entry));
        passwordLen = std::min(passwordLen, uint16_t(64));
        ssidLen = std::min(ssidLen, uint16_t(32));
        memcpy(entry.details.SSID.value, ssid, ssidLen);
        entry.details.SSID.length = ssidLen;
        if (security==WICED_SECURITY_WEP_PSK && passwordLen>1 && password[0]>4) {
            // convert from hex to binary
            entry.security_key_length = hex_decode((uint8_t*)entry.security_key, sizeof(entry.security_key), password);
        }
        else {
            memcpy(entry.security_key, password, passwordLen);
            entry.security_key_length = passwordLen;
        }
        entry.details.security = security;
        entry.details.channel = channel;
        result = wiced_dct_write( (const void*) wifi_config, DCT_WIFI_CONFIG_SECTION, 0, sizeof(*wifi_config) );
        if (!result)
            wifi_creds_changed = true;
        wiced_dct_read_unlock(wifi_config, WICED_TRUE);
    }
    return result;
}
Esempio n. 5
0
int start_smartconfig(void)
{

    wiced_result_t result;
    wiced_config_ap_entry_t* dct_ap_entry;
    WPRINT_APP_INFO(("smart\n"));

    result = 1;

    /* enable protocols */
    easy_setup_enable_cooee(); /* broadcom cooee */
    easy_setup_enable_neeze(); /* broadcom neeze */
    //easy_setup_enable_akiss(); /* wechat akiss */
    //easy_setup_enable_changhong(); /* changhong */

    /* set cooee key */
    //cooee_set_key("1111111111111111");

    /* set airkiss key */
    //akiss_set_key("1111111111111111");

    /* start easy setup */
    if (easy_setup_start() != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("easy setup failed.\r\n"));
    }
    else
    {
        WPRINT_APP_INFO(("easy setup done.\r\n"));
    }

    int up_tries = 3;

    while (up_tries--) {
        result = wiced_network_up( WICED_STA_INTERFACE,\
			WICED_USE_EXTERNAL_DHCP_SERVER, NULL );
        if (result == WICED_SUCCESS) {
            break;
        } else {
            WPRINT_APP_INFO(("Network up failed, try again (%d left)\r\n", up_tries));
        }
    }
    if ( result != WICED_SUCCESS )
    {
        wiced_dct_read_lock( (void**) &dct_ap_entry, WICED_TRUE, \
			DCT_WIFI_CONFIG_SECTION, offsetof(platform_dct_wifi_config_t, stored_ap_list),\
			sizeof(wiced_config_ap_entry_t) );
		
        if (dct_ap_entry->details.security == WICED_SECURITY_WEP_PSK ) // Now try shared instead of open authentication
        {
            dct_ap_entry->details.security = WICED_SECURITY_WEP_SHARED;
            wiced_dct_write( dct_ap_entry, DCT_WIFI_CONFIG_SECTION, \
				offsetof(platform_dct_wifi_config_t, stored_ap_list),\
				sizeof(wiced_config_ap_entry_t) );
            result = wiced_network_up( WICED_STA_INTERFACE,\
				WICED_USE_EXTERNAL_DHCP_SERVER, NULL );
            if ( result != WICED_SUCCESS ) // Restore old value
            {
                //wiced_dct_read_lock( (void**) &dct_ap_entry, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, offsetof(platform_dct_wifi_config_t, stored_ap_list), sizeof(wiced_config_ap_entry_t) );
                dct_ap_entry->details.security = WICED_SECURITY_WEP_PSK;
                wiced_dct_write( dct_ap_entry, DCT_WIFI_CONFIG_SECTION, \
					offsetof(platform_dct_wifi_config_t, stored_ap_list),\
					sizeof(wiced_config_ap_entry_t) );
            }
        }
		
        wiced_dct_read_unlock( dct_ap_entry, WICED_TRUE );
    }

    if ( result != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ("Network up failed\n") );
    }
    else
    {
        WPRINT_APP_INFO( ("Network up success\n") );
    }

    return result;
}
Esempio n. 6
0
static wiced_result_t set_wifi_security( your_security_t security_type )
{
    wiced_result_t   result;
    char             security_key[MAX_KEY_LENGTH];
    uint8_t          key_length = 0;
    wiced_security_t wiced_security_type;
    platform_dct_wifi_config_t* wifi_config_dct_local;

    /* Check if the security type permits us to simply use the default AP passphrase */
    if ( (security_type != YOUR_SECURITY_OPEN ) && ( security_type != YOUR_SECURITY_WEP40_PSK ) && (security_type != YOUR_SECURITY_WEP104_PSK ) )
    {
        memcpy(security_key, YOUR_AP_PASSPHRASE, sizeof( YOUR_AP_PASSPHRASE ));
        key_length = strlen((char*)&security_key);
    }

    switch ( security_type )
    {
        case YOUR_SECURITY_OPEN:
            memset( security_key, 0, sizeof( security_key ) );
            wiced_security_type = WICED_SECURITY_OPEN;
            break;
        case YOUR_SECURITY_WEP40_PSK:
            wiced_security_type = WICED_SECURITY_WEP_PSK;
            key_length          = strlen( YOUR_WEP40_KEY );
            format_wep_keys( security_key, YOUR_WEP40_KEY, &key_length, WEP_KEY_TYPE );
            break;
        case YOUR_SECURITY_WEP104_PSK:
            wiced_security_type = WICED_SECURITY_WEP_PSK;
            key_length          = strlen( YOUR_WEP104_KEY );
            format_wep_keys( security_key, YOUR_WEP104_KEY, &key_length, WEP_KEY_TYPE );
            break;
        case YOUR_SECURITY_WPA_TKIP_PSK:
            wiced_security_type = WICED_SECURITY_WPA_TKIP_PSK;
            break;
        case YOUR_SECURITY_WPA_AES_PSK:
            wiced_security_type = WICED_SECURITY_WPA_AES_PSK;
            break;
        case YOUR_SECURITY_WPA2_AES_PSK:
            wiced_security_type = WICED_SECURITY_WPA2_AES_PSK;
            break;
        case YOUR_SECURITY_WPA2_TKIP_PSK:
            wiced_security_type = WICED_SECURITY_WPA2_TKIP_PSK;
            break;
        case YOUR_SECURITY_WPA2_MIXED_PSK:
            wiced_security_type = WICED_SECURITY_WPA2_MIXED_PSK;
            break;
        default:
            WPRINT_APP_INFO(( "Unrecognised security type\r\n" ));
            return WICED_ERROR;
        break;
    }

    /* Read the Wi-Fi config from the DCT */
    result = wiced_dct_read_lock( (void**) &wifi_config_dct_local, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( platform_dct_wifi_config_t ) );
    if ( result != WICED_SUCCESS )
    {
        return result;
    }

    /* Write the new security settings into the config */
    wifi_config_dct_local->stored_ap_list[0].details.SSID.length = strlen(YOUR_SSID);
    strncpy((char*)&wifi_config_dct_local->stored_ap_list[0].details.SSID.value, YOUR_SSID, MAX_SSID_LENGTH);
    wifi_config_dct_local->stored_ap_list[0].details.security = wiced_security_type;
    memcpy((char*)wifi_config_dct_local->stored_ap_list[0].security_key, (char*)security_key, MAX_PASSPHRASE_LENGTH);
    wifi_config_dct_local->stored_ap_list[0].security_key_length = key_length;

    /* Write the modified config back into the DCT */
    result = wiced_dct_write ( (const void*)wifi_config_dct_local, DCT_WIFI_CONFIG_SECTION, 0, sizeof (platform_dct_wifi_config_t) );
    wiced_dct_read_unlock( (void*)wifi_config_dct_local, WICED_TRUE );
    if ( result != WICED_SUCCESS )
    {
        return result;
    }

    return WICED_SUCCESS;
}
Esempio n. 7
0
void application_start(void)
{
    const your_security_t       your_security_type = YOUR_SECURITY_WEP40_PSK;
    platform_dct_wifi_config_t* wifi_config_dct_local;

    /* Initialise the WICED device */
    wiced_init();

    /* Configure security for the device and join the AP */
    if ( set_wifi_security( your_security_type ) != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ( "Failed to update DCT with security type\r\n" ) );
        return;
    }

    /* Try join the network */
    if ( wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL ) != WICED_SUCCESS )
    {
        /* Check if we were using WEP. It is not possible to tell WEP Open from WEP Shared in a scan so we try Open first and Shared second */
        if ( your_security_type == YOUR_SECURITY_WEP40_PSK || your_security_type == YOUR_SECURITY_WEP104_PSK )
        {
            WPRINT_APP_INFO( ("WEP with open authentication failed, trying WEP with shared authentication...\r\n") );

            /* Modify the Wi-Fi config to use Shared WEP */
            wiced_dct_read_lock( (void**) &wifi_config_dct_local, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( platform_dct_wifi_config_t ) );
            wifi_config_dct_local->stored_ap_list[0].details.security = WICED_SECURITY_WEP_SHARED;
            wiced_dct_write ( (const void*)wifi_config_dct_local, DCT_WIFI_CONFIG_SECTION, 0, sizeof (platform_dct_wifi_config_t) );
            wiced_dct_read_unlock( (void*)wifi_config_dct_local, WICED_TRUE );

            /* Try join the network again */
            if ( wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL ) != WICED_SUCCESS )
            {
                WPRINT_APP_INFO( ("WEP with Shared authentication failed as well\r\n") );

                /* Restore the Wi-Fi config back to the default Open WEP */
                wiced_dct_read_lock( (void**) &wifi_config_dct_local, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( platform_dct_wifi_config_t ) );
                wifi_config_dct_local->stored_ap_list[0].details.security = WICED_SECURITY_WEP_PSK;
                wiced_dct_write ( (const void*)wifi_config_dct_local, DCT_WIFI_CONFIG_SECTION, 0, sizeof (platform_dct_wifi_config_t) );
                wiced_dct_read_unlock( (void*)wifi_config_dct_local, WICED_TRUE );

                /* Nothing more we can do.. Give up */
                WPRINT_APP_INFO(( "Unable to join AP\r\n" ));
                return;
            }
        }
        else
        {
            WPRINT_APP_INFO(( "Unable to join AP\r\n" ));
            return;
        }
    }

    while (1)
    {
        /* Send an ICMP ping to the gateway */
        send_ping( );

        /* Wait between pings */
        wiced_rtos_delay_milliseconds( PING_INTERVAL );
    }
}