summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Murphy <patrick.muprphy@multitech.com>2021-03-24 06:58:47 -0500
committerPatrick Murphy <patrick.muprphy@multitech.com>2021-03-24 06:58:47 -0500
commitadf9a7bb274f4f573ea2a196bc2d360505c0e255 (patch)
tree9c143533069b3f896c62d1a16efaf411492fbe44 /src
parentdec4431752a10e0359ef83514658ba8c5340eb79 (diff)
downloadmts-id-eeprom-adf9a7bb274f4f573ea2a196bc2d360505c0e255.tar.gz
mts-id-eeprom-adf9a7bb274f4f573ea2a196bc2d360505c0e255.tar.bz2
mts-id-eeprom-adf9a7bb274f4f573ea2a196bc2d360505c0e255.zip
added dc_board EEPROM support
Diffstat (limited to 'src')
-rw-r--r--src/eeprom_main.c161
1 files changed, 158 insertions, 3 deletions
diff --git a/src/eeprom_main.c b/src/eeprom_main.c
index d8a81e8..81caa84 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"
@@ -44,9 +45,9 @@ static int eeprom_size = 512;
static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom);
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
@@ -331,6 +332,37 @@ 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, "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)
@@ -504,6 +536,16 @@ 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("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) {
@@ -550,8 +592,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
@@ -590,10 +637,15 @@ enum {
CMD_OPT_ACCESSORY_CARD,
#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,
@@ -633,8 +685,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
@@ -669,6 +726,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;
@@ -690,6 +748,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: expecdted %d, but %d is defined for the part\n",
+ eeprom_size,sizeof mtcdt3dc_eeprom);
+ exit(1);
+ }
#endif
memset(&id_eeprom, 0, eeprom_size);
@@ -713,6 +779,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:
@@ -741,8 +811,11 @@ 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 {
+ } else {
tmp = read(fd, (char *) &id_eeprom, eeprom_size);
}
@@ -761,6 +834,8 @@ int main(int argc, char *argv[]) {
} 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 {
log_info("loaded id eeprom from %s successfully", in_file);
@@ -794,6 +869,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) {
@@ -933,6 +1013,18 @@ 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_BATTERY:
DEVICE_CAPA_SET(id_eeprom.capa, CAPA_BATTERY);
break;
@@ -994,8 +1086,9 @@ int main(int argc, char *argv[]) {
exit(1);
}
mtcdt3b_eeprom.hw_version_eth_switch = u16;
+ break;
}
- break;
+
case CMD_OPT_ETH_SWITCH_MAC_ADDR:
if (base_board) {
tmp = hwaddr_aton(optarg, mtcdt3b_eeprom.mac_eth_switch, sizeof(mtcdt3b_eeprom.mac_eth_switch));
@@ -1004,6 +1097,40 @@ int main(int argc, char *argv[]) {
usage(stderr);
exit(1);
}
+ 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
@@ -1018,6 +1145,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) {
@@ -1035,6 +1167,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)
@@ -1045,6 +1180,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)
@@ -1055,6 +1194,7 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,device_id)
+
#endif
else
EEPROM_SET(id_eeprom,device_id)
@@ -1065,6 +1205,7 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,hw_version)
+
#endif
else
EEPROM_SET(id_eeprom,hw_version)
@@ -1076,6 +1217,7 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if(base_board)
tmp = hwaddr_aton(mac_addr, mtcdt3b_eeprom.mac_addr, sizeof(mtcdt3b_eeprom.mac_addr));
+
#endif
else
tmp = hwaddr_aton(mac_addr, id_eeprom.mac_addr, sizeof(id_eeprom.mac_addr));
@@ -1096,6 +1238,7 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,lora_product_id)
+
#endif
else
EEPROM_SET(id_eeprom,lora_product_id)
@@ -1111,6 +1254,7 @@ int main(int argc, char *argv[]) {
#ifdef MTCDT3B
else if (base_board)
EEPROM_SET(mtcdt3b_eeprom,lora_hw_version)
+
#endif
else
EEPROM_SET(id_eeprom,lora_hw_version)
@@ -1124,6 +1268,7 @@ int main(int argc, char *argv[]) {
usage(stderr);
exit(1);
}
+
#endif
else
tmp = hwaddr_aton(lora_eui, id_eeprom.lora_eui, sizeof(id_eeprom.lora_eui));
@@ -1233,6 +1378,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;
@@ -1244,6 +1392,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);
@@ -1260,6 +1411,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);
@@ -1269,3 +1423,4 @@ int main(int argc, char *argv[]) {
return 0;
}
+