upleb.uk

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

summaryrefslogtreecommitdiff
path: root/main/tollgate_main.c
diff options
context:
space:
mode:
authorYour Name <you@example.com>2026-05-16 11:56:43 +0530
committerYour Name <you@example.com>2026-05-16 11:56:43 +0530
commit38aa9ec3801f5895e09866fe92cb8e44fb987cee (patch)
treec702c27cd59fa0e73bc3e8665e1582e6b9509cf6 /main/tollgate_main.c
parentee4e13680f522253f94e8ebdea5df80332afc495 (diff)
Unique SSID/IP per board + captive detection fix + mint list in portal
- Derive unique SSID (TollGate-{MAC4}{MAC5}) and AP IP (10.{b5}.{subnet}.1) from factory MAC — boards no longer conflict - Board A: TollGate-377C @ 10.55.85.1, Board B: TollGate-5050 @ 10.80.10.1 - Captive portal detection URIs return 200 with portal HTML (matching esp32-mesh working approach) instead of 302 redirect - Dynamic AP IP in portal HTML via __AP_IP__ template substitution - Supported mints section in portal page (shows mint URL, tap to copy) - Fixed mint URL to testnut.cashu.space (was stale in SPIFFS) - DoT reject server on port 853 for DNS-over-TLS fallback - DNS hijack: NXDOMAIN for all non-A queries, no forwarding for unauthed - Playwright tests updated for 200 response on detection URIs - Phase 2 test suite: 20/21 pass (test 22 expiry ping route issue) - Tests 25-27 deferred to Phase 3 (Board B as second client)
Diffstat (limited to 'main/tollgate_main.c')
-rw-r--r--main/tollgate_main.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/main/tollgate_main.c b/main/tollgate_main.c
index 04f64b9..30fad8d 100644
--- a/main/tollgate_main.c
+++ b/main/tollgate_main.c
@@ -18,9 +18,6 @@
18#include "tollgate_api.h" 18#include "tollgate_api.h"
19 19
20#define MAX_STA_RETRY 5 20#define MAX_STA_RETRY 5
21#define AP_IP_ADDR "192.168.4.1"
22#define AP_SUBNET "255.255.255.0"
23
24static const char *TAG = "tollgate_main"; 21static const char *TAG = "tollgate_main";
25 22
26static EventGroupHandle_t s_wifi_event_group; 23static EventGroupHandle_t s_wifi_event_group;
@@ -31,6 +28,7 @@ static esp_netif_t *s_ap_netif = NULL;
31static int s_retry_count = 0; 28static int s_retry_count = 0;
32static bool s_services_running = false; 29static bool s_services_running = false;
33static SemaphoreHandle_t s_services_mutex = NULL; 30static SemaphoreHandle_t s_services_mutex = NULL;
31static char s_ap_ip_str[16] = "10.0.0.1";
34 32
35static void start_services(void); 33static void start_services(void);
36static void stop_services(void); 34static void stop_services(void);
@@ -109,8 +107,9 @@ static void start_services(void)
109 firewall_init(ap_ip_info.ip); 107 firewall_init(ap_ip_info.ip);
110 session_manager_init(); 108 session_manager_init();
111 109
110 const tollgate_config_t *cfg = tollgate_config_get();
112 dns_server_start(ap_ip_info.ip, upstream_dns); 111 dns_server_start(ap_ip_info.ip, upstream_dns);
113 captive_portal_start(); 112 captive_portal_start(cfg->ap_ip_str);
114 tollgate_api_start(); 113 tollgate_api_start();
115 114
116 s_services_running = true; 115 s_services_running = true;
@@ -140,10 +139,18 @@ static void wifi_create_ap_netif(void)
140{ 139{
141 s_ap_netif = esp_netif_create_default_wifi_ap(); 140 s_ap_netif = esp_netif_create_default_wifi_ap();
142 141
142 const tollgate_config_t *cfg = tollgate_config_get();
143 esp_ip4_addr_t ap_ip = cfg->ap_ip;
144 esp_ip4_addr_t ap_gw = cfg->ap_ip;
145 esp_ip4_addr_t ap_mask;
146 IP4_ADDR(&ap_mask, 255, 255, 255, 0);
147
148 strncpy(s_ap_ip_str, cfg->ap_ip_str, sizeof(s_ap_ip_str) - 1);
149
143 esp_netif_ip_info_t ip_info = { 150 esp_netif_ip_info_t ip_info = {
144 .ip.addr = esp_ip4addr_aton(AP_IP_ADDR), 151 .ip.addr = ap_ip.addr,
145 .gw.addr = esp_ip4addr_aton(AP_IP_ADDR), 152 .gw.addr = ap_gw.addr,
146 .netmask.addr = esp_ip4addr_aton(AP_SUBNET), 153 .netmask.addr = ap_mask.addr,
147 }; 154 };
148 ESP_ERROR_CHECK(esp_netif_dhcps_stop(s_ap_netif)); 155 ESP_ERROR_CHECK(esp_netif_dhcps_stop(s_ap_netif));
149 ESP_ERROR_CHECK(esp_netif_set_ip_info(s_ap_netif, &ip_info)); 156 ESP_ERROR_CHECK(esp_netif_set_ip_info(s_ap_netif, &ip_info));
@@ -190,6 +197,7 @@ void app_main(void)
190 ESP_ERROR_CHECK(ret); 197 ESP_ERROR_CHECK(ret);
191 198
192 ESP_ERROR_CHECK(tollgate_config_init()); 199 ESP_ERROR_CHECK(tollgate_config_init());
200 tollgate_config_derive_unique((tollgate_config_t *)tollgate_config_get());
193 ESP_ERROR_CHECK(esp_netif_init()); 201 ESP_ERROR_CHECK(esp_netif_init());
194 ESP_ERROR_CHECK(esp_event_loop_create_default()); 202 ESP_ERROR_CHECK(esp_event_loop_create_default());
195 203