Пример #1
0
static void p2p_discover( p2p_workspace_t* workspace )
{
    wwd_result_t result;
    p2p_message_t  message;
    REFERENCE_DEBUG_ONLY_VARIABLE(result);

    if ( workspace->p2p_current_state == P2P_STATE_SCANNING )
    {
        workspace->p2p_current_state = P2P_STATE_DISCOVERING;
    }

    result = p2p_set_discovery_state( P2P_DISCOVERY_STATE_LISTEN );
    wiced_assert("", result == WWD_SUCCESS);

    while ( host_rtos_pop_from_queue( &p2p_outgoing_packet_queue, &message, 0 ) == WWD_SUCCESS )
    {
        result = wwd_sdpcm_send_iovar( SDPCM_SET, (wiced_buffer_t) message.data, NULL, WICED_STA_INTERFACE );
        wiced_assert("", result == WWD_SUCCESS);
    }
}
wiced_result_t wiced_rtos_pop_from_queue( wiced_queue_t* queue, void* message, uint32_t timeout_ms )
{
    return host_rtos_pop_from_queue( WICED_GET_QUEUE_HANDLE( queue ), message, timeout_ms );
}
Пример #3
0
static void p2p_thread_main( uint32_t arg )
{
    p2p_workspace_t* workspace = (p2p_workspace_t*)arg;
    wwd_result_t   result;
    p2p_message_t    message;
    uint8_t          last_printed_discovered_device = 0;

    BESL_INFO(("P2P discovery enabled. Advertised as '%s'\n", workspace->p2p_name));

    workspace->p2p_result = BESL_IN_PROGRESS;

    while ( workspace->p2p_current_state != P2P_STATE_COMPLETE &&
            workspace->p2p_current_state != P2P_STATE_ABORTED )
    {
        host_rtos_pop_from_queue(&p2p_message_queue, &message, WICED_NEVER_TIMEOUT);

        switch(message.type)
        {
            case P2P_EVENT_SCAN_COMPLETE:
                p2p_discover(workspace);
                break;

            case P2P_EVENT_DISCOVERY_COMPLETE:
                if ( workspace->p2p_current_state == P2P_STATE_NEGOTIATING )
                {
                    p2p_discover(workspace);
                    break;
                }
                /* Otherwise fall through */

            case P2P_EVENT_START_REQUESTED:
                if (workspace->p2p_current_state != P2P_STATE_NEGOTIATING)
                {
                    workspace->p2p_current_state = P2P_STATE_SCANNING;
                }
                result = p2p_set_discovery_state( P2P_DISCOVERY_STATE_SEARCH );
                result = p2p_scan( );
                break;

            case P2P_EVENT_PACKET_TO_BE_SENT:
                result = wwd_sdpcm_send_iovar( SDPCM_SET, (wiced_buffer_t) message.data, NULL, WICED_STA_INTERFACE );
                if (result != WWD_SUCCESS)
                {
                    /*  Packet has been lost.. Maybe. Don't think we can recover it though */
                }
                break;

            case P2P_EVENT_NEGOTIATION_COMPLETE:
                BESL_INFO( ("P2P negotiation complete...\n") );
                workspace->p2p_current_state = P2P_STATE_COMPLETE;
                break;

            case P2P_EVENT_STOP_REQUESTED:
                workspace->p2p_current_state = P2P_STATE_ABORTED;
                break;

            case P2P_EVENT_NEW_DEVICE_DISCOVERED:
                printf( "Found P2P device: %s\r\n", workspace->discovered_devices[last_printed_discovered_device].device_name);
                ++last_printed_discovered_device;
                break;

            default:
                break;
        }
    }

    /*  Remove P2P event handler */
    result = wwd_management_set_event_handler( p2p_events, NULL, workspace, workspace->p2p_interface );
    wiced_assert("", result == WWD_SUCCESS);

    /* Remove the unused WPS and P2P IEs */
    wps_host_remove_vendor_ie( workspace->p2p_interface, workspace->wps_probe_ie,  workspace->wps_probe_ie_length,  VENDOR_IE_PROBE_REQUEST );
    wps_host_remove_vendor_ie( workspace->p2p_interface, workspace->wps_probe_ie, workspace->wps_probe_ie_length, VENDOR_IE_PROBE_RESPONSE );
    p2p_host_remove_vendor_ie( workspace->p2p_interface, workspace->p2p_probe_request_ie,  workspace->p2p_probe_request_ie_length,  VENDOR_IE_PROBE_REQUEST);
    p2p_host_remove_vendor_ie( workspace->p2p_interface, workspace->p2p_probe_response_ie, workspace->p2p_probe_response_ie_length, VENDOR_IE_PROBE_RESPONSE);

    wiced_buffer_t buffer;
    uint32_t* data;

    /* Bring down the P2P interface */
    data = wwd_sdpcm_get_iovar_buffer(&buffer, sizeof(wiced_mac_t), IOVAR_STR_P2P_IFDEL );
    memcpy(data, &workspace->device_info.mac_address, sizeof(wiced_mac_t));
    result = wwd_sdpcm_send_iovar(SDPCM_SET, buffer, NULL, WICED_STA_INTERFACE);
    wiced_assert("", result == WWD_SUCCESS);

    if (workspace->p2p_current_state == P2P_STATE_COMPLETE)
    {
        wps_agent_t* wps_agent = besl_host_malloc( "p2p", sizeof(wps_agent_t) );
        if ( wps_agent == NULL )
        {
            goto return_with_error;
        }
        memset( wps_agent, 0, sizeof(wps_agent_t) );

        if ( workspace->i_am_group_owner == 0 )
        {
            p2p_run_as_client( workspace, wps_agent );
        }
        else
        {
            p2p_run_as_go( workspace, wps_agent );
        }

        besl_host_free(wps_agent);
    }

return_with_error:
    WICED_END_OF_CURRENT_THREAD( );
}