Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Framing.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
#define CMD_WIFI_IP 0x84
#define CMD_WIFI_NM 0x85

#define CMD_IFAC_NETNAME 0x86
#define CMD_IFAC_NETKEY 0x87
#define CMD_IFAC_SIZE 0x88

#define CMD_BOARD 0x47
#define CMD_PLATFORM 0x48
#define CMD_MCU 0x49
Expand Down
82 changes: 74 additions & 8 deletions RNode_Firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public:
_IN = true;
_OUT = true;
_HW_MTU = 508;
_DEFAULT_IFAC_SIZE = 8;
}
LoRaInterface() : LoRaInterface("LoRaInterface") {}
virtual ~LoRaInterface() {
Expand Down Expand Up @@ -634,24 +635,39 @@ void setup() {
RNS::loglevel(RNS::LOG_TRACE);
#endif

HEAD("Creating Reticulum instance...", RNS::LOG_TRACE);
reticulum = RNS::Reticulum();
reticulum.transport_enabled(op_mode == MODE_TNC);
reticulum.probe_destination_enabled(true);

char ifac_netname[33] = {0};
char ifac_netkey[33] = {0};
uint8_t ifac_size = 0;

#ifdef RNS_USE_IFAC
for (uint8_t i = 0; i < 32; i++) {
ifac_netname[i] = EEPROM.read(config_addr(ADDR_CONF_IFAC_NETNAME+i));
if (ifac_netname[i] == 0xFF) ifac_netname[i] = 0x00;
}
for (uint8_t i = 0; i < 32; i++) {
ifac_netkey[i] = EEPROM.read(config_addr(ADDR_CONF_IFAC_NETKEY+i));
if (ifac_netkey[i] == 0xFF) ifac_netkey[i] = 0x00;
}
ifac_size = EEPROM.read(config_addr(ADDR_CONF_IFAC_SIZE));
#endif

HEAD("Registering LoRA Interface...", RNS::LOG_TRACE);
lora_interface = new LoRaInterface();
lora_interface.mode(RNS::Type::Interface::MODE_GATEWAY);
RNS::Transport::register_interface(lora_interface);
reticulum._add_interface(lora_interface, RNS::Type::Interface::MODE_GATEWAY, ifac_size, std::string(ifac_netname), std::string(ifac_netkey));
TRACEF("LoRaInterface hash: %s", lora_interface.get_hash().toHex().c_str());

#if HAS_WIFI && defined(UDP_TRANSPORT)
HEAD("Registering UDP Interface...", RNS::LOG_TRACE);
udp_interface = new UDPInterface();
udp_interface.mode(RNS::Type::Interface::MODE_GATEWAY);
RNS::Transport::register_interface(udp_interface);
reticulum._add_interface(udp_interface, RNS::Type::Interface::MODE_GATEWAY, ifac_size, std::string(ifac_netname), std::string(ifac_netkey));
TRACEF("UDPInterface hash: %s", udp_interface.get_hash().toHex().c_str());
#endif

HEAD("Creating Reticulum instance...", RNS::LOG_TRACE);
reticulum = RNS::Reticulum();
reticulum.transport_enabled(op_mode == MODE_TNC);
reticulum.probe_destination_enabled(true);
reticulum.start();

// Set loop callback only after the Reticulum instance is started
Expand Down Expand Up @@ -1644,6 +1660,56 @@ void serial_callback(uint8_t sbyte) {

if (frame_len == 4) { for (uint8_t i = 0; i<4; i++) { eeprom_update(config_addr(ADDR_CONF_NM+i), cmdbuf[i]); } }
#endif
} else if (command == CMD_IFAC_NETNAME) {
#if defined(RNS_USE_IFAC) && defined(CONFIG_OFFSET)
if (sbyte == FESC) { ESCAPE = true; }
else {
if (ESCAPE) {
if (sbyte == TFEND) sbyte = FEND;
if (sbyte == TFESC) sbyte = FESC;
ESCAPE = false;
}
if (frame_len < CMD_L) cmdbuf[frame_len++] = sbyte;
}

if (frame_len == 1 && cmdbuf[0] == 0xFF) {
kiss_indicate_ifac_netname();
} else if (sbyte == 0x00) {
for (uint8_t i = 0; i < 33; i++) {
if (i < frame_len && i < 32) { eeprom_update(config_addr(ADDR_CONF_IFAC_NETNAME+i), cmdbuf[i]); }
else { eeprom_update(config_addr(ADDR_CONF_IFAC_NETNAME+i), 0x00); }
}
}
#endif
} else if (command == CMD_IFAC_NETKEY) {
#if defined(RNS_USE_IFAC) && defined(CONFIG_OFFSET)
if (sbyte == FESC) { ESCAPE = true; }
else {
if (ESCAPE) {
if (sbyte == TFEND) sbyte = FEND;
if (sbyte == TFESC) sbyte = FESC;
ESCAPE = false;
}
if (frame_len < CMD_L) cmdbuf[frame_len++] = sbyte;
}

if (frame_len == 1 && cmdbuf[0] == 0xFF) {
kiss_indicate_ifac_netkey();
} else if (sbyte == 0x00) {
for (uint8_t i = 0; i < 33; i++) {
if (i < frame_len && i < 32) { eeprom_update(config_addr(ADDR_CONF_IFAC_NETKEY+i), cmdbuf[i]); }
else { eeprom_update(config_addr(ADDR_CONF_IFAC_NETKEY+i), 0x00); }
}
}
#endif
} else if (command == CMD_IFAC_SIZE) {
#if defined(RNS_USE_IFAC) && defined(CONFIG_OFFSET)
if (sbyte == 0xFF) {
kiss_indicate_ifac_size();
} else {
eeprom_update(config_addr(ADDR_CONF_IFAC_SIZE), sbyte);
}
#endif
} else if (command == CMD_BT_CTRL) {
#if HAS_BLUETOOTH || HAS_BLE
if (sbyte == 0x00) {
Expand Down
6 changes: 6 additions & 0 deletions ROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@
#define EEPROM_RESERVED 200

#define CONFIG_SIZE 256

#define ADDR_CONF_SSID 0x00
#define ADDR_CONF_PSK 0x21
#define ADDR_CONF_IP 0x42
#define ADDR_CONF_NM 0x46

#define ADDR_CONF_IFAC_NETNAME 0x4A
#define ADDR_CONF_IFAC_NETKEY 0x6B
#define ADDR_CONF_IFAC_SIZE 0x8C

//////////////////////////////////

#endif
33 changes: 33 additions & 0 deletions Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,39 @@ void kiss_indicate_btpin() {
#endif
}

#if defined(RNS_USE_IFAC) && defined(CONFIG_OFFSET)
void kiss_indicate_ifac_netname() {
serial_write(FEND);
serial_write(CMD_IFAC_NETNAME);
for (uint8_t i = 0; i < 32; i++) {
uint8_t byte = EEPROM.read(config_addr(ADDR_CONF_IFAC_NETNAME+i));
if (byte == 0xFF) byte = 0x00;
escaped_serial_write(byte);
}
serial_write(FEND);
}

void kiss_indicate_ifac_netkey() {
serial_write(FEND);
serial_write(CMD_IFAC_NETKEY);
for (uint8_t i = 0; i < 32; i++) {
uint8_t byte = EEPROM.read(config_addr(ADDR_CONF_IFAC_NETKEY+i));
if (byte == 0xFF) byte = 0x00;
escaped_serial_write(byte);
}
serial_write(FEND);
}

void kiss_indicate_ifac_size() {
serial_write(FEND);
serial_write(CMD_IFAC_SIZE);
uint8_t ifac_size = EEPROM.read(config_addr(ADDR_CONF_IFAC_SIZE));
if (ifac_size == 0x00 || ifac_size == 0xFF) ifac_size = 16;
escaped_serial_write(ifac_size);
serial_write(FEND);
}
#endif

void kiss_indicate_random(uint8_t byte) {
serial_write(FEND);
serial_write(CMD_RANDOM);
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build_flags =
; CBA Define following to include RNS stack
-DHAS_RNS
-DRNS_USE_FS
;-DRNS_USE_IFAC
-DRNS_PERSIST_PATHS
-DMSGPACK_USE_BOOST=OFF
; CBA Define following to disable LFS asserts
Expand Down