AP on/off, hostname on all interfaces, custom mac addressess

This commit is contained in:
2021-10-28 01:01:10 +02:00
parent 0f54574b33
commit 43301b7b0b
5 changed files with 477 additions and 398 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@
// system includes
#include <string>
#include <string_view>
#include <vector>
#include <optional>
@@ -14,13 +15,13 @@
// 3rdparty lib includes
#include <tl/expected.hpp>
#include <espchrono.h>
#include <cppsignal.h>
// local includes
#include "espwifistackconfig.h"
#include "espwifistackenums.h"
#include "espwifiutils.h"
#include "espchrono.h"
#include "cppsignal.h"
namespace wifi_stack {
struct scan_result
@@ -51,11 +52,13 @@ extern const std::vector<mac_t> &pastConnectPlan;
extern const mac_t &currentConnectPlanEntry;
extern const std::vector<mac_t> &connectPlan;
wifi_mode_t get_wifi_mode();
//! Tells the status of the STA interface (connected, ...)
WiFiStaStatus get_sta_status();
//! Tries to begin a new scan, if succeeds clears the old scan result
esp_err_t begin_scan(const config &config);
tl::expected<void, std::string> begin_scan(const sta_config &sta_config);
//! Tells the status of the currently running scan (finished, ...)
WiFiScanStatus get_scan_status();
@@ -67,11 +70,16 @@ const std::optional<scan_result> &get_scan_result();
//! Clears the scan result
void delete_scan_result();
//! Util wrappers
using mac_or_error = tl::expected<mac_t, std::string>;
tl::expected<wifi_ap_record_t, std::string> get_sta_ap_info();
tl::expected<wifi_stack::mac_t, std::string> get_default_mac_addr();
tl::expected<wifi_stack::mac_t, std::string> get_base_mac_addr();
tl::expected<void, std::string> set_base_mac_addr(wifi_stack::mac_t mac_addr);
mac_or_error get_default_mac_addr();
mac_or_error get_custom_mac_addr();
mac_or_error get_base_mac_addr();
tl::expected<void, std::string> set_base_mac_addr(mac_t mac_addr);
tl::expected<tcpip_adapter_ip_info_t, std::string> get_ip_info(tcpip_adapter_if_t tcpip_if);
tl::expected<std::string_view, std::string> get_hostname_for_interface(esp_interface_t interf);
tl::expected<std::string_view, std::string> get_hostname_for_interface(esp_netif_t *esp_netif);
#ifdef CONFIG_ETH_ENABLED
esp_eth_handle_t getEthHandle();

View File

@@ -7,10 +7,14 @@
#include <array>
#include <cstdint>
#include <optional>
#include <variant>
// esp-idf includes
#include <esp_wifi_types.h>
// 3rdparty lib includes
#include <espchrono.h>
// local includes
#include "espwifiutils.h"
@@ -74,17 +78,74 @@ struct wifi_entry
}
};
struct sta_active_scan_config
{
espchrono::milliseconds32 min_per_chan{100};
espchrono::milliseconds32 max_per_chan{300};
friend bool operator==(const sta_active_scan_config &left, const sta_active_scan_config &right)
{
return left.min_per_chan == right.min_per_chan &&
left.max_per_chan == right.max_per_chan;
}
friend bool operator!=(const sta_active_scan_config &left, const sta_active_scan_config &right)
{
return !(left == right);
}
};
struct sta_passive_scan_config
{
espchrono::milliseconds32 max_per_chan{300};
friend bool operator==(const sta_passive_scan_config &left, const sta_passive_scan_config &right)
{
return left.max_per_chan == right.max_per_chan;
}
friend bool operator!=(const sta_passive_scan_config &left, const sta_passive_scan_config &right)
{
return !(left == right);
}
};
struct sta_scan_config
{
std::optional<espchrono::milliseconds32> interval = espchrono::minutes32{10};
uint8_t channel = 0;
bool show_hidden = false;
std::variant<sta_active_scan_config, sta_passive_scan_config> time = sta_active_scan_config{};
friend bool operator==(const sta_scan_config &left, const sta_scan_config &right)
{
return left.interval == right.interval &&
left.channel == right.channel &&
left.show_hidden == right.show_hidden &&
left.time == right.time;
}
friend bool operator!=(const sta_scan_config &left, const sta_scan_config &right)
{
return !(left == right);
}
};
struct sta_config
{
bool enabled;
std::string hostname;
std::array<wifi_entry, 10> wifis;
int8_t min_rssi;
int8_t min_rssi = -90;
bool long_range = false;
sta_scan_config scan;
friend bool operator==(const sta_config &left, const sta_config &right)
{
return left.enabled == right.enabled &&
return left.hostname == right.hostname &&
left.wifis == right.wifis &&
left.min_rssi == right.min_rssi;
left.min_rssi == right.min_rssi &&
left.long_range == right.long_range &&
left.scan == right.scan;
}
friend bool operator!=(const sta_config &left, const sta_config &right)
@@ -95,25 +156,29 @@ struct sta_config
struct ap_config
{
std::string hostname;
std::string ssid;
std::string key;
static_ip_config static_ip;
uint8_t channel;
wifi_auth_mode_t authmode;
bool ssid_hidden;
int max_connection;
uint16_t beacon_interval;
uint8_t channel = 1;
wifi_auth_mode_t authmode = WIFI_AUTH_WPA2_PSK;
bool ssid_hidden = false;
int max_connection = 4;
uint16_t beacon_interval = 100;
bool long_range = false;
friend bool operator==(const ap_config &left, const ap_config &right)
{
return left.ssid == right.ssid &&
return left.hostname == right.hostname &&
left.ssid == right.ssid &&
left.key == right.key &&
left.static_ip == right.static_ip &&
left.channel == right.channel &&
left.authmode == right.authmode &&
left.ssid_hidden == right.ssid_hidden &&
left.max_connection == right.max_connection &&
left.beacon_interval == right.beacon_interval;
left.beacon_interval == right.beacon_interval &&
left.long_range == right.long_range;
}
friend bool operator!=(const ap_config &left, const ap_config &right)
@@ -125,13 +190,13 @@ struct ap_config
#ifdef CONFIG_ETH_ENABLED
struct eth_config
{
bool enabled;
std::string hostname;
std::optional<static_ip_config> static_ip;
static_dns_config static_dns;
friend bool operator==(const eth_config &left, const eth_config &right)
{
return left.enabled == right.enabled &&
return left.hostname == right.hostname &&
left.static_ip == right.static_ip &&
left.static_dns == right.static_dns;
}
@@ -145,16 +210,16 @@ struct eth_config
struct config
{
std::string hostname;
sta_config sta;
ap_config ap;
std::optional<mac_t> base_mac_override;
std::optional<sta_config> sta;
std::optional<ap_config> ap;
#ifdef CONFIG_ETH_ENABLED
eth_config eth;
std::optional<eth_config> eth;
#endif
friend bool operator==(const config &left, const config &right)
{
return left.hostname == right.hostname &&
return left.base_mac_override == right.base_mac_override &&
left.sta == right.sta &&
left.ap == right.ap
#ifdef CONFIG_ETH_ENABLED

View File

@@ -1,7 +1,7 @@
#pragma once
// local includes
#include "cpptypesafeenum.h"
// 3rdparty lib includes
#include <cpptypesafeenum.h>
namespace wifi_stack {

View File

@@ -8,9 +8,7 @@
// 3rdparty lib includes
#include <fmt/core.h>
// local includes
#include "futurecpp.h"
#include <futurecpp.h>
namespace wifi_stack {
namespace {