273
/********************************************************************/
276
AppletNewAutoConnectionCallback callback;
277
gpointer callback_data;
278
NMDeviceModemCapabilities requested_capability;
282
mobile_wizard_done (NMAMobileWizard *wizard,
284
NMAMobileWizardAccessMethod *method,
287
AutoWizardInfo *info = user_data;
288
NMConnection *connection = NULL;
290
if (!cancelled && method) {
293
const char *setting_name;
295
if (method->devtype != info->requested_capability) {
296
g_warning ("Unexpected device type");
301
connection = nm_connection_new ();
303
if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
304
setting_name = NM_SETTING_CDMA_SETTING_NAME;
305
setting = nm_setting_cdma_new ();
306
g_object_set (setting,
307
NM_SETTING_CDMA_NUMBER, "#777",
308
NM_SETTING_CDMA_USERNAME, method->username,
309
NM_SETTING_CDMA_PASSWORD, method->password,
311
nm_connection_add_setting (connection, setting);
312
} else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
313
setting_name = NM_SETTING_GSM_SETTING_NAME;
314
setting = nm_setting_gsm_new ();
315
g_object_set (setting,
316
NM_SETTING_GSM_NUMBER, "*99#",
317
NM_SETTING_GSM_USERNAME, method->username,
318
NM_SETTING_GSM_PASSWORD, method->password,
319
NM_SETTING_GSM_APN, method->gsm_apn,
321
nm_connection_add_setting (connection, setting);
323
g_assert_not_reached ();
326
setting = nm_setting_serial_new ();
327
g_object_set (setting,
328
NM_SETTING_SERIAL_BAUD, 115200,
329
NM_SETTING_SERIAL_BITS, 8,
330
NM_SETTING_SERIAL_PARITY, 'n',
331
NM_SETTING_SERIAL_STOPBITS, 1,
333
nm_connection_add_setting (connection, setting);
335
nm_connection_add_setting (connection, nm_setting_ppp_new ());
337
setting = nm_setting_connection_new ();
338
id = utils_create_mobile_connection_id (method->provider_name, method->plan_name);
339
uuid = nm_utils_uuid_generate ();
340
g_object_set (setting,
341
NM_SETTING_CONNECTION_ID, id,
342
NM_SETTING_CONNECTION_TYPE, setting_name,
343
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
344
NM_SETTING_CONNECTION_UUID, uuid,
348
nm_connection_add_setting (connection, setting);
352
(*(info->callback)) (connection, TRUE, cancelled, info->callback_data);
355
nma_mobile_wizard_destroy (wizard);
360
mobile_helper_wizard (NMDeviceModemCapabilities capabilities,
361
AppletNewAutoConnectionCallback callback,
362
gpointer callback_data)
364
NMAMobileWizard *wizard;
365
AutoWizardInfo *info;
366
NMAMobileWizardAccessMethod *method;
367
NMDeviceModemCapabilities wizard_capability;
369
/* Convert the input capabilities mask into a single value */
370
if (capabilities & NM_DEVICE_MODEM_CAPABILITY_LTE)
371
/* All LTE modems treated as GSM/UMTS for the wizard */
372
wizard_capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
373
else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
374
wizard_capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
375
else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
376
wizard_capability = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
378
g_warning ("Unknown modem capabilities (0x%X): can't launch wizard", capabilities);
382
info = g_malloc0 (sizeof (AutoWizardInfo));
383
info->callback = callback;
384
info->callback_data = callback_data;
385
info->requested_capability = wizard_capability;
387
wizard = nma_mobile_wizard_new (NULL,
394
nma_mobile_wizard_present (wizard);
398
/* Fall back to something */
399
method = g_malloc0 (sizeof (NMAMobileWizardAccessMethod));
400
method->devtype = wizard_capability;
402
if (wizard_capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
403
method->provider_name = _("GSM");
404
else if (wizard_capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
405
method->provider_name = _("CDMA");
407
g_assert_not_reached ();
409
mobile_wizard_done (NULL, FALSE, method, info);
415
/********************************************************************/
418
save_pin_cb (GnomeKeyringResult result, guint32 val, gpointer user_data)
420
if (result != GNOME_KEYRING_RESULT_OK)
421
g_warning ("%s: result %d", (const char *) user_data, result);
425
mobile_helper_save_pin_in_keyring (const char *devid,
429
GnomeKeyringAttributeList *attributes;
430
GnomeKeyringAttribute attr;
434
name = g_strdup_printf (_("PIN code for SIM card '%s' on '%s'"),
435
simid ? simid : "unknown",
438
attributes = gnome_keyring_attribute_list_new ();
439
attr.name = g_strdup ("devid");
440
attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
441
attr.value.string = g_strdup (devid);
442
g_array_append_val (attributes, attr);
445
attr.name = g_strdup ("simid");
446
attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
447
attr.value.string = g_strdup (simid);
448
g_array_append_val (attributes, attr);
451
error_msg = g_strdup_printf ("Saving PIN code in keyring for devid:%s simid:%s failed",
452
devid, simid ? simid : "(unknown)");
454
gnome_keyring_item_create (NULL,
455
GNOME_KEYRING_ITEM_GENERIC_SECRET,
462
(GDestroyNotify) g_free);
464
gnome_keyring_attribute_list_free (attributes);
468
delete_pin_cb (GnomeKeyringResult result, gpointer user_data)
474
delete_pins_find_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
478
if (result == GNOME_KEYRING_RESULT_OK) {
479
for (iter = list; iter; iter = g_list_next (iter)) {
480
GnomeKeyringFound *found = iter->data;
482
gnome_keyring_item_delete (found->keyring, found->item_id, delete_pin_cb, NULL, NULL);
488
mobile_helper_delete_pin_in_keyring (const char *devid)
490
gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
495
GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
500
/********************************************************************/
503
free_secrets_info (SecretsRequest *req)
505
MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req;
508
gtk_widget_hide (info->dialog);
509
gtk_widget_destroy (info->dialog);
512
g_free (info->secret_name);
516
get_secrets_cb (GtkDialog *dialog,
520
SecretsRequest *req = user_data;
521
MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req;
522
GError *error = NULL;
524
if (response == GTK_RESPONSE_OK) {
525
if (info->capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
526
NMSettingGsm *setting;
528
setting = nm_connection_get_setting_gsm (req->connection);
530
g_object_set (G_OBJECT (setting),
531
info->secret_name, gtk_entry_get_text (info->secret_entry),
534
error = g_error_new (NM_SECRET_AGENT_ERROR,
535
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
536
"%s.%d (%s): no GSM setting",
537
__FILE__, __LINE__, __func__);
539
} else if (info->capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
540
NMSettingCdma *setting;
542
setting = nm_connection_get_setting_cdma (req->connection);
544
g_object_set (G_OBJECT (setting),
545
info->secret_name, gtk_entry_get_text (info->secret_entry),
548
error = g_error_new (NM_SECRET_AGENT_ERROR,
549
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
550
"%s.%d (%s): no CDMA setting",
551
__FILE__, __LINE__, __func__);
554
g_assert_not_reached ();
556
error = g_error_new (NM_SECRET_AGENT_ERROR,
557
NM_SECRET_AGENT_ERROR_USER_CANCELED,
558
"%s.%d (%s): canceled",
559
__FILE__, __LINE__, __func__);
562
if (info->capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
563
applet_secrets_request_complete_setting (req, NM_SETTING_GSM_SETTING_NAME, error);
564
else if (info->capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
565
applet_secrets_request_complete_setting (req, NM_SETTING_CDMA_SETTING_NAME, error);
567
g_assert_not_reached ();
569
applet_secrets_request_free (req);
570
g_clear_error (&error);
574
pin_entry_changed (GtkEditable *editable, gpointer user_data)
576
GtkWidget *ok_button = GTK_WIDGET (user_data);
579
gboolean valid = FALSE;
582
s = gtk_entry_get_text (GTK_ENTRY (editable));
585
if ((len >= 4) && (len <= 8)) {
587
for (i = 0; i < len; i++) {
588
if (!g_ascii_isdigit (s[i])) {
596
gtk_widget_set_sensitive (ok_button, valid);
600
ask_for_pin (GtkEntry **out_secret_entry)
603
GtkWidget *w = NULL, *ok_button = NULL;
604
GtkBox *box = NULL, *vbox = NULL;
606
dialog = GTK_DIALOG (gtk_dialog_new ());
607
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
608
gtk_window_set_title (GTK_WINDOW (dialog), _("PIN code required"));
610
ok_button = gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
611
ok_button = gtk_dialog_add_button (dialog, GTK_STOCK_OK, GTK_RESPONSE_OK);
612
gtk_window_set_default (GTK_WINDOW (dialog), ok_button);
614
vbox = GTK_BOX (gtk_dialog_get_content_area (dialog));
616
w = gtk_label_new (_("PIN code is needed for the mobile broadband device"));
617
gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
619
w = gtk_alignment_new (0.5, 0.5, 0, 1.0);
620
gtk_box_pack_start (vbox, w, TRUE, TRUE, 0);
622
#if GTK_CHECK_VERSION(3,1,6)
623
box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6));
625
box = GTK_BOX (gtk_hbox_new (FALSE, 6));
627
gtk_container_set_border_width (GTK_CONTAINER (box), 6);
628
gtk_container_add (GTK_CONTAINER (w), GTK_WIDGET (box));
630
gtk_box_pack_start (box, gtk_label_new ("PIN:"), FALSE, FALSE, 0);
632
w = gtk_entry_new ();
633
*out_secret_entry = GTK_ENTRY (w);
634
gtk_entry_set_max_length (GTK_ENTRY (w), 8);
635
gtk_entry_set_width_chars (GTK_ENTRY (w), 8);
636
gtk_entry_set_activates_default (GTK_ENTRY (w), TRUE);
637
gtk_entry_set_visibility (GTK_ENTRY (w), FALSE);
638
gtk_box_pack_start (box, w, FALSE, FALSE, 0);
639
g_signal_connect (w, "changed", G_CALLBACK (pin_entry_changed), ok_button);
640
pin_entry_changed (GTK_EDITABLE (w), ok_button);
642
gtk_widget_show_all (GTK_WIDGET (vbox));
643
return GTK_WIDGET (dialog);
647
mobile_helper_get_secrets (NMDeviceModemCapabilities capabilities,
651
MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req;
653
GtkEntry *secret_entry = NULL;
655
applet_secrets_request_set_free_func (req, free_secrets_info);
657
if (!req->hints || !g_strv_length (req->hints)) {
659
NM_SECRET_AGENT_ERROR,
660
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
661
"%s.%d (%s): missing secrets hints.",
662
__FILE__, __LINE__, __func__);
665
info->secret_name = g_strdup (req->hints[0]);
667
/* Convert the input capabilities mask into a single value */
668
if (capabilities & NM_DEVICE_MODEM_CAPABILITY_LTE)
669
/* All LTE modems treated as GSM/UMTS for the settings */
670
info->capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
671
else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)
672
info->capability = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS;
673
else if (capabilities & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO)
674
info->capability = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO;
677
NM_SECRET_AGENT_ERROR,
678
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
679
"%s.%d (%s): unknown modem capabilities (0x%X).",
680
__FILE__, __LINE__, __func__, capabilities);
684
if (!strcmp (info->secret_name, NM_SETTING_GSM_PIN)) {
685
widget = ask_for_pin (&secret_entry);
686
} else if (!strcmp (info->secret_name, NM_SETTING_GSM_PASSWORD) ||
687
!strcmp (info->secret_name, NM_SETTING_CDMA_PASSWORD))
688
widget = applet_mobile_password_dialog_new (req->connection, &secret_entry);
691
NM_SECRET_AGENT_ERROR,
692
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
693
"%s.%d (%s): unknown secrets hint '%s'.",
694
__FILE__, __LINE__, __func__, info->secret_name);
697
info->dialog = widget;
698
info->secret_entry = secret_entry;
700
if (!widget || !secret_entry) {
702
NM_SECRET_AGENT_ERROR,
703
NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
704
"%s.%d (%s): error asking for mobile secrets.",
705
__FILE__, __LINE__, __func__);
709
g_signal_connect (widget, "response", G_CALLBACK (get_secrets_cb), info);
711
gtk_window_set_position (GTK_WINDOW (widget), GTK_WIN_POS_CENTER_ALWAYS);
712
gtk_widget_realize (GTK_WIDGET (widget));
713
gtk_window_present (GTK_WINDOW (widget));
718
/********************************************************************/
721
mobile_helper_get_icon (NMDevice *device,
723
NMConnection *connection,
724
GdkPixbuf **out_pixbuf,
725
char **out_indicator_icon,
731
gboolean quality_valid)
733
NMSettingConnection *s_con;
736
id = nm_device_get_iface (NM_DEVICE (device));
738
s_con = nm_connection_get_setting_connection (connection);
739
id = nm_setting_connection_get_id (s_con);
743
case NM_DEVICE_STATE_PREPARE:
744
*tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
746
case NM_DEVICE_STATE_CONFIG:
747
*tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
749
case NM_DEVICE_STATE_NEED_AUTH:
750
*tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
752
case NM_DEVICE_STATE_IP_CONFIG:
753
*tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
755
case NM_DEVICE_STATE_ACTIVATED:
756
*out_pixbuf = mobile_helper_get_status_pixbuf (quality,
762
*out_indicator_icon = mobile_helper_get_quality_icon (quality_valid ?
766
if ((mb_state != MB_STATE_UNKNOWN) && quality_valid) {
767
gboolean roaming = (mb_state == MB_STATE_ROAMING);
769
*tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
772
roaming ? _("roaming") : "");
774
*tip = g_strdup_printf (_("Mobile broadband connection '%s' active"), id);
781
/********************************************************************/
784
mobile_helper_parse_3gpp_operator_name (NMAMobileProvidersDatabase **mpd, /* I/O */
788
NMAMobileProvider *provider;
791
g_assert (mpd != NULL);
793
/* Some devices return the MCC/MNC if they haven't fully initialized
794
* or gotten all the info from the network yet. Handle that.
797
orig_len = orig ? strlen (orig) : 0;
799
/* If the operator name isn't valid, maybe we can look up the MCC/MNC
800
* from the operator code instead.
802
if (op_code && strlen (op_code)) {
804
orig_len = strlen (orig);
807
} else if (orig_len < 5 || orig_len > 6)
808
return g_strdup (orig); /* not an MCC/MNC */
810
for (i = 0; i < orig_len; i++) {
811
if (!isdigit (orig[i]))
812
return strdup (orig);
815
/* At this point we have a 5 or 6 character all-digit string; that's
816
* probably an MCC/MNC. Look that up.
820
GError *error = NULL;
822
*mpd = nma_mobile_providers_database_new_sync (NULL, NULL, NULL, &error);
824
g_warning ("Couldn't read database: %s", error->message);
825
g_error_free (error);
826
return strdup (orig);
830
provider = nma_mobile_providers_database_lookup_3gpp_mcc_mnc (*mpd, orig);
831
return (provider ? g_strdup (nma_mobile_provider_get_name (provider)) : NULL);
835
mobile_helper_parse_3gpp2_operator_name (NMAMobileProvidersDatabase **mpd, /* I/O */
838
NMAMobileProvider *provider;
840
g_assert (mpd != NULL);
846
GError *error = NULL;
848
*mpd = nma_mobile_providers_database_new_sync (NULL, NULL, NULL, &error);
850
g_warning ("Couldn't read database: %s", error->message);
851
g_error_free (error);
856
provider = nma_mobile_providers_database_lookup_cdma_sid (*mpd, sid);
857
return (provider ? g_strdup (nma_mobile_provider_get_name (provider)) : NULL);