From e4bbf230d2e5e39b80e0e85fb7745b3427cbe461 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 10 Mar 2008 21:19:45 +0000 Subject: [PATCH] 2008-03-10 Dan Williams * src/nm-cdma-device.c - (do_dial, init_modem): handle errors from nm_serial_device_send_command_string() * src/nm-gsm-device.c - (do_dial, manual_registration, automatic_registration_get_network, automatic_registration, enter_pin, check_pin, init_modem): handle errors from nm_serial_device_send_command_string() git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3414 4912f4e0-d625-0410-9fb7-b9a5a253dbdc --- ChangeLog | 11 +++++++ src/nm-cdma-device.c | 21 ++++++++++---- src/nm-gsm-device.c | 69 +++++++++++++++++++++++++++++++------------- 3 files changed, 75 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index ccef6d1615..7d9da6e318 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-03-10 Dan Williams + + * src/nm-cdma-device.c + - (do_dial, init_modem): handle errors from + nm_serial_device_send_command_string() + + * src/nm-gsm-device.c + - (do_dial, manual_registration, automatic_registration_get_network, + automatic_registration, enter_pin, check_pin, init_modem): handle + errors from nm_serial_device_send_command_string() + 2008-03-10 Dan Williams Patch based on ideas suggested by Bas Zoetekouw diff --git a/src/nm-cdma-device.c b/src/nm-cdma-device.c index c43f1bc986..8bdfd42794 100644 --- a/src/nm-cdma-device.c +++ b/src/nm-cdma-device.c @@ -112,18 +112,23 @@ do_dial (NMSerialDevice *device) char *command; guint id; char *responses[] = { "CONNECT", "BUSY", "NO DIAL TONE", "NO CARRIER", NULL }; + gboolean success; setting = NM_SETTING_CDMA (cdma_device_get_setting (NM_CDMA_DEVICE (device), NM_TYPE_SETTING_CDMA)); command = g_strconcat ("ATDT", setting->number, NULL); - nm_serial_device_send_command_string (device, command); + success = nm_serial_device_send_command_string (device, command); g_free (command); - id = nm_serial_device_wait_for_reply (device, 60, responses, dial_done, NULL); - if (id) - cdma_device_set_pending (NM_CDMA_DEVICE (device), id); - else + if (success) { + id = nm_serial_device_wait_for_reply (device, 60, responses, dial_done, NULL); + if (id) + cdma_device_set_pending (NM_CDMA_DEVICE (device), id); + else + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } else { nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } } static void @@ -154,7 +159,11 @@ init_modem (NMSerialDevice *device, gpointer user_data) guint id; char *responses[] = { "OK", "ERR", NULL }; - nm_serial_device_send_command_string (device, "ATZ E0"); + if (!nm_serial_device_send_command_string (device, "ATZ E0")) { + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + return; + } + id = nm_serial_device_wait_for_reply (device, 10, responses, init_done, NULL); if (id) diff --git a/src/nm-gsm-device.c b/src/nm-gsm-device.c index 52d0819127..331934055b 100644 --- a/src/nm-gsm-device.c +++ b/src/nm-gsm-device.c @@ -123,18 +123,23 @@ do_dial (NMSerialDevice *device) char *command; guint id; char *responses[] = { "CONNECT", "BUSY", "NO DIAL TONE", "NO CARRIER", NULL }; + gboolean success; setting = NM_SETTING_GSM (gsm_device_get_setting (NM_GSM_DEVICE (device), NM_TYPE_SETTING_GSM)); command = g_strconcat ("ATDT", setting->number, NULL); - nm_serial_device_send_command_string (device, command); + success = nm_serial_device_send_command_string (device, command); g_free (command); - id = nm_serial_device_wait_for_reply (device, 60, responses, dial_done, NULL); - if (id) - gsm_device_set_pending (NM_GSM_DEVICE (device), id); - else + if (success) { + id = nm_serial_device_wait_for_reply (device, 60, responses, dial_done, NULL); + if (id) + gsm_device_set_pending (NM_GSM_DEVICE (device), id); + else + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } else { nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } } static void @@ -166,18 +171,23 @@ manual_registration (NMSerialDevice *device) char *command; guint id; char *responses[] = { "OK", "ERROR", "ERR", NULL }; + gboolean success; setting = NM_SETTING_GSM (gsm_device_get_setting (NM_GSM_DEVICE (device), NM_TYPE_SETTING_GSM)); command = g_strdup_printf ("AT+COPS=1,2,\"%s\"", setting->network_id); - nm_serial_device_send_command_string (device, command); + success = nm_serial_device_send_command_string (device, command); g_free (command); - id = nm_serial_device_wait_for_reply (device, 30, responses, manual_registration_done, NULL); - if (id) - gsm_device_set_pending (NM_GSM_DEVICE (device), id); - else + if (success) { + id = nm_serial_device_wait_for_reply (device, 30, responses, manual_registration_done, NULL); + if (id) + gsm_device_set_pending (NM_GSM_DEVICE (device), id); + else + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } else { nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } } static void @@ -201,7 +211,11 @@ automatic_registration_get_network (NMSerialDevice *device) guint id; const char terminators[] = { '\r', '\n', '\0' }; - nm_serial_device_send_command_string (device, "AT+COPS?"); + if (!nm_serial_device_send_command_string (device, "AT+COPS?")) { + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + return; + } + id = nm_serial_device_get_reply (device, 10, terminators, get_network_done, NULL); if (id) gsm_device_set_pending (NM_GSM_DEVICE (device), id); @@ -253,7 +267,11 @@ automatic_registration (NMSerialDevice *device) guint id; char *responses[] = { "+CREG: 0,1", "+CREG: 0,5", "+CREG: 0,2", NULL }; - nm_serial_device_send_command_string (device, "AT+CREG?"); + if (!nm_serial_device_send_command_string (device, "AT+CREG?")) { + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + return; + } + id = nm_serial_device_wait_for_reply (device, 60, responses, automatic_registration_response, NULL); if (id) gsm_device_set_pending (NM_GSM_DEVICE (device), id); @@ -350,16 +368,21 @@ enter_pin (NMSerialDevice *device, gboolean retry) char *command; guint id; char *responses[] = { "OK", "ERROR", "ERR", NULL }; + gboolean success; command = g_strdup_printf ("AT+CPIN=\"%s\"", secret); - nm_serial_device_send_command_string (device, command); + success = nm_serial_device_send_command_string (device, command); g_free (command); - id = nm_serial_device_wait_for_reply (device, 3, responses, enter_pin_done, NULL); - if (id) - gsm_device_set_pending (NM_GSM_DEVICE (device), id); - else + if (success) { + id = nm_serial_device_wait_for_reply (device, 3, responses, enter_pin_done, NULL); + if (id) + gsm_device_set_pending (NM_GSM_DEVICE (device), id); + else + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } else { nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + } } else { nm_info ("%s required", secret_setting_name); nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_NEED_AUTH); @@ -403,7 +426,10 @@ check_pin (NMSerialDevice *device) guint id; char *responses[] = { "READY", "SIM PIN", "SIM PUK", "ERROR", "ERR", NULL }; - nm_serial_device_send_command_string (device, "AT+CPIN?"); + if (!nm_serial_device_send_command_string (device, "AT+CPIN?")) { + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + return; + } id = nm_serial_device_wait_for_reply (device, 3, responses, check_pin_done, NULL); if (id) @@ -440,9 +466,12 @@ init_modem (NMSerialDevice *device, gpointer user_data) guint id; char *responses[] = { "OK", "ERR", NULL }; - nm_serial_device_send_command_string (device, "ATZ E0"); - id = nm_serial_device_wait_for_reply (device, 10, responses, init_done, NULL); + if (!nm_serial_device_send_command_string (device, "ATZ E0")) { + nm_device_state_changed (NM_DEVICE (device), NM_DEVICE_STATE_FAILED); + return; + } + id = nm_serial_device_wait_for_reply (device, 10, responses, init_done, NULL); if (id) gsm_device_set_pending (NM_GSM_DEVICE (device), id); else