-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
324 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "net_utils.h" | ||
|
||
#include <WiFi.h> | ||
#include <ESPping.h> | ||
#include <HTTPClient.h> | ||
|
||
bool internetConnection(){ | ||
return Ping.ping(IPAddress(8,8,8,8)); | ||
} | ||
|
||
String getManufacturer(const String& mac){ | ||
if( !internetConnection() ){ return "NO_INTERNET_ACCESS"; } | ||
|
||
// there is an official(IEEE) doc that contains all registered mac prefixes | ||
// but it is around 700kb and i don't know a way to get specific part | ||
// without downloading the whole txt | ||
HTTPClient http; | ||
http.begin("https://api.maclookup.app/v2/macs/" + mac); | ||
int httpCode = http.GET(); // Send the request | ||
if( httpCode != 200 ){ http.end(); return "GET failed"; } | ||
|
||
// payload is a json of the format | ||
// {"success":true,"found":true,"macPrefix":"2C3358","company":"Intel Corporate","address":"Lot 8, Jalan Hi-Tech 2/3, Kulim Kedah 09000, MY","country":"MY","blockStart":"2C3358000000","blockEnd":"2C3358FFFFFF","blockSize":16777215,"blockType":"MA-L","updated":"2021-10-13","isRand":false,"isPrivate":false} | ||
// company field is going to be empty if none found | ||
String payload{http.getString()}; | ||
size_t company_start_idx = payload.indexOf("company") + 10; // + 7(company) + 3(":") | ||
String manufacturer = payload.substring(company_start_idx, payload.indexOf('"', company_start_idx)); | ||
if( manufacturer.isEmpty() ) return "UNKNOWN"; | ||
|
||
return manufacturer; | ||
} | ||
|
||
String MAC(uint8_t* data){ | ||
char macStr[18]; | ||
snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x", | ||
data[0], data[1], data[2], | ||
data[3], data[4], data[5]); | ||
|
||
return macStr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <WiFi.h> | ||
#include <ESPping.h> | ||
#include <HTTPClient.h> | ||
|
||
bool internetConnection(); | ||
|
||
String getManufacturer(const String& mac); | ||
|
||
String MAC(uint8_t* data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "scrollableTextArea.h" | ||
|
||
void ScrollableTextArea::scrollUp() { | ||
if( _startLine ) --_startLine; | ||
} | ||
|
||
void ScrollableTextArea::scrollDown() { | ||
if (_startLine + _maxLinesInArea < _lines.size()) { | ||
++_startLine; | ||
} | ||
} | ||
|
||
void ScrollableTextArea::addLine(const String& text) { | ||
String buff; | ||
size_t start{0}; | ||
|
||
// automatically split into multiple lines | ||
while( !(buff = text.substring(start, start + _maxCharsInLine)).isEmpty() ){ | ||
_lines.emplace_back(buff); | ||
start += buff.length(); | ||
} | ||
} | ||
|
||
void ScrollableTextArea::draw() { | ||
_scrollBuffer.fillSprite(TFT_BLACK); | ||
|
||
uint16_t yOffset = 0; | ||
uint16_t lines = 0; | ||
|
||
// if there is text above | ||
if( _startLine ){ | ||
_scrollBuffer.drawString("...", 0, yOffset); | ||
yOffset += _pxlsPerLine; | ||
++lines; | ||
} | ||
|
||
int32_t tmpHeight = _height; | ||
// if there is text below | ||
if( _lines.size() - _startLine > _maxLinesInArea ){ | ||
_scrollBuffer.drawString("...", 0, _height - _pxlsPerLine); | ||
tmpHeight -= _pxlsPerLine; | ||
++lines; | ||
} | ||
|
||
size_t idx{_startLine}; | ||
while( yOffset < tmpHeight && lines < _maxLinesInArea && idx < _lines.size() ){ | ||
_scrollBuffer.drawString(_lines[idx], 0, yOffset); | ||
yOffset += _pxlsPerLine; | ||
++lines; | ||
++idx; | ||
} | ||
|
||
_scrollBuffer.pushSprite(_startX, _startY); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "core/display.h" | ||
|
||
class ScrollableTextArea { | ||
public: | ||
ScrollableTextArea(uint8_t textSize, int16_t startX, int16_t startY, int32_t width, int32_t height) | ||
: _fontSize(textSize), | ||
_startX(startX), | ||
_startY(startY), | ||
_width(width), | ||
_height(height), | ||
_scrollBuffer(&tft) { | ||
|
||
_scrollBuffer.createSprite(_width, _height); | ||
_scrollBuffer.setTextColor(FGCOLOR); | ||
_scrollBuffer.setTextSize(_fontSize); | ||
_scrollBuffer.fillSprite(TFT_BLACK); | ||
|
||
_maxCharsInLine = floor(width / _scrollBuffer.textWidth("w", _fontSize)); | ||
_pxlsPerLine = _scrollBuffer.fontHeight() + 2; | ||
_maxLinesInArea = floor(_height / _pxlsPerLine); | ||
} | ||
|
||
~ScrollableTextArea() { | ||
_scrollBuffer.deleteSprite(); | ||
} | ||
|
||
void scrollUp(); | ||
|
||
void scrollDown(); | ||
|
||
void addLine(const String& text); | ||
|
||
void draw(); | ||
private: | ||
uint16_t _startLine; | ||
TFT_eSprite _scrollBuffer; | ||
uint8_t _fontSize; | ||
int16_t _startX, _startY; | ||
int32_t _width, _height; | ||
int32_t _pxlsPerLine; | ||
int32_t _maxLinesInArea; | ||
uint16_t _maxCharsInLine; | ||
std::vector<String> _lines; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
#include "ap_info.h" | ||
|
||
#include <WiFi.h> | ||
#include "esp_wifi.h" | ||
#include "core/display.h" | ||
#include "core/mykeyboard.h" | ||
#include "core/net_utils.h" | ||
#include "core/globals.h" | ||
#include "lwip/etharp.h" | ||
#include "core/scrollableTextArea.h" | ||
|
||
String autoMode2String(wifi_auth_mode_t authMode) { | ||
switch (authMode) { | ||
case WIFI_AUTH_OPEN: | ||
return "OPEN"; | ||
case WIFI_AUTH_WEP: | ||
return "WEP"; | ||
case WIFI_AUTH_WPA_PSK: | ||
return "WPA_PSK"; | ||
case WIFI_AUTH_WPA2_PSK: | ||
return "WPA2_PSK"; | ||
case WIFI_AUTH_WPA_WPA2_PSK: | ||
return "WPA_WPA2_PSK"; | ||
case WIFI_AUTH_ENTERPRISE: | ||
return "WPA2_ENTERPRISE"; | ||
case WIFI_AUTH_WPA3_PSK: | ||
return "WPA3_PSK"; | ||
case WIFI_AUTH_WPA2_WPA3_PSK: | ||
return "WPA2_WPA3_PSK"; | ||
case WIFI_AUTH_WAPI_PSK: | ||
return "WAPI_PSK"; | ||
case WIFI_AUTH_WPA3_ENT_192: | ||
return "WPA3_ENT_192"; | ||
default: | ||
return "UNKNOWN"; | ||
} | ||
} | ||
|
||
String cypherType2String(wifi_cipher_type_t cipherType) { | ||
switch (cipherType) { | ||
case WIFI_CIPHER_TYPE_NONE: | ||
return "NONE"; | ||
case WIFI_CIPHER_TYPE_WEP40: | ||
return "WEP40"; | ||
case WIFI_CIPHER_TYPE_WEP104: | ||
return "WEP104"; | ||
case WIFI_CIPHER_TYPE_TKIP: | ||
return "TKIP"; | ||
case WIFI_CIPHER_TYPE_CCMP: | ||
return "CCMP"; | ||
case WIFI_CIPHER_TYPE_TKIP_CCMP: | ||
return "TKIP_CCMP"; | ||
case WIFI_CIPHER_TYPE_AES_CMAC128: | ||
return "AES_CMAC128"; | ||
case WIFI_CIPHER_TYPE_SMS4: | ||
return "SMS4"; | ||
case WIFI_CIPHER_TYPE_GCMP: | ||
return "GCMP"; | ||
case WIFI_CIPHER_TYPE_GCMP256: | ||
return "GCMP256"; | ||
case WIFI_CIPHER_TYPE_AES_GMAC128: | ||
return "AES_GMAC128"; | ||
case WIFI_CIPHER_TYPE_AES_GMAC256: | ||
return "AES_GMAC256"; | ||
case WIFI_CIPHER_TYPE_UNKNOWN: | ||
default: | ||
return "UNKNOWN"; | ||
} | ||
} | ||
|
||
String phyModes2String(wifi_ap_record_t record) { | ||
String modes; | ||
if( record.phy_11b || record.phy_11g | ||
|| record.phy_11g || record.phy_11n ) modes = "11"; | ||
if (record.phy_11b) modes += "b/"; | ||
if (record.phy_11g) modes += "g/"; | ||
if (record.phy_11n) modes += "n/"; | ||
if (record.phy_lr) modes += "low/"; | ||
if ( !modes.isEmpty() ) modes[modes.length() - 1] = ' '; | ||
|
||
if( record.ftm_responder || record.ftm_initiator ){ | ||
modes += "FTM: "; | ||
if( record.ftm_responder ) modes += "RESP "; | ||
if( record.ftm_initiator ) modes += "INIT "; | ||
} | ||
|
||
return modes.isEmpty() ? "None" : modes; | ||
} | ||
|
||
String getChannelWidth(wifi_second_chan_t secondChannel) { | ||
switch (secondChannel) { | ||
case WIFI_SECOND_CHAN_NONE: | ||
return "HT20"; // 20 MHz channel width (no secondary channel) | ||
case WIFI_SECOND_CHAN_ABOVE: | ||
return "HT40+"; // 40 MHz channel width with secondary channel above | ||
case WIFI_SECOND_CHAN_BELOW: | ||
return "HT40-"; // 40 MHz channel width with secondary channel below | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
|
||
void fillInfo(ScrollableTextArea& area){ | ||
wifi_ap_record_t ap_info; | ||
err_t res; | ||
if( (res = esp_wifi_sta_get_ap_info(&ap_info)) != ESP_OK ){ | ||
String err; | ||
switch (res) | ||
{ | ||
case ESP_ERR_WIFI_CONN: | ||
err = "iface is not initialized"; | ||
break; | ||
case ESP_ERR_WIFI_NOT_CONNECT: | ||
err = "station disconnected"; | ||
break; | ||
default: | ||
err = "failed with" + String(res); | ||
break; | ||
} | ||
|
||
tft.print(err); | ||
|
||
while(checkSelPress()) yield(); | ||
while(!checkSelPress()) yield(); | ||
} | ||
|
||
const auto mac = MAC(ap_info.bssid); | ||
|
||
displayRedStripe("Gathering...",TFT_WHITE,FGCOLOR); | ||
|
||
// in promiscius mode also Rx/Tx can be gathered | ||
// organized in the most to least usable | ||
area.addLine("SSID: " + String((char*)ap_info.ssid)); | ||
area.addLine("PSK: " + wifiPSK); | ||
area.addLine("Internet: " + String(internetConnection() ? "available" : "unavailable")); | ||
area.addLine("Modes: " + phyModes2String(ap_info)); | ||
area.addLine("Signal strength: " + String(ap_info.rssi) + "db"); | ||
// AP might not have assigned IP and gateway ip might differ from an ap ip | ||
area.addLine("Gateway: " + WiFi.gatewayIP().toString()); | ||
area.addLine("Channel: " + String(ap_info.primary) + " " + getChannelWidth(ap_info.second)); | ||
area.addLine("BSSID: " + mac); // sometimes MAC != BSSID (but we ignore that case) | ||
area.addLine("Manufacturer: " + getManufacturer(mac)); // sometimes MAC != BSSID (but we ignore that case) | ||
area.addLine("Auth mode: " + autoMode2String(ap_info.authmode) + " WPA: " + String(ap_info.wps ? "enabled" : "disabled")); | ||
area.addLine("Cypher uni: " + cypherType2String(ap_info.pairwise_cipher) + " mulit: " + cypherType2String(ap_info.group_cipher)); | ||
area.addLine("Antenna: " + String(ap_info.ant)); | ||
} | ||
|
||
void update(ScrollableTextArea& area){ | ||
if( checkPrevPress() ){ | ||
area.scrollUp(); | ||
} else if( checkNextPress() ){ | ||
area.scrollDown(); | ||
} | ||
area.draw(); | ||
} | ||
|
||
void displayAPInfo(){ | ||
drawMainBorder(); | ||
|
||
// offset header and border | ||
ScrollableTextArea area(FP, 10, 30, WIDTH - 20, HEIGHT - 40); | ||
|
||
fillInfo(area); | ||
|
||
while(checkSelPress()){ update(area); yield();} | ||
while(!checkSelPress()){ update(area); yield();} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
void displayAPInfo(); |
Oops, something went wrong.