CARRIER SIGNAL START

- start working on autocon via phonebook
- try to avoid autoconnecting to a guru meditation.
This commit is contained in:
2023-10-06 08:39:30 +00:00
parent bec470f6d7
commit fbeb54a830
13 changed files with 1361 additions and 8 deletions

44
include/Arena.h Normal file
View File

@@ -0,0 +1,44 @@
#ifndef KIMODEM_ARENA_H
#define KIMODEM_ARENA_H
#include <sys/stat.h>
#include <cstddef>
#include <cstdint>
typedef struct {
uint8_t *Store;
size_t Size;
int fd;
uint8_t Type;
} Arena;
/*
* InitializeArena is intended for use only with systems that
* do not initialize new variables to zero. It should be called
* exactly once, at the start of the program. Any other time the
* arena needs to be reset, it should be called with clear_arena
* or destroy_arena.
*/
void InitializeArena(Arena &arena);
int NewStaticArena(Arena &, uint8_t *, size_t);
int AllocNewArena(Arena &, size_t);
#if defined(__linux__)
int MMapArena(Arena &, int); /* arena will own fd */
int CreateArena(Arena &arena, const char *path, size_t size, mode_t mode);
int OpenArena(Arena &, const char *, size_t);
#endif
void ClearArena(Arena &);
int DestroyArena(Arena &); /* dispose of any memory used by arena */
/* DANGER: if arena is file backed (mmap or open), DO NOT WRITE TO THE
* BACKING FILE! */
int WriteArena(const Arena &arena, const char *path);
void DisplayArena(const Arena &arena);
#endif

44
include/Dictionary.h Normal file
View File

@@ -0,0 +1,44 @@
#ifndef KLIB_DICTIONARY_H
#define KLIB_DICTIONARY_H
#include "Arena.h"
#include "TLV.h"
#define DICTIONARY_TAG_KEY 1
#define DICTIONARY_TAG_VAL 2
/*
* A Dictionary is a collection of key-value pairs, similar to how
* a dictionary is a mapping of names to definitions.
*/
class Dictionary {
public:
Dictionary(Arena &arena) :
arena(arena),
kTag(DICTIONARY_TAG_KEY),
vTag(DICTIONARY_TAG_VAL) {} ;
Dictionary(Arena &arena, uint8_t kt, uint8_t vt) :
arena(arena),
kTag(kt),
vTag(vt) {};
bool Lookup(const char *key, uint8_t klen, TLV::Record &res);
int Set(const char *key, uint8_t klen, const char *val,
uint8_t vlen);
bool Has(const char *key, uint8_t klen);
void DumpKVPairs();
void DumpToFile(const char *path);
private:
uint8_t *seek(const char *key, uint8_t klen);
bool spaceAvailable(uint8_t klen, uint8_t vlen);
Arena &arena;
uint8_t kTag;
uint8_t vTag;
};
#endif

48
include/TLV.h Normal file
View File

@@ -0,0 +1,48 @@
#ifndef KIMODEM_TLV_H
#define KIMODEM_TLV_H
#include <cstdint>
#include "Arena.h"
#ifndef TLV_MAX_LEN
#define TLV_MAX_LEN 253
#endif
#define TAG_EMPTY 0
namespace TLV {
struct Record {
uint8_t Tag;
uint8_t Len;
char Val[TLV_MAX_LEN];
};
uint8_t *WriteToMemory(Arena &, uint8_t *, Record &);
void ReadFromMemory(Record &, uint8_t *);
void SetRecord(Record &, uint8_t, uint8_t, const char *);
void DeleteRecord(Arena &, uint8_t *);
/*
* returns a pointer to memory where the record was found,
* e.g. LocateTag(...)[0] is the tag of the found record.
* FindTag will call LocateTag and then SkipRecord if the
* tag was found.
*/
uint8_t *FindTag(Arena &, uint8_t *, Record &);
uint8_t *LocateTag(Arena &, uint8_t *, Record &);
uint8_t *FindEmpty(Arena &, uint8_t *);
uint8_t *SkipRecord(Record &, uint8_t *);
} // namespace TLV
#endif

15
include/WiFiMgr.h Normal file
View File

@@ -0,0 +1,15 @@
#ifndef KIMODEM_WIFI_H
#define KIMODEM_WIFI_H
#include "Dictionary.h"
#include "WiFiMgr.h"
bool SetupWiFi();
bool Autoconnect(Dictionary &pb);
bool Autoconnect(Dictionary &pb, bool reset);
#endif