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.
This commit is contained in:

committed by
Dan Williams

parent
0e02771e5c
commit
51c4626471
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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 */
|
||||
|
@@ -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
|
||||
|
@@ -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. */
|
||||
|
Reference in New Issue
Block a user