Porting ESP8266 Packet Injection to ESP32

I would like to port the attached code from an ESP8266 over to an ESP32 for simple WiFi packet injection. As the ESP32 has different libraries, has anyone come across a similar injector on the ESP32 or recommend a way to port this code over please.

Many thanks for any help offered.

#include <ESP8266WiFi.h>

extern "C" {
  #include "user_interface.h"

byte channel;

int maxssids=10; /* how much SSIDs we have */
char *ssids[] = {

byte rnd;
byte i;
byte count;

byte wifipkt[128] = { 0x80, 0x00, 0x00, 0x00, 
                /*4*/   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
                /*10*/  0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
                /*16*/  0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 
                /*22*/  0xc0, 0x6c, 
                /*24*/  0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, 
                /*32*/  0x64, 0x00, 
                /*34*/  0x01, 0x04, 
                /* SSID */
                /*36*/  0x00};

byte pktsuffix[] = {
                        0x01, 0x08, 0x82, 0x84,
                        0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, 0x03, 0x01, 
                        0x04 };                       

void setup() {

void loop() {

    wifipkt[10] = wifipkt[16] = random(256);
    wifipkt[11] = wifipkt[17] = random(256);
    wifipkt[12] = wifipkt[18] = random(256);
    wifipkt[13] = wifipkt[19] = random(256);
    wifipkt[14] = wifipkt[20] = random(256);
    wifipkt[15] = wifipkt[21] = random(256);


    for (i=0; i<strlen(ssids[rnd]); i++) {
    for (i=0; i<sizeof(pktsuffix); i++) {

    channel = random(1,12); 
    wifipkt[count-1] = channel;
    wifi_send_pkt_freedom(wifipkt, count, 0);
    wifi_send_pkt_freedom(wifipkt, count, 0);
    wifi_send_pkt_freedom(wifipkt, count, 0);

The only system library that code uses is ESP8266WiFi.h. The equivalent library for the ESP is WiFi.h

Where does user_interface.h come from ?

Hi @UKHeliBob, thank you for your reply.

You can ignore the "user_interface.h" bit, it's left over code and not relevant.

I cannot find a function within WiFI.h that will do packet injection like the wifi_send_pkt_freedom(wifipkt, count, 0) command. However there must be something surely as ESP32 is the successor to the ESP8266.

wifi_send_pkt_freedom(wifipkt, count, 0)

Where is that function located when you use an ESP8266 ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.