2008-03-10 Dan Williams <dcbw@redhat.com>

* 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
This commit is contained in:
Dan Williams 2008-03-10 21:19:45 +00:00
parent 43fe2c90c4
commit e4bbf230d2
3 changed files with 75 additions and 26 deletions

View file

@ -1,3 +1,14 @@
2008-03-10 Dan Williams <dcbw@redhat.com>
* 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 <dcbw@redhat.com>
Patch based on ideas suggested by Bas Zoetekouw <bas@debian.org>

View file

@ -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)

View file

@ -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