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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user