Issue with wiced_network_send_ethernet_data

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

cross mob
DaCi_2122796
Level 3
Level 3
So, Im attempting to send raw ethernet frames out the wifi interface, but Im never seeing them come out over the air. I have confirmed that the wifi chip is a) connected to the AP, b) has the same MAC as the sender MAC in the frame, and c) is receiving frames from other devices on the network. The frame is 80 bytes long (longer than the minimum, and a multiple of 4), and there is sufficient space at the front of the buffer for the SDPCM headers. Relevant details:

RTOS: FreeRTOS

Net Stack: LWIP

Processor: STM32F205

Wifi Chip: 43362

Bus: SDIO

Anyone have any suggestions as to what Im doing wrong?
0 Likes
1 Solution
DaCi_2122796
Level 3
Level 3
Scratch that... turns out I was sending the test frame out the ethernet, because I swapped functions while making sure things were approximately sane. I cannot for the life of me figure out what Im doing wrong; Im watching whats going on when LWIP is sending a ping packet and emulating the payload, length, and total length, byte for byte. The one thing Ive noticed is that the buffers have 2 references to them, instead of just one. Ive also confirmed that the alignment of the payload pointer is the same (for 4 byte alignments).

Is it possible my buffers are being freed before their transmitted? Can anyone get a simple small test app running for wiced_send_network_data()? Im absolutely confused now.

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable
Please post a minimal sample app showing the issue
0 Likes
DaCi_2122796
Level 3
Level 3
Here is a minimal app to demonstrate (built out of APSTA.c).

Also, as for the length maniputaltion, I remember having an issue with length/alignment problems earlier, but I honestly cant remember what the exact solution was (mod 4? mod 4 + 2?), so Ive tried both adjusting and not adjusting.

#include "wiced.h"

#include "http_server.h"

#include "resources.h"

#include "dns_redirect.h"

/******************************************************

*                      Macros

******************************************************/

/******************************************************

*                    Constants

******************************************************/

#define BASE_ETHER_BUFFER_SIZE (1520)

#define ETHER_BUFFER_SIZE (BASE_ETHER_BUFFER_SIZE + WICED_LINK_OVERHEAD_BELOW_ETHERNET_FRAME)

/******************************************************

*                   Enumerations

******************************************************/

/******************************************************

*                 Type Definitions

******************************************************/

/******************************************************

*                    Structures

******************************************************/

/******************************************************

*               Function Declarations

******************************************************/

//static wiced_result_t send_ping ( void* arg );

/******************************************************

*               Variables Definitions

******************************************************/

static const wiced_ip_setting_t host_ip_settings =

{

    INITIALISER_IPV4_ADDRESS( .ip_address, MAKE_IPV4_ADDRESS( 192,168,  1,  199 ) ),

    INITIALISER_IPV4_ADDRESS( .netmask,    MAKE_IPV4_ADDRESS( 255,255,255,  0 ) ),

    INITIALISER_IPV4_ADDRESS( .gateway,    MAKE_IPV4_ADDRESS( 192,168,  1,  10 ) ),

};

//uint8_t testPing[] = {

//    0x00, 0x1b, 0x21, 0x43, 0x79, 0x99, 0x02, 0x0a,

//    0xf7, 0xdc, 0xb4, 0xc7, 0x08, 0x00, 0x45, 0x00,

//    0x00, 0x3c, 0x12, 0x34, 0x01, 0x00, 0x3c, 0x01,

//    0xe7, 0x6a, 0xc0, 0xa8, 0x01, 0xc8, 0xc0, 0xa8,

//    0x01, 0x0a, 0x08, 0x00, 0xf0, 0xdd, 0x00, 0x05,

//    0x00, 0x06, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,

//    0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,

//    0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76,

//    0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e,

//    0x7f, 0x80

//};

