wifi.h
  1  #pragma once
  2  
  3  #include <config.h>
  4  #include <stddef.h>
  5  #include <stdint.h>
  6  
  7  struct APConfig {
  8      char ssid[33];
  9      char password[65];
 10  };
 11  
 12  struct APSnapshot {
 13      bool active;
 14      char ssid[33];
 15      char password[65];
 16      char ip[16];
 17      uint16_t clients;
 18      char hostname[config::shell::HOSTNAME_SIZE + 1];
 19      char mac[18];
 20  };
 21  
 22  struct NetworkStatusSnapshot {
 23      bool connected;
 24      char ssid[33];
 25      char bssid[18];
 26      int32_t rssi;
 27      int32_t channel;
 28      char ip[16];
 29      char gateway[16];
 30      char subnet[16];
 31      char dns[16];
 32      char mac[18];
 33      char hostname[config::shell::HOSTNAME_SIZE + 1];
 34      APSnapshot ap;
 35  };
 36  
 37  struct WifiConnectRequest {
 38      const char *ssid;
 39      const char *password;
 40      bool enable_ap_fallback;
 41  };
 42  
 43  struct WifiConnectResult {
 44      bool connected;
 45      int status_code;
 46      bool ap_enabled_for_fallback;
 47  };
 48  
 49  struct WifiScanResult {
 50      char ssid[33];
 51      char bssid[18];
 52      int32_t rssi;
 53      int32_t channel;
 54      char encryption[24];
 55      bool open;
 56  };
 57  
 58  struct WifiSavedConfig {
 59      char ssid[33];
 60      char password[65];
 61      bool valid;
 62  };
 63  
 64  struct WifiConnectCommand {
 65      WifiConnectRequest request;
 66      WifiConnectResult result;
 67  };
 68  
 69  struct WifiScanCommand {
 70      WifiScanResult *results;
 71      size_t max_results;
 72      int result_count;
 73  };
 74  
 75  struct APConfigureCommand {
 76      APConfig config;
 77      APSnapshot snapshot;
 78  };
 79  
 80  struct APEnabledCommand {
 81      bool enabled;
 82      APSnapshot snapshot;
 83  };
 84  
 85  namespace networking::wifi {
 86  
 87  void configure_hostname(const char *hostname);
 88  bool accessSnapshot(NetworkStatusSnapshot *snapshot);
 89  bool accessConfig(WifiSavedConfig *config);
 90  bool storeConfig(WifiSavedConfig *config);
 91  bool connect(WifiConnectCommand *command);
 92  bool scan(WifiScanCommand *command);
 93  
 94  #ifdef PIO_UNIT_TESTING
 95  void test(void);
 96  #endif
 97  
 98  } // namespace networking::wifi
 99  
100  namespace networking::wifi::sta {
101  
102  void initialize();
103  bool connect();
104  
105  } // namespace networking::wifi::sta
106  
107  namespace networking::wifi::ap {
108  
109  void enable();
110  void disable();
111  bool isActive();
112  void accessConfig(APConfig *config);
113  bool accessSnapshot(APSnapshot *snapshot);
114  bool applyConfig(APConfigureCommand *command);
115  bool setEnabled(APEnabledCommand *command);
116  
117  } // namespace networking::wifi::ap
118