Explicitly check the PIN after modem is enabled.
This commit is contained in:
@@ -24,59 +24,53 @@ mm_modem_option_new (const char *data_device,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
enable_done (MMSerial *serial,
|
check_pin_done (MMSerial *serial,
|
||||||
GString *response,
|
GString *response,
|
||||||
GError *error,
|
GError *error,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
gboolean parsed = FALSE;
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
info->error = g_error_copy (error);
|
info->error = g_error_copy (error);
|
||||||
else {
|
else if (g_str_has_prefix (response->str, "+CPIN: ")) {
|
||||||
/* Option returns OK on +CFUN=1 right away but needs some time
|
const char *str = response->str + 7;
|
||||||
to finish initialization */
|
|
||||||
sleep (7);
|
if (g_str_has_prefix (str, "READY"))
|
||||||
|
parsed = TRUE;
|
||||||
|
else if (g_str_has_prefix (str, "SIM PIN"))
|
||||||
|
info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_SIM_PIN);
|
||||||
|
else if (g_str_has_prefix (str, "SIM PUK"))
|
||||||
|
info->error = mm_mobile_error_for_code (MM_MOBILE_ERROR_SIM_PUK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!info->error && !parsed)
|
||||||
|
info->error = g_error_new (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL,
|
||||||
|
"%s", "Could not parse PIN request results");
|
||||||
|
|
||||||
mm_callback_info_schedule (info);
|
mm_callback_info_schedule (info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_done (MMSerial *serial,
|
parent_enable_done (MMModem *modem, GError *error, gpointer user_data)
|
||||||
GString *response,
|
|
||||||
GError *error,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
MMCallbackInfo *info = (MMCallbackInfo *) user_data;
|
||||||
|
|
||||||
if (error) {
|
if (error)
|
||||||
info->error = g_error_copy (error);
|
info->error = g_error_copy (error);
|
||||||
mm_callback_info_schedule (info);
|
else if (GPOINTER_TO_INT (mm_callback_info_get_data (info, "option-enable"))) {
|
||||||
} else
|
/* Option returns OK on +CFUN=1 right away but needs some time
|
||||||
mm_serial_queue_command (serial, "+CFUN=1", 5, enable_done, user_data);
|
to finish initialization */
|
||||||
}
|
sleep (10);
|
||||||
|
|
||||||
static void
|
/* Now check the PIN explicitly, option doesn't seem to report
|
||||||
enable_flash_done (MMSerial *serial, gpointer user_data)
|
that it needs it otherwise */
|
||||||
{
|
mm_serial_queue_command (MM_SERIAL (modem), "+CPIN?", 3, check_pin_done, info);
|
||||||
mm_serial_queue_command (serial, "Z E0 V1 X4 &C1 +CMEE=1", 3, init_done, user_data);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
mm_callback_info_schedule (info);
|
||||||
disable_done (MMSerial *serial,
|
|
||||||
GString *response,
|
|
||||||
GError *error,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
mm_serial_close (serial);
|
|
||||||
mm_callback_info_schedule ((MMCallbackInfo *) user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
disable_flash_done (MMSerial *serial, gpointer user_data)
|
|
||||||
{
|
|
||||||
mm_serial_queue_command (serial, "+CFUN=0", 5, disable_done, user_data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -85,25 +79,14 @@ enable (MMModem *modem,
|
|||||||
MMModemFn callback,
|
MMModemFn callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
|
MMModem *parent_modem_iface;
|
||||||
MMCallbackInfo *info;
|
MMCallbackInfo *info;
|
||||||
|
|
||||||
/* First, reset the previously used CID */
|
|
||||||
mm_generic_gsm_set_cid (MM_GENERIC_GSM (modem), 0);
|
|
||||||
|
|
||||||
info = mm_callback_info_new (modem, callback, user_data);
|
info = mm_callback_info_new (modem, callback, user_data);
|
||||||
|
mm_callback_info_set_data (info, "option-enable", GINT_TO_POINTER (enable), NULL);
|
||||||
|
|
||||||
if (!enable) {
|
parent_modem_iface = g_type_interface_peek_parent (MM_MODEM_GET_INTERFACE (modem));
|
||||||
if (mm_serial_is_connected (MM_SERIAL (modem)))
|
parent_modem_iface->enable (modem, enable, parent_enable_done, info);
|
||||||
mm_serial_flash (MM_SERIAL (modem), 1000, disable_flash_done, info);
|
|
||||||
else
|
|
||||||
disable_flash_done (MM_SERIAL (modem), info);
|
|
||||||
} else {
|
|
||||||
if (mm_serial_open (MM_SERIAL (modem), &info->error))
|
|
||||||
mm_serial_flash (MM_SERIAL (modem), 100, enable_flash_done, info);
|
|
||||||
|
|
||||||
if (info->error)
|
|
||||||
mm_callback_info_schedule (info);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user