Skip to content

Commit

Permalink
Some code sanitizations
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberman54 committed Feb 18, 2022
1 parent 885f079 commit c374b87
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 25 deletions.
12 changes: 6 additions & 6 deletions lib/libpax/blescan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static int host_rcv_pkt(uint8_t *data, uint16_t len) {

data_pkt = (uint8_t *)malloc(sizeof(uint8_t) * len);
if (data_pkt == NULL) {
ESP_LOGE(TAG, "Malloc data_pkt failed!");
ESP_LOGE(TAG, "Malloc data_pkt failed");
return ESP_FAIL;
}
memcpy(data_pkt, data, len);
Expand Down Expand Up @@ -110,14 +110,14 @@ static void hci_cmd_send_ble_scan_start(void) {
uint16_t sz =
make_cmd_ble_set_scan_enable(hci_cmd_buf, scan_enable, filter_duplicates);
esp_vhci_host_send_packet(hci_cmd_buf, sz);
ESP_LOGI(TAG, "BLE Scanning started..");
ESP_LOGI(TAG, "BLE Scanning started");
}

void hci_evt_process(void *pvParameters) {
host_rcv_data_t *rcv_data =
(host_rcv_data_t *)malloc(sizeof(host_rcv_data_t));
if (rcv_data == NULL) {
ESP_LOGE(TAG, "Malloc rcv_data failed!");
ESP_LOGE(TAG, "Malloc rcv_data failed");
return;
}

Expand Down Expand Up @@ -159,7 +159,7 @@ void hci_evt_process(void *pvParameters) {
// see # Bluetooth Specification v5.0, Vol 2, Part E, sec 5.2
addr = (uint8_t *)malloc(sizeof(uint8_t) * 6 * num_responses);
if (addr == NULL) {
ESP_LOGE(TAG, "Malloc addr failed!");
ESP_LOGE(TAG, "Malloc addr failed");
goto reset;
}
for (int i = 0; i < num_responses; i += 1) {
Expand Down Expand Up @@ -215,11 +215,11 @@ void start_BLE_scan(uint16_t blescantime, uint16_t blescanwindow,
/* A queue for storing received HCI packets. */
adv_queue = xQueueCreate(30, sizeof(host_rcv_data_t));
if (adv_queue == NULL) {
ESP_LOGE(TAG, "Queue creation failed\n");
ESP_LOGE(TAG, "Queue creation failed");
return;
}

/* start HCI event processor task */
/* start HCI event processor task with prio 1 on core 0 */
xTaskCreatePinnedToCore(&hci_evt_process, "hci_evt_process", 2048, NULL, 1,
&hci_eventprocessor, 0);

Expand Down
10 changes: 5 additions & 5 deletions lib/libpax/libpax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ enum { BITS_PER_WORD = sizeof(bitmap_t) * CHAR_BIT };
#define LIBPAX_MAX_SIZE 0xFFFF // full enumeration of uint16_t
#define LIBPAX_MAP_SIZE (LIBPAX_MAX_SIZE / BITS_PER_WORD)

bitmap_t seen_ids_map[LIBPAX_MAP_SIZE];
DRAM_ATTR bitmap_t seen_ids_map[LIBPAX_MAP_SIZE];
int seen_ids_count = 0;

uint16_t volatile macs_wifi = 0;
uint16_t volatile macs_ble = 0;

uint8_t volatile channel = 0; // channel rotation counter

void set_id(bitmap_t *bitmap, uint16_t id) {
IRAM_ATTR void set_id(bitmap_t *bitmap, uint16_t id) {
bitmap[WORD_OFFSET(id)] |= ((bitmap_t)1 << BIT_OFFSET(id));
}

int get_id(bitmap_t *bitmap, uint16_t id) {
IRAM_ATTR int get_id(bitmap_t *bitmap, uint16_t id) {
bitmap_t bit = bitmap[WORD_OFFSET(id)] & ((bitmap_t)1 << BIT_OFFSET(id));
return bit != 0;
}

/** remember given id
* returns 1 if id is new, 0 if already seen this is since last reset
*/
int add_to_bucket(uint16_t id) {
IRAM_ATTR int add_to_bucket(uint16_t id) {
if (get_id(seen_ids_map, id)) {
return 0; // already seen
} else {
Expand All @@ -69,7 +69,7 @@ int libpax_wifi_counter_count() { return macs_wifi; }

int libpax_ble_counter_count() { return macs_ble; }

int mac_add(uint8_t *paddr, snifftype_t sniff_type) {
IRAM_ATTR int mac_add(uint8_t *paddr, snifftype_t sniff_type) {
uint16_t *id;
// mac addresses are 6 bytes long, we only use the last two bytes
id = (uint16_t *)(paddr + 4);
Expand Down
6 changes: 2 additions & 4 deletions lib/libpax/libpax.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ int libpax_ble_counter_count();
void libpax_counter_reset();

void reset_bucket();
int mac_add(uint8_t *paddr, snifftype_t sniff_type);
int add_to_bucket(uint16_t id);

extern void IRAM_ATTR libpax_wifi_counter_add_mac_IRAM(uint32_t mac_input);
IRAM_ATTR int mac_add(uint8_t *paddr, snifftype_t sniff_type);
IRAM_ATTR int add_to_bucket(uint16_t id);

void wifiDefaultConfig();
#endif
6 changes: 1 addition & 5 deletions lib/libpax/wifiscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ Which in turn is based of Łukasz Marcin Podkalicki's ESP32/016 WiFi Sniffer
TimerHandle_t WifiChanTimer;
int initialized_wifi = 0;
int wifi_rssi_threshold = 0;

// configData_t cfg_pax;
uint16_t channels_map = WIFI_CHANNEL_ALL;

#define WIFI_CHANNEL_MAX 13
// default values for country configuration
Expand All @@ -63,7 +62,6 @@ wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) {
mac_add((uint8_t *)hdr->addr2, MAC_SNIFF_WIFI);
}

uint16_t channels_map;
// Software-timer driven Wifi channel rotation callback function
void switchWifiChannel(TimerHandle_t xTimer) {
configASSERT(xTimer);
Expand Down Expand Up @@ -117,8 +115,6 @@ void wifi_sniffer_init(uint16_t wifi_channel_switch_interval) {
esp_wifi_set_promiscuous(true)); // now switch on monitor mode

// setup wifi channel rotation timer


if(wifi_channel_switch_interval > 0) {
WifiChanTimer = xTimerCreate("WifiChannelTimer", pdMS_TO_TICKS(wifi_channel_switch_interval * 10),
pdTRUE, (void*)0, switchWifiChannel);
Expand Down
5 changes: 0 additions & 5 deletions lib/libpax/wifiscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ typedef struct {
uint8_t payload[0]; // network data ended with 4 bytes csum (CRC32)
} wifi_ieee80211_packet_t;

// extern const wifi_ieee80211_mac_hdr_t *hdr;

void set_wifi_country(uint8_t country_code);
void set_wifi_channels(uint16_t channels_map);
void set_wifi_rssi_filter(int set_rssi_threshold);

void wifi_sniffer_init(uint16_t wifi_channel_switch_interval);
void wifi_sniffer_stop();

extern int run_count;
extern int timeback_delta;

#endif

0 comments on commit c374b87

Please sign in to comment.