diff options
| -rw-r--r-- | components/tollgate_core/src/tollgate_core.c | 5 | ||||
| -rw-r--r-- | components/tollgate_core/src/tollgate_core_session.h | 2 | ||||
| -rw-r--r-- | main/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | main/captive_portal.c | 15 | ||||
| -rw-r--r-- | main/config.h | 3 | ||||
| -rw-r--r-- | main/tollgate_main.c | 16 | ||||
| -rw-r--r-- | main/tollgate_platform.c | 1 | ||||
| -rw-r--r-- | tests/unit/Makefile | 3 |
8 files changed, 17 insertions, 33 deletions
diff --git a/components/tollgate_core/src/tollgate_core.c b/components/tollgate_core/src/tollgate_core.c index 3813258..666d2e0 100644 --- a/components/tollgate_core/src/tollgate_core.c +++ b/components/tollgate_core/src/tollgate_core.c | |||
| @@ -45,11 +45,6 @@ esp_err_t tollgate_core_dns_start(esp_ip4_addr_t upstream_dns) | |||
| 45 | return tollgate_core_dns_start_internal(s_ap_ip, upstream_dns); | 45 | return tollgate_core_dns_start_internal(s_ap_ip, upstream_dns); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void tollgate_core_dns_stop(void) | ||
| 49 | { | ||
| 50 | tollgate_core_dns_stop_internal(); | ||
| 51 | } | ||
| 52 | |||
| 53 | esp_err_t tollgate_core_process_payment(uint32_t client_ip, const char *token_str) | 48 | esp_err_t tollgate_core_process_payment(uint32_t client_ip, const char *token_str) |
| 54 | { | 49 | { |
| 55 | if (!s_platform || !token_str) return ESP_FAIL; | 50 | if (!s_platform || !token_str) return ESP_FAIL; |
diff --git a/components/tollgate_core/src/tollgate_core_session.h b/components/tollgate_core/src/tollgate_core_session.h index 95b5c48..444b9fa 100644 --- a/components/tollgate_core/src/tollgate_core_session.h +++ b/components/tollgate_core/src/tollgate_core_session.h | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | #define TOLLGATE_CORE_SESSION_H | 2 | #define TOLLGATE_CORE_SESSION_H |
| 3 | 3 | ||
| 4 | #include "esp_err.h" | 4 | #include "esp_err.h" |
| 5 | #include "tollgate_platform.h" | ||
| 5 | #include <stdint.h> | 6 | #include <stdint.h> |
| 6 | #include <stdbool.h> | 7 | #include <stdbool.h> |
| 7 | 8 | ||
| @@ -19,6 +20,7 @@ typedef struct { | |||
| 19 | } tg_session_t; | 20 | } tg_session_t; |
| 20 | 21 | ||
| 21 | esp_err_t tollgate_core_session_init(void); | 22 | esp_err_t tollgate_core_session_init(void); |
| 23 | void tollgate_core_session_set_platform(const tollgate_platform_t *platform); | ||
| 22 | 24 | ||
| 23 | tg_session_t *tollgate_core_session_create(uint32_t client_ip, uint64_t allotment_ms); | 25 | tg_session_t *tollgate_core_session_create(uint32_t client_ip, uint64_t allotment_ms); |
| 24 | tg_session_t *tollgate_core_session_create_bytes(uint32_t client_ip, uint64_t allotment_bytes); | 26 | tg_session_t *tollgate_core_session_create_bytes(uint32_t client_ip, uint64_t allotment_bytes); |
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 5f195c3..c3f8019 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt | |||
| @@ -12,12 +12,9 @@ idf_component_register(SRCS "tollgate_main.c" | |||
| 12 | "lightning_payout.c" | 12 | "lightning_payout.c" |
| 13 | "nip04.c" | 13 | "nip04.c" |
| 14 | "mcp_handler.c" | 14 | "mcp_handler.c" |
| 15 | "cvm_server.c" | ||
| 16 | "display.c" | ||
| 17 | "font.c" | ||
| 18 | INCLUDE_DIRS "." | 15 | INCLUDE_DIRS "." |
| 19 | REQUIRES esp_wifi esp_event esp_netif nvs_flash esp_http_server | 16 | REQUIRES esp_wifi esp_event esp_netif nvs_flash esp_http_server |
| 20 | lwip json esp_http_client mbedtls esp-tls log spiffs | 17 | lwip json esp_http_client mbedtls esp-tls log spiffs |
| 21 | nucula_lib secp256k1 axs15231b qrcode | 18 | nucula_lib secp256k1 |
| 22 | tollgate_core | 19 | tollgate_core |
| 23 | PRIV_REQUIRES esp-tls) | 20 | PRIV_REQUIRES esp-tls) |
diff --git a/main/captive_portal.c b/main/captive_portal.c index 1a3d5ce..98dc637 100644 --- a/main/captive_portal.c +++ b/main/captive_portal.c | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include "captive_portal.h" | 1 | #include "captive_portal.h" |
| 2 | #include "firewall.h" | 2 | #include "tollgate_core.h" |
| 3 | #include "session.h" | 3 | #include "tollgate_core_firewall.h" |
| 4 | #include "tollgate_core_session.h" | ||
| 4 | #include "config.h" | 5 | #include "config.h" |
| 5 | #include "esp_log.h" | 6 | #include "esp_log.h" |
| 6 | #include "esp_wifi.h" | 7 | #include "esp_wifi.h" |
| @@ -182,7 +183,7 @@ static esp_err_t grant_access_handler(httpd_req_t *req) | |||
| 182 | { | 183 | { |
| 183 | uint32_t client_ip; | 184 | uint32_t client_ip; |
| 184 | if (get_client_ip(req, &client_ip) == ESP_OK) { | 185 | if (get_client_ip(req, &client_ip) == ESP_OK) { |
| 185 | firewall_grant_access(client_ip); | 186 | tollgate_core_fw_grant(client_ip); |
| 186 | } | 187 | } |
| 187 | const char *resp = "{\"status\":\"granted\"}"; | 188 | const char *resp = "{\"status\":\"granted\"}"; |
| 188 | httpd_resp_set_type(req, "application/json"); | 189 | httpd_resp_set_type(req, "application/json"); |
| @@ -211,7 +212,7 @@ static esp_err_t whoami_handler(httpd_req_t *req) | |||
| 211 | if (get_client_ip(req, &client_ip) == ESP_OK) { | 212 | if (get_client_ip(req, &client_ip) == ESP_OK) { |
| 212 | char mac[18] = {0}; | 213 | char mac[18] = {0}; |
| 213 | esp_ip4_addr_t ip = { .addr = client_ip }; | 214 | esp_ip4_addr_t ip = { .addr = client_ip }; |
| 214 | if (firewall_get_mac_for_ip(client_ip, mac, sizeof(mac)) == ESP_OK) { | 215 | if (tollgate_core_fw_get_mac_for_ip(client_ip, mac, sizeof(mac)) == ESP_OK) { |
| 215 | snprintf(resp, sizeof(resp), "ip=" IPSTR " mac=%s", IP2STR(&ip), mac); | 216 | snprintf(resp, sizeof(resp), "ip=" IPSTR " mac=%s", IP2STR(&ip), mac); |
| 216 | } else { | 217 | } else { |
| 217 | snprintf(resp, sizeof(resp), "ip=" IPSTR " mac=unknown", IP2STR(&ip)); | 218 | snprintf(resp, sizeof(resp), "ip=" IPSTR " mac=unknown", IP2STR(&ip)); |
| @@ -233,7 +234,7 @@ static esp_err_t usage_handler(httpd_req_t *req) | |||
| 233 | return ESP_OK; | 234 | return ESP_OK; |
| 234 | } | 235 | } |
| 235 | 236 | ||
| 236 | session_t *session = session_find_by_ip(client_ip); | 237 | tg_session_t *session = tollgate_core_session_find_by_ip(client_ip); |
| 237 | if (!session || !session->active) { | 238 | if (!session || !session->active) { |
| 238 | httpd_resp_set_type(req, "text/plain"); | 239 | httpd_resp_set_type(req, "text/plain"); |
| 239 | httpd_resp_send(req, "-1/-1", 5); | 240 | httpd_resp_send(req, "-1/-1", 5); |
| @@ -261,8 +262,8 @@ static esp_err_t usage_handler(httpd_req_t *req) | |||
| 261 | 262 | ||
| 262 | static esp_err_t reset_auth_handler(httpd_req_t *req) | 263 | static esp_err_t reset_auth_handler(httpd_req_t *req) |
| 263 | { | 264 | { |
| 264 | session_revoke_all(); | 265 | tollgate_core_session_revoke_all(); |
| 265 | firewall_revoke_all(); | 266 | tollgate_core_fw_revoke_all(); |
| 266 | const char *resp = "{\"status\":\"reset\"}"; | 267 | const char *resp = "{\"status\":\"reset\"}"; |
| 267 | httpd_resp_set_type(req, "application/json"); | 268 | httpd_resp_set_type(req, "application/json"); |
| 268 | httpd_resp_send(req, resp, strlen(resp)); | 269 | httpd_resp_send(req, resp, strlen(resp)); |
diff --git a/main/config.h b/main/config.h index fa4d95c..b8a3136 100644 --- a/main/config.h +++ b/main/config.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "esp_err.h" | 4 | #include "esp_err.h" |
| 5 | #include "esp_wifi.h" | 5 | #include "esp_wifi.h" |
| 6 | #include "esp_netif.h" | 6 | #include "esp_netif.h" |
| 7 | #include "tollgate_platform.h" | ||
| 7 | #include <stdbool.h> | 8 | #include <stdbool.h> |
| 8 | 9 | ||
| 9 | #include "lightning_payout.h" | 10 | #include "lightning_payout.h" |
| @@ -72,4 +73,6 @@ const tollgate_config_t *tollgate_config_get(void); | |||
| 72 | esp_err_t tollgate_config_get_wifi(wifi_config_t *wifi_config); | 73 | esp_err_t tollgate_config_get_wifi(wifi_config_t *wifi_config); |
| 73 | esp_err_t tollgate_config_get_next_wifi(wifi_config_t *wifi_config); | 74 | esp_err_t tollgate_config_get_next_wifi(wifi_config_t *wifi_config); |
| 74 | 75 | ||
| 76 | const tollgate_platform_t *tollgate_get_platform(void); | ||
| 77 | |||
| 75 | #endif | 78 | #endif |
diff --git a/main/tollgate_main.c b/main/tollgate_main.c index 697dae3..f8998bd 100644 --- a/main/tollgate_main.c +++ b/main/tollgate_main.c | |||
| @@ -20,8 +20,6 @@ | |||
| 20 | #include "wifistr.h" | 20 | #include "wifistr.h" |
| 21 | #include "tollgate_client.h" | 21 | #include "tollgate_client.h" |
| 22 | #include "lightning_payout.h" | 22 | #include "lightning_payout.h" |
| 23 | #include "cvm_server.h" | ||
| 24 | #include "display.h" | ||
| 25 | 23 | ||
| 26 | #define MAX_STA_RETRY 5 | 24 | #define MAX_STA_RETRY 5 |
| 27 | static const char *TAG = "tollgate_main"; | 25 | static const char *TAG = "tollgate_main"; |
| @@ -152,19 +150,9 @@ static void start_services(void) | |||
| 152 | 150 | ||
| 153 | xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL); | 151 | xTaskCreate(publish_wifistr_task, "wifistr_init", 16384, NULL, 3, NULL); |
| 154 | 152 | ||
| 155 | if (cfg->cvm_enabled) { | ||
| 156 | cvm_server_init(); | ||
| 157 | cvm_server_start(); | ||
| 158 | } | ||
| 159 | |||
| 160 | s_services_running = true; | 153 | s_services_running = true; |
| 161 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); | 154 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); |
| 162 | ESP_LOGI(TAG, "=== TollGate services started ==="); | 155 | ESP_LOGI(TAG, "=== TollGate services started ==="); |
| 163 | |||
| 164 | display_set_state(DISPLAY_READY); | ||
| 165 | char portal_url[128]; | ||
| 166 | snprintf(portal_url, sizeof(portal_url), "http://%s/", cfg->ap_ip_str); | ||
| 167 | display_update(cfg->ap_ssid, 0, 0, portal_url); | ||
| 168 | } | 156 | } |
| 169 | 157 | ||
| 170 | static void stop_services(void) | 158 | static void stop_services(void) |
| @@ -178,7 +166,6 @@ static void stop_services(void) | |||
| 178 | captive_portal_stop(); | 166 | captive_portal_stop(); |
| 179 | tollgate_api_stop(); | 167 | tollgate_api_stop(); |
| 180 | tollgate_core_dns_stop(); | 168 | tollgate_core_dns_stop(); |
| 181 | cvm_server_stop(); | ||
| 182 | s_services_running = false; | 169 | s_services_running = false; |
| 183 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); | 170 | if (s_services_mutex) xSemaphoreGive(s_services_mutex); |
| 184 | ESP_LOGI(TAG, "=== TollGate services stopped ==="); | 171 | ESP_LOGI(TAG, "=== TollGate services stopped ==="); |
| @@ -244,9 +231,6 @@ void app_main(void) | |||
| 244 | { | 231 | { |
| 245 | ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); | 232 | ESP_LOGI(TAG, "=== TollGate ESP32 Starting ==="); |
| 246 | 233 | ||
| 247 | display_init(); | ||
| 248 | display_set_state(DISPLAY_BOOT); | ||
| 249 | |||
| 250 | esp_err_t ret = nvs_flash_init(); | 234 | esp_err_t ret = nvs_flash_init(); |
| 251 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { | 235 | if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { |
| 252 | ESP_ERROR_CHECK(nvs_flash_erase()); | 236 | ESP_ERROR_CHECK(nvs_flash_erase()); |
diff --git a/main/tollgate_platform.c b/main/tollgate_platform.c index c992ea1..4083c4e 100644 --- a/main/tollgate_platform.c +++ b/main/tollgate_platform.c | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | #include "tollgate_core.h" | 2 | #include "tollgate_core.h" |
| 3 | #include "config.h" | 3 | #include "config.h" |
| 4 | #include "esp_log.h" | 4 | #include "esp_log.h" |
| 5 | #include "esp_timer.h" | ||
| 6 | #include "freertos/FreeRTOS.h" | 5 | #include "freertos/FreeRTOS.h" |
| 7 | #include "freertos/task.h" | 6 | #include "freertos/task.h" |
| 8 | 7 | ||
diff --git a/tests/unit/Makefile b/tests/unit/Makefile index 7ebc3b2..ebf8d0f 100644 --- a/tests/unit/Makefile +++ b/tests/unit/Makefile | |||
| @@ -14,6 +14,9 @@ CFLAGS := -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-sign-com | |||
| 14 | -DECMULT_WINDOW_SIZE=8 -DECMULT_GEN_PREC_BITS=4 \ | 14 | -DECMULT_WINDOW_SIZE=8 -DECMULT_GEN_PREC_BITS=4 \ |
| 15 | -include stubs/esp_err.h \ | 15 | -include stubs/esp_err.h \ |
| 16 | -I stubs \ | 16 | -I stubs \ |
| 17 | -I $(REPO_ROOT)/components/tollgate_core/include \ | ||
| 18 | -I $(REPO_ROOT)/components/tollgate_core/src \ | ||
| 19 | -I $(REPO_ROOT)/main \ | ||
| 17 | -I $(SECP256K1_INC) \ | 20 | -I $(SECP256K1_INC) \ |
| 18 | -I $(SECP256K1_CFG) \ | 21 | -I $(SECP256K1_CFG) \ |
| 19 | -I /usr/include/cjson | 22 | -I /usr/include/cjson |