add TargetClass support
authorFelix Fietkau <nbd@openwrt.org>
Thu, 17 Oct 2013 10:50:17 +0000 (12:50 +0200)
committerFelix Fietkau <nbd@nbd.name>
Tue, 19 Jul 2016 12:22:14 +0000 (14:22 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
main.c
switch.c
switch.h

diff --git a/main.c b/main.c
index 859a90a421c84ede8512ddd123ef60a78f64c962..6cfe3b22bea35ff4aaa96ba0797a1810b91babaa 100644 (file)
--- a/main.c
+++ b/main.c
@@ -215,6 +215,7 @@ parse_interface_config(libusb_device *dev, struct usbdev_data *data)
 
        alt = &iface->altsetting[0];
        data->interface = alt->bInterfaceNumber;
+       data->dev_class = alt->bInterfaceClass;
 
        for (i = 0; i < alt->bNumEndpoints; i++) {
                const struct libusb_endpoint_descriptor *ep = &alt->endpoint[i];
index 2c33d9c25f81e28f6f90ff9320459390be5ec1a1..b2835610203e27efc833c55ce9a7ec490554a17c 100644 (file)
--- a/switch.c
+++ b/switch.c
@@ -11,6 +11,7 @@ enum {
        DATA_RELEASE_DELAY,
        DATA_CONFIG,
        DATA_ALT,
+       DATA_DEV_CLASS,
        __DATA_MAX
 };
 
@@ -410,12 +411,17 @@ void handle_switch(struct usbdev_data *data)
                [DATA_RESPONSE] = { .name = "response", .type = BLOBMSG_TYPE_BOOL },
                [DATA_CONFIG] = { .name = "config", .type = BLOBMSG_TYPE_INT32 },
                [DATA_ALT] = { .name = "alt", .type = BLOBMSG_TYPE_INT32 },
+               [DATA_DEV_CLASS] = { .name = "t_class", .type = BLOBMSG_TYPE_INT32 },
        };
        struct blob_attr *tb[__DATA_MAX];
        int mode = MODE_GENERIC;
+       int t_class = 0;
 
        blobmsg_parse(data_policy, __DATA_MAX, tb, blobmsg_data(data->info), blobmsg_data_len(data->info));
 
+       if (tb[DATA_DEV_CLASS])
+               t_class = blobmsg_get_u32(tb[DATA_DEV_CLASS]);
+
        if (tb[DATA_INTERFACE])
                data->interface = blobmsg_get_u32(tb[DATA_INTERFACE]);
 
@@ -431,6 +437,9 @@ void handle_switch(struct usbdev_data *data)
        if (tb[DATA_RESPONSE])
                data->need_response = blobmsg_get_bool(tb[DATA_RESPONSE]);
 
+       if (t_class > 0 && data->dev_class != t_class)
+               return;
+
        if (tb[DATA_MODE]) {
                const char *modestr;
                int i;
index 97c14f3ce411a3a181e64719a10c600bffc54dfc..e4993267bbe112773ad50bae47cc2ff8b0bb0363 100644 (file)
--- a/switch.h
+++ b/switch.h
@@ -14,6 +14,7 @@ struct usbdev_data {
        int msg_endpoint;
        int response_endpoint;
        int release_delay;
+       int dev_class;
        bool need_response;
 
        char idstr[10];