diff options
author | Hans de Goede <hdegoede@redhat.com> | 2012-02-13 15:25:34 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2012-02-14 18:56:08 +0100 |
commit | 952d838efab53b2817a2783aa9ee31f6485a1a76 (patch) | |
tree | 6b764c176571c89faa53b9f0a3fac471fc2a9818 /usbredirhost | |
parent | 79e2330bc5c7127d9bfaba3291a3aa3630fbd253 (diff) |
Add a usb_redir_filter_filter packet
Make this conditional on the same cap as device_reject, rename
the cap to usb_redir_cap_filter. Rename device_reject to filter_reject to
reflect that it is filtering related and that the the cap and packet names
are consistent with each other. Also cleanup some related comments / docs.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'usbredirhost')
-rw-r--r-- | usbredirhost/usbredirhost.c | 45 | ||||
-rw-r--r-- | usbredirhost/usbredirhost.h | 5 |
2 files changed, 39 insertions, 11 deletions
diff --git a/usbredirhost/usbredirhost.c b/usbredirhost/usbredirhost.c index 0781b02..32a1cfb 100644 --- a/usbredirhost/usbredirhost.c +++ b/usbredirhost/usbredirhost.c @@ -117,6 +117,8 @@ struct usbredirhost { uint8_t driver_detached[MAX_INTERFACES]; uint8_t alt_setting[MAX_INTERFACES]; struct usbredirtransfer transfers_head; + struct usbredirfilter_rule *filter_rules; + int filter_rules_count; }; static void va_log(struct usbredirhost *host, int level, @@ -147,7 +149,6 @@ static void va_log(struct usbredirhost *host, int level, "usbredirhost: " __VA_ARGS__) static void usbredirhost_hello(void *priv, struct usb_redir_hello_header *h); -static void usbredirhost_device_reject(void *priv); static void usbredirhost_reset(void *priv); static void usbredirhost_set_configuration(void *priv, uint32_t id, struct usb_redir_set_configuration_header *set_configuration); @@ -169,6 +170,9 @@ static void usbredirhost_alloc_bulk_streams(void *priv, uint32_t id, static void usbredirhost_free_bulk_streams(void *priv, uint32_t id, struct usb_redir_free_bulk_streams_header *free_bulk_streams); static void usbredirhost_cancel_data_packet(void *priv, uint32_t id); +static void usbredirhost_filter_reject(void *priv); +static void usbredirhost_filter_filter(void *priv, + struct usbredirfilter_rule *rules, int rules_count); static void usbredirhost_control_packet(void *priv, uint32_t id, struct usb_redir_control_packet_header *control_packet, uint8_t *data, int data_len); @@ -519,7 +523,6 @@ struct usbredirhost *usbredirhost_open_full( host->parser->read_func = usbredirhost_read; host->parser->write_func = usbredirhost_write; host->parser->hello_func = usbredirhost_hello; - host->parser->device_reject_func = usbredirhost_device_reject; host->parser->reset_func = usbredirhost_reset; host->parser->set_configuration_func = usbredirhost_set_configuration; host->parser->get_configuration_func = usbredirhost_get_configuration; @@ -534,6 +537,8 @@ struct usbredirhost *usbredirhost_open_full( host->parser->alloc_bulk_streams_func = usbredirhost_alloc_bulk_streams; host->parser->free_bulk_streams_func = usbredirhost_free_bulk_streams; host->parser->cancel_data_packet_func = usbredirhost_cancel_data_packet; + host->parser->filter_reject_func = usbredirhost_filter_reject; + host->parser->filter_filter_func = usbredirhost_filter_filter; host->parser->control_packet_func = usbredirhost_control_packet; host->parser->bulk_packet_func = usbredirhost_bulk_packet; host->parser->iso_packet_func = usbredirhost_iso_packet; @@ -553,7 +558,7 @@ struct usbredirhost *usbredirhost_open_full( } usbredirparser_caps_set_cap(caps, usb_redir_cap_connect_device_version); - usbredirparser_caps_set_cap(caps, usb_redir_cap_reject_device); + usbredirparser_caps_set_cap(caps, usb_redir_cap_filter); usbredirparser_init(host->parser, version, caps, USB_REDIR_CAPS_SIZE, parser_flags); @@ -622,6 +627,7 @@ void usbredirhost_close(struct usbredirhost *host) if (host->parser) { usbredirparser_destroy(host->parser); } + free(host->filter_rules); free(host); } @@ -1307,14 +1313,6 @@ static void usbredirhost_hello(void *priv, struct usb_redir_hello_header *h) FLUSH(host); } -static void usbredirhost_device_reject(void *priv) -{ - struct usbredirhost *host = priv; - - INFO("device rejected"); - host->rejected = 1; -} - static void usbredirhost_reset(void *priv) { struct usbredirhost *host = priv; @@ -1565,6 +1563,24 @@ static void usbredirhost_free_bulk_streams(void *priv, uint32_t id, /* struct usbredirhost *host = priv; */ } +static void usbredirhost_filter_reject(void *priv) +{ + struct usbredirhost *host = priv; + + INFO("device rejected"); + host->rejected = 1; +} + +static void usbredirhost_filter_filter(void *priv, + struct usbredirfilter_rule *rules, int rules_count) +{ + struct usbredirhost *host = priv; + + free(host->filter_rules); + host->filter_rules = rules; + host->filter_rules_count = rules_count; +} + /**************************************************************************/ static void usbredirhost_cancel_data_packet(void *priv, uint32_t id) @@ -2024,6 +2040,13 @@ static void usbredirhost_interrupt_packet(void *priv, uint32_t id, /**************************************************************************/ +void usbredirhost_get_guest_filter(struct usbredirhost *host, + struct usbredirfilter_rule **rules_ret, int *rules_count_ret) +{ + *rules_ret = host->filter_rules; + *rules_count_ret = host->filter_rules_count; +} + int usbredirhost_check_device_filter(struct usbredirfilter_rule *rules, int rules_count, libusb_device *dev, int flags) { diff --git a/usbredirhost/usbredirhost.h b/usbredirhost/usbredirhost.h index 2439d88..87bcf54 100644 --- a/usbredirhost/usbredirhost.h +++ b/usbredirhost/usbredirhost.h @@ -118,6 +118,11 @@ int usbredirhost_write_guest_data(struct usbredirhost *host); passed to write_guest_data_func when done with this buffer. */ void usbredirhost_free_write_buffer(struct usbredirhost *host, uint8_t *data); +/* Get the *usbredir-guest's* filter, if any. If there is no filter, + rules is set to NULL and rules_count to 0. */ +void usbredirhost_get_guest_filter(struct usbredirhost *host, + struct usbredirfilter_rule **rules_ret, int *rules_count_ret); + /* Get device and config descriptors from the USB device dev, and call usbredirfilter_check with the passed in filter rules and the needed info from the descriptors, flags gets passed to usbredirfilter_check unmodified. |