diff options
author | Tambet Ingo <tambet@gmail.com> | 2008-09-01 15:45:55 +0300 |
---|---|---|
committer | Tambet Ingo <tambet@gmail.com> | 2008-09-01 15:45:55 +0300 |
commit | 1bb60347b503e1aaf043548b853f19156a31b5e4 (patch) | |
tree | b3443048e8e9e3b4ae19d076a1ae235e579461d5 | |
parent | 209a6390cb5a3aaa3aeee4c8e6a23a59e705316c (diff) |
Implement reading IMEI, IMSI, manufacturer, model, and version (revision).
-rw-r--r-- | plugins/mm-modem-huawei.c | 28 | ||||
-rw-r--r-- | src/mm-callback-info.c | 91 | ||||
-rw-r--r-- | src/mm-callback-info.h | 22 | ||||
-rw-r--r-- | src/mm-generic-cdma.c | 2 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 172 |
5 files changed, 251 insertions, 64 deletions
diff --git a/plugins/mm-modem-huawei.c b/plugins/mm-modem-huawei.c index 27752865..79eb689b 100644 --- a/plugins/mm-modem-huawei.c +++ b/plugins/mm-modem-huawei.c @@ -277,21 +277,24 @@ get_network_mode_done (MMSerial *serial, const char *reply, gpointer user_data) MMCallbackInfo *info = (MMCallbackInfo *) user_data; int a, b, u1, u2; guint32 band; + guint32 result = 0; if (parse_syscfg (reply, &a, &b, &band, &u1, &u2)) { if (a == 2 && b == 1) - info->uint_result = MM_MODEM_GSM_NETWORK_MODE_PREFER_2G; + result = MM_MODEM_GSM_NETWORK_MODE_PREFER_2G; else if (a == 2 && b == 2) - info->uint_result = MM_MODEM_GSM_NETWORK_MODE_PREFER_3G; + result = MM_MODEM_GSM_NETWORK_MODE_PREFER_3G; else if (a == 13 && b == 1) - info->uint_result = MM_MODEM_GSM_NETWORK_MODE_GPRS; + result = MM_MODEM_GSM_NETWORK_MODE_GPRS; else if (a == 14 && b == 2) - info->uint_result = MM_MODEM_GSM_NETWORK_MODE_3G; + result = MM_MODEM_GSM_NETWORK_MODE_3G; } - if (info->uint_result == 0) + if (result == 0) info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Could not parse network mode results"); + else + mm_callback_info_set_result (info, GUINT_TO_POINTER (result), NULL); mm_callback_info_schedule (info); } @@ -409,23 +412,22 @@ get_band_done (MMSerial *serial, const char *reply, gpointer user_data) MMCallbackInfo *info = (MMCallbackInfo *) user_data; int a, b, u1, u2; guint32 band; - - info->uint_result = 0xdeadbeaf; + guint32 result = 0xdeadbeaf; if (parse_syscfg (reply, &a, &b, &band, &u1, &u2)) { if (band == 0x3FFFFFFF) - info->uint_result = MM_MODEM_GSM_NETWORK_BAND_ANY; + result = MM_MODEM_GSM_NETWORK_BAND_ANY; else if (band == 0x400380) - info->uint_result = MM_MODEM_GSM_NETWORK_BAND_DCS; + result = MM_MODEM_GSM_NETWORK_BAND_DCS; else if (band == 0x200000) - info->uint_result = MM_MODEM_GSM_NETWORK_BAND_PCS; + result = MM_MODEM_GSM_NETWORK_BAND_PCS; } - if (info->uint_result == 0xdeadbeaf) { - info->uint_result = 0; + if (result == 0xdeadbeaf) info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Could not parse band results"); - } + else + mm_callback_info_set_result (info, GUINT_TO_POINTER (result), NULL); mm_callback_info_schedule (info); } diff --git a/src/mm-callback-info.c b/src/mm-callback-info.c index d4fa55c5..d016aad4 100644 --- a/src/mm-callback-info.c +++ b/src/mm-callback-info.c @@ -6,36 +6,41 @@ static void callback_info_done (gpointer user_data) { - MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + gpointer result; - info->pending_id = 0; + info->pending_id = 0; - if (info->callback) - info->callback (info->modem, info->error, info->user_data); + result = mm_callback_info_get_data (info, "callback-info-result"); + + if (info->async_callback) + info->async_callback (info->modem, info->error, info->user_data); else if (info->uint_callback) - info->uint_callback (info->modem, info->uint_result, info->error, info->user_data); + info->uint_callback (info->modem, GPOINTER_TO_UINT (result), info->error, info->user_data); + else if (info->str_callback) + info->str_callback (info->modem, (const char *) result, info->error, info->user_data); - if (info->error) - g_error_free (info->error); + if (info->error) + g_error_free (info->error); - g_object_unref (info->modem); - g_datalist_clear (&info->qdata); + g_object_unref (info->modem); + g_datalist_clear (&info->qdata); - g_slice_free (MMCallbackInfo, info); + g_slice_free (MMCallbackInfo, info); } static gboolean callback_info_do (gpointer user_data) { - /* Nothing here, everything is done in callback_info_done to make sure the info->callback - always gets called, even if the pending call gets cancelled. */ - return FALSE; + /* Nothing here, everything is done in callback_info_done to make sure the info->callback + always gets called, even if the pending call gets cancelled. */ + return FALSE; } void mm_callback_info_schedule (MMCallbackInfo *info) { - info->pending_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, callback_info_do, info, callback_info_done); + info->pending_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE, callback_info_do, info, callback_info_done); } void @@ -50,15 +55,15 @@ mm_callback_info_cancel (MMCallbackInfo *info) MMCallbackInfo * mm_callback_info_new (MMModem *modem, MMModemFn callback, gpointer user_data) { - MMCallbackInfo *info; + MMCallbackInfo *info; - info = g_slice_new0 (MMCallbackInfo); - g_datalist_init (&info->qdata); - info->modem = g_object_ref (modem); - info->callback = callback; - info->user_data = user_data; + info = g_slice_new0 (MMCallbackInfo); + g_datalist_init (&info->qdata); + info->modem = g_object_ref (modem); + info->async_callback = callback; + info->user_data = user_data; - return info; + return info; } MMCallbackInfo * @@ -68,13 +73,37 @@ mm_callback_info_uint_new (MMModem *modem, { MMCallbackInfo *info; - info = g_slice_new0 (MMCallbackInfo); - g_datalist_init (&info->qdata); - info->modem = g_object_ref (modem); - info->uint_callback = callback; - info->user_data = user_data; + info = g_slice_new0 (MMCallbackInfo); + g_datalist_init (&info->qdata); + info->modem = g_object_ref (modem); + info->uint_callback = callback; + info->user_data = user_data; + + return info; +} - return info; +MMCallbackInfo * +mm_callback_info_string_new (MMModem *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + + info = g_slice_new0 (MMCallbackInfo); + g_datalist_init (&info->qdata); + info->modem = g_object_ref (modem); + info->str_callback = callback; + info->user_data = user_data; + + return info; +} + +void +mm_callback_info_set_result (MMCallbackInfo *info, + gpointer data, + GDestroyNotify destroy) +{ + mm_callback_info_set_data (info, "callback-info-result", data, destroy); } void @@ -83,16 +112,16 @@ mm_callback_info_set_data (MMCallbackInfo *info, gpointer data, GDestroyNotify destroy) { - g_datalist_id_set_data_full (&info->qdata, g_quark_from_string (key), data, + g_datalist_id_set_data_full (&info->qdata, g_quark_from_string (key), data, data ? destroy : (GDestroyNotify) NULL); } gpointer mm_callback_info_get_data (MMCallbackInfo *info, const char *key) { - GQuark quark; + GQuark quark; - quark = g_quark_try_string (key); + quark = g_quark_try_string (key); - return quark ? g_datalist_id_get_data (&info->qdata, quark) : NULL; + return quark ? g_datalist_id_get_data (&info->qdata, quark) : NULL; } diff --git a/src/mm-callback-info.h b/src/mm-callback-info.h index c8321bb1..eef2073f 100644 --- a/src/mm-callback-info.h +++ b/src/mm-callback-info.h @@ -6,13 +6,15 @@ #include "mm-modem.h" typedef struct { - GData *qdata; - MMModem *modem; - MMModemFn callback; + GData *qdata; + MMModem *modem; + + MMModemFn async_callback; MMModemUIntFn uint_callback; - guint32 uint_result; - gpointer user_data; - GError *error; + MMModemStringFn str_callback; + + gpointer user_data; + GError *error; guint pending_id; } MMCallbackInfo; @@ -24,9 +26,17 @@ MMCallbackInfo *mm_callback_info_uint_new (MMModem *modem, MMModemUIntFn callback, gpointer user_data); +MMCallbackInfo *mm_callback_info_string_new (MMModem *modem, + MMModemStringFn callback, + gpointer user_data); + void mm_callback_info_schedule (MMCallbackInfo *info); void mm_callback_info_cancel (MMCallbackInfo *info); +void mm_callback_info_set_result (MMCallbackInfo *info, + gpointer data, + GDestroyNotify destroy); + void mm_callback_info_set_data (MMCallbackInfo *info, const char *key, gpointer data, diff --git a/src/mm-generic-cdma.c b/src/mm-generic-cdma.c index 8e64a5e4..9167f418 100644 --- a/src/mm-generic-cdma.c +++ b/src/mm-generic-cdma.c @@ -191,7 +191,7 @@ get_signal_quality_done (MMSerial *serial, const char *reply, gpointer user_data info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Could not parse signal quality results"); - info->uint_result = result; + mm_callback_info_set_result (info, GUINT_TO_POINTER (result), NULL); mm_callback_info_schedule (info); } diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index 3e3fbe75..8a32c9e9 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -190,9 +190,150 @@ enable (MMModem *modem, } static void -set_pin_done (MMSerial *serial, - int reply_index, - gpointer user_data) +get_string_done (MMSerial *serial, const char *reply, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + mm_callback_info_set_result (info, g_strdup (reply), g_free); + mm_callback_info_schedule (info); +} + +static void +get_imei (MMModemGsmCard *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + const char *terminators = "\r\n"; + guint id = 0; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data); + + if (mm_serial_send_command_string (MM_SERIAL (modem), "AT+CGSN")) + id = mm_serial_get_reply (MM_SERIAL (modem), 3, terminators, get_string_done, info); + + if (!id) { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading IMEI failed."); + mm_callback_info_schedule (info); + } +} + +static void +get_imsi (MMModemGsmCard *modem, + MMModemStringFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + const char *terminators = "\r\n"; + guint id = 0; + + info = mm_callback_info_string_new (MM_MODEM (modem), callback, user_data); + + if (mm_serial_send_command_string (MM_SERIAL (modem), "AT+CIMI")) + id = mm_serial_get_reply (MM_SERIAL (modem), 3, terminators, get_string_done, info); + + if (!id) { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading IMSI failed."); + mm_callback_info_schedule (info); + } +} + + +static void +card_info_wrapper (MMModem *modem, + GError *error, + gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModemGsmCardInfoFn info_cb; + gpointer data; + + info_cb = (MMModemGsmCardInfoFn) mm_callback_info_get_data (info, "card-info-callback"); + data = mm_callback_info_get_data (info, "card-info-data"); + + info_cb (MM_MODEM_GSM_CARD (modem), + (char *) mm_callback_info_get_data (info, "card-info-manufacturer"), + (char *) mm_callback_info_get_data (info, "card-info-model"), + (char *) mm_callback_info_get_data (info, "card-info-version"), + error, data); +} + +static void +get_version_done (MMSerial *serial, const char *reply, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + + if (reply) + mm_callback_info_set_data (info, "card-info-version", g_strdup (reply), g_free); + else + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading version failed."); + + mm_callback_info_schedule (info); +} + +static void +get_model_done (MMSerial *serial, const char *reply, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + char *terminators = "\r\n"; + guint id = 0; + + if (reply && mm_serial_send_command_string (serial, "AT+CGMR")) + id = mm_serial_get_reply (serial, 5, terminators, get_version_done, info); + + if (id) + mm_callback_info_set_data (info, "card-info-model", g_strdup (reply), g_free); + else { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading model failed."); + mm_callback_info_schedule (info); + } +} + +static void +get_manufacturer_done (MMSerial *serial, const char *reply, gpointer user_data) +{ + MMCallbackInfo *info = (MMCallbackInfo *) user_data; + char *terminators = "\r\n"; + guint id = 0; + + if (reply && mm_serial_send_command_string (serial, "AT+CGMM")) + id = mm_serial_get_reply (serial, 5, terminators, get_model_done, info); + + if (id) + mm_callback_info_set_data (info, "card-info-manufacturer", g_strdup (reply), g_free); + else { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading manufacturer failed."); + mm_callback_info_schedule (info); + } +} + +static void +get_card_info (MMModemGsmCard *modem, + MMModemGsmCardInfoFn callback, + gpointer user_data) +{ + MMCallbackInfo *info; + char *terminators = "\r\n"; + guint id = 0; + + info = mm_callback_info_new (MM_MODEM (modem), card_info_wrapper, NULL); + info->user_data = info; + mm_callback_info_set_data (info, "card-info-callback", callback, NULL); + mm_callback_info_set_data (info, "card-info-data", user_data, NULL); + + if (mm_serial_send_command_string (MM_SERIAL (modem), "AT+CGMI")) + id = mm_serial_get_reply (MM_SERIAL (modem), 5, terminators, get_manufacturer_done, info); + + if (!id) { + info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading card information failed."); + mm_callback_info_schedule (info); + } +} + +static void +send_pin_done (MMSerial *serial, + int reply_index, + gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; @@ -227,7 +368,7 @@ send_pin (MMModemGsmCard *modem, command = g_strdup_printf ("AT+CPIN=\"%s\"", pin); if (mm_serial_send_command_string (MM_SERIAL (modem), command)) - id = mm_serial_wait_for_reply (MM_SERIAL (modem), 3, responses, responses, set_pin_done, info); + id = mm_serial_wait_for_reply (MM_SERIAL (modem), 3, responses, responses, send_pin_done, info); g_free (command); @@ -326,36 +467,38 @@ get_reg_status_done (MMSerial *serial, gpointer user_data) { MMCallbackInfo *info = (MMCallbackInfo *) user_data; + MMModemGsmNetworkRegStatus status; switch (reply_index) { case 0: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_IDLE; break; case 1: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_HOME; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_HOME; break; case 2: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_SEARCHING; break; case 3: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_DENIED; break; case 4: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING; break; case -1: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN; info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading registration status timed out"); break; default: - info->uint_result = (guint32) MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN; + status = MM_MODEM_GSM_NETWORK_REG_STATUS_UNKNOWN; info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Reading registration status failed"); break; } - mm_generic_gsm_set_reg_status (MM_GENERIC_GSM (serial), info->uint_result); + mm_generic_gsm_set_reg_status (MM_GENERIC_GSM (serial), status); + mm_callback_info_set_result (info, GUINT_TO_POINTER (status), NULL); mm_callback_info_schedule (info); } @@ -803,7 +946,7 @@ get_signal_quality_done (MMSerial *serial, const char *reply, gpointer user_data info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, "%s", "Could not parse signal quality results"); - info->uint_result = result; + mm_callback_info_set_result (info, GUINT_TO_POINTER (result), NULL); mm_callback_info_schedule (info); } @@ -840,6 +983,9 @@ modem_init (MMModem *modem_class) static void modem_gsm_card_init (MMModemGsmCard *class) { + class->get_imei = get_imei; + class->get_imsi = get_imsi; + class->get_info = get_card_info; class->send_pin = send_pin; } |