summaryrefslogtreecommitdiff
path: root/io-module
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2016-09-27 10:33:16 -0500
committerJohn Klug <john.klug@multitech.com>2016-09-27 10:33:16 -0500
commit995083ea6f80c1ea7d749fbd6d58127ae1c75455 (patch)
tree91b147d1bed0214e9437fe8a1cc51af864ef78e3 /io-module
parent7a1ed1a7788c76630723d9f0f49f3862ca6fb300 (diff)
downloadmts-io-995083ea6f80c1ea7d749fbd6d58127ae1c75455.tar.gz
mts-io-995083ea6f80c1ea7d749fbd6d58127ae1c75455.tar.bz2
mts-io-995083ea6f80c1ea7d749fbd6d58127ae1c75455.zip
Add MTAC-LORA-1.5 and string subset issue with hardware version
Diffstat (limited to 'io-module')
-rw-r--r--io-module/mtac.c1
-rw-r--r--io-module/mtac_lora.c19
-rw-r--r--io-module/mts_io.h4
3 files changed, 20 insertions, 4 deletions
diff --git a/io-module/mtac.c b/io-module/mtac.c
index 43436f8..b89f51f 100644
--- a/io-module/mtac.c
+++ b/io-module/mtac.c
@@ -112,6 +112,7 @@ static bool ap_add_product_info_attributes(int port, int type, struct attribute*
case MTAC_LORA_0_0:
case MTAC_LORA_1_0:
+ case MTAC_LORA_1_5:
sprintf(buf, "eui");
kobj_attr = create_attribute(buf, MTS_ATTR_MODE_RO);
if (! kobj_attr) {
diff --git a/io-module/mtac_lora.c b/io-module/mtac_lora.c
index 3668f67..29e37ff 100644
--- a/io-module/mtac_lora.c
+++ b/io-module/mtac_lora.c
@@ -28,6 +28,14 @@ static char* lora_gpio_pin_name_by_attr_name(const char* name, int port) {
// NULL
static size_t ap_lora_attrs_size = 8;
+// Set the hardware version if the ROM string matches one of the valid
+// hardware versions.
+// Lengths of strings must be the same for a match, then can compare
+// text. Without a length check a subset of a string could be a match.
+#define COMPARE_AND_ASSIGN(CANDIDATE) ((hw_version_len == (sizeof(HW_VERSION_ ## CANDIDATE)-1)) && \
+ (strncmp(ap_eeprom[port_index].hw_version, HW_VERSION_ ## CANDIDATE, sizeof(HW_VERSION_ ## CANDIDATE)) == 0)) \
+ lora_hw_version = CANDIDATE;
+
static bool lora_setup(enum ap port) {
int i;
int port_index = port - 1;
@@ -38,6 +46,7 @@ static bool lora_setup(enum ap port) {
struct kobj_attribute* attr;
struct attribute **attrs;
int lora_hw_version;
+ int hw_version_len;
log_info("loading LORA accessory card in port %d", port);
@@ -76,10 +85,12 @@ static bool lora_setup(enum ap port) {
return false;
}
- if (strncmp(ap_eeprom[port_index].hw_version, HW_VERSION_MTAC_LORA_0_0, strlen(HW_VERSION_MTAC_LORA_0_0)) == 0)
- lora_hw_version = MTAC_LORA_0_0;
- else if (strncmp(ap_eeprom[port_index].hw_version, HW_VERSION_MTAC_LORA_1_0, strlen(HW_VERSION_MTAC_LORA_1_0)) == 0)
- lora_hw_version = MTAC_LORA_1_0;
+ // hw_version string length, null character not counted.
+ hw_version_len = strnlen(ap_eeprom[port_index].hw_version,sizeof ap_eeprom[port_index].hw_version);
+
+ if COMPARE_AND_ASSIGN(MTAC_LORA_0_0)
+ else if COMPARE_AND_ASSIGN(MTAC_LORA_1_0)
+ else if COMPARE_AND_ASSIGN(MTAC_LORA_1_5)
else {
log_error("Unknown hw-version in port %d", port);
kfree(attrs);
diff --git a/io-module/mts_io.h b/io-module/mts_io.h
index 791235f..fefc35e 100644
--- a/io-module/mts_io.h
+++ b/io-module/mts_io.h
@@ -50,10 +50,13 @@ struct device_attribute _dev_name = { \
#define PRODUCT_ID_MTAC_ETH "MTAC-ETH"
#define PRODUCT_ID_MTAC_LORA "MTAC-LORA"
+/* Hardware version must be fewer characters than hw_version
+ in struct mts_ap_eeprom_layout */
/* MTAC-LORA with native SPI or FTDI FT4222 */
#define HW_VERSION_MTAC_LORA_0_0 "MTAC-LORA-0.0"
/* MTAC-LORA2 with FTDI FT232H */
#define HW_VERSION_MTAC_LORA_1_0 "MTAC-LORA-1.0"
+#define HW_VERSION_MTAC_LORA_1_5 "MTAC-LORA-1.5"
#define HW_VERSION_MTCBA2_2_0 "MTCBA2-2.0"
#define HW_VERSION_MTCDP_0_0 "MTCDP-0.0"
@@ -83,6 +86,7 @@ enum {
MTAC_ETH_0_0,
MTAC_LORA_0_0,
MTAC_LORA_1_0,
+ MTAC_LORA_1_5,
};
// GPIO pin types:input, output, open drain (1 = high Z, 0 = output low)