upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/unit/stubs/esp_wifi.h
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-19 13:14:48 +0530
committerYour Name <you@example.com>2026-05-19 13:14:48 +0530
commitfe6aa9663d4cdabdc6e71db6068f8cd9e3739ffe (patch)
tree8cadb07243c07a6b3fa9453b239c9ac5cb02b454 /tests/unit/stubs/esp_wifi.h
parent77031f06a9a87320d011f501590985161d1eb305 (diff)
feat: WiFi beacon price discovery via Vendor IE (two-board verified)
Price discovery allows TollGate ESP32 boards to advertise their per-step price via WiFi Vendor-Specific Information Elements (OUI 0xC0FFEE) in beacon and probe response frames. Nearby boards passively scan and build a market view of competing TollGates without requiring internet access. Features: - beacon_price.c/h: 26-byte packed Vendor IE payload (price, step, metric, mint_hash, geohash, npub_hash), injected via esp_wifi_set_vendor_ie() - market.c/h: Passive WiFi scan receiver, vendor IE callback parsing, BSSID-correlated market entries, effective price ranking - GET /market API endpoint: JSON market snapshot with discovered entries - AP-only services: beacon + market + API start on WIFI_EVENT_AP_START, independent of STA connectivity - STA reconnect fix: 2s delay between retries creates scan windows; s_sta_connecting guard prevents double-connect - write-config-ap-only-a/b Makefile targets for STA-less testing - market_tick() in main loop, client price comparison logging Hardware verified: both boards discover each other via Vendor IE beacons. Board A sees TollGate-C0E9CA (RSSI=-30), Board B sees TollGate-B96D80 (RSSI=-25). test-market.mjs: 9/9, test-price-discovery.mjs: 7/7 per board. Unit tests: 45 new assertions across test_beacon_price (28) and test_market (17). All 15 test suites pass. ESP-IDF build clean for ESP32-S3.
Diffstat (limited to 'tests/unit/stubs/esp_wifi.h')
-rw-r--r--tests/unit/stubs/esp_wifi.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/unit/stubs/esp_wifi.h b/tests/unit/stubs/esp_wifi.h
index 6aa5787..5eb14bf 100644
--- a/tests/unit/stubs/esp_wifi.h
+++ b/tests/unit/stubs/esp_wifi.h
@@ -2,6 +2,7 @@
2#define STUBS_ESP_WIFI_H 2#define STUBS_ESP_WIFI_H
3 3
4#include <stdint.h> 4#include <stdint.h>
5#include <stdbool.h>
5#include <string.h> 6#include <string.h>
6#include "esp_err.h" 7#include "esp_err.h"
7 8
@@ -37,4 +38,67 @@ static inline esp_err_t esp_wifi_set_config(int ifx, const wifi_config_t *cfg) {
37static inline esp_err_t esp_wifi_set_mode(uint8_t mode) { (void)mode; return ESP_OK; } 38static inline esp_err_t esp_wifi_set_mode(uint8_t mode) { (void)mode; return ESP_OK; }
38static inline esp_err_t esp_wifi_start(void) { return ESP_OK; } 39static inline esp_err_t esp_wifi_start(void) { return ESP_OK; }
39 40
41#define WIFI_VENDOR_IE_ELEMENT_ID 0xDD
42
43typedef enum {
44 WIFI_VND_IE_TYPE_BEACON,
45 WIFI_VND_IE_TYPE_PROBE_REQ,
46 WIFI_VND_IE_TYPE_PROBE_RESP,
47 WIFI_VND_IE_TYPE_ASSOC_REQ,
48 WIFI_VND_IE_TYPE_ASSOC_RESP,
49} wifi_vendor_ie_type_t;
50
51typedef enum {
52 WIFI_VND_IE_ID_0,
53 WIFI_VND_IE_ID_1,
54} wifi_vendor_ie_id_t;
55
56typedef struct {
57 uint8_t element_id;
58 uint8_t length;
59 uint8_t vendor_oui[3];
60 uint8_t vendor_oui_type;
61 uint8_t payload[0];
62} vendor_ie_data_t;
63
64typedef void (*esp_vendor_ie_cb_t)(void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi);
65
66static inline esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, const void *vnd_ie) { (void)enable; (void)type; (void)idx; (void)vnd_ie; return ESP_OK; }
67static inline esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx) { (void)cb; (void)ctx; return ESP_OK; }
68
69#define WIFI_SCAN_TYPE_PASSIVE 0
70
71typedef struct {
72 uint8_t bssid[6];
73 uint8_t ssid[33];
74 uint8_t primary;
75 int second;
76 int8_t rssi;
77 int authmode;
78} wifi_ap_record_t;
79
80typedef struct {
81 uint8_t *ssid;
82 uint8_t *bssid;
83 uint8_t channel;
84 bool show_hidden;
85 int scan_type;
86 union {
87 struct { int min; int max; } active;
88 int passive;
89 } scan_time;
90} wifi_scan_config_t;
91
92static inline esp_err_t esp_wifi_scan_start(const wifi_scan_config_t *cfg, bool block) { (void)cfg; (void)block; return ESP_OK; }
93static inline esp_err_t esp_wifi_scan_get_ap_num(uint16_t *n) { *n = 0; return ESP_OK; }
94static inline esp_err_t esp_wifi_scan_get_ap_records(uint16_t *n, wifi_ap_record_t *records) { (void)records; *n = 0; return ESP_OK; }
95
96#define WIFI_EVENT_SCAN_DONE 3
97
98typedef void *esp_event_handler_instance_t;
99typedef const char *esp_event_base_t;
100#define WIFI_EVENT "WIFI_EVENT"
101
102static inline esp_err_t esp_event_handler_instance_register(esp_event_base_t a, int32_t b, void *c, void *d, esp_event_handler_instance_t *e) { (void)a; (void)b; (void)c; (void)d; (void)e; return ESP_OK; }
103
40#endif 104#endif