WiFiScan.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #ifndef WiFiScan_h
  2. #define WiFiScan_h
  3. #include <BLEDevice.h>
  4. #include <BLEUtils.h>
  5. #include <BLEScan.h>
  6. #include <BLEAdvertisedDevice.h>
  7. #include "esp_wifi.h"
  8. #include "esp_wifi_types.h"
  9. #include "Display.h"
  10. //#include "MenuFunctions.h"
  11. #define bad_list_length 3
  12. #define WIFI_SCAN_OFF 0
  13. #define WIFI_SCAN_PROBE 1
  14. #define WIFI_SCAN_AP 2
  15. #define WIFI_SCAN_ST 3
  16. #define WIFI_SCAN_ALL 4
  17. #define WIFI_ATTACK_BEACON_SPAM 5
  18. #define BT_SCAN_ALL 6
  19. #define BT_SCAN_SKIMMERS 7
  20. extern Display display_obj;
  21. class WiFiScan
  22. {
  23. private:
  24. uint32_t initTime = 0;
  25. bool run_setup = true;
  26. int set_channel = 1;
  27. int bluetoothScanTime = 5;
  28. const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
  29. BLEScan* pBLEScan;
  30. esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
  31. String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
  32. char* prefix = "G";
  33. typedef struct
  34. {
  35. int16_t fctl;
  36. int16_t duration;
  37. uint8_t da;
  38. uint8_t sa;
  39. uint8_t bssid;
  40. int16_t seqctl;
  41. unsigned char payload[];
  42. } __attribute__((packed)) WifiMgmtHdr;
  43. typedef struct {
  44. WifiMgmtHdr hdr;
  45. uint8_t payload[0];
  46. } wifi_ieee80211_packet_t;
  47. // barebones packet
  48. uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
  49. /*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
  50. /*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
  51. /*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
  52. /*22*/ 0xc0, 0x6c, //Seq-ctl
  53. /*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
  54. /*32*/ 0x64, 0x00, //Beacon interval
  55. /*34*/ 0x01, 0x04, //Capability info
  56. /* SSID */
  57. /*36*/ 0x00
  58. };
  59. void RunBeaconScan(uint8_t scan_mode, uint16_t color);
  60. void RunProbeScan(uint8_t scan_mode, uint16_t color);
  61. void RunBluetoothScan(uint8_t scan_mode, uint16_t color);
  62. static void scanCompleteCB(BLEScanResults scanResults);
  63. public:
  64. WiFiScan();
  65. void channelHop();
  66. uint8_t currentScanMode = 0;
  67. void main(uint32_t currentTime);
  68. void StartScan(uint8_t scan_mode, uint16_t color = 0);
  69. void StopScan(uint8_t scan_mode);
  70. static void getMAC(char *addr, uint8_t* data, uint16_t offset);
  71. static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  72. static void probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
  73. };
  74. #endif