Closed ENB213-xiaoh closed 3 years ago
Ok. Never mind. I have made it. Next is replacing one item in the control block to PN.
Good idea! What did you change in the code to make it work? It would be really nice to be able to add that feature to the library (as a option for others).
What is PN?
So, PN is the sequence number. The wifi chipset uses it to count the number of transmitted frames. I think you already know it. It resides in the payload, contains two bytes right after the transmitter and source mac address. So, I basically copied a promiscuous mode callback function from some other sniffer codes.
Were you able to write some clean code for the implementation? I don't have time to implement this into the project at this time, but I would be so happy if you could try creating a pull request with this. The feature would very helpful to other users :)
Okay. My pleasure. I can see your email address. So, I will email you what I have done precisely, maybe tonight or tomorrow. Then, we can discuss it, to see if you are okay with the modification.
Hi, I'm interested in receiving the wifi sequence number along with the CSI as well. Can you share how you were able to obtain it? Thanks!
static void extract_macaddr(char addr, uint8_t data, uint16_t offset) { sprintf(addr, "%02X:%02X:%02X:%02X:%02X:%02X", data[offset+0], data[offset+1], data[offset+2], data[offset+3], data[offset+4], data[offset+5]); } // #define LOG_TAG "CSI-DATA"
static void wifi_monitor_cb(void recv_buf, wifi_promiscuous_pkt_type_t type) { if(type != WIFI_PKT_MGMT) return; // Management frames wifi_promiscuous_pkt_t recv_pkt = (wifi_promiscuous_pkt_t *)recv_buf;
// Extract MAC address and print out the result
if (recv_pkt->rx_ctrl.rate == 0) return; // Exclude IEEE802.11b
char addr[] = "00:00:00:00:00:00";
extract_macaddr(addr, recv_pkt->payload, 10);
uint16_t offset = 22;
outprintf("CSI_PN,");
outprintf("%s,", addr);
outprintf("0X%02X%02X,", recv_pkt->payload[offset+0], recv_pkt->payload[offset+1]);
outprintf("%02X%02X", recv_pkt->payload[offset+2], recv_pkt->payload[offset+3]);
outprintf("%02X%02X", recv_pkt->payload[offset+4], recv_pkt->payload[offset+5]);
outprintf("%02X%02X", recv_pkt->payload[offset+6], recv_pkt->payload[offset+7]);
outprintf("%02X%02X", recv_pkt->payload[offset+8], recv_pkt->payload[offset+9]);
outprintf("\n");
sd_flush();
vTaskDelay(0);
// ESP_LOGI(LOG_TAG, "MAC: %s, RSSI: %d, PN: 0x%x%x", addr, recv_pkt->rx_ctrl.rate, recv_pkt->payload[22], recv_pkt->payload[23]);
}
void passive_init() { tcpip_adapter_init(); wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL)); ESP_ERROR_CHECK(esp_wifi_start());
const wifi_promiscuous_filter_t filt = {
.filter_mask = WIFI_PROMIS_FILTER_MASK_MGMT
};
int curChannel = 3;
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(wifi_monitor_cb));
esp_wifi_set_promiscuous(true);
esp_wifi_set_promiscuous_filter(&filt);
esp_wifi_set_channel(curChannel, WIFI_SECOND_CHAN_NONE);
}
void app_main() { nvs_init(); sd_init(); passive_init(); csi_init("PASSIVE"); input_loop(); }
Hi, tobiaswer. This is the modified main code under passive mode I used to get SN with CSI. I didn't look into the station or AP modes. You will get 2 lines of information for each CSI sequence, one line tagged with "CSI_DATA" is the collected CSI, and another line tagged with "CSI_PN" is the sequence number of the corresponding packet.
Hi All
I'm wondering if it is possible to get the packet payload along with CSI. Because I need the sequence number. I saw some other small projects that did wifi sniffing and get payload, so I want to know if I can combine these two projects. Please kindly advise