summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Hatch <jhatch@multitech.com>2022-09-16 15:01:34 -0500
committerJeff Hatch <jhatch@multitech.com>2022-09-16 15:01:34 -0500
commitf32c2681ee4d1f8d07af881a3e68366e5fe646db (patch)
treeaf077b2a45ac02bfab46a3356fcb575f61c2d901
parent4bbd03047c616a4d2b838e57fb73c7413d2f461a (diff)
parentdc1ab19c393118ba60a30cb18fef43e34fad927c (diff)
downloadmts-id-eeprom-f32c2681ee4d1f8d07af881a3e68366e5fe646db.tar.gz
mts-id-eeprom-f32c2681ee4d1f8d07af881a3e68366e5fe646db.tar.bz2
mts-id-eeprom-f32c2681ee4d1f8d07af881a3e68366e5fe646db.zip
Merge branch 'dc_board' into 'master'
added daughter board EEPROM support See merge request !2
-rw-r--r--src/eeprom_main.c169
1 files changed, 163 insertions, 6 deletions
diff --git a/src/eeprom_main.c b/src/eeprom_main.c
index ed7d674..7b1c78c 100644
--- a/src/eeprom_main.c
+++ b/src/eeprom_main.c
@@ -33,6 +33,7 @@
#include <mts-kernel-headers/linux/mts_eeprom.h>
#ifdef MTCDT3B
#include <mts-kernel-headers/linux/mtcdt3b_eeprom.h>
+#include <mts-kernel-headers/linux/mtcdt3dc_eeprom.h>
#endif
#include "log.h"
@@ -47,6 +48,7 @@ static void mts_ap_eeprom_inspect(struct mts_ap_eeprom_layout *ap_eeprom);
#ifdef MTCDT3B
static void mtcdt3b_eeprom_inspect(struct mtcdt3b_eeprom_layout *mtcdt3b_eeprom);
+static void mtcdt3dc_eeprom_inspect(struct mtcdt3dc_eeprom_layout *mtcdt3dc_eeprom);
#endif
//Returns 0 on success, 1 on failure
@@ -337,6 +339,39 @@ static int mtcdt3b_yaml_out(const char *name, struct mtcdt3b_eeprom_layout *mtcd
return 0;
}
+
+static int mtcdt3dc_yaml_out(const char *name, struct mtcdt3dc_eeprom_layout *mtcdt3dc_eeprom)
+{
+ FILE *file;
+
+ if (!strcmp(name, "-")) {
+ file = stdout;
+ } else {
+ file = fopen(name, "w+");
+ if (!file) {
+ log_error("could not open %s: %m", name);
+ return -1;
+ }
+ }
+
+ fprintf(file, "---\n");
+ fprintf(file, "\n");
+ fprintf(file, "vendor-id: \"%.32s\"\n", mtcdt3dc_eeprom->vendor_id);
+ fprintf(file, "product-id: \"%.32s\"\n", mtcdt3dc_eeprom->product_id);
+ fprintf(file, "device-id: \"%.32s\"\n", mtcdt3dc_eeprom->device_id);
+ fprintf(file, "hw-version: \"%.32s\"\n", mtcdt3dc_eeprom->hw_version);
+ fprintf(file, "capa-mei-serial: %.32s\n", DEVICE_CAPA(mtcdt3dc_eeprom->capa, MTCDT3DC_CAPA_SERIAL) ? "true" : "false");
+ fprintf(file, "capa-mtac: %.32s\n", DEVICE_CAPA(mtcdt3dc_eeprom->capa, MTCDT3DC_CAPA_MTAC) ? "true" : "false");
+ fprintf(file, "mei-serial-count: %hu\n", mtcdt3dc_eeprom->serial_cnt);
+ fprintf(file, "mtac-count: %hu\n", mtcdt3dc_eeprom->mtac_cnt);
+
+ fprintf(file, "...\n");
+ fclose(file);
+
+ return 0;
+
+}
+
#endif
static int bin_out(const char *name, char *eeprom)
@@ -516,6 +551,18 @@ static void mtcdt3b_eeprom_inspect(struct mtcdt3b_eeprom_layout *mtcdt3b_eeprom)
mtcdt3b_eeprom->mac_eth_switch[4],
mtcdt3b_eeprom->mac_eth_switch[5]);
}
+
+static void mtcdt3dc_eeprom_inspect(struct mtcdt3dc_eeprom_layout *mtcdt3dc_eeprom)
+{
+ log_info("vendor-id: %.32s", mtcdt3dc_eeprom->vendor_id);
+ log_info("product-id: %.32s", mtcdt3dc_eeprom->product_id);
+ log_info("device-id: %.32s", mtcdt3dc_eeprom->device_id);
+ log_info("hw-version: %.32s", mtcdt3dc_eeprom->hw_version);
+ log_info("capa-mei-serial: %.32s", DEVICE_CAPA(mtcdt3dc_eeprom->capa, MTCDT3DC_CAPA_MTAC) ? "true" : "false");
+ log_info("capa-mtac: %.32s", DEVICE_CAPA(mtcdt3dc_eeprom->capa, MTCDT3DC_CAPA_SERIAL) ? "true" : "false");
+ log_info("mei-serial count: %hu", mtcdt3dc_eeprom->serial_cnt);
+ log_info("mtac count: %hu", mtcdt3dc_eeprom->mtac_cnt);
+}
#endif
static void print_version(const char *name) {
@@ -568,8 +615,13 @@ static void usage(FILE *out) {
fprintf(out, " --accessory-card\n");
#ifdef MTCDT3B
fprintf(out, " --base-board\n");
+ fprintf(out, " --daughter-board\n");
fprintf(out, " --slot i=0,device-id=<device-id>,lora-eui=<EUI-64>,i=1,...\n");
fprintf(out, " --capa-eth-switch \n");
+ fprintf(out, " --capa-mtac \n");
+ fprintf(out, " --capa-serial \n");
+ fprintf(out, " --mtac-count <mtac-count> \n");
+ fprintf(out, " --serial-count <serial-count> \n");
fprintf(out, " --eth-switch-version <switch-version> \n");
fprintf(out, " --eth-switch-mac-addr <switch-mac-addr> \n");
#endif
@@ -614,10 +666,15 @@ enum {
#endif
#ifdef MTCDT3B
CMD_OPT_BASE_BOARD,
+ CMD_OPT_DAUGHTER_BOARD,
CMD_OPT_SLOTS,
CMD_OPT_CAPA_ETH_SWITCH,
CMD_OPT_ETH_SWITCH_VERSION,
CMD_OPT_ETH_SWITCH_MAC_ADDR,
+ CMD_OPT_CAPA_MTAC,
+ CMD_OPT_CAPA_SERIAL,
+ CMD_OPT_NUM_MTAC,
+ CMD_OPT_NUM_SERIAL,
#endif
CMD_OPT_VERSION,
CMD_OPT_HELP,
@@ -663,8 +720,13 @@ static struct option long_options[] = {
{"accessory-card", 0, NULL, CMD_OPT_ACCESSORY_CARD},
#ifdef MTCDT3B
{"base-board", 0, NULL, CMD_OPT_BASE_BOARD},
+ {"daughter-board", 0, NULL, CMD_OPT_DAUGHTER_BOARD},
{"slots", 1, NULL, CMD_OPT_SLOTS},
{"capa-eth-switch", 0, NULL, CMD_OPT_CAPA_ETH_SWITCH},
+ {"capa-mtac", 0, NULL, CMD_OPT_CAPA_MTAC},
+ {"capa-serial", 0, NULL, CMD_OPT_CAPA_SERIAL},
+ {"mtac-count", 1, NULL, CMD_OPT_NUM_MTAC},
+ {"serial-count", 1, NULL, CMD_OPT_NUM_SERIAL},
{"eth-switch-version", 1, NULL, CMD_OPT_ETH_SWITCH_VERSION},
{"eth-switch-mac-addr", 1, NULL, CMD_OPT_ETH_SWITCH_MAC_ADDR},
#endif
@@ -699,6 +761,7 @@ int main(int argc, char *argv[]) {
int accessory_card = 0;
#ifdef MTCDT3B
int base_board = 0;
+ int daughter_board = 0;
char *slots = NULL;
#endif
char *vendor_id = NULL;
@@ -724,6 +787,14 @@ int main(int argc, char *argv[]) {
eeprom_size,sizeof mtcdt3b_eeprom);
exit(1);
}
+
+ struct mtcdt3dc_eeprom_layout mtcdt3dc_eeprom;
+ memset (&mtcdt3dc_eeprom, 0, eeprom_size);
+ if (sizeof mtcdt3dc_eeprom != eeprom_size) {
+ fprintf(stderr, "Internal error:\n mtcdt3dc_eeprom is not the correct size: expected %d, but %d is defined for the part\n",
+ eeprom_size,sizeof mtcdt3dc_eeprom);
+ exit(1);
+ }
#endif
memset(&id_eeprom, 0, eeprom_size);
@@ -747,6 +818,10 @@ int main(int argc, char *argv[]) {
case CMD_OPT_BASE_BOARD:
base_board = 1;
break;
+
+ case CMD_OPT_DAUGHTER_BOARD:
+ daughter_board = 1;
+ break;
#endif
case CMD_OPT_VERSION:
@@ -773,10 +848,13 @@ int main(int argc, char *argv[]) {
if (accessory_card) {
tmp = read(fd, (char *) &ap_eeprom, eeprom_size);
#ifdef MTCDT3B
- } else if (base_board) {
- tmp = read(fd, (char *) &mtcdt3b_eeprom, eeprom_size);
+ } else if (base_board) {
+ tmp = read(fd, (char *) &mtcdt3b_eeprom, eeprom_size);
+
+ } else if (daughter_board) {
+ tmp = read(fd, (char *) &mtcdt3dc_eeprom, eeprom_size);
#endif
- } else {
+ } else {
tmp = read(fd, (char *) &id_eeprom, eeprom_size);
}
@@ -792,11 +870,13 @@ int main(int argc, char *argv[]) {
log_info("loaded ap eeprom from %s successfully", in_file);
mts_ap_eeprom_inspect(&ap_eeprom);
#ifdef MTCDT3B
- } else if (base_board) {
+ } else if (base_board) {
log_info("loaded ap eeprom from %s successfully", in_file);
mtcdt3b_eeprom_inspect(&mtcdt3b_eeprom);
+ } else if (daughter_board) {
+ mtcdt3dc_eeprom_inspect(&mtcdt3dc_eeprom);
#endif
- } else {
+ } else {
log_info("loaded id eeprom from %s successfully", in_file);
mts_id_eeprom_inspect(&id_eeprom);
}
@@ -828,6 +908,11 @@ int main(int argc, char *argv[]) {
case CMD_OPT_BASE_BOARD:
// handled above
break;
+
+ case CMD_OPT_DAUGHTER_BOARD:
+ // handled above
+ break;
+
case CMD_OPT_SLOTS:
// concatenate slots arguments
if (base_board) {
@@ -977,7 +1062,19 @@ int main(int argc, char *argv[]) {
#endif
DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA);
break;
-
+#ifdef MTCDT3B
+ case CMD_OPT_CAPA_MTAC:
+ if (daughter_board) {
+ DEVICE_CAPA_SET(mtcdt3dc_eeprom.capa, MTCDT3DC_CAPA_MTAC);
+ }
+ break;
+
+ case CMD_OPT_CAPA_SERIAL:
+ if (daughter_board) {
+ DEVICE_CAPA_SET(mtcdt3dc_eeprom.capa, MTCDT3DC_CAPA_SERIAL);
+ }
+ break;
+#endif
case CMD_OPT_CAPA_LORA_LBT:
DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA_LBT);
break;
@@ -1059,6 +1156,39 @@ int main(int argc, char *argv[]) {
}
}
break;
+ case CMD_OPT_NUM_MTAC:
+ if (daughter_board) {
+ uint16_t u16_mtac_test;
+ if (sscanf(optarg, "%hu", &u16_mtac_test) != 1) {
+ log_error("invalid mtac count %s", optarg);
+ usage(stderr);
+ exit(1);
+ }
+ if (u16_mtac_test < MTAC_MIN || u16_mtac_test >MTAC_MAX) {
+ log_error("invalid mtac count %s", optarg);
+ usage(stderr);
+ exit(1);
+ }
+ mtcdt3dc_eeprom.mtac_cnt = u16_mtac_test;
+ }
+ break;
+
+ case CMD_OPT_NUM_SERIAL:
+ if (daughter_board) {
+ uint16_t u16_serial_test;
+ if (sscanf(optarg, "%hu", &u16_serial_test) !=1) {
+ log_error("invalid serial count %s", optarg);
+ usage(stderr);
+ exit(1);
+ }
+ if (u16_serial_test < SERIAL_MIN || u16_serial_test > SERIAL_MAX) {
+ log_error("invalid serial count %s", optarg);
+ usage(stderr);
+ exit(1);
+ }
+ mtcdt3dc_eeprom.serial_cnt = u16_serial_test;
+ }
+ break;
#endif
default:
usage(stderr);
@@ -1071,6 +1201,11 @@ int main(int argc, char *argv[]) {
memset(mtcdt3b_eeprom.capa, 0, sizeof(mtcdt3b_eeprom.capa));
capa_clear = 0;
}
+
+ if(daughter_board && capa_clear) {
+ memset(mtcdt3dc_eeprom.capa, 0, sizeof(mtcdt3dc_eeprom.capa));
+ capa_clear = 0;
+ }
#endif
if(capa_clear) {
@@ -1088,6 +1223,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,vendor_id)
+
+ else if (daughter_board)
+ EEPROM_SET(mtcdt3dc_eeprom,vendor_id)
#endif
else
EEPROM_SET(id_eeprom,vendor_id)
@@ -1098,6 +1236,10 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,product_id)
+
+ else if (daughter_board)
+ EEPROM_SET(mtcdt3dc_eeprom,product_id)
+
#endif
else
EEPROM_SET(id_eeprom,product_id)
@@ -1108,6 +1250,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,device_id)
+ else if (daughter_board)
+ EEPROM_SET(mtcdt3dc_eeprom,device_id)
+
#endif
else
EEPROM_SET(id_eeprom,device_id)
@@ -1118,6 +1263,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,hw_version)
+ else if (daughter_board)
+ EEPROM_SET(mtcdt3dc_eeprom,hw_version)
+
#endif
else
EEPROM_SET(id_eeprom,hw_version)
@@ -1306,6 +1454,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
bin_out(out_file, (char*) &mtcdt3b_eeprom);
+
+ else if (daughter_board)
+ bin_out(out_file, (char*) &mtcdt3dc_eeprom);
#endif
else {
id_eeprom.eeprom_layout_version = EEPROM_LAYOUT_VERSION;
@@ -1317,6 +1468,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
mtcdt3b_yaml_out(out_file, &mtcdt3b_eeprom);
+
+ else if (daughter_board)
+ mtcdt3dc_yaml_out(out_file, &mtcdt3dc_eeprom);
#endif
else
id_yaml_out(out_file, &id_eeprom);
@@ -1333,6 +1487,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
mtcdt3b_eeprom_inspect(&mtcdt3b_eeprom);
+
+ else if (daughter_board)
+ mtcdt3dc_eeprom_inspect(&mtcdt3dc_eeprom);
#endif
else
mts_id_eeprom_inspect(&id_eeprom);