https://github.com/Jeija/esp32-80211-tx ... ain/main.c
With the help of above example i have used the api esp_wifi_set_vendor_ie() to set the IE but still facing some issues.
I have removed the spam part and used it as a simple beacon, while setting the vendor specific IE data using api esp_wifi_set_vendor_ie() it returns success but while sniffing the network frames using the api esp_wifi_set_vendor_ie_cb() it wont run as expected, means i can sniff all the network frames using the promiscuous callback the IE callback wont run.
Can anyone suggest the problem here or refer to the usage of the api api esp_wifi_set_vendor_ie() & esp_wifi_set_vendor_ie_cb()
Beacon Transmit
Code: Select all
vendor_ie_data_t remoteID_IEdata = {
.element_id = 0xDD,
.length = 26,
.vendor_oui = {1,2,3},
.vendor_oui_type = 22,
.payload = "Example vendor IE data"
};
char *beaconSSID = "RemoteId-BeaconAP";
void spam_task(void *pvParameter) {
// Keep track of beacon sequence numbers
uint16_t seqnum = 0;
uint8_t mac[6];
esp_wifi_get_mac(WIFI_IF_AP, mac);
for(int i=0;i<6;i++)
{
beacon_raw[SRCADDR_OFFSET+i] = mac[i];
}
esp_err_t resp = esp_wifi_set_vendor_ie(true, WIFI_VND_IE_TYPE_BEACON, WIFI_VND_IE_ID_0, &exampleIEdata);
if (resp == ESP_OK)
printf("IE Success\n");
else
printf("IE Fail %d\n", resp);
while(1)
{
vTaskDelay(500);
printf("%i %s\r\n", strlen(beaconSSID), beaconSSID);
uint8_t beacon_msg[500];
memcpy(beacon_msg, beacon_raw, BEACON_SSID_OFFSET - 1);
beacon_msg[BEACON_SSID_OFFSET - 1] = strlen(beaconSSID);
memcpy(&beacon_msg[BEACON_SSID_OFFSET], beaconSSID, strlen(beaconSSID));
memcpy(&beacon_msg[BEACON_SSID_OFFSET + strlen(beaconSSID)], &beacon_raw[BEACON_SSID_OFFSET], sizeof(beacon_raw) - BEACON_SSID_OFFSET);
// Last byte of source address / BSSID will be line number - emulate multiple APs broadcasting one song line each
// beacon_msg[SRCADDR_OFFSET + 5] = 1;
beacon_msg[BSSID_OFFSET + 5] = 1;
// Update sequence number
beacon_msg[SEQNUM_OFFSET] = (seqnum & 0x0f) << 4;
beacon_msg[SEQNUM_OFFSET + 1] = (seqnum & 0xff0) >> 4;
seqnum++;
if (seqnum > 0xfff)
seqnum = 0;
resp = esp_wifi_80211_tx(WIFI_IF_AP, beacon_msg, sizeof(beacon_raw) + strlen(beaconSSID), true);
if (resp == ESP_OK)
printf("Success");
else
printf("Fail");
}
}
Code: Select all
void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type)
{
.........
}
void TEST_IE(void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi)
{
printf("%d[%x: %x: %x: %x: %x: %x]\r\n", rssi, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
printf("%s\n",vnd_ie->payload);
printf("%d\n",vnd_ie->vendor_oui_type);
printf("%d\n",vnd_ie->element_id);
printf("%d\n",type);
// if(true) {
// ets_printf("%d[%x: %x: %x: %x: %x: %x]\r\n", (char *)rssi, sa[0], sa[1], sa[2], sa[3], sa[4], sa[5]);
// }
}
void wifiInit()
{
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
// ESP_ERROR_CHECK( esp_wifi_set_country(&wifi_country) ); /* set country for channel range [1, 13] */
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
ESP_ERROR_CHECK( esp_wifi_start() );
esp_wifi_set_promiscuous(true);
esp_wifi_set_promiscuous_rx_cb(&wifi_sniffer_packet_handler);
esp_wifi_set_channel(6, WIFI_SECOND_CHAN_NONE);
esp_err_t resp = esp_wifi_set_vendor_ie_cb(&TEST_IE, NULL);
if (resp == ESP_OK) printf("IE CB PASS\n");
}