diff options
| author | Your Name <you@example.com> | 2026-05-16 23:55:05 +0530 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-05-16 23:55:05 +0530 |
| commit | 4c47ae188b288e7d24bd9566ab3e6a6805d9484f (patch) | |
| tree | 33b74b2090b4f3b7597841734a56a4006a86d73f /main/tollgate_main.c | |
| parent | 133e40c82afb4d7659758b1fa57925ac57af4621 (diff) | |
Phase 3: Nostr identity derivation + wifistr service discovery
- Add identity.c/h: HMAC-SHA512 derivation from nsec → npub, STA/AP MAC, SSID, AP IP
- Add nostr_event.c/h: NIP-01 event serialization + Schnorr signing (BIP-340)
- Add geohash.c/h: lat/lon to geohash encoding
- Add wifistr.c/h: kind 38787 event builder + WebSocket publish to Nostr relays
- Update config.c/h: nsec-based identity, Nostr relay/geo config, remove static SSID/IP
- Replace custom mbedTLS wallet with nucula library (libsecp256k1)
- Remove wallet.c/h, wallet_persist.c/h (replaced by nucula_lib component)
- Verified on Board A: derived SSID, captive portal, payment, wallet, wifistr publish
Diffstat (limited to 'main/tollgate_main.c')
| -rw-r--r-- | main/tollgate_main.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index d4b29bc..7fa1be1 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c | |||
| @@ -11,12 +11,14 @@ | |||
| 11 | #include "lwip/dns.h" | 11 | #include "lwip/dns.h" |
| 12 | #include "dhcpserver/dhcpserver.h" | 12 | #include "dhcpserver/dhcpserver.h" |
| 13 | #include "config.h" | 13 | #include "config.h" |
| 14 | #include "identity.h" | ||
| 14 | #include "dns_server.h" | 15 | #include "dns_server.h" |
| 15 | #include "captive_portal.h" | 16 | #include "captive_portal.h" |
| 16 | #include "firewall.h" | 17 | #include "firewall.h" |
| 17 | #include "session.h" | 18 | #include "session.h" |
| 18 | #include "tollgate_api.h" | 19 | #include "tollgate_api.h" |
| 19 | #include "wallet.h" | 20 | #include "nucula_wallet.h" |
| 21 | #include "wifistr.h" | ||
| 20 | 22 | ||
| 21 | #define MAX_STA_RETRY 5 | 23 | #define MAX_STA_RETRY 5 |
| 22 | static const char *TAG = "tollgate_main"; | 24 | static const char *TAG = "tollgate_main"; |
| @@ -92,8 +94,16 @@ static void ip_event_handler(void *arg, esp_event_base_t event_base, | |||
| 92 | static void wallet_init_task(void *pvParameters) | 94 | static void wallet_init_task(void *pvParameters) |
| 93 | { | 95 | { |
| 94 | const tollgate_config_t *cfg = tollgate_config_get(); | 96 | const tollgate_config_t *cfg = tollgate_config_get(); |
| 95 | wallet_init(); | 97 | nucula_wallet_init(cfg->mint_url); |
| 96 | wallet_fetch_keysets(cfg->mint_url); | 98 | vTaskDelete(NULL); |
| 99 | } | ||
| 100 | |||
| 101 | static void publish_wifistr_task(void *pvParameters) | ||
| 102 | { | ||
| 103 | vTaskDelay(pdMS_TO_TICKS(5000)); | ||
| 104 | wifistr_publish(); | ||
| 105 | const tollgate_config_t *cfg = tollgate_config_get(); | ||
| 106 | wifistr_start_periodic(cfg->nostr_publish_interval_s); | ||
| 97 | vTaskDelete(NULL); | 107 | vTaskDelete(NULL); |
| 98 | } | 108 | } |
| 99 | 109 | ||
| @@ -123,6 +133,8 @@ static void start_services(void) | |||
| 123 | captive_portal_start(cfg->ap_ip_str); | 133 | captive_portal_start(cfg->ap_ip_str); |
| 124 | tollgate_api_start(); | 134 | tollgate_api_start(); |
| 125 | 135 | ||
| 136 | xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL); | ||
| 137 | |||
| 126 | s_services_running = true; | 138 | s_services_running = true; |
| 127 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); | 139 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); |
| 128 | ESP_LOGI(TAG, "=== TollGate services started ==="); | 140 | ESP_LOGI(TAG, "=== TollGate services started ==="); |
| @@ -214,7 +226,11 @@ void app_main(void) | |||
| 214 | ESP_ERROR_CHECK(ret); | 226 | ESP_ERROR_CHECK(ret); |
| 215 | 227 | ||
| 216 | ESP_ERROR_CHECK(tollgate_config_init()); | 228 | ESP_ERROR_CHECK(tollgate_config_init()); |
| 229 | |||
| 230 | ESP_ERROR_CHECK(identity_init(tollgate_config_get()->nsec)); | ||
| 231 | |||
| 217 | tollgate_config_derive_unique((tollgate_config_t *)tollgate_config_get()); | 232 | tollgate_config_derive_unique((tollgate_config_t *)tollgate_config_get()); |
| 233 | |||
| 218 | ESP_ERROR_CHECK(esp_netif_init()); | 234 | ESP_ERROR_CHECK(esp_netif_init()); |
| 219 | ESP_ERROR_CHECK(esp_event_loop_create_default()); | 235 | ESP_ERROR_CHECK(esp_event_loop_create_default()); |
| 220 | 236 | ||
| @@ -227,6 +243,11 @@ void app_main(void) | |||
| 227 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); | 243 | wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); |
| 228 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); | 244 | ESP_ERROR_CHECK(esp_wifi_init(&cfg)); |
| 229 | 245 | ||
| 246 | const tollgate_config_t *tcfg = tollgate_config_get(); | ||
| 247 | ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_STA, tcfg->sta_mac)); | ||
| 248 | ESP_ERROR_CHECK(esp_wifi_set_mac(WIFI_IF_AP, tcfg->ap_mac)); | ||
| 249 | ESP_LOGI(TAG, "MACs set from identity"); | ||
| 250 | |||
| 230 | ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, | 251 | ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, |
| 231 | &wifi_event_handler, NULL, NULL)); | 252 | &wifi_event_handler, NULL, NULL)); |
| 232 | ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, | 253 | ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, |
| @@ -241,8 +262,8 @@ void app_main(void) | |||
| 241 | wifi_config_t sta_config; | 262 | wifi_config_t sta_config; |
| 242 | if (tollgate_config_get_wifi(&sta_config) == ESP_OK) { | 263 | if (tollgate_config_get_wifi(&sta_config) == ESP_OK) { |
| 243 | ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config)); | 264 | ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config)); |
| 244 | const tollgate_config_t *tcfg = tollgate_config_get(); | 265 | const tollgate_config_t *tcfg2 = tollgate_config_get(); |
| 245 | ESP_LOGI(TAG, "STA configured for SSID: %s", tcfg->networks[tcfg->current_network].ssid); | 266 | ESP_LOGI(TAG, "STA configured for SSID: %s", tcfg2->networks[tcfg2->current_network].ssid); |
| 246 | } | 267 | } |
| 247 | 268 | ||
| 248 | ESP_ERROR_CHECK(esp_wifi_start()); | 269 | ESP_ERROR_CHECK(esp_wifi_start()); |