diff options
author | Dan Williams <dcbw@redhat.com> | 2010-10-21 16:57:37 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2010-10-21 16:57:37 -0500 |
commit | 328d2369a9dadfae786e4c524b5ff2fd0d1a9e17 (patch) | |
tree | 66eec3af08301dbb9ffbd8a26b1f558134fb289b /src/mm-modem-helpers.c | |
parent | 9fa20cd018ddbbcc95fd600ca140ac85661567bd (diff) |
core: add DeviceIdentifier property
This is computed before any PIN is entered, and thus before we can
usually get IMEI or MEID/ESN out of the device in many cases. It's
therefore not the same as EquipmentIdentifier.
This is intended to be used by UI programs for matching devices with
PIN numbers for automatic unlocking. While the PIN number is actually
*SIM* specific, no modems allow access to the IMSI before the PIN is
entered, and thus we cannot actually match the PIN with the SIM. The
device ID is the next best thing we can use and should allow auto
unlocking in most cases.
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r-- | src/mm-modem-helpers.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index 6e76f461..11950da1 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -15,6 +15,7 @@ */ #include <config.h> +#include <ctype.h> #include <glib.h> #include <string.h> #include <ctype.h> @@ -803,3 +804,67 @@ mm_gsm_string_to_access_tech (const char *string) return MM_MODEM_GSM_ACCESS_TECH_UNKNOWN; } +/*************************************************************************/ + +char * +mm_create_device_identifier (const char *vid, + const char *pid, + const char *ati, + const char *ati1, + const char *gsn, + const char *revision, + const char *model, + const char *manf, + gboolean debug) +{ + GString *devid; + GChecksum *sum; + char *p, *ret = NULL, *j = NULL, *dbg = NULL; + + /* Build up the device identifier */ + devid = g_string_sized_new (50); + if (ati) + g_string_append (devid, ati); + if (ati1) { + /* Only append "ATI1" if it's differnet than "ATI" */ + if (!ati || (strcmp (ati, ati1) != 0)) + g_string_append (devid, ati1); + } + if (gsn) + g_string_append (devid, gsn); + if (revision) + g_string_append (devid, revision); + if (model) + g_string_append (devid, model); + if (manf) + g_string_append (devid, manf); + + if (!strlen (devid->str)) + return NULL; + + p = devid->str; + if (debug) + j = dbg = g_malloc0 (strlen (devid->str) + 1); + + sum = g_checksum_new (G_CHECKSUM_SHA1); + while (*p) { + /* Strip spaces and linebreaks */ + if (!isblank (*p) && !isspace (*p) && isascii (*p)) { + g_checksum_update (sum, (const guchar *) p, 1); + if (dbg) + *j++ = *p; + } + p++; + } + ret = g_strdup (g_checksum_get_string (sum)); + g_checksum_free (sum); + + if (dbg) { + g_debug ("Device ID source '%s'", dbg); + g_debug ("Device ID '%s'", ret); + g_free (dbg); + } + + return ret; +} + |