diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2019-09-08 22:22:37 +0200 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2019-09-11 18:01:50 +0000 |
commit | 51c4626471ce5ddf9035b0c7570141b12929a52d (patch) | |
tree | 365db9ce9a6bb9b68962571b02f428ab281eb667 /src | |
parent | 0e02771e5cb185d8939930e65cc6e63ca226b6f7 (diff) |
filter: update plugin whitelist logic to use 'allowed product ids'
Several plugins define the specific device vid:pid pairs they
support. Let's use this information as a direct indication that
ModemManager can probe the devices.
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-filter.c | 51 | ||||
-rw-r--r-- | src/mm-filter.h | 7 | ||||
-rw-r--r-- | src/mm-plugin-manager.c | 18 | ||||
-rw-r--r-- | src/mm-plugin.c | 6 | ||||
-rw-r--r-- | src/mm-plugin.h | 5 |
5 files changed, 80 insertions, 7 deletions
diff --git a/src/mm-filter.c b/src/mm-filter.c index 3695fa9a..73c6bde1 100644 --- a/src/mm-filter.c +++ b/src/mm-filter.c @@ -36,6 +36,7 @@ enum { struct _MMFilterPrivate { MMFilterRule enabled_rules; GList *plugin_whitelist_tags; + GArray *plugin_whitelist_product_ids; }; /*****************************************************************************/ @@ -50,6 +51,31 @@ mm_filter_register_plugin_whitelist_tag (MMFilter *self, } } +void +mm_filter_register_plugin_whitelist_product_id (MMFilter *self, + guint16 vid, + guint16 pid) +{ + mm_uint16_pair new_item; + guint i; + + if (!self->priv->plugin_whitelist_product_ids) + self->priv->plugin_whitelist_product_ids = g_array_sized_new (FALSE, FALSE, sizeof (mm_uint16_pair), 10); + + for (i = 0; i < self->priv->plugin_whitelist_product_ids->len; i++) { + mm_uint16_pair *item; + + item = &g_array_index (self->priv->plugin_whitelist_product_ids, mm_uint16_pair, i); + if (item->l == vid && item->r == pid) + return; + } + + new_item.l = vid; + new_item.r = pid; + g_array_append_val (self->priv->plugin_whitelist_product_ids, new_item); + mm_dbg ("[filter] registered plugin whitelist product id: %04x:%04x", vid, pid); +} + /*****************************************************************************/ gboolean @@ -82,15 +108,35 @@ mm_filter_port (MMFilter *self, /* If the device is whitelisted by a plugin, we allow it. */ if (self->priv->enabled_rules & MM_FILTER_RULE_PLUGIN_WHITELIST) { - GList *l; + GList *l; + guint16 vid = 0; + guint16 pid = 0; for (l = self->priv->plugin_whitelist_tags; l; l = g_list_next (l)) { if (mm_kernel_device_get_global_property_as_boolean (port, (const gchar *)(l->data)) || mm_kernel_device_get_property_as_boolean (port, (const gchar *)(l->data))) { - mm_dbg ("[filter] (%s/%s) port allowed: device is whitelisted by plugin", subsystem, name); + mm_dbg ("[filter] (%s/%s) port allowed: device is whitelisted by plugin (tag)", subsystem, name); return TRUE; } } + + vid = mm_kernel_device_get_physdev_vid (port); + if (vid) + pid = mm_kernel_device_get_physdev_pid (port); + + if (vid && pid && self->priv->plugin_whitelist_product_ids) { + guint i; + + for (i = 0; i < self->priv->plugin_whitelist_product_ids->len; i++) { + mm_uint16_pair *item; + + item = &g_array_index (self->priv->plugin_whitelist_product_ids, mm_uint16_pair, i); + if (item->l == vid && item->r == pid) { + mm_dbg ("[filter] (%s/%s) port allowed: device is whitelisted by plugin (vid/pid)", subsystem, name); + return TRUE; + } + } + } } /* If this is a virtual device, don't allow it */ @@ -426,6 +472,7 @@ finalize (GObject *object) { MMFilter *self = MM_FILTER (object); + g_clear_pointer (&self->priv->plugin_whitelist_product_ids, g_array_unref); g_list_free_full (self->priv->plugin_whitelist_tags, g_free); G_OBJECT_CLASS (mm_filter_parent_class)->finalize (object); diff --git a/src/mm-filter.h b/src/mm-filter.h index 73fc9894..0fc4ade9 100644 --- a/src/mm-filter.h +++ b/src/mm-filter.h @@ -143,8 +143,11 @@ gboolean mm_filter_device_and_port (MMFilter *self, MMDevice *device, MMKernelDevice *port); -void mm_filter_register_plugin_whitelist_tag (MMFilter *self, - const gchar *tag); +void mm_filter_register_plugin_whitelist_tag (MMFilter *self, + const gchar *tag); +void mm_filter_register_plugin_whitelist_product_id (MMFilter *self, + guint16 vid, + guint16 pid); gboolean mm_filter_check_rule_enabled (MMFilter *self, MMFilterRule rule); diff --git a/src/mm-plugin-manager.c b/src/mm-plugin-manager.c index 557c2d5d..f0045af7 100644 --- a/src/mm-plugin-manager.c +++ b/src/mm-plugin-manager.c @@ -1511,6 +1511,21 @@ register_plugin_whitelist_tags (MMPluginManager *self, mm_filter_register_plugin_whitelist_tag (self->priv->filter, tags[i]); } +static void +register_plugin_whitelist_product_ids (MMPluginManager *self, + MMPlugin *plugin) +{ + const mm_uint16_pair *product_ids; + guint i; + + if (!mm_filter_check_rule_enabled (self->priv->filter, MM_FILTER_RULE_PLUGIN_WHITELIST)) + return; + + product_ids = mm_plugin_get_allowed_product_ids (plugin); + for (i = 0; product_ids && product_ids[i].l; i++) + mm_filter_register_plugin_whitelist_product_id (self->priv->filter, product_ids[i].l, product_ids[i].r); +} + static MMPlugin * load_plugin (const gchar *path) { @@ -1625,8 +1640,9 @@ load_plugins (MMPluginManager *self, /* Vendor specific plugin */ self->priv->plugins = g_list_append (self->priv->plugins, plugin); - /* Register plugin whitelist tags in filter, if any */ + /* Register plugin whitelist rules in filter, if any */ register_plugin_whitelist_tags (self, plugin); + register_plugin_whitelist_product_ids (self, plugin); } /* Check the generic plugin once all looped */ diff --git a/src/mm-plugin.c b/src/mm-plugin.c index fbb0d5c8..8ef9e623 100644 --- a/src/mm-plugin.c +++ b/src/mm-plugin.c @@ -147,6 +147,12 @@ mm_plugin_get_allowed_udev_tags (MMPlugin *self) return (const gchar **) self->priv->udev_tags; } +const mm_uint16_pair * +mm_plugin_get_allowed_product_ids (MMPlugin *self) +{ + return self->priv->product_ids; +} + /*****************************************************************************/ static gboolean diff --git a/src/mm-plugin.h b/src/mm-plugin.h index 84df989c..926840bf 100644 --- a/src/mm-plugin.h +++ b/src/mm-plugin.h @@ -124,8 +124,9 @@ struct _MMPluginClass { GType mm_plugin_get_type (void); -const gchar *mm_plugin_get_name (MMPlugin *self); -const gchar **mm_plugin_get_allowed_udev_tags (MMPlugin *self); +const gchar *mm_plugin_get_name (MMPlugin *self); +const gchar **mm_plugin_get_allowed_udev_tags (MMPlugin *self); +const mm_uint16_pair *mm_plugin_get_allowed_product_ids (MMPlugin *self); /* This method will run all pre-probing filters, to see if we can discard this * plugin from the probing logic as soon as possible. */ |