wiced_result_t uuid_create( uuid_t* uuid ) { uint8_t temp[ 16 ]; uint8_t a; char* iter = uuid->data; wwd_wifi_get_random( temp, 16 ); temp[ 6 ] = 0x40 | ( temp[ 6 ] & 0xf ); temp[ 8 ] = 0x80 | ( temp[ 8 ] & 0x3f ); for ( a = 0; a < 16; ++a ) { *iter++ = nibble_to_hexchar( temp[ a ] >> 4 ); *iter++ = nibble_to_hexchar( temp[ a ] & 0x0F ); switch ( a ) { case 3: case 5: case 7: case 9: *iter = '-'; ++iter; break; default: break; } } return WICED_SUCCESS; }
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; }