static void dun_connect_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); GError *error = NULL; char *device; g_message ("%s: processing Connect reply", __func__); if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &device, G_TYPE_INVALID)) { dun_error (self, __func__, error, _("failed to connect to the phone.")); g_clear_error (&error); goto out; } if (!device || !strlen (device)) { dun_error (self, __func__, NULL, _("failed to connect to the phone.")); g_free (device); goto out; } g_free (priv->rfcomm_iface); priv->rfcomm_iface = device; g_message ("%s: new rfcomm interface '%s'", __func__, device); out: g_message ("%s: finished", __func__); }
static void dun_connect_cb (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data) { PluginInfo *info = user_data; GError *error = NULL; char *device; g_message ("%s: processing Connect reply", __func__); if (!dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_STRING, &device, G_TYPE_INVALID)) { dun_error (info, __func__, error, _("failed to connect to the phone.")); g_clear_error (&error); goto out; } if (!device || !strlen (device)) { dun_error (info, __func__, NULL, _("failed to connect to the phone.")); g_free (device); goto out; } info->rfcomm_iface = device; g_message ("%s: new rfcomm interface '%s'", __func__, device); out: g_message ("%s: finished", __func__); }
static void wizard_done_cb (MobileWizard *self, gboolean canceled, MobileWizardAccessMethod *method, gpointer user_data) { PluginInfo *info = user_data; BMConnection *connection = NULL; BMAGConfSettings *gconf_settings; BMAGConfConnection *exported; GByteArray *mac; BMSetting *s_bt; g_message ("%s: mobile wizard done", __func__); if (canceled || !method) { dun_error (info, __func__, NULL, _("Mobile wizard was canceled")); return; } if (method->devtype == BM_DEVICE_TYPE_CDMA) connection = dun_new_cdma (method); else if (method->devtype == BM_DEVICE_TYPE_GSM) connection = dun_new_gsm (method); else { dun_error (info, __func__, NULL, _("Unknown phone device type (not GSM or CDMA)")); return; } mobile_wizard_destroy (info->wizard); info->wizard = NULL; g_assert (connection); /* The Bluetooth settings */ mac = get_array_from_bdaddr (info->bdaddr); g_assert (mac); s_bt = bm_setting_bluetooth_new (); g_object_set (G_OBJECT (s_bt), BM_SETTING_BLUETOOTH_BDADDR, mac, BM_SETTING_BLUETOOTH_TYPE, BM_SETTING_BLUETOOTH_TYPE_DUN, NULL); g_byte_array_free (mac, TRUE); bm_connection_add_setting (connection, s_bt); g_message ("%s: adding new setting to GConf", __func__); gconf_settings = nma_gconf_settings_new (NULL); exported = nma_gconf_settings_add_connection (gconf_settings, connection); if (exported) info->dun_connection = BM_SETTINGS_CONNECTION_INTERFACE (exported); g_message ("%s: success!", __func__); dun_cleanup (info, _("Your phone is now ready to use!"), FALSE); }
static void wizard_done_cb (NMAMobileWizard *wizard, gboolean canceled, NMAMobileWizardAccessMethod *method, gpointer user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); NMConnection *connection = NULL; NMSetting *s_bt; g_return_if_fail (wizard == priv->wizard); g_message ("%s: mobile wizard done", __func__); if (canceled || !method) { dun_error (self, __func__, NULL, _("Mobile wizard was canceled")); return; } if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) connection = dun_new_cdma (method); else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) connection = dun_new_gsm (method); else { dun_error (self, __func__, NULL, _("Unknown phone device type (not GSM or CDMA)")); return; } nma_mobile_wizard_destroy (priv->wizard); priv->wizard = NULL; g_assert (connection); /* The Bluetooth settings */ s_bt = nm_setting_bluetooth_new (); g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, priv->bdaddr_array, NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_DUN, NULL); nm_connection_add_setting (connection, s_bt); g_message ("%s: adding new setting", __func__); /* Add the connection to the settings service */ nm_remote_settings_add_connection (priv->settings, connection, dun_add_cb, self); g_message ("%s: waiting for add connection result...", __func__); }
static void start_wizard (NmaBtDevice *self, const gchar *path, NMDeviceType devtype) { NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); if (devtype == NM_DEVICE_TYPE_UNKNOWN) { dun_error (self, __func__, NULL, _("unknown modem type.")); return; } if (priv->wizard) { g_message ("%s: (%s) oops! not starting Wizard as one is already in progress", __func__, path); return; } g_message ("%s: (%s) starting the mobile wizard", __func__, path); g_source_remove (priv->dun_timeout_id); priv->dun_timeout_id = 0; /* Start the mobile wizard */ priv->wizard = nma_mobile_wizard_new (priv->parent_window, priv->window_group, devtype, FALSE, wizard_done_cb, self); nma_mobile_wizard_present (priv->wizard); }
static gboolean dun_timeout_cb (gpointer user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); NMA_BT_DEVICE_GET_PRIVATE (self)->dun_timeout_id = 0; dun_error (self, __func__, NULL, _("timed out detecting phone details.")); return FALSE; }
static gboolean dun_timeout_cb (gpointer user_data) { PluginInfo *info = user_data; info->dun_timeout_id = 0; dun_error (info, __func__, NULL, _("timed out detecting phone details.")); return FALSE; }
static void dun_property_changed (DBusGProxy *proxy, const char *property, GValue *value, gpointer user_data) { NmaBtDevice *self = NMA_BT_DEVICE (user_data); gboolean connected; if (strcmp (property, "Connected") == 0) { connected = g_value_get_boolean (value); g_message ("%s: device property Connected changed to %s", __func__, connected ? "TRUE" : "FALSE"); if (connected) { /* Wait for MM here ? */ } else dun_error (self, __func__, NULL, _("unexpectedly disconnected from the phone.")); } }
static void dun_property_changed (DBusGProxy *proxy, const char *property, GValue *value, gpointer user_data) { PluginInfo *info = user_data; gboolean connected; if (strcmp (property, "Connected")) return; connected = g_value_get_boolean (value); g_message ("%s: device property Connected changed to %s", __func__, connected ? "TRUE" : "FALSE"); if (connected) { /* Wait for MM here ? */ } else dun_error (info, __func__, NULL, _("unexpectedly disconnected from the phone.")); }
void nma_bt_device_cancel_dun (NmaBtDevice *device) { dun_error (device, __func__, NULL, _("The default Bluetooth adapter must be enabled before setting up a Dial-Up-Networking connection.")); }
static void dun_start (NmaBtDevice *self) { NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); gboolean have_mm = FALSE, have_mm1 = TRUE; g_message ("%s: starting DUN device discovery...", __func__); _set_status (self, _("Detecting phone configuration...")); /* ModemManager stuff */ priv->mm_proxy = dbus_g_proxy_new_for_name (priv->bus, MM_SERVICE, MM_PATH, MM_INTERFACE); g_assert (priv->mm_proxy); have_mm = _name_has_owner (priv->bus, MM_SERVICE); dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, G_TYPE_BOXED, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->mm_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->mm_proxy, "DeviceAdded", G_CALLBACK (modem_added), self, NULL); dbus_g_proxy_add_signal (priv->mm_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->mm_proxy, "DeviceRemoved", G_CALLBACK (modem_removed), self, NULL); #if WITH_MODEM_MANAGER_1 /* ModemManager1 stuff */ { priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL); if (priv->dbus_connection) { priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, NULL, NULL); if (priv->modem_manager_1) { g_signal_connect (priv->modem_manager_1, "object-added", G_CALLBACK (modem_object_added), self); g_signal_connect (priv->modem_manager_1, "object-removed", G_CALLBACK (modem_object_removed), self); } } have_mm1 = !!priv->modem_manager_1; } #endif /* Ensure at least one of ModemManager or ModemManager1 are around */ if (!have_mm && !have_mm1) { dun_error (self, __func__, NULL, _("ModemManager is not running")); return; } /* Bluez */ priv->dun_proxy = dbus_g_proxy_new_for_name (priv->bus, BLUEZ_SERVICE, priv->object_path, BLUEZ_SERIAL_INTERFACE); g_assert (priv->dun_proxy); priv->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, self); g_message ("%s: calling Connect...", __func__); /* Watch for BT device property changes */ dbus_g_object_register_marshaller (_nma_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->dun_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->dun_proxy, "PropertyChanged", G_CALLBACK (dun_property_changed), self, NULL); /* Request a connection to the device and get the port */ dbus_g_proxy_begin_call_with_timeout (priv->dun_proxy, "Connect", dun_connect_cb, self, NULL, 20000, G_TYPE_STRING, "dun", G_TYPE_INVALID); g_message ("%s: waiting for Connect success...", __func__); }
static void dun_start (PluginInfo *info) { GError *error = NULL; GtkTreeIter iter; g_message ("%s: starting DUN device discovery...", __func__); /* Set up dbus */ info->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error || !info->bus) { dun_error (info, __func__, error, _("could not connect to the system bus.")); g_clear_error (&error); goto out; } gtk_label_set_text (GTK_LABEL (info->label), _("Detecting phone configuration...")); /* Start the spinner */ if (!info->spinner) { info->spinner = nma_bling_spinner_new (); gtk_box_pack_start (GTK_BOX (info->hbox), info->spinner, FALSE, FALSE, 6); } nma_bling_spinner_start (BMA_BLING_SPINNER (info->spinner)); gtk_widget_show_all (info->hbox); gtk_widget_set_sensitive (info->dun_button, FALSE); /* ModemManager stuff */ info->mm_proxy = dbus_g_proxy_new_for_name (info->bus, MM_SERVICE, MM_PATH, MM_INTERFACE); g_assert (info->mm_proxy); dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, G_TYPE_BOXED, G_TYPE_INVALID); dbus_g_proxy_add_signal (info->mm_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (info->mm_proxy, "DeviceAdded", G_CALLBACK (modem_added), info, NULL); dbus_g_proxy_add_signal (info->mm_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (info->mm_proxy, "DeviceRemoved", G_CALLBACK (modem_removed), info, NULL); /* Get the device we're looking for */ info->dun_proxy = NULL; if (get_device_iter (info->btmodel, info->bdaddr, &iter)) gtk_tree_model_get (info->btmodel, &iter, BLUETOOTH_COLUMN_PROXY, &info->dun_proxy, -1); if (info->dun_proxy) { info->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, info); dbus_g_proxy_set_interface (info->dun_proxy, BLUEZ_SERIAL_INTERFACE); g_message ("%s: calling Connect...", __func__); /* Watch for BT device property changes */ dbus_g_object_register_marshaller (nma_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_add_signal (info->dun_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_connect_signal (info->dun_proxy, "PropertyChanged", G_CALLBACK (dun_property_changed), info, NULL); /* Request a connection to the device and get the port */ dbus_g_proxy_begin_call_with_timeout (info->dun_proxy, "Connect", dun_connect_cb, info, NULL, 20000, G_TYPE_STRING, "dun", G_TYPE_INVALID); } else dun_error (info, __func__, error, _("could not find the Bluetooth device.")); out: g_message ("%s: finished", __func__); }