feat: introduce the network state model and secure persistent storage
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#ifndef NETWORK_CREDENTIAL_STORE_H
|
||||
#define NETWORK_CREDENTIAL_STORE_H
|
||||
#include <stdbool.h>
|
||||
#include "network_state.h"
|
||||
bool network_credential_store_load(network_profile_t *profile);
|
||||
bool network_credential_store_replace(const network_profile_t *profile);
|
||||
bool network_credential_store_delete(void);
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef NETWORK_CREDENTIALS_H
|
||||
#define NETWORK_CREDENTIALS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "network_state.h"
|
||||
|
||||
typedef struct { uint32_t magic; uint16_t version; uint16_t reserved; network_profile_t profile; uint32_t checksum; } network_credential_record_t;
|
||||
typedef bool (*network_credential_read_fn)(void *context, network_credential_record_t *record);
|
||||
typedef bool (*network_credential_write_fn)(void *context, const network_credential_record_t *record);
|
||||
typedef bool (*network_credential_delete_fn)(void *context);
|
||||
typedef struct {
|
||||
void *context;
|
||||
network_credential_read_fn read;
|
||||
network_credential_write_fn write;
|
||||
network_credential_delete_fn remove;
|
||||
} network_credential_backend_t;
|
||||
|
||||
bool network_credential_encode(const network_profile_t *profile, network_credential_record_t *record);
|
||||
bool network_credential_decode(const network_credential_record_t *record, network_profile_t *profile);
|
||||
bool network_credential_load(const network_credential_backend_t *backend, network_profile_t *profile);
|
||||
bool network_credential_replace(const network_credential_backend_t *backend, const network_profile_t *profile);
|
||||
bool network_credential_delete(const network_credential_backend_t *backend);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef NETWORK_STATE_H
|
||||
#define NETWORK_STATE_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum { kNetworkSsidBytes = 32, kNetworkPasswordBytes = 63, kNetworkConnectWindowMs = 30000 };
|
||||
typedef struct { char ssid[kNetworkSsidBytes + 1]; char password[kNetworkPasswordBytes + 1]; } network_profile_t;
|
||||
typedef enum { NETWORK_STATE_FALLBACK, NETWORK_STATE_CONNECTING, NETWORK_STATE_EXTERNAL, NETWORK_STATE_VALIDATING } network_state_t;
|
||||
typedef enum { NETWORK_ACTION_NONE, NETWORK_ACTION_CONNECT, NETWORK_ACTION_FALLBACK } network_action_t;
|
||||
typedef struct { network_state_t state; network_state_t state_before_validation; network_profile_t profile; network_profile_t candidate; uint32_t started_ms; bool has_profile; } network_manager_t;
|
||||
|
||||
bool network_profile_valid(const network_profile_t *profile);
|
||||
network_action_t network_manager_init(network_manager_t *manager, const network_profile_t *profile, uint32_t now_ms);
|
||||
network_action_t network_manager_tick(network_manager_t *manager, uint32_t now_ms);
|
||||
network_action_t network_manager_connected(network_manager_t *manager);
|
||||
network_action_t network_manager_disconnected(network_manager_t *manager, uint32_t now_ms);
|
||||
bool network_manager_begin_validation(network_manager_t *manager, const network_profile_t *candidate);
|
||||
network_action_t network_manager_finish_validation(network_manager_t *manager, bool success, uint32_t now_ms);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user