Skip to content

Commit

Permalink
Feature/improve network config (#139)
Browse files Browse the repository at this point in the history
* Remove BSSID from config

* Increase credentials id limit to 255
  • Loading branch information
hhvrc authored Nov 29, 2023
1 parent 202924e commit 85353e4
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 279 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// automatically generated by the FlatBuffers compiler, do not modify

export { BSSID } from './serialization/configuration/bssid.js';
export { BackendConfig } from './serialization/configuration/backend-config.js';
export { CaptivePortalConfig } from './serialization/configuration/captive-portal-config.js';
export { Config } from './serialization/configuration/config.js';
Expand Down
33 changes: 0 additions & 33 deletions WebUI/src/lib/_fbs/open-shock/serialization/configuration/bssid.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import * as flatbuffers from 'flatbuffers';

import { BSSID } from '../../../open-shock/serialization/configuration/bssid.js';


export class WiFiCredentials {
bb: flatbuffers.ByteBuffer|null = null;
bb_pos = 0;
Expand Down Expand Up @@ -35,20 +32,15 @@ ssid(optionalEncoding?:any):string|Uint8Array|null {
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

bssid(obj?:BSSID):BSSID|null {
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? (obj || new BSSID()).__init(this.bb_pos + offset, this.bb!) : null;
}

password():string|null
password(optionalEncoding:flatbuffers.Encoding):string|Uint8Array|null
password(optionalEncoding?:any):string|Uint8Array|null {
const offset = this.bb!.__offset(this.bb_pos, 10);
const offset = this.bb!.__offset(this.bb_pos, 8);
return offset ? this.bb!.__string(this.bb_pos + offset, optionalEncoding) : null;
}

static startWiFiCredentials(builder:flatbuffers.Builder) {
builder.startObject(4);
builder.startObject(3);
}

static addId(builder:flatbuffers.Builder, id:number) {
Expand All @@ -59,17 +51,20 @@ static addSsid(builder:flatbuffers.Builder, ssidOffset:flatbuffers.Offset) {
builder.addFieldOffset(1, ssidOffset, 0);
}

static addBssid(builder:flatbuffers.Builder, bssidOffset:flatbuffers.Offset) {
builder.addFieldStruct(2, bssidOffset, 0);
}

static addPassword(builder:flatbuffers.Builder, passwordOffset:flatbuffers.Offset) {
builder.addFieldOffset(3, passwordOffset, 0);
builder.addFieldOffset(2, passwordOffset, 0);
}

static endWiFiCredentials(builder:flatbuffers.Builder):flatbuffers.Offset {
const offset = builder.endObject();
return offset;
}

static createWiFiCredentials(builder:flatbuffers.Builder, id:number, ssidOffset:flatbuffers.Offset, passwordOffset:flatbuffers.Offset):flatbuffers.Offset {
WiFiCredentials.startWiFiCredentials(builder);
WiFiCredentials.addId(builder, id);
WiFiCredentials.addSsid(builder, ssidOffset);
WiFiCredentials.addPassword(builder, passwordOffset);
return WiFiCredentials.endWiFiCredentials(builder);
}
}
5 changes: 1 addition & 4 deletions include/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ namespace OpenShock::Config {
bool SetRFConfigTxPin(std::uint8_t txPin);
bool SetRFConfigKeepAliveEnabled(bool enabled);

std::uint8_t AddWiFiCredentials(const std::string& ssid, const std::uint8_t (&bssid)[6], const std::string& password);
std::uint8_t AddWiFiCredentials(const std::string& ssid, const std::string& password);
bool TryGetWiFiCredentialsByID(std::uint8_t id, WiFiCredentials& out);
bool TryGetWiFiCredentialsBySSID(const char* ssid, WiFiCredentials& out);
bool TryGetWiFiCredentialsByBSSID(const std::uint8_t (&bssid)[6], WiFiCredentials& out);
std::uint8_t GetWiFiCredentialsIDbySSID(const char* ssid);
std::uint8_t GetWiFiCredentialsIDbyBSSID(const std::uint8_t (&bssid)[6]);
std::uint8_t GetWiFiCredentialsIDbyBSSIDorSSID(const std::uint8_t (&bssid)[6], const char* ssid);
bool RemoveWiFiCredentials(std::uint8_t id);
void ClearWiFiCredentials();

Expand Down
3 changes: 1 addition & 2 deletions include/config/WiFiCredentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
namespace OpenShock::Config {
struct WiFiCredentials : public ConfigBase<Serialization::Configuration::WiFiCredentials> {
WiFiCredentials();
WiFiCredentials(std::uint8_t id, const std::string& ssid, const std::uint8_t (&bssid)[6], const std::string& password);
WiFiCredentials(std::uint8_t id, const std::string& ssid, const std::string& password);

std::uint8_t id;
std::string ssid;
std::uint8_t bssid[6];
std::string password;

void ToDefault() override;
Expand Down
41 changes: 1 addition & 40 deletions include/serialization/_fbs/ConfigFile_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ namespace OpenShock {
namespace Serialization {
namespace Configuration {

struct BSSID;

struct RFConfig;
struct RFConfigBuilder;

Expand All @@ -37,31 +35,6 @@ struct BackendConfigBuilder;
struct Config;
struct ConfigBuilder;

FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(1) BSSID FLATBUFFERS_FINAL_CLASS {
private:
uint8_t array_[6];

public:
struct Traits;
static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
return "OpenShock.Serialization.Configuration.BSSID";
}
BSSID()
: array_() {
}
BSSID(::flatbuffers::span<const uint8_t, 6> _array) {
::flatbuffers::CastToArray(array_).CopyFromSpan(_array);
}
const ::flatbuffers::Array<uint8_t, 6> *array() const {
return &::flatbuffers::CastToArray(array_);
}
};
FLATBUFFERS_STRUCT_END(BSSID, 6);

struct BSSID::Traits {
using type = BSSID;
};

struct RFConfig FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
typedef RFConfigBuilder Builder;
struct Traits;
Expand Down Expand Up @@ -131,18 +104,14 @@ struct WiFiCredentials FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
VT_ID = 4,
VT_SSID = 6,
VT_BSSID = 8,
VT_PASSWORD = 10
VT_PASSWORD = 8
};
uint8_t id() const {
return GetField<uint8_t>(VT_ID, 0);
}
const ::flatbuffers::String *ssid() const {
return GetPointer<const ::flatbuffers::String *>(VT_SSID);
}
const OpenShock::Serialization::Configuration::BSSID *bssid() const {
return GetStruct<const OpenShock::Serialization::Configuration::BSSID *>(VT_BSSID);
}
const ::flatbuffers::String *password() const {
return GetPointer<const ::flatbuffers::String *>(VT_PASSWORD);
}
Expand All @@ -151,7 +120,6 @@ struct WiFiCredentials FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
VerifyField<uint8_t>(verifier, VT_ID, 1) &&
VerifyOffset(verifier, VT_SSID) &&
verifier.VerifyString(ssid()) &&
VerifyField<OpenShock::Serialization::Configuration::BSSID>(verifier, VT_BSSID, 1) &&
VerifyOffset(verifier, VT_PASSWORD) &&
verifier.VerifyString(password()) &&
verifier.EndTable();
Expand All @@ -168,9 +136,6 @@ struct WiFiCredentialsBuilder {
void add_ssid(::flatbuffers::Offset<::flatbuffers::String> ssid) {
fbb_.AddOffset(WiFiCredentials::VT_SSID, ssid);
}
void add_bssid(const OpenShock::Serialization::Configuration::BSSID *bssid) {
fbb_.AddStruct(WiFiCredentials::VT_BSSID, bssid);
}
void add_password(::flatbuffers::Offset<::flatbuffers::String> password) {
fbb_.AddOffset(WiFiCredentials::VT_PASSWORD, password);
}
Expand All @@ -189,11 +154,9 @@ inline ::flatbuffers::Offset<WiFiCredentials> CreateWiFiCredentials(
::flatbuffers::FlatBufferBuilder &_fbb,
uint8_t id = 0,
::flatbuffers::Offset<::flatbuffers::String> ssid = 0,
const OpenShock::Serialization::Configuration::BSSID *bssid = nullptr,
::flatbuffers::Offset<::flatbuffers::String> password = 0) {
WiFiCredentialsBuilder builder_(_fbb);
builder_.add_password(password);
builder_.add_bssid(bssid);
builder_.add_ssid(ssid);
builder_.add_id(id);
return builder_.Finish();
Expand All @@ -208,15 +171,13 @@ inline ::flatbuffers::Offset<WiFiCredentials> CreateWiFiCredentialsDirect(
::flatbuffers::FlatBufferBuilder &_fbb,
uint8_t id = 0,
const char *ssid = nullptr,
const OpenShock::Serialization::Configuration::BSSID *bssid = nullptr,
const char *password = nullptr) {
auto ssid__ = ssid ? _fbb.CreateString(ssid) : 0;
auto password__ = password ? _fbb.CreateString(password) : 0;
return OpenShock::Serialization::Configuration::CreateWiFiCredentials(
_fbb,
id,
ssid__,
bssid,
password__);
}

Expand Down
22 changes: 0 additions & 22 deletions include/wifi/WiFiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,11 @@ namespace OpenShock::WiFiManager {
/// @return True if the network was saved successfully
bool Save(const char* ssid, const std::string& password);

/// @brief Saves a network to the config by it's BSSID (supports hidden networks)
/// @param bssid BSSID of the network
/// @param password Password of the network
/// @return True if the network was saved successfully
bool Save(const std::uint8_t (&bssid)[6], const std::string& password);

/// @brief Removes a network from the config by it's SSID
/// @param ssid SSID of the network
/// @return True if the network was removed successfully
bool Forget(const char* ssid);

/// @brief Removes a network from the config by it's BSSID
/// @param bssid BSSID of the network
/// @return True if the network was removed successfully
bool Forget(const std::uint8_t (&bssid)[6]);

/// @brief Refreshes all the networks with updated credential IDs from the config
/// @return True if the networks were refreshed successfully
bool RefreshNetworkCredentials();
Expand All @@ -41,17 +30,6 @@ namespace OpenShock::WiFiManager {
/// @return True if a saved network matches the given SSID
bool IsSaved(const char* ssid);

/// @brief Checks if a network is saved in the config by it's BSSID
/// @param bssid BSSID of the network
/// @return True if a saved network matches the given BSSID
bool IsSaved(const std::uint8_t (&bssid)[6]);

/// @brief Checks if a network is saved in the config by it's SSID and BSSID
/// @param ssid SSID of the network
/// @param bssid BSSID of the network
/// @return True if a saved network matches both the given SSID and BSSID
bool IsSaved(const char* ssid, const std::uint8_t (&bssid)[6]);

/// @brief Connects to a saved network by it's SSID
/// @param ssid SSID of the network
/// @return True if the saved network was found and the connection process was started successfully
Expand Down
5 changes: 0 additions & 5 deletions schemas/ConfigFile.fbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
namespace OpenShock.Serialization.Configuration;

struct BSSID {
array:[ubyte:6];
}

table RFConfig {
tx_pin:uint8;
keepalive_enabled:bool;
Expand All @@ -12,7 +8,6 @@ table RFConfig {
table WiFiCredentials {
id:uint8;
ssid:string;
bssid:BSSID;
password:string;
}

Expand Down
Loading

0 comments on commit 85353e4

Please sign in to comment.