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:
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