diff options
Diffstat (limited to 'main/config.c')
| -rw-r--r-- | main/config.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/main/config.c b/main/config.c index b44c3c5..d7837bc 100644 --- a/main/config.c +++ b/main/config.c | |||
| @@ -1,8 +1,12 @@ | |||
| 1 | #include "config.h" | 1 | #include "config.h" |
| 2 | #include "esp_log.h" | 2 | #include "esp_log.h" |
| 3 | #include "esp_spiffs.h" | 3 | #include "esp_spiffs.h" |
| 4 | #include "esp_system.h" | ||
| 5 | #include "esp_mac.h" | ||
| 6 | #include "lwip/ip4_addr.h" | ||
| 4 | #include "cJSON.h" | 7 | #include "cJSON.h" |
| 5 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <stdio.h> | ||
| 6 | 10 | ||
| 7 | static const char *TAG = "tollgate_config"; | 11 | static const char *TAG = "tollgate_config"; |
| 8 | static tollgate_config_t g_config; | 12 | static tollgate_config_t g_config; |
| @@ -140,3 +144,25 @@ esp_err_t tollgate_config_get_next_wifi(wifi_config_t *wifi_config) | |||
| 140 | g_config.current_network = (g_config.current_network + 1) % g_config.network_count; | 144 | g_config.current_network = (g_config.current_network + 1) % g_config.network_count; |
| 141 | return tollgate_config_get_wifi(wifi_config); | 145 | return tollgate_config_get_wifi(wifi_config); |
| 142 | } | 146 | } |
| 147 | |||
| 148 | void tollgate_config_derive_unique(tollgate_config_t *cfg) | ||
| 149 | { | ||
| 150 | if (cfg->unique_derived) return; | ||
| 151 | |||
| 152 | uint8_t mac[6]; | ||
| 153 | esp_read_mac(mac, ESP_MAC_WIFI_STA); | ||
| 154 | |||
| 155 | snprintf(cfg->ap_ssid + strlen(cfg->ap_ssid), | ||
| 156 | TOLLGATE_MAX_AP_SSID_LEN - strlen(cfg->ap_ssid), | ||
| 157 | "-%02X%02X", mac[4], mac[5]); | ||
| 158 | |||
| 159 | uint8_t b5 = mac[4]; | ||
| 160 | uint8_t b6 = mac[5]; | ||
| 161 | uint8_t subnet = (b5 ^ b6) % 200 + 10; | ||
| 162 | IP4_ADDR(&cfg->ap_ip, 10, b5, subnet, 1); | ||
| 163 | snprintf(cfg->ap_ip_str, sizeof(cfg->ap_ip_str), IPSTR, IP2STR(&cfg->ap_ip)); | ||
| 164 | |||
| 165 | cfg->unique_derived = true; | ||
| 166 | |||
| 167 | ESP_LOGI(TAG, "Unique config: SSID='%s', AP_IP=%s", cfg->ap_ssid, cfg->ap_ip_str); | ||
| 168 | } | ||