From 31e7d30482ee2e6708c479183b57ce4c2e056d74 Mon Sep 17 00:00:00 2001 From: Andrii Pientsov Date: Sun, 24 Jan 2021 16:36:22 +0200 Subject: MTRE: Add oem strings --- src/eeprom_main.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/eeprom_main.c b/src/eeprom_main.c index d8a81e8..26cfe70 100644 --- a/src/eeprom_main.c +++ b/src/eeprom_main.c @@ -211,6 +211,10 @@ static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) fprintf(file, "lora-product-id: \"%.32s\"\n", id_eeprom->lora_product_id); fprintf(file, "lora-hw-version: \"%.32s\"\n", id_eeprom->lora_hw_version); +#ifdef MTRE + fprintf(file, "oem-string1: %.32s\n", id_eeprom->oem_string1); + fprintf(file, "oem-string2: %.32s\n", id_eeprom->oem_string2); +#endif fprintf(file, "...\n"); @@ -425,6 +429,10 @@ static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom) log_info("lora-product-id: %.32s", id_eeprom->lora_product_id); log_info("lora-hw-version: %.32s", id_eeprom->lora_hw_version); +#ifdef MTRE + log_info("oem-string1: %.32s", id_eeprom->oem_string1); + log_info("oem-string2: %.32s", id_eeprom->oem_string2); +#endif } static void mts_ap_eeprom_inspect(struct mts_ap_eeprom_layout *ap_eeprom) @@ -532,6 +540,10 @@ static void usage(FILE *out) { fprintf(out, " --lora-eui |\n"); fprintf(out, " --lora-hw-version |\n"); fprintf(out, " --lora-product-id |\n"); +#ifdef MTRE + fprintf(out, " --oem-string1 |\n"); + fprintf(out, " --oem-string2 |\n"); +#endif fprintf(out, " --imei |\n"); fprintf(out, " --capa-gps |\n"); fprintf(out, " --capa-din |\n"); @@ -588,6 +600,10 @@ enum { CMD_OPT_OUT_FORMAT, CMD_OPT_UPDATE, CMD_OPT_ACCESSORY_CARD, +#ifdef MTRE + CMD_OPT_OEM_STRING1, + CMD_OPT_OEM_STRING2, +#endif #ifdef MTCDT3B CMD_OPT_BASE_BOARD, CMD_OPT_SLOTS, @@ -611,6 +627,10 @@ static struct option long_options[] = { {"hw-version", 1, NULL, CMD_OPT_HW_VERSION}, {"lora-product-id", 1, NULL, CMD_OPT_LORA_PRODUCT_ID}, {"lora-hw-version", 1, NULL, CMD_OPT_LORA_HW_VERSION}, +#ifdef MTRE + {"oem-string1", 1, NULL, CMD_OPT_OEM_STRING1}, + {"oem-string2", 1, NULL, CMD_OPT_OEM_STRING2}, +#endif {"mac-addr", 1, NULL, CMD_OPT_MAC_ADDR}, {"mac-bluetooth", 1, NULL, CMD_OPT_MAC_BLUETOOTH}, {"mac-wifi", 1, NULL, CMD_OPT_MAC_WIFI}, @@ -679,6 +699,10 @@ int main(int argc, char *argv[]) { char *lora_eui = NULL; char *lora_product_id = NULL; char *lora_hw_version = NULL; +#ifdef MTRE + char *oem_string1 = NULL; + char *oem_string2 = NULL; +#endif struct mts_id_eeprom_layout id_eeprom; struct mts_ap_eeprom_layout ap_eeprom; @@ -837,6 +861,16 @@ int main(int argc, char *argv[]) { lora_product_id = optarg; break; +#ifdef MTRE + case CMD_OPT_OEM_STRING1: + oem_string1 = optarg; + break; + + case CMD_OPT_OEM_STRING2: + oem_string2 = optarg; + break; +#endif + case CMD_OPT_DEVICE_ID: device_id = optarg; break; @@ -1115,6 +1149,26 @@ int main(int argc, char *argv[]) { else EEPROM_SET(id_eeprom,lora_hw_version) } +#ifdef MTRE + if (oem_string1) { + if (! accessory_card) { + strncpy(id_eeprom.oem_string1, oem_string1, sizeof(id_eeprom.oem_string1) - 1); + } else { + log_error("--oem-string1 option is not supported on accessory card eeprom"); + usage(stderr); + exit(1); + } + } + if (oem_string2) { + if (! accessory_card) { + strncpy(id_eeprom.oem_string2, oem_string2, sizeof(id_eeprom.oem_string2) - 1); + } else { + log_error("--oem-string2 option is not supported on accessory card eeprom"); + usage(stderr); + exit(1); + } + } +#endif if (lora_eui) { if (accessory_card) tmp = hwaddr_aton(lora_eui, ap_eeprom.eui, sizeof(ap_eeprom.eui)); -- cgit v1.2.3 From 664cabb5ef828734b730c83e2f779532cc55cc27 Mon Sep 17 00:00:00 2001 From: John Klug Date: Mon, 20 Dec 2021 11:15:37 -0600 Subject: Add mts-wait-for-cell-reset to detect cellular reset completion detection --- configure.in | 2 +- src/Makefile.am | 3 +- src/mts_wait_for_cell_reset.c | 108 ++++++++++++++++++++++++++++++++++++++++++ src/x | 108 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 src/mts_wait_for_cell_reset.c create mode 100644 src/x diff --git a/configure.in b/configure.in index df4c0b1..6aca9d6 100644 --- a/configure.in +++ b/configure.in @@ -1,5 +1,5 @@ AC_INIT([src/eeprom_main.c]) -AM_INIT_AUTOMAKE([mts-id-eeprom], [0.6.0]) +AM_INIT_AUTOMAKE([mts-id-eeprom], [0.6.3]) AM_CONFIG_HEADER([config.h]) AC_PROG_CC diff --git a/src/Makefile.am b/src/Makefile.am index 99145a4..7dadb83 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,10 +2,11 @@ AUTOMAKE_OPTIONS = gnu AM_CFLAGS = -Wall -bin_PROGRAMS = mts-id-eeprom +bin_PROGRAMS = mts-id-eeprom mts-wait-for-cell-reset sbin_PROGRAMS = mts-hashpwd mts-fpga-loader mts_hashpwd_SOURCES = hashpwd.cpp mts_id_eeprom_SOURCES = eeprom_main.c +mts_wait_for_cell_reset_SOURCES = mts_wait_for_cell_reset.c noinst_HEADERS = eeprom.h log.h mts_error_codes.h mts_fpga_hash.h mts_fpga_reg.h mts_fpga_spi.h mts_hashpwd_LDADD = -lcrypto diff --git a/src/mts_wait_for_cell_reset.c b/src/mts_wait_for_cell_reset.c new file mode 100644 index 0000000..9f7de31 --- /dev/null +++ b/src/mts_wait_for_cell_reset.c @@ -0,0 +1,108 @@ +/* + * mts-wait-for-cell-reset + * + * Block signal + * If not in reset, exit + * Register with mts-io for reset + * If not in reset, exit + * Suspend process for signal + * If signal occurs, exit + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *name = "mts-wait-for-cell-reset"; +const int RST_SIG=SIGUSR2; // Wait for this signal +const char *MONITOR="/sys/devices/platform/mts-io/radio-reset-monitor"; +const char *RADIO_DISCOVERY="/sys/devices/platform/mts-io/radio-udev-discovery"; + +/* Return 0 if Cellular modem is being reset + * Return 1 if Cellular modem is not being reset + */ +int +not_reset(const char *attr_name) +{ + int not_in_reset, result; + char buf[256]; + int discovery; + + discovery = open(attr_name,O_RDONLY); + if (discovery == -1) { + fprintf(stderr,"FAILED: %s cannot open attribute %s: %s\n",name,attr_name,strerror(errno)); + exit(1); + } + result = read(discovery,buf,sizeof buf); + if (result > 0) + not_in_reset = atoi(buf); + else if (result == 0) { + fprintf(stderr,"FAILED: %s attribute %s has no state\n",name,attr_name); + exit(1); + } else { + fprintf(stderr,"FAILED: %s attribute %s error: %s\n",name,attr_name,strerror(errno)); + exit(1); + } + close(discovery); + return not_in_reset; +} + +void +handler(int sig) +{ + /* Normal way out of this program + * exit not safe from signal handler so + * use _exit() + */ + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + sigset_t blockedset,nullset; + int monitor; + int result; + char buf[128]; + struct sigaction action; + + memset(&action,0,sizeof action); + action.sa_handler = handler; + memset(&blockedset,0,sizeof blockedset); + sigaddset(&blockedset,RST_SIG); + memset(&nullset,0,sizeof nullset); + + sigprocmask(SIG_BLOCK,&blockedset,NULL); // Blocked RST_SIG + + sigaction(RST_SIG,&action,NULL); + + if (not_reset(RADIO_DISCOVERY)) + exit(0); // Not in reset + sprintf(buf,"%d %d",getpid(),RST_SIG); + + monitor = open(MONITOR,O_WRONLY); + if (monitor == -1) { + fprintf(stderr,"FAILED: %s cannot open attribute %s: %s\n",name,MONITOR,strerror(errno)); + exit(2); + } + result = write(monitor,buf,strlen(buf)); + if(result != strlen(buf)) { + if (result == -1) { + fprintf(stderr,"FAILED: %s attribute %s write error: %s\n",name,MONITOR,strerror(errno)); + exit(3); + } + fprintf(stderr,"FAILED: %s attribute %s incomplete write error: %d/%d\n",name,MONITOR,result,(int)strlen(buf)); + exit(4); + } + close(monitor); + if (not_reset(RADIO_DISCOVERY)) + exit(0); + + sigsuspend(&nullset); // Allow all signals + /* NOTREACHED */ +} diff --git a/src/x b/src/x new file mode 100644 index 0000000..9f7de31 --- /dev/null +++ b/src/x @@ -0,0 +1,108 @@ +/* + * mts-wait-for-cell-reset + * + * Block signal + * If not in reset, exit + * Register with mts-io for reset + * If not in reset, exit + * Suspend process for signal + * If signal occurs, exit + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char *name = "mts-wait-for-cell-reset"; +const int RST_SIG=SIGUSR2; // Wait for this signal +const char *MONITOR="/sys/devices/platform/mts-io/radio-reset-monitor"; +const char *RADIO_DISCOVERY="/sys/devices/platform/mts-io/radio-udev-discovery"; + +/* Return 0 if Cellular modem is being reset + * Return 1 if Cellular modem is not being reset + */ +int +not_reset(const char *attr_name) +{ + int not_in_reset, result; + char buf[256]; + int discovery; + + discovery = open(attr_name,O_RDONLY); + if (discovery == -1) { + fprintf(stderr,"FAILED: %s cannot open attribute %s: %s\n",name,attr_name,strerror(errno)); + exit(1); + } + result = read(discovery,buf,sizeof buf); + if (result > 0) + not_in_reset = atoi(buf); + else if (result == 0) { + fprintf(stderr,"FAILED: %s attribute %s has no state\n",name,attr_name); + exit(1); + } else { + fprintf(stderr,"FAILED: %s attribute %s error: %s\n",name,attr_name,strerror(errno)); + exit(1); + } + close(discovery); + return not_in_reset; +} + +void +handler(int sig) +{ + /* Normal way out of this program + * exit not safe from signal handler so + * use _exit() + */ + _exit(0); +} + +int +main(int argc, char *argv[]) +{ + sigset_t blockedset,nullset; + int monitor; + int result; + char buf[128]; + struct sigaction action; + + memset(&action,0,sizeof action); + action.sa_handler = handler; + memset(&blockedset,0,sizeof blockedset); + sigaddset(&blockedset,RST_SIG); + memset(&nullset,0,sizeof nullset); + + sigprocmask(SIG_BLOCK,&blockedset,NULL); // Blocked RST_SIG + + sigaction(RST_SIG,&action,NULL); + + if (not_reset(RADIO_DISCOVERY)) + exit(0); // Not in reset + sprintf(buf,"%d %d",getpid(),RST_SIG); + + monitor = open(MONITOR,O_WRONLY); + if (monitor == -1) { + fprintf(stderr,"FAILED: %s cannot open attribute %s: %s\n",name,MONITOR,strerror(errno)); + exit(2); + } + result = write(monitor,buf,strlen(buf)); + if(result != strlen(buf)) { + if (result == -1) { + fprintf(stderr,"FAILED: %s attribute %s write error: %s\n",name,MONITOR,strerror(errno)); + exit(3); + } + fprintf(stderr,"FAILED: %s attribute %s incomplete write error: %d/%d\n",name,MONITOR,result,(int)strlen(buf)); + exit(4); + } + close(monitor); + if (not_reset(RADIO_DISCOVERY)) + exit(0); + + sigsuspend(&nullset); // Allow all signals + /* NOTREACHED */ +} -- cgit v1.2.3 From 0998bd1bb800149dd1bbf9ff567d3cdb643841dc Mon Sep 17 00:00:00 2001 From: Andrii Pientsov Date: Fri, 21 Jan 2022 10:11:50 +0200 Subject: MTX-4356 mPower R.6.0.x: MTCAP3 - GP-1352, PP-477 : need --capa-lora-lbt for MTCAP3 in mts-id-eeprom --- src/eeprom_main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/eeprom_main.c b/src/eeprom_main.c index 26cfe70..66c948b 100644 --- a/src/eeprom_main.c +++ b/src/eeprom_main.c @@ -169,6 +169,7 @@ static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) fprintf(file, "capa-wifi: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_WIFI) ? "true" : "false"); fprintf(file, "capa-bluetooth: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_BLUETOOTH) ? "true" : "false"); fprintf(file, "capa-lora: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA) ? "true" : "false"); + fprintf(file, "capa-lora-lbt: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA_LBT) ? "true" : "false"); fprintf(file, "capa-battery: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_BATTERY) ? "true" : "false"); fprintf(file, "capa-supercap: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_SUPERCAP) ? "true" : "false"); fprintf(file, "capa-cellular: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_CELLULAR) ? "true" : "false"); @@ -393,6 +394,7 @@ static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom) log_info("capa-wifi: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_WIFI) ? "yes" : "no"); log_info("capa-bluetooth: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_BLUETOOTH) ? "yes" : "no"); log_info("capa-lora: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA) ? "yes" : "no"); + log_info("capa-lora-lbt: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA_LBT) ? "yes" : "no"); log_info("capa-supercap: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_SUPERCAP) ? "yes" : "no"); log_info("capa-cellular: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_CELLULAR) ? "yes" : "no"); @@ -552,6 +554,7 @@ static void usage(FILE *out) { fprintf(out, " --capa-wifi |\n"); fprintf(out, " --capa-bluetooth |\n"); fprintf(out, " --capa-lora |\n"); + fprintf(out, " --capa-lora-lbt |\n"); fprintf(out, " --capa-battery |\n"); fprintf(out, " --capa-supercap |\n"); fprintf(out, " --capa-cellular |\n"); @@ -593,6 +596,7 @@ enum { CMD_OPT_CAPA_WIFI, CMD_OPT_CAPA_BLUETOOTH, CMD_OPT_CAPA_LORA, + CMD_OPT_CAPA_LORA_LBT, CMD_OPT_CAPA_BATTERY, CMD_OPT_CAPA_SUPERCAP, CMD_OPT_CAPA_CELLULAR, @@ -643,6 +647,7 @@ static struct option long_options[] = { {"capa-wifi", 0, NULL, CMD_OPT_CAPA_WIFI}, {"capa-bluetooth", 0, NULL, CMD_OPT_CAPA_BLUETOOTH}, {"capa-lora", 0, NULL, CMD_OPT_CAPA_LORA}, + {"capa-lora-lbt", 0, NULL, CMD_OPT_CAPA_LORA_LBT}, {"capa-battery", 0, NULL, CMD_OPT_CAPA_BATTERY}, {"capa-supercap", 0, NULL, CMD_OPT_CAPA_SUPERCAP}, {"capa-cellular", 0, NULL, CMD_OPT_CAPA_CELLULAR}, @@ -967,6 +972,9 @@ int main(int argc, char *argv[]) { #endif DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA); break; + case CMD_OPT_CAPA_LORA_LBT: + DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA_LBT); + break; case CMD_OPT_CAPA_BATTERY: DEVICE_CAPA_SET(id_eeprom.capa, CAPA_BATTERY); break; -- cgit v1.2.3 From e0f209ee7cd8ea28a2f436d363fdfd5470312b3f Mon Sep 17 00:00:00 2001 From: Mykola Salomatin Date: Fri, 13 May 2022 18:40:43 +0300 Subject: [MTX-4480] mPower R.6.0.X: MTCAP3 - Filesystem Encryption capability GP-1586 Added user data encryption capability for encryption purposes in MTCAP3 devices. --- src/eeprom_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/eeprom_main.c b/src/eeprom_main.c index 66c948b..ed7d674 100644 --- a/src/eeprom_main.c +++ b/src/eeprom_main.c @@ -173,6 +173,7 @@ static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) fprintf(file, "capa-battery: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_BATTERY) ? "true" : "false"); fprintf(file, "capa-supercap: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_SUPERCAP) ? "true" : "false"); fprintf(file, "capa-cellular: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_CELLULAR) ? "true" : "false"); + fprintf(file, "capa-user-data-encryption: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_USER_DATA_ENCRYPTION) ? "true" : "false"); fprintf(file, "capa: \""); for (i = 0; i < sizeof(id_eeprom->capa); i++) { @@ -397,6 +398,7 @@ static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom) log_info("capa-lora-lbt: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_LORA_LBT) ? "yes" : "no"); log_info("capa-supercap: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_SUPERCAP) ? "yes" : "no"); log_info("capa-cellular: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_CELLULAR) ? "yes" : "no"); + log_info("capa-user-data-encryption: %s", DEVICE_CAPA(id_eeprom->capa, CAPA_USER_DATA_ENCRYPTION) ? "yes" : "no"); log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X", id_eeprom->mac_bluetooth[0], @@ -558,6 +560,7 @@ static void usage(FILE *out) { fprintf(out, " --capa-battery |\n"); fprintf(out, " --capa-supercap |\n"); fprintf(out, " --capa-cellular |\n"); + fprintf(out, " --capa-user-data-encryption |\n"); fprintf(out, " --capa-clear (clears all flags) |\n"); fprintf(out, " --hex-to-bin | \n"); fprintf(out, " --out-format { bin | yaml (default) } |\n"); @@ -600,6 +603,7 @@ enum { CMD_OPT_CAPA_BATTERY, CMD_OPT_CAPA_SUPERCAP, CMD_OPT_CAPA_CELLULAR, + CMD_OPT_CAPA_USER_DATA_ENCRYPTION, CMD_OPT_CAPA_CLEAR, CMD_OPT_OUT_FORMAT, CMD_OPT_UPDATE, @@ -651,6 +655,7 @@ static struct option long_options[] = { {"capa-battery", 0, NULL, CMD_OPT_CAPA_BATTERY}, {"capa-supercap", 0, NULL, CMD_OPT_CAPA_SUPERCAP}, {"capa-cellular", 0, NULL, CMD_OPT_CAPA_CELLULAR}, + {"capa-user-data-encryption", 0, NULL, CMD_OPT_CAPA_USER_DATA_ENCRYPTION}, {"capa-clear", 0, NULL, CMD_OPT_CAPA_CLEAR}, {"hex-to-bin", 0, NULL, CMD_OPT_HEX_TO_BIN}, {"out-format", 1, NULL, CMD_OPT_OUT_FORMAT}, @@ -972,9 +977,11 @@ int main(int argc, char *argv[]) { #endif DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA); break; + case CMD_OPT_CAPA_LORA_LBT: DEVICE_CAPA_SET(id_eeprom.capa, CAPA_LORA_LBT); break; + case CMD_OPT_CAPA_BATTERY: DEVICE_CAPA_SET(id_eeprom.capa, CAPA_BATTERY); break; @@ -987,6 +994,10 @@ int main(int argc, char *argv[]) { DEVICE_CAPA_SET(id_eeprom.capa, CAPA_CELLULAR); break; + case CMD_OPT_CAPA_USER_DATA_ENCRYPTION: + DEVICE_CAPA_SET(id_eeprom.capa, CAPA_USER_DATA_ENCRYPTION); + break; + case CMD_OPT_CAPA_CLEAR: capa_clear = 1; break; -- cgit v1.2.3