static gboolean check_connection_compatible (NMModem *modem, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingGsm *s_gsm; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); if (strcmp (nm_setting_connection_get_connection_type (s_con), NM_SETTING_GSM_SETTING_NAME)) { g_set_error (error, NM_GSM_ERROR, NM_GSM_ERROR_CONNECTION_NOT_GSM, "The connection was not a GSM connection."); return FALSE; } s_gsm = nm_connection_get_setting_gsm (connection); if (!s_gsm) { g_set_error (error, NM_GSM_ERROR, NM_GSM_ERROR_CONNECTION_INVALID, "The connection was not a valid GSM connection."); return FALSE; } return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingGsm *s_gsm; NMSettingCdma *s_cdma; NMDeviceModemCapabilities current_caps; if (!NM_DEVICE_CLASS (nm_device_modem_parent_class)->connection_compatible (device, connection, error)) return FALSE; if ( !nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME) && !nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The connection was not a modem connection.")); return FALSE; } s_gsm = nm_connection_get_setting_gsm (connection); s_cdma = nm_connection_get_setting_cdma (connection); if (!s_cdma && !s_gsm) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, _("The connection was not a valid modem connection.")); return FALSE; } current_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device)); if (!(s_gsm && MODEM_CAPS_3GPP (current_caps)) && !(s_cdma && MODEM_CAPS_3GPP2 (current_caps))) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION, _("The device is lacking capabilities required by the connection.")); return FALSE; } return TRUE; }
static gboolean extract_details_from_connection (NMConnection *connection, const char *secrets_setting_name, const char **username, const char **password, GError **error) { NMSettingConnection *s_con; NMSetting *setting; const char *setting_name; g_return_val_if_fail (connection != NULL, FALSE); g_return_val_if_fail (username != NULL, FALSE); g_return_val_if_fail (password != NULL, FALSE); if (secrets_setting_name) setting_name = secrets_setting_name; else { /* Get the setting matching the connection type */ s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); setting_name = nm_setting_connection_get_connection_type (s_con); g_assert (setting_name); /* In case of bluetooth connection, use GSM or CDMA setting */ if (strcmp (setting_name, NM_SETTING_BLUETOOTH_SETTING_NAME) == 0) { if (nm_connection_get_setting_gsm (connection)) setting_name = NM_SETTING_GSM_SETTING_NAME; else setting_name = NM_SETTING_CDMA_SETTING_NAME; } } setting = nm_connection_get_setting_by_name (connection, setting_name); if (!setting) { /* This shouldn't ever happen */ g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_FAILED, "Missing type-specific setting; no secrets could be found."); return FALSE; } if (NM_IS_SETTING_PPPOE (setting)) { *username = nm_setting_pppoe_get_username (NM_SETTING_PPPOE (setting)); *password = nm_setting_pppoe_get_password (NM_SETTING_PPPOE (setting)); } else if (NM_IS_SETTING_ADSL (setting)) { *username = nm_setting_adsl_get_username (NM_SETTING_ADSL (setting)); *password = nm_setting_adsl_get_password (NM_SETTING_ADSL (setting)); } else if (NM_IS_SETTING_GSM (setting)) { *username = nm_setting_gsm_get_username (NM_SETTING_GSM (setting)); *password = nm_setting_gsm_get_password (NM_SETTING_GSM (setting)); } else if (NM_IS_SETTING_CDMA (setting)) { *username = nm_setting_cdma_get_username (NM_SETTING_CDMA (setting)); *password = nm_setting_cdma_get_password (NM_SETTING_CDMA (setting)); } return TRUE; }
static void get_secrets_cb (GtkDialog *dialog, gint response, gpointer user_data) { SecretsRequest *req = user_data; MobileHelperSecretsInfo *info = (MobileHelperSecretsInfo *) req; GError *error = NULL; if (response == GTK_RESPONSE_OK) { if (info->capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) { NMSettingGsm *setting; setting = nm_connection_get_setting_gsm (req->connection); if (setting) { g_object_set (G_OBJECT (setting), info->secret_name, gtk_entry_get_text (info->secret_entry), NULL); } else { error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, "%s.%d (%s): no GSM setting", __FILE__, __LINE__, __func__); } } else if (info->capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) { NMSettingCdma *setting; setting = nm_connection_get_setting_cdma (req->connection); if (setting) { g_object_set (G_OBJECT (setting), info->secret_name, gtk_entry_get_text (info->secret_entry), NULL); } else { error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_INTERNAL_ERROR, "%s.%d (%s): no CDMA setting", __FILE__, __LINE__, __func__); } } else g_assert_not_reached (); } else { error = g_error_new (NM_SECRET_AGENT_ERROR, NM_SECRET_AGENT_ERROR_USER_CANCELED, "%s.%d (%s): canceled", __FILE__, __LINE__, __func__); } if (info->capability == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) applet_secrets_request_complete_setting (req, NM_SETTING_GSM_SETTING_NAME, error); else if (info->capability == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) applet_secrets_request_complete_setting (req, NM_SETTING_CDMA_SETTING_NAME, error); else g_assert_not_reached (); applet_secrets_request_free (req); g_clear_error (&error); }
static gboolean get_user_pass (NMModem *modem, NMConnection *connection, const char **user, const char **pass) { NMSettingGsm *s_gsm; s_gsm = nm_connection_get_setting_gsm (connection); if (!s_gsm) return FALSE; if (user) *user = nm_setting_gsm_get_username (s_gsm); if (pass) *pass = nm_setting_gsm_get_password (s_gsm); return TRUE; }
static gboolean complete_connection (NMModem *modem, NMConnection *connection, const GSList *existing_connections, GError **error) { NMSettingGsm *s_gsm; NMSettingPPP *s_ppp; s_gsm = nm_connection_get_setting_gsm (connection); if (!s_gsm || !nm_setting_gsm_get_apn (s_gsm)) { /* Need an APN at least */ g_set_error_literal (error, NM_SETTING_GSM_ERROR, NM_SETTING_GSM_ERROR_MISSING_PROPERTY, NM_SETTING_GSM_APN); return FALSE; } if (!nm_setting_gsm_get_number (s_gsm)) g_object_set (G_OBJECT (s_gsm), NM_SETTING_GSM_NUMBER, "*99#", NULL); s_ppp = nm_connection_get_setting_ppp (connection); if (!s_ppp) { s_ppp = (NMSettingPPP *) nm_setting_ppp_new (); g_object_set (G_OBJECT (s_ppp), NM_SETTING_PPP_LCP_ECHO_FAILURE, 5, NM_SETTING_PPP_LCP_ECHO_INTERVAL, 30, NULL); nm_connection_add_setting (connection, NM_SETTING (s_ppp)); } nm_utils_complete_generic (connection, NM_SETTING_GSM_SETTING_NAME, existing_connections, _("GSM connection %d"), NULL, FALSE); /* No IPv6 yet by default */ return TRUE; }
static gboolean connection_compatible (NMDevice *device, NMConnection *connection, GError **error) { NMSettingConnection *s_con; NMSettingGsm *s_gsm; NMSettingCdma *s_cdma; const char *ctype; NMDeviceModemCapabilities current_caps; g_return_val_if_fail (error == NULL || *error == NULL, FALSE); s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); ctype = nm_setting_connection_get_connection_type (s_con); if ( strcmp (ctype, NM_SETTING_GSM_SETTING_NAME) != 0 && strcmp (ctype, NM_SETTING_CDMA_SETTING_NAME) != 0) { g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_NOT_MODEM_CONNECTION, "The connection was not a modem connection."); return FALSE; } s_gsm = nm_connection_get_setting_gsm (connection); s_cdma = nm_connection_get_setting_cdma (connection); if (!s_cdma && !s_gsm) { g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_INVALID_MODEM_CONNECTION, "The connection was not a valid modem connection."); return FALSE; } current_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device)); if ( !(s_gsm && (current_caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS)) && !(s_cdma && (current_caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO))) { g_set_error (error, NM_DEVICE_MODEM_ERROR, NM_DEVICE_MODEM_ERROR_MISSING_DEVICE_CAPS, "The device missed capabilities required by the GSM/CDMA connection."); return FALSE; } return TRUE; }
static gboolean verify (NMSetting *setting, NMConnection *connection, GError **error) { NMSettingBluetoothPrivate *priv = NM_SETTING_BLUETOOTH_GET_PRIVATE (setting); if (!priv->bdaddr) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR); return FALSE; } if (!nm_utils_hwaddr_valid (priv->bdaddr, ETH_ALEN)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("property is invalid")); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_BDADDR); return FALSE; } if (!priv->type) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY, _("property is missing")); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE); return FALSE; } else if (!g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN) && !g_str_equal (priv->type, NM_SETTING_BLUETOOTH_TYPE_PANU)) { g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("'%s' is not a valid value for the property"), priv->type); g_prefix_error (error, "%s.%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME, NM_SETTING_BLUETOOTH_TYPE); return FALSE; } /* Make sure the corresponding 'type' setting is present */ if ( connection && !strcmp (priv->type, NM_SETTING_BLUETOOTH_TYPE_DUN)) { gboolean gsm = FALSE, cdma = FALSE; gsm = !!nm_connection_get_setting_gsm (connection); cdma = !!nm_connection_get_setting_cdma (connection); if (!gsm && !cdma) { /* We can't return MISSING_SETTING here, because we don't know * whether to prefix the message with NM_SETTING_GSM_SETTING_NAME or * NM_SETTING_CDMA_SETTING_NAME. */ g_set_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_SETTING, _("'%s' connection requires '%s' or '%s' setting"), NM_SETTING_BLUETOOTH_TYPE_DUN, NM_SETTING_GSM_SETTING_NAME, NM_SETTING_CDMA_SETTING_NAME); g_prefix_error (error, "%s: ", NM_SETTING_BLUETOOTH_SETTING_NAME); return FALSE; } } /* PANU doesn't need a 'type' setting since no further configuration * is required at the interface level. */ return TRUE; }
static void request_secrets_from_ui (NMSecretAgentSimpleRequest *request) { GPtrArray *secrets; NMSecretAgentSimpleSecret *secret; const char *title; char *msg; gboolean ok = TRUE; secrets = g_ptr_array_new_with_free_func ((GDestroyNotify) nm_secret_agent_simple_secret_free); if (nm_connection_is_type (request->connection, NM_SETTING_WIRELESS_SETTING_NAME)) { NMSettingWireless *s_wireless; GBytes *ssid; char *ssid_utf8; s_wireless = nm_connection_get_setting_wireless (request->connection); ssid = nm_setting_wireless_get_ssid (s_wireless); ssid_utf8 = nm_utils_ssid_to_utf8 (g_bytes_get_data (ssid, NULL), g_bytes_get_size (ssid)); title = _("Authentication required by wireless network"); msg = g_strdup_printf (_("Passwords or encryption keys are required to access the wireless network '%s'."), ssid_utf8); ok = add_wireless_secrets (request, secrets); } else if (nm_connection_is_type (request->connection, NM_SETTING_WIRED_SETTING_NAME)) { NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (request->connection); title = _("Wired 802.1X authentication"); msg = NULL; secret = nm_secret_agent_simple_secret_new (_("Network name"), NM_SETTING (s_con), NM_SETTING_CONNECTION_ID, FALSE); g_ptr_array_add (secrets, secret); ok = add_8021x_secrets (request, secrets); } else if (nm_connection_is_type (request->connection, NM_SETTING_PPPOE_SETTING_NAME)) { title = _("DSL authentication"); msg = NULL; ok = add_pppoe_secrets (request, secrets); } else if (nm_connection_is_type (request->connection, NM_SETTING_GSM_SETTING_NAME)) { NMSettingGsm *s_gsm = nm_connection_get_setting_gsm (request->connection); if (strv_has (request->hints, "pin")) { title = _("PIN code required"); msg = g_strdup (_("PIN code is needed for the mobile broadband device")); secret = nm_secret_agent_simple_secret_new (_("PIN"), NM_SETTING (s_gsm), NM_SETTING_GSM_PIN, FALSE); g_ptr_array_add (secrets, secret); } else { title = _("Mobile broadband network password"); msg = g_strdup_printf (_("A password is required to connect to '%s'."), nm_connection_get_id (request->connection)); secret = nm_secret_agent_simple_secret_new (_("Password"), NM_SETTING (s_gsm), NM_SETTING_GSM_PASSWORD, TRUE); g_ptr_array_add (secrets, secret); } } else if (nm_connection_is_type (request->connection, NM_SETTING_CDMA_SETTING_NAME)) { NMSettingCdma *s_cdma = nm_connection_get_setting_cdma (request->connection); title = _("Mobile broadband network password"); msg = g_strdup_printf (_("A password is required to connect to '%s'."), nm_connection_get_id (request->connection)); secret = nm_secret_agent_simple_secret_new (_("Password"), NM_SETTING (s_cdma), NM_SETTING_CDMA_PASSWORD, TRUE); g_ptr_array_add (secrets, secret); } else if (nm_connection_is_type (request->connection, NM_SETTING_BLUETOOTH_SETTING_NAME)) { NMSetting *setting; setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_GSM_SETTING_NAME); if (!setting) setting = nm_connection_get_setting_by_name (request->connection, NM_SETTING_CDMA_SETTING_NAME); title = _("Mobile broadband network password"); msg = g_strdup_printf (_("A password is required to connect to '%s'."), nm_connection_get_id (request->connection)); secret = nm_secret_agent_simple_secret_new (_("Password"), setting, "password", TRUE); g_ptr_array_add (secrets, secret); } else ok = FALSE; if (!ok) { g_ptr_array_unref (secrets); return; } g_signal_emit (request->self, signals[REQUEST_SECRETS], 0, request->request_id, title, msg, secrets); }
static GHashTable * create_connect_properties (NMConnection *connection) { NMSettingGsm *setting; NMSettingPPP *s_ppp; GHashTable *properties; const char *str; setting = nm_connection_get_setting_gsm (connection); properties = value_hash_create (); str = nm_setting_gsm_get_number (setting); if (str) value_hash_add_str (properties, "number", str); str = nm_setting_gsm_get_apn (setting); if (str) value_hash_add_str (properties, "apn", str); str = nm_setting_gsm_get_network_id (setting); if (str) value_hash_add_str (properties, "network_id", str); str = nm_setting_gsm_get_pin (setting); if (str) value_hash_add_str (properties, "pin", str); str = nm_setting_gsm_get_username (setting); if (str) value_hash_add_str (properties, "username", str); str = nm_setting_gsm_get_password (setting); if (str) value_hash_add_str (properties, "password", str); /* Add both old and new preferred modes */ switch (nm_setting_gsm_get_network_type (setting)) { case NM_SETTING_GSM_NETWORK_TYPE_UMTS_HSPA: value_hash_add_uint (properties, "network_mode", MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_ONLY); value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_3G_ONLY); break; case NM_SETTING_GSM_NETWORK_TYPE_GPRS_EDGE: value_hash_add_uint (properties, "network_mode", MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_ONLY); value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_2G_ONLY); break; case NM_SETTING_GSM_NETWORK_TYPE_PREFER_UMTS_HSPA: value_hash_add_uint (properties, "network_mode", MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_3G_PREFERRED); value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_3G_PREFERRED); break; case NM_SETTING_GSM_NETWORK_TYPE_PREFER_GPRS_EDGE: value_hash_add_uint (properties, "network_mode", MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_2G_PREFERRED); value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_2G_PREFERRED); break; case NM_SETTING_GSM_NETWORK_TYPE_PREFER_4G: /* deprecated modes not extended for 4G, so no need to set them here */ value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_4G_PREFERRED); break; case NM_SETTING_GSM_NETWORK_TYPE_4G: /* deprecated modes not extended for 4G, so no need to set them here */ value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_4G_ONLY); break; default: value_hash_add_uint (properties, "network_mode", MM_MODEM_GSM_NETWORK_DEPRECATED_MODE_ANY); value_hash_add_uint (properties, "allowed_mode", MM_MODEM_GSM_ALLOWED_MODE_ANY); break; } /* Roaming */ if (nm_setting_gsm_get_home_only (setting)) value_hash_add_bool (properties, "home_only", TRUE); /* For IpMethod == STATIC or DHCP */ s_ppp = nm_connection_get_setting_ppp (connection); if (s_ppp) { guint32 auth = MM_MODEM_GSM_ALLOWED_AUTH_UNKNOWN; if (nm_setting_ppp_get_noauth (s_ppp)) auth |= MM_MODEM_GSM_ALLOWED_AUTH_NONE; if (!nm_setting_ppp_get_refuse_pap (s_ppp)) auth |= MM_MODEM_GSM_ALLOWED_AUTH_PAP; if (!nm_setting_ppp_get_refuse_chap (s_ppp)) auth |= MM_MODEM_GSM_ALLOWED_AUTH_CHAP; if (!nm_setting_ppp_get_refuse_mschap (s_ppp)) auth |= MM_MODEM_GSM_ALLOWED_AUTH_MSCHAP; if (!nm_setting_ppp_get_refuse_mschapv2 (s_ppp)) auth |= MM_MODEM_GSM_ALLOWED_AUTH_MSCHAPV2; if (!nm_setting_ppp_get_refuse_eap (s_ppp)) auth |= MM_MODEM_GSM_ALLOWED_AUTH_EAP; if (auth != MM_MODEM_GSM_ALLOWED_AUTH_UNKNOWN) value_hash_add_uint (properties, "allowed_auth", auth); } return properties; }
gboolean nm_modem_check_connection_compatible (NMModem *self, NMConnection *connection) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); NMSettingConnection *s_con; s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); if (g_str_equal (nm_setting_connection_get_connection_type (s_con), NM_SETTING_GSM_SETTING_NAME)) { NMSettingGsm *s_gsm; const char *str; s_gsm = nm_connection_get_setting_gsm (connection); if (!s_gsm) return FALSE; str = nm_setting_gsm_get_device_id (s_gsm); if (str) { if (!priv->device_id) { nm_log_dbg (LOGD_MB, "(%s): %s/%s has device-id, device does not", priv->uid, nm_connection_get_uuid (connection), nm_connection_get_id (connection)); return FALSE; } if (strcmp (str, priv->device_id)) { nm_log_dbg (LOGD_MB, "(%s): %s/%s device-id mismatch", priv->uid, nm_connection_get_uuid (connection), nm_connection_get_id (connection)); return FALSE; } } /* SIM properties may not be available before the SIM is unlocked, so * to ensure that autoconnect works, the connection's SIM properties * are only compared if present on the device. */ str = nm_setting_gsm_get_sim_id (s_gsm); if (str && priv->sim_id) { if (strcmp (str, priv->sim_id)) { nm_log_dbg (LOGD_MB, "(%s): %s/%s sim-id mismatch", priv->uid, nm_connection_get_uuid (connection), nm_connection_get_id (connection)); return FALSE; } } str = nm_setting_gsm_get_sim_operator_id (s_gsm); if (str && priv->sim_operator_id) { if (strcmp (str, priv->sim_operator_id)) { nm_log_dbg (LOGD_MB, "(%s): %s/%s sim-operator-id mismatch", priv->uid, nm_connection_get_uuid (connection), nm_connection_get_id (connection)); return FALSE; } } } if (NM_MODEM_GET_CLASS (self)->check_connection_compatible) return NM_MODEM_GET_CLASS (self)->check_connection_compatible (self, connection); return FALSE; }
static gboolean complete_connection (NMDevice *device, NMConnection *connection, const char *specific_object, const GSList *existing_connections, GError **error) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device); NMSettingBluetooth *s_bt; const GByteArray *setting_bdaddr; struct ether_addr *devaddr = ether_aton (priv->bdaddr); const char *ctype; gboolean is_dun = FALSE, is_pan = FALSE; NMSettingGsm *s_gsm; NMSettingCdma *s_cdma; NMSettingSerial *s_serial; NMSettingPPP *s_ppp; const char *format = NULL, *preferred = NULL; s_gsm = nm_connection_get_setting_gsm (connection); s_cdma = nm_connection_get_setting_cdma (connection); s_serial = nm_connection_get_setting_serial (connection); s_ppp = nm_connection_get_setting_ppp (connection); s_bt = nm_connection_get_setting_bluetooth (connection); if (!s_bt) { s_bt = (NMSettingBluetooth *) nm_setting_bluetooth_new (); nm_connection_add_setting (connection, NM_SETTING (s_bt)); } ctype = nm_setting_bluetooth_get_connection_type (s_bt); if (ctype) { if (!strcmp (ctype, NM_SETTING_BLUETOOTH_TYPE_DUN)) is_dun = TRUE; else if (!strcmp (ctype, NM_SETTING_BLUETOOTH_TYPE_PANU)) is_pan = TRUE; } else { if (s_gsm || s_cdma) is_dun = TRUE; else if (priv->capabilities & NM_BT_CAPABILITY_NAP) is_pan = TRUE; } if (is_pan) { /* Make sure the device supports PAN */ if (!(priv->capabilities & NM_BT_CAPABILITY_NAP)) { g_set_error_literal (error, NM_SETTING_BLUETOOTH_ERROR, NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, "PAN required but Bluetooth device does not support NAP"); return FALSE; } /* PAN can't use any DUN-related settings */ if (s_gsm || s_cdma || s_serial || s_ppp) { g_set_error_literal (error, NM_SETTING_BLUETOOTH_ERROR, NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, "PAN incompatible with GSM, CDMA, or serial settings"); return FALSE; } g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_PANU, NULL); format = _("PAN connection %d"); } else if (is_dun) { /* Make sure the device supports PAN */ if (!(priv->capabilities & NM_BT_CAPABILITY_DUN)) { g_set_error_literal (error, NM_SETTING_BLUETOOTH_ERROR, NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, "DUN required but Bluetooth device does not support DUN"); return FALSE; } /* Need at least a GSM or a CDMA setting */ if (!s_gsm && !s_cdma) { g_set_error_literal (error, NM_SETTING_BLUETOOTH_ERROR, NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, "Setting requires DUN but no GSM or CDMA setting is present"); return FALSE; } g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_DUN, NULL); if (s_gsm) { format = _("GSM connection %d"); if (!nm_setting_gsm_get_number (s_gsm)) g_object_set (G_OBJECT (s_gsm), NM_SETTING_GSM_NUMBER, "*99#", NULL); } else if (s_cdma) { format = _("CDMA connection %d"); if (!nm_setting_cdma_get_number (s_cdma)) g_object_set (G_OBJECT (s_cdma), NM_SETTING_GSM_NUMBER, "#777", NULL); } else format = _("DUN connection %d"); } else { g_set_error_literal (error, NM_SETTING_BLUETOOTH_ERROR, NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, "Unknown/unhandled Bluetooth connection type"); return FALSE; } nm_utils_complete_generic (connection, NM_SETTING_BLUETOOTH_SETTING_NAME, existing_connections, format, preferred, is_dun ? FALSE : TRUE); /* No IPv6 yet for DUN */ setting_bdaddr = nm_setting_bluetooth_get_bdaddr (s_bt); if (setting_bdaddr) { /* Make sure the setting BT Address (if any) matches the device's */ if (memcmp (setting_bdaddr->data, devaddr->ether_addr_octet, ETH_ALEN)) { g_set_error_literal (error, NM_SETTING_BLUETOOTH_ERROR, NM_SETTING_BLUETOOTH_ERROR_INVALID_PROPERTY, NM_SETTING_BLUETOOTH_BDADDR); return FALSE; } } else { GByteArray *bdaddr; const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; /* Lock the connection to this device by default */ if (memcmp (devaddr->ether_addr_octet, null_mac, ETH_ALEN)) { bdaddr = g_byte_array_sized_new (ETH_ALEN); g_byte_array_append (bdaddr, devaddr->ether_addr_octet, ETH_ALEN); g_object_set (G_OBJECT (s_bt), NM_SETTING_BLUETOOTH_BDADDR, bdaddr, NULL); g_byte_array_free (bdaddr, TRUE); } } return TRUE; }