static gint sort_nsps (gconstpointer a, gconstpointer b) { const char *name_a = NULL, *name_b = NULL; if (a) name_a = nm_wimax_nsp_get_name (NM_WIMAX_NSP (a)); if (b) name_b = nm_wimax_nsp_get_name (NM_WIMAX_NSP (b)); return g_strcmp0 (name_a, name_b); }
static GtkWidget * new_nsp_menu_item (NMDeviceWimax *device, NMConnection *connection, gboolean active, NMWimaxNsp *nsp, NMApplet *applet) { GtkWidget *item; WimaxMenuItemInfo *info; #ifdef ENABLE_INDICATOR char *text = NULL; GtkWidget *signal_icon = NULL; #endif g_return_val_if_fail (nsp != NULL, NULL); #ifndef ENABLE_INDICATOR item = nm_mb_menu_item_new (nm_wimax_nsp_get_name (nsp), nm_wimax_nsp_get_signal_quality (nsp), NULL, active, MB_TECH_WIMAX, nsp_type_to_mb_state (nm_wimax_nsp_get_network_type (nsp)), TRUE, applet); #else text = g_strdup (nm_wimax_nsp_get_name (nsp)); item = gtk_image_menu_item_new_with_label (text); g_free (text); text = mobile_helper_get_quality_icon (nm_wimax_nsp_get_signal_quality (nsp), applet); signal_icon = gtk_image_new_from_icon_name (text, GTK_ICON_SIZE_LARGE_TOOLBAR); g_free (text); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), signal_icon); gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE); #endif /* ENABLE_INDICATOR */ gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); info = g_slice_new0 (WimaxMenuItemInfo); info->applet = applet; info->device = g_object_ref (G_OBJECT (device)); info->connection = connection ? g_object_ref (connection) : NULL; info->nsp = g_object_ref (nsp); g_signal_connect_data (item, "activate", G_CALLBACK (wimax_menu_item_activate), info, (GClosureNotify) wimax_menu_item_info_destroy, 0); return item; }
static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NMWimaxNsp *nsp = NM_WIMAX_NSP (object); _nm_object_ensure_inited (NM_OBJECT (object)); switch (prop_id) { case PROP_NAME: g_value_set_string (value, nm_wimax_nsp_get_name (nsp)); break; case PROP_SIGNAL_QUALITY: g_value_set_uint (value, nm_wimax_nsp_get_signal_quality (nsp)); break; case PROP_NETWORK_TYPE: g_value_set_uint (value, nm_wimax_nsp_get_network_type (nsp)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
/** * nm_wimax_nsp_connection_valid: * @nsp: an #NMWimaxNsp to validate @connection against * @connection: an #NMConnection to validate against @nsp * * Validates a given connection against a given WiMAX NSP to ensure that the * connection may be activated with that NSP. The connection must match the * @nsp's network name and other attributes. * * Returns: %TRUE if the connection may be activated with this WiMAX NSP, * %FALSE if it cannot be. **/ gboolean nm_wimax_nsp_connection_valid (NMWimaxNsp *nsp, NMConnection *connection) { NMSettingConnection *s_con; NMSettingWimax *s_wimax; const char *ctype; const char *nsp_name; const char *setting_name; 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_WIMAX_SETTING_NAME) != 0) return FALSE; s_wimax = nm_connection_get_setting_wimax (connection); if (!s_wimax) return FALSE; setting_name = nm_setting_wimax_get_network_name (s_wimax); if (!setting_name) return FALSE; nsp_name = nm_wimax_nsp_get_name (nsp); g_warn_if_fail (nsp_name != NULL); if (g_strcmp0 (nsp_name, setting_name) != 0) return FALSE; return TRUE; }
static GtkWidget * new_nsp_menu_item (NMDeviceWimax *device, NMConnection *connection, gboolean active, NMWimaxNsp *nsp, NMApplet *applet) { GtkWidget *item; WimaxMenuItemInfo *info; g_return_val_if_fail (nsp != NULL, NULL); item = nm_mb_menu_item_new (nm_wimax_nsp_get_name (nsp), nm_wimax_nsp_get_signal_quality (nsp), NULL, active, MB_TECH_WIMAX, nsp_type_to_mb_state (nm_wimax_nsp_get_network_type (nsp)), TRUE, applet); gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE); info = g_slice_new0 (WimaxMenuItemInfo); info->applet = applet; info->device = g_object_ref (G_OBJECT (device)); info->connection = connection ? g_object_ref (connection) : NULL; info->nsp = g_object_ref (nsp); g_signal_connect_data (item, "activate", G_CALLBACK (wimax_menu_item_activate), info, (GClosureNotify) wimax_menu_item_info_destroy, 0); return item; }
static NMWimaxNsp * get_nsp_by_name (NMDeviceWimax *self, const char *name) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); GSList *iter; for (iter = priv->nsp_list; iter; iter = iter->next) { NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); if (!g_strcmp0 (nm_wimax_nsp_get_name (nsp), name)) return nsp; } return NULL; }
gboolean nm_wimax_nsp_check_compatible (NMWimaxNsp *self, NMConnection *connection) { NMWimaxNspPrivate *priv; NMSettingWimax *s_wimax; g_return_val_if_fail (NM_IS_WIMAX_NSP (self), FALSE); g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE); priv = GET_PRIVATE (self); s_wimax = nm_connection_get_setting_wimax (connection); if (!s_wimax) return FALSE; return g_strcmp0 (nm_wimax_nsp_get_name (self), nm_setting_wimax_get_network_name (s_wimax)) == 0; }
static NMConnection * get_connection_for_nsp (GSList *connections, NMWimaxNsp *nsp) { GSList *iter; const char *nsp_name, *candidate_name; nsp_name = nm_wimax_nsp_get_name (nsp); for (iter = connections; iter; iter = g_slist_next (iter)) { NMConnection *candidate = NM_CONNECTION (iter->data); NMSettingWimax *s_wimax; s_wimax = nm_connection_get_setting_wimax (candidate); if (s_wimax) { candidate_name = nm_setting_wimax_get_network_name (s_wimax); if (g_strcmp0 (nsp_name, candidate_name) == 0) return candidate; } } return NULL; }
static void remove_outdated_nsps (NMDeviceWimax *self, WIMAX_API_NSP_INFO_EX *nsp_list, guint32 list_size) { NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); GSList *iter; GSList *to_remove = NULL; for (iter = priv->nsp_list; iter; iter = iter->next) { NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); gboolean found = FALSE; int i; for (i = 0; i < list_size; i++) { WIMAX_API_NSP_INFO_EX *info = &nsp_list[i]; if (!g_strcmp0 (nm_wimax_nsp_get_name (nsp), (char *) info->NSPName)) { found = TRUE; break; } } if (!found) to_remove = g_slist_prepend (to_remove, nsp); } for (iter = to_remove; iter; iter = iter->next) { NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); emit_nsp_added_removed (self, NSP_REMOVED, nsp, FALSE); priv->nsp_list = g_slist_remove (priv->nsp_list, nsp); g_object_unref (nsp); } if (g_slist_length(to_remove) > 0) nm_device_recheck_available_connections (NM_DEVICE (self)); g_slist_free (to_remove); }
static gboolean wimax_new_auto_connection (NMDevice *device, gpointer dclass_data, AppletNewAutoConnectionCallback callback, gpointer callback_data) { WimaxMenuItemInfo *info = dclass_data; NMConnection *connection; NMSettingWimax *s_wimax = NULL; NMSettingConnection *s_con; char *uuid; const char *nsp_name; nsp_name = nm_wimax_nsp_get_name (info->nsp); connection = nm_connection_new (); s_wimax = NM_SETTING_WIMAX (nm_setting_wimax_new ()); g_object_set (s_wimax, NM_SETTING_WIMAX_NETWORK_NAME, nsp_name, NULL); nm_connection_add_setting (connection, NM_SETTING (s_wimax)); s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ()); uuid = nm_utils_uuid_generate (); g_object_set (s_con, NM_SETTING_CONNECTION_ID, nsp_name, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_CONNECTION_AUTOCONNECT, TRUE, NM_SETTING_CONNECTION_UUID, uuid, NULL); g_free (uuid); nm_connection_add_setting (connection, NM_SETTING (s_con)); (*callback) (connection, TRUE, FALSE, callback_data); return TRUE; }
static void detail_nsp (gpointer data, gpointer user_data) { NMWimaxNsp *nsp = NM_WIMAX_NSP (data); const char *active_name = (const char *) user_data; const char *name; char *label; char *data_str; gboolean active = FALSE; name = nm_wimax_nsp_get_name (nsp); if (active_name) active = g_strcmp0 (active_name, name) == 0; label = g_strdup_printf (" %s%s", active ? "*" : "", name); data_str = g_strdup_printf ("%d%% (%s)", nm_wimax_nsp_get_signal_quality (nsp), wimax_network_type_to_str (nm_wimax_nsp_get_network_type (nsp))); print_string (label, data_str); g_free (label); g_free (data_str); }
static void wmx_state_change_cb (struct wmxsdk *wmxsdk, WIMAX_API_DEVICE_STATUS new_status, WIMAX_API_DEVICE_STATUS old_status, WIMAX_API_STATUS_REASON reason, WIMAX_API_CONNECTION_PROGRESS_INFO progress, void *user_data) { NMDeviceWimax *self = NM_DEVICE_WIMAX (user_data); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMDeviceState state; const char *iface; gboolean old_available = FALSE; const char *nsp_name = NULL; iface = nm_device_get_iface (NM_DEVICE (self)); nm_log_info (LOGD_WIMAX, "(%s): wimax state change %s -> %s (%s (%d))", iface, iwmx_sdk_dev_status_to_str (old_status), iwmx_sdk_dev_status_to_str (new_status), iwmx_sdk_con_progress_to_str (progress), progress); if (new_status == old_status) return; state = nm_device_get_state (NM_DEVICE (self)); old_available = nm_device_is_available (NM_DEVICE (self)); priv->status = new_status; if (priv->current_nsp) nsp_name = nm_wimax_nsp_get_name (priv->current_nsp); switch (new_status) { case WIMAX_API_DEVICE_STATUS_UnInitialized: case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW: case WIMAX_API_DEVICE_STATUS_RF_OFF_HW: case WIMAX_API_DEVICE_STATUS_RF_OFF_SW: if (priv->wimaxd_enabled) { priv->wimaxd_enabled = FALSE; if (update_availability (self, old_available)) return; } break; case WIMAX_API_DEVICE_STATUS_Connecting: case WIMAX_API_DEVICE_STATUS_Data_Connected: /* If for some reason we're initially connected, force a disconnect here */ if (state < NM_DEVICE_STATE_DISCONNECTED) force_disconnect (self, wmxsdk); /* Fall through */ case WIMAX_API_DEVICE_STATUS_Ready: case WIMAX_API_DEVICE_STATUS_Scanning: if (priv->wimaxd_enabled == FALSE) { priv->wimaxd_enabled = TRUE; if (update_availability (self, old_available)) return; } break; default: nm_log_warn (LOGD_WIMAX, "(%s): unhandled WiMAX device state %d", iface, new_status); break; } /* Handle activation success and failure */ if (nm_device_is_activating (NM_DEVICE (self))) { if (new_status == WIMAX_API_DEVICE_STATUS_Data_Connected) { /* Success */ clear_activation_timeout (self); nm_log_info (LOGD_WIMAX, "(%s): connected to '%s'", iface, nsp_name); nm_device_activate_schedule_stage3_ip_config_start (NM_DEVICE (self)); return; } if (priv->connect_failed) { /* Connection attempt failed */ nm_log_info (LOGD_WIMAX, "(%s): connection to '%s' failed: (%d) %s", iface, nsp_name, reason, iwmx_sdk_reason_to_str (reason)); nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_CONFIG_FAILED); return; } /* If stage2 was postponed because the device was scanning or something, * then check if we need to move to stage2 now that the device might be * ready. */ if (state == NM_DEVICE_STATE_PREPARE && priv->prepare_done) { if ( new_status == WIMAX_API_DEVICE_STATUS_Ready || new_status == WIMAX_API_DEVICE_STATUS_Connecting) { nm_device_activate_schedule_stage2_device_config (NM_DEVICE (self)); return; } } } /* Handle disconnection */ if (state == NM_DEVICE_STATE_ACTIVATED) { if ( old_status == WIMAX_API_DEVICE_STATUS_Data_Connected && new_status < WIMAX_API_DEVICE_STATUS_Connecting) { nm_log_info (LOGD_WIMAX, "(%s): disconnected from '%s': (%d) %s", iface, nsp_name, reason, iwmx_sdk_reason_to_str (reason)); nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_CONFIG_FAILED); } } }
static gboolean complete_connection (NMDevice *device, NMConnection *connection, const char *specific_object, const GSList *existing_connections, GError **error) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMSettingWimax *s_wimax; const char *setting_mac; const char *hw_address; const char *nsp_name = NULL; NMWimaxNsp *nsp = NULL; GSList *iter; s_wimax = nm_connection_get_setting_wimax (connection); if (!specific_object) { /* If not given a specific object, we need at minimum an NSP name */ if (!s_wimax) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "A 'wimax' setting is required if no NSP path was given."); return FALSE; } nsp_name = nm_setting_wimax_get_network_name (s_wimax); if (!nsp_name || !strlen (nsp_name)) { g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION, "A 'wimax' setting with a valid network name is required if no NSP path was given."); return FALSE; } /* Find a compatible NSP in the list */ nsp = get_nsp_by_name (self, nsp_name); /* If we still don't have an NSP, then the WiMAX settings needs to be * fully specified by the client. Might not be able to find the NSP * if the scan didn't find the NSP yet. */ if (!nsp) { if (!nm_setting_verify (NM_SETTING (s_wimax), NULL, error)) return FALSE; } } else { /* Find a compatible NSP in the list */ for (iter = priv->nsp_list; iter; iter = g_slist_next (iter)) { if (!strcmp (specific_object, nm_wimax_nsp_get_dbus_path (NM_WIMAX_NSP (iter->data)))) { nsp = NM_WIMAX_NSP (iter->data); break; } } if (!nsp) { g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_SPECIFIC_OBJECT_NOT_FOUND, "The NSP %s was not in the scan list.", specific_object); return FALSE; } nsp_name = nm_wimax_nsp_get_name (nsp); } /* Add a WiMAX setting if one doesn't exist */ if (!s_wimax) { s_wimax = (NMSettingWimax *) nm_setting_wimax_new (); nm_connection_add_setting (connection, NM_SETTING (s_wimax)); } g_assert (nsp_name); nm_utils_complete_generic (connection, NM_SETTING_WIMAX_SETTING_NAME, existing_connections, nsp_name, nsp_name, NULL, TRUE); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_NETWORK_NAME, nsp_name, NULL); setting_mac = nm_setting_wimax_get_mac_address (s_wimax); hw_address = nm_device_get_hw_address (device); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's permanent MAC */ if (!nm_utils_hwaddr_matches (setting_mac, -1, hw_address, -1)) { g_set_error_literal (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY, _("connection does not match device")); g_prefix_error (error, "%s.%s: ", NM_SETTING_WIMAX_SETTING_NAME, NM_SETTING_WIMAX_MAC_ADDRESS); return FALSE; } } else { /* Lock the connection to this device by default */ if (!nm_utils_hwaddr_matches (hw_address, -1, NULL, ETH_ALEN)) g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, hw_address, NULL); } return TRUE; }
static void detail_device (gpointer data, gpointer user_data) { NMDevice *device = NM_DEVICE (data); char *tmp; NMDeviceState state; guint32 caps; guint32 speed; const GArray *array; gboolean is_default = FALSE; const char *id = NULL; NMActiveConnection *active; active = nm_device_get_active_connection (device); if (active) { NMConnection *connection; NMSettingConnection *s_con; is_default = nm_active_connection_get_default (active); connection = get_connection_for_active (active); if (connection) { s_con = nm_connection_get_setting_connection (connection); if (s_con) id = nm_setting_connection_get_id (s_con); } } print_header ("Device", nm_device_get_iface (device), id); /* General information */ if (NM_IS_DEVICE_ETHERNET (device)) print_string ("Type", "Wired"); else if (NM_IS_DEVICE_WIFI (device)) print_string ("Type", "802.11 WiFi"); else if (NM_IS_DEVICE_MODEM (device)) { NMDeviceModemCapabilities modem_caps; modem_caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device)); if (modem_caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) print_string ("Type", "Mobile Broadband (GSM)"); else if (modem_caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) print_string ("Type", "Mobile Broadband (CDMA)"); else print_string ("Type", "Mobile Broadband (unknown)"); } else if (NM_IS_DEVICE_BT (device)) print_string ("Type", "Bluetooth"); else if (NM_IS_DEVICE_WIMAX (device)) print_string ("Type", "WiMAX"); print_string ("Driver", nm_device_get_driver (device) ? nm_device_get_driver (device) : "(unknown)"); state = nm_device_get_state (device); print_string ("State", get_dev_state_string (state)); if (is_default) print_string ("Default", "yes"); else print_string ("Default", "no"); tmp = NULL; if (NM_IS_DEVICE_ETHERNET (device)) tmp = g_strdup (nm_device_ethernet_get_hw_address (NM_DEVICE_ETHERNET (device))); else if (NM_IS_DEVICE_WIFI (device)) tmp = g_strdup (nm_device_wifi_get_hw_address (NM_DEVICE_WIFI (device))); else if (NM_IS_DEVICE_WIMAX (device)) tmp = g_strdup (nm_device_wimax_get_hw_address (NM_DEVICE_WIMAX (device))); if (tmp) { print_string ("HW Address", tmp); g_free (tmp); } /* Capabilities */ caps = nm_device_get_capabilities (device); printf ("\n Capabilities:\n"); if (caps & NM_DEVICE_CAP_CARRIER_DETECT) print_string (" Carrier Detect", "yes"); speed = 0; if (NM_IS_DEVICE_ETHERNET (device)) { /* Speed in Mb/s */ speed = nm_device_ethernet_get_speed (NM_DEVICE_ETHERNET (device)); } else if (NM_IS_DEVICE_WIFI (device)) { /* Speed in b/s */ speed = nm_device_wifi_get_bitrate (NM_DEVICE_WIFI (device)); speed /= 1000; } if (speed) { char *speed_string; speed_string = g_strdup_printf ("%u Mb/s", speed); print_string (" Speed", speed_string); g_free (speed_string); } /* Wireless specific information */ if ((NM_IS_DEVICE_WIFI (device))) { guint32 wcaps; NMAccessPoint *active_ap = NULL; const char *active_bssid = NULL; const GPtrArray *aps; printf ("\n Wireless Properties\n"); wcaps = nm_device_wifi_get_capabilities (NM_DEVICE_WIFI (device)); if (wcaps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) print_string (" WEP Encryption", "yes"); if (wcaps & NM_WIFI_DEVICE_CAP_WPA) print_string (" WPA Encryption", "yes"); if (wcaps & NM_WIFI_DEVICE_CAP_RSN) print_string (" WPA2 Encryption", "yes"); if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) { active_ap = nm_device_wifi_get_active_access_point (NM_DEVICE_WIFI (device)); active_bssid = active_ap ? nm_access_point_get_hw_address (active_ap) : NULL; } printf ("\n Wireless Access Points %s\n", active_ap ? "(* = current AP)" : ""); aps = nm_device_wifi_get_access_points (NM_DEVICE_WIFI (device)); if (aps && aps->len) g_ptr_array_foreach ((GPtrArray *) aps, detail_access_point, (gpointer) active_bssid); } else if (NM_IS_DEVICE_ETHERNET (device)) { printf ("\n Wired Properties\n"); if (nm_device_ethernet_get_carrier (NM_DEVICE_ETHERNET (device))) print_string (" Carrier", "on"); else print_string (" Carrier", "off"); } else if (NM_IS_DEVICE_WIMAX (device)) { NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device); NMWimaxNsp *active_nsp = NULL; const char *active_name = NULL; const GPtrArray *nsps; if (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED) { guint tmp_uint; gint tmp_int; const char *tmp_str; active_nsp = nm_device_wimax_get_active_nsp (wimax); active_name = active_nsp ? nm_wimax_nsp_get_name (active_nsp) : NULL; printf ("\n Link Status\n"); tmp_uint = nm_device_wimax_get_center_frequency (wimax); if (tmp_uint) tmp = g_strdup_printf ("%'.1f MHz", (double) tmp_uint / 1000.0); else tmp = g_strdup ("(unknown)"); print_string (" Center Freq.", tmp); g_free (tmp); tmp_int = nm_device_wimax_get_rssi (wimax); if (tmp_int) tmp = g_strdup_printf ("%d dBm", tmp_int); else tmp = g_strdup ("(unknown)"); print_string (" RSSI", tmp); g_free (tmp); tmp_int = nm_device_wimax_get_cinr (wimax); if (tmp_int) tmp = g_strdup_printf ("%d dB", tmp_int); else tmp = g_strdup ("(unknown)"); print_string (" CINR", tmp); g_free (tmp); tmp_int = nm_device_wimax_get_tx_power (wimax); if (tmp_int) tmp = g_strdup_printf ("%'.2f dBm", (float) tmp_int / 2.0); else tmp = g_strdup ("(unknown)"); print_string (" TX Power", tmp); g_free (tmp); tmp_str = nm_device_wimax_get_bsid (wimax); if (tmp_str) print_string (" BSID", tmp_str); else print_string (" BSID", "(unknown)"); } printf ("\n WiMAX NSPs %s\n", active_nsp ? "(* current NSP)" : ""); nsps = nm_device_wimax_get_nsps (NM_DEVICE_WIMAX (device)); if (nsps && nsps->len) g_ptr_array_foreach ((GPtrArray *) nsps, detail_nsp, (gpointer) active_name); } /* IP Setup info */ if (state == NM_DEVICE_STATE_ACTIVATED) { NMIP4Config *cfg4 = nm_device_get_ip4_config (device); NMIP6Config *cfg6 = nm_device_get_ip6_config (device); GSList *iter; if (cfg4) { printf ("\n IPv4 Settings:\n"); for (iter = (GSList *) nm_ip4_config_get_addresses (cfg4); iter; iter = g_slist_next (iter)) { NMIP4Address *addr = (NMIP4Address *) iter->data; guint32 prefix = nm_ip4_address_get_prefix (addr); char *tmp2; tmp = ip4_address_as_string (nm_ip4_address_get_address (addr)); print_string (" Address", tmp); g_free (tmp); tmp2 = ip4_address_as_string (nm_utils_ip4_prefix_to_netmask (prefix)); tmp = g_strdup_printf ("%d (%s)", prefix, tmp2); g_free (tmp2); print_string (" Prefix", tmp); g_free (tmp); tmp = ip4_address_as_string (nm_ip4_address_get_gateway (addr)); print_string (" Gateway", tmp); g_free (tmp); printf ("\n"); } array = nm_ip4_config_get_nameservers (cfg4); if (array) { int i; for (i = 0; i < array->len; i++) { tmp = ip4_address_as_string (g_array_index (array, guint32, i)); print_string (" DNS", tmp); g_free (tmp); } } } if (cfg6) { printf ("\n IPv6 Settings:\n"); for (iter = (GSList *) nm_ip6_config_get_addresses (cfg6); iter; iter = g_slist_next (iter)) { NMIP6Address *addr = (NMIP6Address *) iter->data; guint32 prefix = nm_ip6_address_get_prefix (addr); tmp = ip6_address_as_string (nm_ip6_address_get_address (addr)); print_string (" Address", tmp); g_free (tmp); tmp = g_strdup_printf ("%d", prefix); print_string (" Prefix", tmp); g_free (tmp); tmp = ip6_address_as_string (nm_ip6_address_get_gateway (addr)); print_string (" Gateway", tmp); g_free (tmp); printf ("\n"); } for (iter = (GSList *) nm_ip6_config_get_nameservers (cfg6); iter; iter = g_slist_next (iter)) { tmp = ip6_address_as_string (iter->data); print_string (" DNS", tmp); g_free (tmp); } } } printf ("\n\n"); }
static gboolean real_complete_connection (NMDevice *device, NMConnection *connection, const char *specific_object, const GSList *existing_connections, GError **error) { NMDeviceWimax *self = NM_DEVICE_WIMAX (device); NMDeviceWimaxPrivate *priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); NMSettingWimax *s_wimax; const GByteArray *setting_mac; char *format; const char *nsp_name = NULL; NMWimaxNsp *nsp = NULL; GSList *iter; s_wimax = nm_connection_get_setting_wimax (connection); if (!specific_object) { /* If not given a specific object, we need at minimum an NSP name */ if (!s_wimax) { g_set_error_literal (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INVALID, "A 'wimax' setting is required if no NSP path was given."); return FALSE; } nsp_name = nm_setting_wimax_get_network_name (s_wimax); if (!nsp_name || !strlen (nsp_name)) { g_set_error_literal (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_CONNECTION_INVALID, "A 'wimax' setting with a valid network name is required if no NSP path was given."); return FALSE; } /* Find a compatible NSP in the list */ nsp = get_nsp_by_name (self, nsp_name); /* If we still don't have an NSP, then the WiMAX settings needs to be * fully specified by the client. Might not be able to find the NSP * if the scan didn't find the NSP yet. */ if (!nsp) { if (!nm_setting_verify (NM_SETTING (s_wimax), NULL, error)) return FALSE; } } else { /* Find a compatible NSP in the list */ for (iter = priv->nsp_list; iter; iter = g_slist_next (iter)) { if (!strcmp (specific_object, nm_wimax_nsp_get_dbus_path (NM_WIMAX_NSP (iter->data)))) { nsp = NM_WIMAX_NSP (iter->data); break; } } if (!nsp) { g_set_error (error, NM_WIMAX_ERROR, NM_WIMAX_ERROR_NSP_NOT_FOUND, "The NSP %s was not in the scan list.", specific_object); return FALSE; } nsp_name = nm_wimax_nsp_get_name (nsp); } /* Add a WiMAX setting if one doesn't exist */ if (!s_wimax) { s_wimax = (NMSettingWimax *) nm_setting_wimax_new (); nm_connection_add_setting (connection, NM_SETTING (s_wimax)); } g_assert (nsp_name); format = g_strdup_printf ("%s %%d", nsp_name); nm_utils_complete_generic (connection, NM_SETTING_WIMAX_SETTING_NAME, existing_connections, format, nsp_name, TRUE); g_free (format); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_NETWORK_NAME, nsp_name, NULL); setting_mac = nm_setting_wimax_get_mac_address (s_wimax); if (setting_mac) { /* Make sure the setting MAC (if any) matches the device's permanent MAC */ if (memcmp (setting_mac->data, &priv->hw_addr.ether_addr_octet, ETH_ALEN)) { g_set_error (error, NM_SETTING_WIMAX_ERROR, NM_SETTING_WIMAX_ERROR_INVALID_PROPERTY, NM_SETTING_WIMAX_MAC_ADDRESS); return FALSE; } } else { GByteArray *mac; const guint8 null_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; /* Lock the connection to this device by default */ if (memcmp (&priv->hw_addr.ether_addr_octet, null_mac, ETH_ALEN)) { mac = g_byte_array_sized_new (ETH_ALEN); g_byte_array_append (mac, priv->hw_addr.ether_addr_octet, ETH_ALEN); g_object_set (G_OBJECT (s_wimax), NM_SETTING_WIMAX_MAC_ADDRESS, mac, NULL); g_byte_array_free (mac, TRUE); } } return TRUE; }