So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By TarableCode
#60812 Hiya!
I've been fiddling with low level networking for the past few weeks and wanted to try it on my ESP module but I've run into a bit of a bump.

What I would like to do is listen on the WiFi interface for all packets, not just those intended for the ESP module.
This is different from the promiscuous mode I've read about in relation to the ESP which seems to be for sniffing an entirely different thing.

With this code:
Code: Select allnetif_input_fn OriginalInputFn = NULL;

struct EtherFrame {
    uint8_t DestMAC[ 6 ];
    uint8_t SourceMAC[ 6 ];
    uint16_t LengthOrType;
} __attribute__( ( packed ) );

int MACsprintf( const uint8_t* MAC, char* Buffer, size_t BufferLength ) {
    return snprintf( Buffer, BufferLength, "%02X:%02X:%02X:%02X:%02X:%02X", MAC[ 0 ], MAC[ 1 ], MAC[ 2 ], MAC[ 3 ], MAC[ 4 ], MAC[ 5 ] );
}

err_t MyInputFn( struct pbuf* p, struct netif* inp ) {
  struct EtherFrame* FrameHeader = ( struct EtherFrame* ) p->payload;
  static char Text[ 1024 ];
  char SourceMAC[ 32 ];
  char DestMAC[ 32 ];
  uint16_t Type = 0;

  MACsprintf( FrameHeader->SourceMAC, SourceMAC, sizeof( SourceMAC ) );
  MACsprintf( FrameHeader->DestMAC, DestMAC, sizeof( DestMAC ) );

  Type = ( ( FrameHeader->LengthOrType >> 8 ) & 0xFF ) | ( ( FrameHeader->LengthOrType << 8 ) & 0xFF00 );
 
  snprintf( Text, sizeof( Text ), "%s: Source: %s Dest: %s Type: %04X\n", __FUNCTION__, SourceMAC, DestMAC, Type );
  Serial.print( Text );
 
  return OriginalInputFn( p, inp );
}
....
void setup( void ) {
  struct netif* ESPif = NULL;
  int i = 0;

  Serial.begin( 115200 );

  while ( ! Serial.availableForWrite( ) )
    yield( );

  for ( i = 0; i < 32; i++ ) {
    Serial.write( 0 );
    delay( 1 );
  }
 
  Serial.println( "\nReady..." );

  do {
    IsConnectedToWiFi = ConnectToWiFi( 10000 );
  } while ( ! IsConnectedToWiFi );

  Serial.println( " Connected!" );
  Serial.print( "Local IP: " );
  Serial.println( WiFi.localIP( ) );
 
  /* DebugPort.begin( ); */

  if ( ( ESPif = eagle_lwip_getif( 0 ) ) != NULL ) {
    Serial.println( "Got ESP IF\n" );

    OriginalInputFn = ESPif->input;
    ESPif->input = MyInputFn;
  }
}


I am able to see some raw ethernet frames, but obviously none that aren't intended for the ESP.
Is it at all possible to put the connected WiFi interface into promiscuous mode so I can receive and send whatever I would like on the ethernet layer?

From what I've read it's not looking too good :(
Thank you for any input you might have.
User avatar
By TarableCode
#60842 Unfortunately that doesn't describe ethernet frames, but rather capturing WiFi beacons and it seems like that mode isn't going to work for that I would like to do.

EDIT:
It looks like netif->linkoutput outputs my packets fine... as long as they are broadcast packets.
If not it looks like they're just dropped.