wlan_result_t wlan_disconnect_now() { socket_close_all(); wlan_connect_cancel(false); wiced_result_t result = wiced_network_down(WICED_STA_INTERFACE); HAL_WLAN_notify_disconnected(); return result; }
/** * Do what is needed to finalize the connection. * @return */ wlan_result_t wlan_connect_finalize() { const static_ip_config_t& ip_config = *wlan_fetch_saved_ip_config(); // enable connection from stored profiles wlan_result_t result = wiced_interface_up(WICED_STA_INTERFACE); if (!result) { HAL_WLAN_notify_connected(); wiced_ip_setting_t settings; wiced_ip_address_t dns; switch (IPAddressSource(ip_config.config_mode)) { case STATIC_IP: to_wiced_ip_address(settings.ip_address, ip_config.host); to_wiced_ip_address(settings.netmask, ip_config.netmask); to_wiced_ip_address(settings.gateway, ip_config.gateway); result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_STATIC_IP, &settings); if (!result) { if (to_wiced_ip_address(dns, ip_config.dns1)) dns_client_add_server_address(dns); if (to_wiced_ip_address(dns, ip_config.dns2)) dns_client_add_server_address(dns); } default: result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL); break; } } else { wiced_network_down(WICED_STA_INTERFACE); } // DHCP happens synchronously HAL_WLAN_notify_dhcp(!result); wiced_network_up_cancel = 0; return result; }
besl_result_t besl_p2p_init( p2p_workspace_t* workspace, const besl_p2p_device_detail_t* device_details ) { wiced_buffer_t buffer; wiced_buffer_t response; uint32_t* data; wwd_result_t result; REFERENCE_DEBUG_ONLY_VARIABLE(result); memset(workspace, 0, sizeof(p2p_workspace_t)); workspace->p2p_capability = 0x0000; workspace->p2p_name = device_details->device_name; workspace->group_owner_intent = 1; /* Turn off all the other Wi-Fi interfaces */ wiced_network_down(WICED_STA_INTERFACE); wiced_network_down(WICED_AP_INTERFACE); /* Query the AP interface to ensure that it is up */ data = (uint32_t*) wwd_sdpcm_get_iovar_buffer( &buffer, (uint16_t) 36, IOVAR_STR_BSSCFG_SSID ); memset(data, 0, 36); data[0] = (uint32_t) CHIP_AP_INTERFACE; wwd_sdpcm_send_iovar( SDPCM_SET, buffer, NULL, WWD_STA_INTERFACE ); /* 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 == WWD_SUCCESS); /* Find what interface is the P2P device */ 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 == WWD_SUCCESS); workspace->p2p_interface = BESL_READ_32(host_buffer_get_current_piece_data_pointer(response)); host_buffer_release(response, WWD_NETWORK_RX); /* Get the P2P interface MAC address */ besl_host_get_mac_address(&workspace->device_info.mac_address, workspace->p2p_interface); /* Set the standard interface MAC address to be the same as the P2P interface */ besl_host_set_mac_address(&workspace->device_info.mac_address, WICED_STA_INTERFACE); besl_host_set_mac_address(&workspace->device_info.mac_address, WICED_AP_INTERFACE); /* Get the standard MAC address to confirm */ besl_host_get_mac_address(&workspace->intended_mac_address, WICED_STA_INTERFACE); BESL_INFO( ("STA MAC: %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", workspace->intended_mac_address.octet[0], workspace->intended_mac_address.octet[1], workspace->intended_mac_address.octet[2], workspace->intended_mac_address.octet[3], workspace->intended_mac_address.octet[4], workspace->intended_mac_address.octet[5]) ); /* Set the device details */ workspace->wps_device_details = &device_details->wps_device_details; /* Allow the P2P library to initialize */ p2p_init(workspace, workspace->p2p_name); /* Bring up P2P interface */ wwd_sdpcm_get_ioctl_buffer( &buffer, 0 ); result = wwd_sdpcm_send_ioctl( SDPCM_SET, WLC_UP, buffer, NULL, workspace->p2p_interface); wiced_assert("", result == WWD_SUCCESS); /* Set wsec to any non-zero value in the discovery bsscfg to ensure our P2P probe responses have the privacy bit set in the 802.11 WPA IE. * Some peer devices may not initiate WPS with us if this bit is not set. */ data = wwd_sdpcm_get_iovar_buffer(&buffer, 8, IOVAR_STR_BSSCFG_WSEC ); data[0] = workspace->p2p_interface; data[1] = WICED_SECURITY_WPA2_AES_PSK; result = wwd_sdpcm_send_iovar(SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE); wiced_assert("", result == WWD_SUCCESS); workspace->p2p_current_state = P2P_STATE_DISCOVERING; /* Add P2P event handler */ result = wwd_management_set_event_handler( p2p_events, p2p_event_handler, workspace, workspace->p2p_interface ); wiced_assert("", result == WWD_SUCCESS); /* Create the message queue */ host_rtos_init_queue(&p2p_message_queue, p2p_message_queue_buffer, sizeof(p2p_message_queue_buffer), sizeof(p2p_message_t)); /* Create the pending outgoing packet queue */ host_rtos_init_queue(&p2p_outgoing_packet_queue, p2p_outgoing_packet_queue_buffer, sizeof(p2p_outgoing_packet_queue_buffer), sizeof(p2p_message_t)); /* Create the P2P thread */ host_rtos_create_thread_with_arg( &p2p_thread, p2p_thread_main, "p2p", p2p_thread_stack, sizeof(p2p_thread_stack), RTOS_HIGHER_PRIORTIY_THAN(RTOS_DEFAULT_THREAD_PRIORITY), (uint32_t)workspace ); return BESL_SUCCESS; }