diff --git a/Framing.h b/Framing.h index 634fd22f..73a8a643 100644 --- a/Framing.h +++ b/Framing.h @@ -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 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index f0e4032c..09e201bc 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -103,6 +103,7 @@ public: _IN = true; _OUT = true; _HW_MTU = 508; + _DEFAULT_IFAC_SIZE = 8; } LoRaInterface() : LoRaInterface("LoRaInterface") {} virtual ~LoRaInterface() { @@ -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 @@ -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) { diff --git a/ROM.h b/ROM.h index c8834348..35babfcf 100644 --- a/ROM.h +++ b/ROM.h @@ -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 diff --git a/Utilities.h b/Utilities.h index d37245f7..22b3d258 100644 --- a/Utilities.h +++ b/Utilities.h @@ -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); diff --git a/platformio.ini b/platformio.ini index 3c5c94ea..ae3b0f99 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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