209 lines
6.7 KiB
C
209 lines
6.7 KiB
C
#include <tap.h>
|
|
#include "../src/librnode.h"
|
|
#include "../src/libs/logging/log.h"
|
|
#include "../src/libs/util.h"
|
|
#include <time.h>
|
|
#include <openssl/evp.h>
|
|
#include <openssl/decoder.h>
|
|
#include <openssl/rsa.h>
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h> // todo remove me
|
|
#include <openssl/sha.h> // todo remove me
|
|
|
|
//char* port = "/dev/serial/by-id/usb-Silicon_Labs_CP2102_USB_to_UART_Bridge_Controller_0001-if00-port0";
|
|
char* port = "/dev/ttyACM0";
|
|
//char* port = "/dev/serial/by-id/usb-Heltec_HT-n5262_1E35113239EFFE55-if00";
|
|
char* zip = "/home/elimin8/Downloads/rnode_firmware_t3s3_sx1280_pa.zip";
|
|
char* key = "/home/elimin8/.config/rnodeconf/firmware/signing.key";
|
|
uint32_t baud = 115200;
|
|
struct RNode rn = {0};
|
|
|
|
EVP_PKEY* load_key(struct RNode* rn, char* path) {
|
|
EVP_PKEY *priv_key = EVP_PKEY_new();
|
|
OSSL_DECODER_CTX *dctx;
|
|
const char *format = "DER"; /* NULL for any format */
|
|
const char *structure = NULL; /* any structure */
|
|
const char *keytype = "RSA"; /* NULL for any key */
|
|
size_t len;
|
|
uint8_t key_buf[1024];
|
|
const uint8_t *data = key_buf;
|
|
|
|
FILE *file = fopen(path, "rb");
|
|
if (file <= 0) {
|
|
return NULL;
|
|
}
|
|
fseek(file, 0L, SEEK_END);
|
|
len = ftell(file);
|
|
|
|
fseek(file, 0L, SEEK_SET);
|
|
|
|
fread(key_buf, sizeof(uint8_t), len, file);
|
|
|
|
fclose(file);
|
|
|
|
dctx = OSSL_DECODER_CTX_new_for_pkey(&priv_key, format, structure,
|
|
keytype,
|
|
OSSL_KEYMGMT_SELECT_KEYPAIR,
|
|
NULL, NULL);
|
|
if (dctx == NULL) {
|
|
/* error: no suitable potential decoders found */
|
|
return NULL;
|
|
}
|
|
//if (pass != NULL)
|
|
// OSSL_DECODER_CTX_set_passphrase(dctx, pass, strlen(pass));
|
|
|
|
if (!OSSL_DECODER_from_data(dctx, &data, &len)) {
|
|
/* decoding failure */
|
|
return NULL;
|
|
}
|
|
OSSL_DECODER_CTX_free(dctx);
|
|
|
|
return priv_key;
|
|
}
|
|
|
|
void esp32_flash(struct RNode* rn, char* zip) {
|
|
uint8_t serial[4] = {0};
|
|
|
|
ok(rnode_set_platform(rn, PLATFORM_ESP32) == 0, "RNode set platform");
|
|
|
|
time_t start = time(NULL);
|
|
EVP_PKEY *priv_key = load_key(rn, key);
|
|
ok(priv_key != NULL, "Load EEPROM signing key");
|
|
rn->product = 0xf0;
|
|
rn->model = 0xac;
|
|
rn->hw_rev = 0x01;
|
|
rn->boot_app0_addr = 0xe000;
|
|
rn->bootloader_addr = 0x0;
|
|
rn->bin_addr = 0x10000;
|
|
rn->partitions_addr = 0x8000;
|
|
rn->console_image_addr = 0x210000;
|
|
ok(rnode_flash(rn, zip, false, serial, priv_key, true) == 0, "RNode update");
|
|
time_t end = time(NULL);
|
|
printf("Time taken for flash: %ld seconds.\n", end - start);
|
|
}
|
|
|
|
void nrf52_flash(struct RNode* rn, char* zip) {
|
|
uint8_t serial[4] = {0};
|
|
|
|
ok(rnode_set_platform(rn, PLATFORM_NRF52) == 0, "RNode set platform");
|
|
|
|
time_t start = time(NULL);
|
|
EVP_PKEY *priv_key = load_key(rn, key);
|
|
ok(priv_key != NULL, "Load EEPROM signing key");
|
|
rn->product = 0x10;
|
|
rn->model = 0x12;
|
|
rn->hw_rev = 0x01;
|
|
ok(rnode_flash(rn, zip, false, serial, priv_key, true) == 0, "RNode update");
|
|
time_t end = time(NULL);
|
|
printf("Time taken for flash: %ld seconds.\n", end - start);
|
|
}
|
|
|
|
int main() {
|
|
//printf("--- RNode reset test ---\n\n");
|
|
|
|
ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
|
|
//ok(rnode_reset(&rn) == 0, "RNode reset");
|
|
//sleep_ms(5000);
|
|
|
|
//ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
|
|
//ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
|
|
//printf("--- RNode display test --- \n\n");
|
|
//ok(rnode_set_disp_int(&rn, 255) == 0, "Set display intensity to 255");
|
|
//sleep_ms(500);
|
|
//ok(rnode_set_disp_int(&rn, 0) == 0, "Set display intensity to 0");
|
|
//sleep_ms(500);
|
|
//ok(rnode_set_disp_int(&rn, 127) == 0, "Set display intensity to 127");
|
|
//sleep_ms(100);
|
|
|
|
//ok(rnode_set_disp_timeout(&rn, 1) == 0, "Set display timeout to 1 second");
|
|
//sleep_ms(5000);
|
|
//ok(rnode_set_disp_timeout(&rn, 1) == 0, "Disable display timeout");
|
|
//sleep_ms(500);
|
|
|
|
//ok(rnode_set_disp_addr(&rn, 0x3B) == 0, "Set display address to 0x3B");
|
|
//sleep_ms(500);
|
|
//ok(rnode_set_disp_addr(&rn, 0x3C) == 0, "Set display address to 0x3C");
|
|
//sleep_ms(500);
|
|
|
|
//ok(rnode_set_disp_rot(&rn, 0) == 0, "Set display rotation to 0");
|
|
//sleep_ms(2000);
|
|
//ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
//ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
//ok(rnode_set_disp_rot(&rn, 1) == 0, "Set display rotation to 1");
|
|
//sleep_ms(2000);
|
|
//ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
//ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
//ok(rnode_set_disp_rot(&rn, 2) == 0, "Set display rotation to 2");
|
|
//sleep_ms(2000);
|
|
//ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
//ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
//ok(rnode_set_disp_rot(&rn, 3) == 0, "Set display rotation to 3");
|
|
//sleep_ms(2000);
|
|
//ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
//ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
|
|
//ok(rnode_start_disp_recon(&rn) == 0, "Start display reconditioning (5s)");
|
|
//sleep_ms(5000);
|
|
|
|
//ok(rnode_reset(&rn) == 0, "RNode reset");
|
|
//sleep_ms(5000);
|
|
|
|
//ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
//ok(rnode_init(&rn, port, baud, true, false) == 0, "RNode initialisation & detection");
|
|
|
|
//printf("--- RNode NP test (if present) --- \n\n");
|
|
|
|
//ok(rnode_set_np_int(&rn, 0) == 0, "Set NP intensity to 0");
|
|
//sleep_ms(500);
|
|
|
|
//ok(rnode_set_np_int(&rn, 255) == 0, "Set NP intensity to 255");
|
|
//sleep_ms(500);
|
|
//
|
|
//printf("--- RNode BT test --- \n\n");
|
|
|
|
//ok(rnode_set_bt(&rn, BT_OFF) == 0, "Disable Bluetooth");
|
|
//sleep_ms(1000);
|
|
|
|
//ok(rnode_set_bt(&rn, BT_ON) == 0, "Enable Bluetooth");
|
|
//sleep_ms(1000);
|
|
|
|
//ok(rnode_set_bt(&rn, BT_PAIRING) == 0, "Enable Bluetooth pairing");
|
|
//sleep_ms(1000);
|
|
|
|
//int pin = rnode_get_bt_pin(&rn, 30000);
|
|
|
|
//ok(pin > 0, "Get Bluetooth code (30s timeout)");
|
|
|
|
//printf("Pin: %u\n", pin);
|
|
|
|
//ok(rnode_wipe_eeprom(&rn) == 0, "Wipe RNode EEPROM");
|
|
|
|
//esp32_flash(&rn, zip);
|
|
//printf("--- RNode flash & provision test ---\n\n");
|
|
|
|
|
|
printf("--- RNode TNC mode test ---\n\n");
|
|
|
|
ok(rnode_get_interfaces(&rn) == 0, "Get interfaces");
|
|
|
|
ok(rnode_select_interface(&rn, 0) == 0, "Select interface 0");
|
|
|
|
ok(rnode_set_freq(&rn, 865700000) > 0, "Set frequency");
|
|
|
|
ok(rnode_set_sf(&rn, 7) == 0, "Set spreading factor");
|
|
|
|
ok(rnode_set_cr(&rn, 7) == 0, "Set coding rate");
|
|
|
|
ok(rnode_set_txp(&rn, 7) == 0, "Set TX power");
|
|
|
|
ok(rnode_set_tnc_mode(&rn) == 0, "Enable TNC mode");
|
|
|
|
ok(rnode_cleanup(&rn) == 0, "RNode cleanup");
|
|
|
|
done_testing();
|
|
}
|