diff options
author | John Klug <john.klug@multitech.com> | 2016-09-27 10:33:16 -0500 |
---|---|---|
committer | John Klug <john.klug@multitech.com> | 2016-09-27 10:33:16 -0500 |
commit | 995083ea6f80c1ea7d749fbd6d58127ae1c75455 (patch) | |
tree | 91b147d1bed0214e9437fe8a1cc51af864ef78e3 /io-module/mtac_lora.c | |
parent | 7a1ed1a7788c76630723d9f0f49f3862ca6fb300 (diff) | |
download | mts-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/mtac_lora.c')
-rw-r--r-- | io-module/mtac_lora.c | 19 |
1 files changed, 15 insertions, 4 deletions
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); |