uint8_t testPing2[] = {

    0x00, 0x1b, 0x21, 0x43, 0x79, 0x99, 0x02, 0x0a,

    0xf7, 0x46, 0x09, 0x83, 0x08, 0x00, 0x45, 0x00,

    0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xff, 0x01,

    0x37, 0x9f, 0xc0, 0xa8, 0x01, 0xc7, 0xc0, 0xa8,

    0x01, 0x0a, 0x08, 0x00, 0x57, 0x4e, 0xaf, 0xaf,

    0x00, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,

    0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,

    0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,

    0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,

    0x1e, 0x1f,

};

/******************************************************

*               Function Definitions

******************************************************/

void SendTestPing();

void ShowData( uint8_t *fromptr, uint16_t len );

void SendTestPing()

{

    wiced_buffer_t buffer;

    wiced_mac_t MAC;

    int payload, mod4, plus2;

    wiced_wifi_get_mac_address(&MAC);

    host_buffer_get( &buffer, WICED_NETWORK_TX, ETHER_BUFFER_SIZE, WICED_TRUE);

    host_buffer_add_remove_at_front( &buffer, WICED_LINK_OVERHEAD_BELOW_ETHERNET_FRAME);

    memcpy( buffer->payload, testPing2, sizeof(testPing2));

    memcpy( ((uint8_t *)buffer->payload) + 6, MAC.octet, sizeof(MAC.octet) );

    buffer->len = sizeof(testPing2);

    payload = buffer->len - 14;

    mod4    = payload % 4;

    plus2   = payload + mod4 + 2;

    buffer->len = plus2 + 14;

    ShowData(buffer->payload, buffer->len);

    wiced_network_send_ethernet_data(buffer, WICED_STA_INTERFACE);

}

void ShowData( uint8_t *fromptr, uint16_t len )

{

   uint8_t *pPos = fromptr;

   uint16_t left = len;

   uint16_t i;

   while ( left > 16 )

   {

      for ( i = 0; i < 16; i++ )

      {

         iprintf( "%02x ", ( unsigned ) * ( pPos + i ) );

      }

      putchar(   );

      for ( i = 0; i < 16; i++ )

      {

         char c = ( char ) ( *( pPos + i ) );

         if ( c <   )

         {

            putchar( . );

         }

         else

         {

            putchar( c );

         }

      }

      putchar(  );

      putchar(

);

      pPos += 16;

      left -= 16;

   }

   for ( i = 0; i < left; i++ )

   {

      iprintf( "%02x ", ( unsigned ) * ( pPos + i ) );

   }

   for ( ; i < 16; i++ )

   {

      iprintf( " . " );

   }

   putchar(   );

   for ( i = 0; i < left; i++ )

   {

      char c = ( char ) ( *( pPos + i ) );

      if ( c <   )

      {

         putchar( . );

      }

      else

      {

         putchar( c );

      }

   }

   puts( "

" );

}

void application_start(void)

{

    /* Initialise the device */

wiced_init();

    /* Configure the device */

    //wiced_configure_device( app_config );  /* Config bypassed in local makefile and wifi_config_dct.h */

    /* Bring up the STA (client) interface ------------------------------------------------------- */

    wiced_network_up(WICED_STA_INTERFACE, WICED_USE_STATIC_IP, &host_ip_settings);

    SendTestPing();

    while (1)

    {

    }

}

0 Likes
DaCi_2122796
Level 3
Level 3
Argh... Found the problem. It turns out to have been an alignment/length issue.

I was focusing on the length of the _payload_ section of the ethernet frame, trying to adjust the length to make that segment mod 4 plus 2 long. It turns out that the entire _frame_ needs to mod 4 plus 2 bytes long.
0 Likes
DaCi_2122796
Level 3
Level 3
Scratch that... turns out I was sending the test frame out the ethernet, because I swapped functions while making sure things were approximately sane. I cannot for the life of me figure out what Im doing wrong; Im watching whats going on when LWIP is sending a ping packet and emulating the payload, length, and total length, byte for byte. The one thing Ive noticed is that the buffers have 2 references to them, instead of just one. Ive also confirmed that the alignment of the payload pointer is the same (for 4 byte alignments).

Is it possible my buffers are being freed before their transmitted? Can anyone get a simple small test app running for wiced_send_network_data()? Im absolutely confused now.
0 Likes