summaryrefslogtreecommitdiff
path: root/io-module/mtac_lora.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mtac_lora.c')
-rw-r--r--io-module/mtac_lora.c19
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);