summaryrefslogtreecommitdiff
path: root/io-module/mts_capab.c
diff options
context:
space:
mode:
authorJohn Klug <john.klug@multitech.com>2016-12-02 16:50:38 -0600
committerJohn Klug <john.klug@multitech.com>2016-12-02 16:50:38 -0600
commit47f3a89441324f4912a7c83bad4f40837bc365b5 (patch)
tree9f21537439bbfee6cebdc8893f983dd7f5db10b3 /io-module/mts_capab.c
parenteee329cd45e5ead12223bf060b33f4fe1e2a5c8c (diff)
downloadmts-io-47f3a89441324f4912a7c83bad4f40837bc365b5.tar.gz
mts-io-47f3a89441324f4912a7c83bad4f40837bc365b5.tar.bz2
mts-io-47f3a89441324f4912a7c83bad4f40837bc365b5.zip
Fix ethernet accessory card bug and add capability directory
Diffstat (limited to 'io-module/mts_capab.c')
-rw-r--r--io-module/mts_capab.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/io-module/mts_capab.c b/io-module/mts_capab.c
new file mode 100644
index 0000000..35a91c6
--- /dev/null
+++ b/io-module/mts_capab.c
@@ -0,0 +1,69 @@
+/*
+ * capab.c
+ *
+ * Created on: Dec 1, 2016
+ * Author: jklug
+ */
+static ssize_t capab_show_value(struct kobject *kobj, struct kobj_attribute *attr, char *buf) {
+ ssize_t value;
+
+ if (! strcmp(attr->attr.name, "gps"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_GPS) != 0);
+ else if (! strcmp(attr->attr.name, "din"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_DIN) != 0);
+ else if (! strcmp(attr->attr.name, "dout"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_DOUT) != 0);
+ else if (! strcmp(attr->attr.name, "adc"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_ADC) != 0);
+ else if (! strcmp(attr->attr.name, "bluetooth"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_BLUETOOTH) != 0);
+ else if (! strcmp(attr->attr.name, "wifi"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI) != 0);
+ else if (! strcmp(attr->attr.name, "wifi_bt"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_WIFI_BT) != 0);
+ else if (! strcmp(attr->attr.name, "gnss"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_GNSS) != 0);
+ else if (! strcmp(attr->attr.name, "lora"))
+ value = snprintf(buf, 32, "%lu\n", DEVICE_CAPA(id_eeprom.capa, CAPA_LORA) != 0);
+ else {
+ log_error("attribute [%s] not found", attr->attr.name);
+ value = -1;
+ }
+
+ return value;
+}
+
+static char *attribute_names[] = {
+ "gps",
+ "din",
+ "dout",
+ "adc",
+ "bluetooth",
+ "wifi",
+ "wifi_bt",
+ "gnss",
+ "lora",
+};
+
+static bool capab_add_attributes(struct attribute** attrs) {
+ struct kobj_attribute* kobj_attr;
+ int i;
+ int count = sizeof(attribute_names)/sizeof(attribute_names[0]);
+
+ // We must keep the number of attributes in sync
+ BUG_ON(CAPA_COUNT != count);
+ log_info("capab_add_attributes, add %d attributes",count);
+ for(i=0;i<count;i++) {
+ kobj_attr = create_attribute(attribute_names[i], MTS_ATTR_MODE_RO);
+ if (! kobj_attr) {
+ log_error("failed to create attribute [%s]", attribute_names[i]);
+ return false;
+ }
+
+ kobj_attr->show = capab_show_value;
+ attrs[i] = &kobj_attr->attr;
+ log_error("created attribute [%s]", attribute_names[i]);
+ }
+
+ return true;
+}