diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2017-10-16 21:33:15 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-12-05 10:58:29 +0100 |
commit | c4bf785d6771764cbee116e36c6780462223c4fa (patch) | |
tree | fb3b8640074d727c4371077628410a4b5b41e4e0 /src/mm-context.c | |
parent | 7bfd5270ef846582d97314f3e9e550129317d631 (diff) |
filter: allow selection of filter policy on startup
Added a new '--filter-policy=[POLICY]' option in the daemon, which
allows selecting between the supported filter policies. For now, only
two policies are defined:
* default: the default policy used by ModemManager, where it tries
to probe and detect as many modem ports as possible.
* whitelist-only: only devices explicitly tagged via udev (with the
ID_MM_DEVICE_PROCESS tag) will be probed and used.
Diffstat (limited to 'src/mm-context.c')
-rw-r--r-- | src/mm-context.c | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/src/mm-context.c b/src/mm-context.c index b7d2a281..3dac3903 100644 --- a/src/mm-context.c +++ b/src/mm-context.c @@ -16,6 +16,10 @@ #include <config.h> #include <stdlib.h> +#include <ModemManager.h> +#define _LIBMM_INSIDE_MM +#include <libmm-glib.h> + #include "mm-context.h" /*****************************************************************************/ @@ -31,14 +35,42 @@ # define NO_AUTO_SCAN_DEFAULT TRUE #endif -static gboolean help_flag; -static gboolean version_flag; -static gboolean debug; -static gboolean no_auto_scan = NO_AUTO_SCAN_DEFAULT; -static const gchar *initial_kernel_events; +static gboolean help_flag; +static gboolean version_flag; +static gboolean debug; +static MMFilterRule filter_policy = MM_FILTER_POLICY_DEFAULT; +static gboolean no_auto_scan = NO_AUTO_SCAN_DEFAULT; +static const gchar *initial_kernel_events; + +static gboolean +filter_policy_option_arg (const gchar *option_name, + const gchar *value, + gpointer data, + GError **error) +{ + if (!g_ascii_strcasecmp (value, "default")) { + filter_policy = MM_FILTER_POLICY_DEFAULT; + return TRUE; + } + + if (!g_ascii_strcasecmp (value, "whitelist-only")) { + filter_policy = MM_FILTER_POLICY_WHITELIST_ONLY; + return TRUE; + } + + g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, + "Invalid filter policy value given: %s", + value); + return FALSE; +} static const GOptionEntry entries[] = { { + "filter-policy", 0, 0, G_OPTION_ARG_CALLBACK, filter_policy_option_arg, + "Filter policy: one of DEFAULT, WHITELIST-ONLY", + "[POLICY]" + }, + { "no-auto-scan", 0, NO_AUTO_SCAN_OPTION_FLAG, G_OPTION_ARG_NONE, &no_auto_scan, "Don't auto-scan looking for devices", NULL @@ -84,6 +116,12 @@ mm_context_get_no_auto_scan (void) return no_auto_scan; } +MMFilterRule +mm_context_get_filter_policy (void) +{ + return filter_policy; +} + /*****************************************************************************/ /* Log context */ |