46
48
static guint signals[LAST_SIGNAL] = { 0 };
48
50
static void enter_pin (NMGsmDevice *device, gboolean retry);
51
static void manual_registration (NMGsmDevice *device);
49
52
static void automatic_registration (NMGsmDevice *device);
72
75
modem_wait_for_reply (NMGsmDevice *self,
77
NMSerialWaitForReplyFn callback,
78
const char **responses,
79
const char **terminators,
80
NMSerialWaitForReplyFn callback,
80
83
NMSerialDevice *serial = NM_SERIAL_DEVICE (self);
87
90
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_UNKNOWN);
91
modem_get_reply (NMGsmDevice *self,
94
const char *terminators,
95
NMSerialGetReplyFn callback)
97
NMSerialDevice *serial = NM_SERIAL_DEVICE (self);
100
if (nm_serial_device_send_command_string (serial, command))
101
id = nm_serial_device_get_reply (serial, timeout, terminators, callback, NULL);
104
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_UNKNOWN);
107
93
static NMSetting *
108
94
gsm_device_get_setting (NMGsmDevice *device, GType setting_type)
169
156
NMSettingGsm *setting;
171
char *responses[] = { "CONNECT", "BUSY", "NO DIAL TONE", "NO CARRIER", NULL };
158
const char *responses[] = { "CONNECT", "BUSY", "NO DIAL TONE", "NO CARRIER", NULL };
173
160
setting = NM_SETTING_GSM (gsm_device_get_setting (NM_GSM_DEVICE (device), NM_TYPE_SETTING_GSM));
212
200
set_apn (NMGsmDevice *device)
202
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device);
214
203
NMSettingGsm *setting;
216
char *responses[] = { "OK", "ERROR", NULL };
205
const char *responses[] = { "OK", "ERROR", NULL };
219
210
setting = NM_SETTING_GSM (gsm_device_get_setting (NM_GSM_DEVICE (device), NM_TYPE_SETTING_GSM));
220
211
if (!setting->apn) {
221
212
/* APN not set, nothing to do */
226
217
command = g_strdup_printf ("AT+CGDCONT=%d, \"IP\", \"%s\"", cid, setting->apn);
227
modem_wait_for_reply (device, command, 3, responses, responses, set_apn_done, GUINT_TO_POINTER (cid));
218
modem_wait_for_reply (device, command, 7, responses, responses, set_apn_done, GUINT_TO_POINTER (cid));
228
219
g_free (command);
232
manual_registration_done (NMSerialDevice *device,
223
manual_registration_again (gpointer data)
225
manual_registration (NM_GSM_DEVICE (data));
230
schedule_manual_registration_again (NMGsmDevice *self)
232
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (self);
234
if (priv->pending_id)
235
g_source_remove (priv->pending_id);
237
priv->pending_id = g_idle_add (manual_registration_again, self);
241
manual_registration_response (NMSerialDevice *device,
246
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device);
236
248
switch (reply_index) {
238
250
set_apn (NM_GSM_DEVICE (device));
241
nm_warning ("Manual registration timed out");
242
nm_device_state_changed (NM_DEVICE (device),
243
NM_DEVICE_STATE_FAILED,
244
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT);
253
/* Some cards (ex. Sierra AC860) don't immediately respond to commands
254
* after they are powered up with CFUN=1, but take a few seconds to come
255
* back to life. So try registration a few times.
257
if (priv->reg_tries++ < 6) {
258
schedule_manual_registration_again (NM_GSM_DEVICE (device));
260
nm_warning ("Manual registration timed out");
262
nm_device_state_changed (NM_DEVICE (device),
263
NM_DEVICE_STATE_FAILED,
264
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT);
247
268
nm_warning ("Manual registration failed");
258
279
NMSettingGsm *setting;
260
char *responses[] = { "OK", "ERROR", "ERR", NULL };
281
const char *responses[] = { "OK", "ERROR", "ERR", NULL };
262
283
setting = NM_SETTING_GSM (gsm_device_get_setting (device, NM_TYPE_SETTING_GSM));
264
285
command = g_strdup_printf ("AT+COPS=1,2,\"%s\"", setting->network_id);
265
modem_wait_for_reply (device, command, 30, responses, responses, manual_registration_done, NULL);
286
modem_wait_for_reply (device, command, 15, responses, responses, manual_registration_response, NULL);
266
287
g_free (command);
270
get_network_done (NMSerialDevice *device,
271
const char *response,
291
get_network_response (NMSerialDevice *device,
275
nm_info ("Associated with network: %s", response);
296
switch (reply_index) {
298
nm_info ("Associated with network: %s", reply);
277
301
nm_warning ("Couldn't read active network name");
279
305
set_apn (NM_GSM_DEVICE (device));
283
309
automatic_registration_get_network (NMGsmDevice *device)
285
const char terminators[] = { '\r', '\n', '\0' };
311
const char *responses[] = { "+COPS: ", NULL };
312
const char *terminators[] = { "OK", "ERROR", "ERR", NULL };
287
modem_get_reply (device, "AT+COPS?", 10, terminators, get_network_done);
314
modem_wait_for_reply (device, "AT+COPS?", 10, responses, terminators, get_network_response, NULL);
325
schedule_automatic_registration_again (NMGsmDevice *self)
327
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (self);
329
if (priv->pending_id)
330
g_source_remove (priv->pending_id);
332
priv->pending_id = g_idle_add (automatic_registration_again, self);
298
336
automatic_registration_response (NMSerialDevice *device,
341
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device);
302
343
switch (reply_index) {
304
nm_warning ("Automatic registration failed: not registered and not searching.");
305
nm_device_state_changed (NM_DEVICE (device),
306
NM_DEVICE_STATE_FAILED,
307
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING);
345
/* Try autoregistration a few times here because the card is actually
346
* responding to the query and thus we aren't waiting as long for
347
* each CREG request. Some cards (ex. Option iCON 225) return OK
348
* immediately from CFUN, but take a bit to start searching for a network.
350
if (priv->reg_tries++ < 15) {
351
/* Can happen a few times while the modem is powering up */
352
schedule_automatic_registration_again (NM_GSM_DEVICE (device));
355
nm_warning ("Automatic registration failed: not registered and not searching.");
356
nm_device_state_changed (NM_DEVICE (device),
357
NM_DEVICE_STATE_FAILED,
358
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING);
310
362
nm_info ("Registered on Home network");
311
363
automatic_registration_get_network (NM_GSM_DEVICE (device));
314
NM_GSM_DEVICE_GET_PRIVATE (device)->pending_id = g_timeout_add (1000, automatic_registration_again, device);
366
nm_info ("Searching for a network...");
367
schedule_automatic_registration_again (NM_GSM_DEVICE (device));
317
370
nm_warning ("Automatic registration failed: registration denied.");
324
377
automatic_registration_get_network (NM_GSM_DEVICE (device));
380
/* Some cards (ex. Sierra AC860) don't immediately respond to commands
381
* after they are powered up with CFUN=1, but take a few seconds to come
382
* back to life. So try registration a few times.
327
384
nm_warning ("Automatic registration timed out");
328
nm_device_state_changed (NM_DEVICE (device),
329
NM_DEVICE_STATE_FAILED,
330
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT);
385
if (priv->reg_tries++ < 6) {
386
schedule_automatic_registration_again (NM_GSM_DEVICE (device));
389
nm_device_state_changed (NM_DEVICE (device),
390
NM_DEVICE_STATE_FAILED,
391
NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT);
333
395
nm_warning ("Automatic registration failed");
342
404
automatic_registration (NMGsmDevice *device)
344
char *responses[] = { "+CREG: 0,0", "+CREG: 0,1", "+CREG: 0,2", "+CREG: 0,3", "+CREG: 0,5", NULL };
345
char *terminators[] = { "OK", "ERROR", "ERR", NULL };
406
const char *responses[] = { "+CREG: 0,0", "+CREG: 0,1", "+CREG: 0,2", "+CREG: 0,3", "+CREG: 0,5", NULL };
407
const char *terminators[] = { "OK", "ERROR", "ERR", NULL };
347
modem_wait_for_reply (device, "AT+CREG?", 60, responses, terminators, automatic_registration_response, NULL);
409
modem_wait_for_reply (device, "AT+CREG?", 15, responses, terminators, automatic_registration_response, NULL);
351
413
do_register (NMGsmDevice *device)
415
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device);
353
416
NMSettingGsm *setting;
355
418
setting = NM_SETTING_GSM (gsm_device_get_setting (device, NM_TYPE_SETTING_GSM));
357
421
if (setting->network_id)
358
422
manual_registration (device);
428
power_up_response (NMSerialDevice *device,
434
do_register (NM_GSM_DEVICE (device));
438
power_up (NMGsmDevice *device)
440
const char *responses[] = { "OK", "ERROR", "ERR", NULL };
442
nm_info ("(%s): powering up...", nm_device_get_iface (NM_DEVICE (device)));
443
modem_wait_for_reply (device, "AT+CFUN=1", 10, responses, responses, power_up_response, NULL);
364
447
init_full_done (NMSerialDevice *device,
368
452
switch (reply_index) {
370
do_register (NM_GSM_DEVICE (device));
454
power_up (NM_GSM_DEVICE (device));
373
457
nm_warning ("Modem second stage initialization timed out");
388
472
init_modem_full (NMGsmDevice *device)
390
char *responses[] = { "OK", "ERROR", "ERR", NULL };
474
const char *responses[] = { "OK", "ERROR", "ERR", NULL };
392
476
/* Send E0 too because some devices turn echo back on after CPIN which
393
477
* just breaks stuff since echo-ed commands are interpreted as replies.
396
modem_wait_for_reply (device, "ATZ E0", 10, responses, responses, init_full_done, NULL);
480
modem_wait_for_reply (device, "ATZ E0 V1 X4 &C1 +FCLASS=0", 10, responses, responses, init_full_done, NULL);
400
484
enter_pin_done (NMSerialDevice *device,
404
489
NMSettingGsm *setting;
464
549
secret_name = NM_SETTING_GSM_PUK;
467
do_register (device);
473
char *responses[] = { "OK", "ERROR", "ERR", NULL };
558
const char *responses[] = { "OK", "ERROR", "ERR", NULL };
475
560
command = g_strdup_printf ("AT+CPIN=\"%s\"", secret);
476
561
modem_wait_for_reply (device, command, 3, responses, responses, enter_pin_done, NULL);
493
578
check_pin_done (NMSerialDevice *device,
497
583
switch (reply_index) {
499
do_register (NM_GSM_DEVICE (device));
585
power_up (NM_GSM_DEVICE (device));
502
588
NM_GSM_DEVICE_GET_PRIVATE (device)->need_secret = NM_GSM_SECRET_PIN;
525
611
check_pin (NMGsmDevice *self)
527
char *responses[] = { "READY", "SIM PIN", "SIM PUK", "ERROR", "ERR", NULL };
528
char *terminators[] = { "OK", "ERROR", "ERR", NULL };
613
const char *responses[] = { "READY", "SIM PIN", "SIM PUK", "ERROR", "ERR", NULL };
614
const char *terminators[] = { "OK", "ERROR", "ERR", NULL };
530
616
modem_wait_for_reply (self, "AT+CPIN?", 3, responses, terminators, check_pin_done, NULL);
534
620
init_done (NMSerialDevice *device,
538
625
switch (reply_index) {
558
645
init_modem (NMSerialDevice *device, gpointer user_data)
560
char *responses[] = { "OK", "ERROR", "ERR", NULL };
647
const char *responses[] = { "OK", "ERROR", "ERR", NULL };
562
modem_wait_for_reply (NM_GSM_DEVICE (device), "AT E0", 10, responses, responses, init_done, NULL);
649
modem_wait_for_reply (NM_GSM_DEVICE (device), "ATZ E0 V1 X4 &C1 +FCLASS=0", 10, responses, responses, init_done, NULL);
565
652
static NMActStageReturn
681
768
NMGsmDevicePrivate *priv = NM_GSM_DEVICE_GET_PRIVATE (device);
683
772
if (priv->pending_id) {
684
773
g_source_remove (priv->pending_id);
685
774
priv->pending_id = 0;
688
NM_DEVICE_CLASS (nm_gsm_device_parent_class)->deactivate_quickly (device);
777
if (NM_DEVICE_CLASS (nm_gsm_device_parent_class)->deactivate_quickly)
778
NM_DEVICE_CLASS (nm_gsm_device_parent_class)->deactivate_quickly (device);
691
781
/*****************************************************************************/
793
883
priv->state_to_disconnected_id = 0;
796
/* If transitioning to UNAVAILBLE and we have a carrier, transition to
797
* DISCONNECTED because the device is ready to use. Otherwise the carrier-on
798
* handler will handle the transition to DISCONNECTED when the carrier is detected.
886
/* Transition to DISCONNECTED from an idle handler */
800
887
if (new_state == NM_DEVICE_STATE_UNAVAILABLE)
801
888
priv->state_to_disconnected_id = g_idle_add (unavailable_to_disconnected, self);