summaryrefslogtreecommitdiff
path: root/io-module/mtac.c
diff options
context:
space:
mode:
Diffstat (limited to 'io-module/mtac.c')
-rw-r--r--io-module/mtac.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/io-module/mtac.c b/io-module/mtac.c
index b9a2520..99e2ce7 100644
--- a/io-module/mtac.c
+++ b/io-module/mtac.c
@@ -20,3 +20,94 @@ static struct kobj_attribute* create_attribute(const char* _name, umode_t _mode)
return _attr;
}
+
+static ssize_t ap_show_product_info(struct kobject *kobj, struct kobj_attribute *attr, char *buf) {
+ ssize_t value;
+ int port;
+
+ if (sscanf(attr->attr.name, "vendor-id:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].vendor_id);
+ } else if (sscanf(attr->attr.name, "product-id:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].product_id);
+ } else if (sscanf(attr->attr.name, "device-id:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].device_id);
+ } else if (sscanf(attr->attr.name, "hw-version:%d", &port) > 0) {
+ value = snprintf(buf, 32, "%s\n", ap_eeprom[port - 1].hw_version);
+ } else if (sscanf(attr->attr.name, "mac-eth:%d", &port) > 0) {
+ value = sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X\n",
+ ap_eeprom[port - 1].mac_addr[0],
+ ap_eeprom[port - 1].mac_addr[1],
+ ap_eeprom[port - 1].mac_addr[2],
+ ap_eeprom[port - 1].mac_addr[3],
+ ap_eeprom[port - 1].mac_addr[4],
+ ap_eeprom[port - 1].mac_addr[5]);
+ } else {
+ log_error("attribute '%s' not found", attr->attr.name);
+ value = -1;
+ }
+
+ return value;
+}
+
+static bool ap_add_product_info_attributes(int port, int type) {
+ struct kobj_attribute *attr;
+ char buf[32];
+
+ switch (type) {
+ case MTAC_ETH_0_0:
+ sprintf(buf, "mac-eth:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+ break;
+
+ case MTAC_GPIOB_0_0:
+ case MTAC_MFSER_0_0:
+ break;
+ default:
+ log_error("invalid accessory card type");
+ return false;
+ }
+
+ sprintf(buf, "vendor-id:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ sprintf(buf, "product-id:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ sprintf(buf, "device-id:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ sprintf(buf, "hw-version:%d", port);
+ attr = create_attribute(buf, MTS_ATTR_MODE_RO);
+ if (! attr) {
+ log_error("failed to create attribute[%s]", buf);
+ return false;
+ }
+ attr->show = ap_show_product_info;
+ device_attrs[device_attrs_size++] = &attr->attr;
+
+ return true;
+}