summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io-module/mts-io.c74
1 files changed, 55 insertions, 19 deletions
diff --git a/io-module/mts-io.c b/io-module/mts-io.c
index 0477f2e..c595973 100644
--- a/io-module/mts-io.c
+++ b/io-module/mts-io.c
@@ -136,26 +136,36 @@ static time_t time_now_secs(void);
bool sent_extra_long = false;
/*
- * This function takes the product_id and tries to check
- * for a modem. If there is an error, assume there is a
- * modem. Saying there is a modem when there is not
+ * For EEPROM layout after version 0, we use the
+ * CAPA_CELLULAR flag to determine if we have a cellular
+ * modem and this code is not used.
+ *
+ * Version 0 uses the product-id to determine if there is
+ * a modem or not.
+ *
+ * Saying there is a modem when there is not
* just results in a slower boot.
* If no hyphen in product ID, or no product ID,
* assume we have a radio.
- * If there is a hyphen test the character after the
+ * If there is a hyphen, test the character after the
* first hyphen:
* If the character is numeric, we have no modem.
- * if the chracter is not a B, we have a modem.
+ * if the chracter is not a B or an I, we have a modem.
* If the character is a B, and it is followed
* by a numeric, we have no modem.
- * If the B is the last character or is followed
- * by a numeric, we have no modem.
+ * If the B is the last character we have a modem.
+ * If the modem field starts with IN, we have an
+ * India LoRa channel plan with no cellular modem.
* All other cases, we have a modem.
+ *
+ * TRUE: 1 for return result
+ * FALSE: 0 for return result
*/
int
mts_has_radio(const char *product_id, size_t len)
{
char *p;
+ int found_i = 0;
if (!product_id || ! *product_id)
return 1; /* No Product ID? */
p = memchr(product_id,'-',len);
@@ -170,16 +180,30 @@ mts_has_radio(const char *product_id, size_t len)
log_debug("Found digit after hypen");
return 0; /* Modem name never starts with a digit */
}
- if (*p != 'B') {
- log_debug("Found neither B nor digit after hypen");
- return 1; /* Modem starting with a letter, but not B */
+
+ /* For eeprom version 0, if the 2nd field starts with a B[n]
+ * it is a build #, and does not have a modem. If the 2nd field
+ * starts with an IN8, it is an Indian LoRa channel plan,
+ * and does not have a modem. */
+ if (*p == 'I')
+ found_i = 1;
+ if ((*p != 'B') && (! found_i)) {
+ log_debug("Did not find B, I, or digit after hyphen in product-id");
+ return 1; /* Modem starting with a letter, but not B or I */
}
- /* Found a B */
+ /* Found a B or an I */
p++;
if (p >= product_id+len) {
- log_debug("B at end of product-id string");
- return 1; /* Last character was B */
+ log_debug("B or I at end of product-id string");
+ return 1; /* Last character was B or I */
}
+
+ /* No modem starts with IN */
+ if (found_i && (*p == 'N')) {
+ log_debug("IN found in 2nd product-id field -- India LoRa Channel plan");
+ return 0;
+ }
+
if (isdigit(*p)) {
log_debug("B followed by digit after hyphen - no modem");
return 0; /* B[numeric] is MTR Build number */
@@ -515,8 +539,12 @@ static ssize_t mts_attr_show_product_info(struct device *dev,
} else if (strcmp(attr->attr.name, "product-id") == 0) {
value = sprintf(buf, "%.32s\n", id_eeprom.product_id);
} else if (strcmp(attr->attr.name, "has-radio") == 0) {
- value = sprintf(buf, "%1d\n",
- mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id));
+ if(id_eeprom.eeprom_layout_version == 0)
+ value = sprintf(buf, "%1lu\n",
+ mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id));
+ else
+ /* Newer EEPROM version with CAPA_CELLULAR */
+ value = sprintf(buf, "%1d\n",DEVICE_CAPA(id_eeprom.capa, CAPA_CELLULAR));
} else if (strcmp(attr->attr.name, "device-id") == 0) {
value = sprintf(buf, "%.32s\n", id_eeprom.device_id);
} else if (strcmp(attr->attr.name, "uuid") == 0) {
@@ -636,7 +664,7 @@ mts_id_eeprom_load(void)
int current_count; // Number of items in array
struct attribute **all_attrs = NULL;
char *tmp;
- int noradio;
+ int noradio, has_cellular_capaflag = 0;
int ret;
const struct firmware* fw = NULL;
@@ -658,8 +686,14 @@ mts_id_eeprom_load(void)
// If we are an MTCPM, the base board sets the radio existance.
if (strncmp(id_eeprom.hw_version,HW_VERSION_MTCPM_DASH,sizeof HW_VERSION_MTCPM_DASH) != 0) {
- noradio = ! mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id);
- log_debug("mts_id_eeprom: noradio=%d",noradio);
+ if (id_eeprom.eeprom_layout_version == 0) {
+ noradio = ! mts_has_radio(id_eeprom.product_id,sizeof id_eeprom.product_id);
+ log_debug("mts_id_eeprom_load: noradio=%d",noradio);
+ } else {
+ has_cellular_capaflag = 1;
+ noradio = ! DEVICE_CAPA(id_eeprom.capa, CAPA_CELLULAR);
+ log_debug("mts_id_eeprom_load: noradio=%d",noradio);
+ }
}
if (((tmp=HW_VERSION_MTCAP_0_0),strncmp(id_eeprom.hw_version, tmp, strlen(tmp)) == 0) ||
@@ -926,6 +960,7 @@ mts_id_eeprom_load(void)
return -ENODEV;
}
+ log_info("EEPROM-Layout-Version: %u",id_eeprom.eeprom_layout_version);
log_info("sizeof: %lu", (unsigned long) sizeof(struct mts_id_eeprom_layout));
log_info("vendor-id: %.32s", id_eeprom.vendor_id);
log_info("product-id: %.32s", id_eeprom.product_id);
@@ -950,7 +985,8 @@ mts_id_eeprom_load(void)
log_info("capa-lora: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) ? "yes" : "no");
log_info("capa-battery: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_BATTERY) ? "yes" : "no");
log_info("capa-supercap: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_SUPERCAP) ? "yes" : "no");
-
+ if(has_cellular_capaflag)
+ log_info("capa-cellular: %s", DEVICE_CAPA(id_eeprom.capa, CAPA_CELLULAR) ? "yes" : "no");
if (DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH)) {
log_info("mac-bluetooth: %02X:%02X:%02X:%02X:%02X:%02X",