Send UDP packets in WiFi Direct

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

Hello.

I'm new in Wiked.

I have to establish P2P connection with an Android Tablet. Tablet has to be GO, WICED has to be GC.

After connection I have to send UDP packets with 1024Byte payload.

I write this task.

wiced_result_t tx_udp_packet(const wiced_ip_address_t target_ip_addr)

{

    wiced_packet_t*          packet;

    char*                    udp_data;

    uint16_t                 available_data_length;

   /* Wait P2P Connection */

    wiced_rtos_get_semaphore(&semaphoreHandle, WICED_WAIT_FOREVER);

    /* Create UDP socket */

    if (wiced_udp_create_socket(&udp_socket, UDP_TARGET_PORT, WICED_P2P_INTERFACE) != WICED_SUCCESS)

    {

        WPRINT_APP_INFO( ("UDP socket creation failed\n") );

        return WICED_ERROR;

    }

    while(WICED_TRUE)

    {

        /* Create the UDP packet */

        if ( wiced_packet_create_udp( &udp_socket, 1024, &packet, (uint8_t**) &udp_data, &available_data_length ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("UDP tx packet creation failed\n") );

            return WICED_ERROR;

        }

        /* Set the end of the data portion */

        wiced_packet_set_data_end( packet, (uint8_t*) udp_data + 1024 );

        /* Send the UDP packet */

        if ( wiced_udp_send( &udp_socket, &target_ip_addr, UDP_TARGET_PORT, packet ) != WICED_SUCCESS )

        {

            WPRINT_APP_INFO( ("UDP packet send failed\n") );

            wiced_packet_delete( packet ); /* Delete packet, since the send failed */

            return WICED_ERROR;

        }

        /* Delay 1 sec */

        wiced_rtos_delay_milliseconds(1000);

    }

    /*

     * NOTE : It is not necessary to delete the packet created above, the packet

     *        will be automatically deleted *AFTER* it has been successfully sent

     */

    return WICED_SUCCESS;

}

Is it correct ?

This task pends for a semaphore (semaphoreHandle) that is signalled in a P2P result callback if result is CONNECTION_P2P_CONNECTED.

P2P result callback is registered in this way:

connection_register_p2p_result_callback(&p2p_result_callback);

Can someone help me ?

0 Likes
1 Solution

Hello:

  I think you can enable this define for ip address allocation.

#ifdef P2P_IP_ALLOCATION

        /* Get ip retrieved from eapol frame */

        ip_up_result = p2p_get_ip_addr(&device_init_ip_settings);

        if (ip_up_result == WICED_SUCCESS)

        {

            ip_up_result = wiced_ip_up( ( wiced_interface_t ) WWD_P2P_INTERFACE, WICED_USE_STATIC_IP, &device_init_ip_settings );

        }

#endif

View solution in original post

0 Likes
3 Replies
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

Hello:

   We can use command/console to create p2p link,  then use iperf to do a UDP test firstly .

then we can try to add UDP socket to do the data transfer.

  already add a reference in another thread reply .

0 Likes

How can I obtain GO IPv4 address ?

0 Likes

Hello:

  I think you can enable this define for ip address allocation.

#ifdef P2P_IP_ALLOCATION

        /* Get ip retrieved from eapol frame */

        ip_up_result = p2p_get_ip_addr(&device_init_ip_settings);

        if (ip_up_result == WICED_SUCCESS)

        {

            ip_up_result = wiced_ip_up( ( wiced_interface_t ) WWD_P2P_INTERFACE, WICED_USE_STATIC_IP, &device_init_ip_settings );

        }

#endif

0 Likes