summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/eeprom_main.c163
1 files changed, 160 insertions, 3 deletions
diff --git a/src/eeprom_main.c b/src/eeprom_main.c
index ed7d674..04887c8 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, "hardware-id: \"%.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("hw-version: %.32s", mtcdt3dc_eeprom->hw_version);
+ log_info("device-id: %.32s", mtcdt3dc_eeprom->device_id);
+ 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, " --sub-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_DC_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},
+ {"sub-board", 0, NULL, CMD_OPT_DC_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 dc_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_DC_BOARD:
+ dc_board = 1;
+ break;
#endif
case CMD_OPT_VERSION:
@@ -775,6 +850,9 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
} else if (base_board) {
tmp = read(fd, (char *) &mtcdt3b_eeprom, eeprom_size);
+
+ } else if (dc_board) {
+ tmp = read(fd, (char *) &mtcdt3dc_eeprom, eeprom_size);
#endif
} 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 (dc_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_DC_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 (dc_board) {
+ DEVICE_CAPA_SET(mtcdt3dc_eeprom.capa, MTCDT3DC_CAPA_MTAC);
+ }
+ break;
+
+ case CMD_OPT_CAPA_SERIAL:
+ if (dc_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 (dc_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 (dc_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(dc_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 (dc_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 (dc_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 (dc_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 (dc_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 (dc_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 (dc_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 (dc_board)
+ mtcdt3dc_eeprom_inspect(&mtcdt3dc_eeprom);
#endif
else
mts_id_eeprom_inspect(&id_eeprom);