diff --git a/ChangeLog b/ChangeLog index c1154f6987..31f5ee0dbe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +2006-03-02 Robert Love + + Add support for retrieving both the per-device speed and the + per-network maximum supported rate. Then change the getProperties + DBUS API for both networks and devices to report this informaiton. + Finally, display the information via both nm-applet and nm-tool: + * gnome/applet/applet-dbus-devices.c: Grab the speed from getProperties + and set it. + * gnome/applet/applet.c: Display the device's speed in the 'Connection + Information' dialog. + * gnome/applet/applet.glade: Update the UI to show per-device speed. + * gnome/applet/nm-device.c, gnome/applet/nm-device.h: Add interfaces + network_device_get_speed() and network_device_set_speed() for + retrieving and setting, respectively, a network device's current + speed. + * src/nm-dbus-device.c: Send the device's speed on getProperties. + * src/nm-device-802-11-wireless.c: Return the rate in Mb/s, not Kb/s, + in the function nm_device_802_11_wireless_get_bitrate() -- it does + not matter (yet) what the units are, because we only feed it its own + output. Implement SIOCGIRATE and set the per-network maximum + supported rate during scanning. + * src/nm-device-802-11-wireless.h: Export the function + nm_device_802_11_wireless_get_bitrate(). + * src/nm-device-802-3-ethernet.c, src/nm-device-802-3-ethernet.h: Add + function nm_device_802_3_ethernet_get_speed() for returning an + 802.3's current speed, in Mb/s. + * test/nm-tool.c: Display the per-device current speed, if available, + and the per-network maximum rate. + 2006-03-02 Dan Williams * src/nm-device-802-11-wireless.c diff --git a/gnome/applet/applet-dbus-devices.c b/gnome/applet/applet-dbus-devices.c index f4e1b68867..6f6dda9b22 100644 --- a/gnome/applet/applet-dbus-devices.c +++ b/gnome/applet/applet-dbus-devices.c @@ -745,6 +745,7 @@ static void nma_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_da const char * secondary_dns = NULL; dbus_int32_t mode = -1; dbus_int32_t strength = -1; + dbus_int32_t speed = 0; char * active_network_path = NULL; dbus_bool_t link_active = FALSE; dbus_uint32_t caps = NM_DEVICE_CAP_NONE; @@ -787,6 +788,7 @@ static void nma_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_da DBUS_TYPE_INT32, &mode, DBUS_TYPE_INT32, &strength, DBUS_TYPE_BOOLEAN,&link_active, + DBUS_TYPE_INT32, &speed, DBUS_TYPE_UINT32, &caps, DBUS_TYPE_UINT32, &type_caps, DBUS_TYPE_STRING, &active_network_path, @@ -798,6 +800,7 @@ static void nma_dbus_device_properties_cb (DBusPendingCall *pcall, void *user_da network_device_set_hal_udi (dev, udi); network_device_set_address (dev, hw_addr); + network_device_set_speed (dev, speed); network_device_set_active (dev, active); network_device_set_link (dev, link_active); network_device_set_capabilities (dev, caps); diff --git a/gnome/applet/applet.c b/gnome/applet/applet.c index 179d56fead..53880d8cbd 100644 --- a/gnome/applet/applet.c +++ b/gnome/applet/applet.c @@ -190,8 +190,9 @@ static gboolean nma_update_info (NMApplet *applet) { GtkWidget *info_dialog; char *addr = NULL, *broadcast = NULL, *primary_dns = NULL, *secondary_dns = NULL; - char *mac = NULL, *iface_and_type = NULL, *route = NULL, *mask = NULL; + char *mac = NULL, *iface_and_type = NULL, *route = NULL, *mask = NULL, *speed = NULL; GtkWidget *label; + int mbs; const char *iface = NULL, *driver = NULL; NetworkDevice *dev; @@ -225,6 +226,11 @@ static gboolean nma_update_info (NMApplet *applet) primary_dns = (char*) network_device_get_primary_dns (dev); secondary_dns = (char*) network_device_get_secondary_dns (dev); + printf ("WOLF %d\n", network_device_get_speed (dev)); + mbs = network_device_get_speed (dev); + if (mbs) + speed = g_strdup_printf ("%d Mb/s", mbs); + if (network_device_is_wired (dev)) iface_and_type = g_strdup_printf (_("Wired Ethernet (%s)"), iface); else @@ -233,6 +239,9 @@ static gboolean nma_update_info (NMApplet *applet) label = get_label (info_dialog, applet->info_dialog_xml, "label-interface"); gtk_label_set_text (GTK_LABEL (label), iface_and_type); + label = get_label (info_dialog, applet->info_dialog_xml, "label-speed"); + gtk_label_set_text (GTK_LABEL (label), mbs ? speed : "Unknown"); + label = get_label (info_dialog, applet->info_dialog_xml, "label-driver"); gtk_label_set_text (GTK_LABEL (label), driver); @@ -258,6 +267,7 @@ static gboolean nma_update_info (NMApplet *applet) gtk_label_set_text (GTK_LABEL (label), mac); g_free (iface_and_type); + g_free (speed); return TRUE; } diff --git a/gnome/applet/applet.glade b/gnome/applet/applet.glade index a0252a95f6..fd8a852ff8 100644 --- a/gnome/applet/applet.glade +++ b/gnome/applet/applet.glade @@ -924,7 +924,7 @@ WEP 40/128-bit ASCII 1 True - 13 + 14 2 False 3 @@ -1091,8 +1091,8 @@ WEP 40/128-bit ASCII 0 1 - 12 - 13 + 13 + 14 fill @@ -1120,8 +1120,8 @@ WEP 40/128-bit ASCII 1 2 - 12 - 13 + 13 + 14 fill @@ -1148,8 +1148,8 @@ WEP 40/128-bit ASCII 0 1 - 11 - 12 + 12 + 13 fill @@ -1177,8 +1177,8 @@ WEP 40/128-bit ASCII 1 2 - 11 - 12 + 12 + 13 fill @@ -1205,8 +1205,8 @@ WEP 40/128-bit ASCII 0 1 - 10 - 11 + 11 + 12 fill @@ -1234,8 +1234,8 @@ WEP 40/128-bit ASCII 1 2 - 10 - 11 + 11 + 12 fill @@ -1262,8 +1262,8 @@ WEP 40/128-bit ASCII 0 1 - 9 - 10 + 10 + 11 fill @@ -1291,8 +1291,8 @@ WEP 40/128-bit ASCII 1 2 - 9 - 10 + 10 + 11 fill @@ -1319,8 +1319,8 @@ WEP 40/128-bit ASCII 0 1 - 8 - 9 + 9 + 10 fill @@ -1348,8 +1348,8 @@ WEP 40/128-bit ASCII 1 2 - 8 - 9 + 9 + 10 fill @@ -1376,8 +1376,8 @@ WEP 40/128-bit ASCII 0 1 - 7 - 8 + 8 + 9 fill @@ -1405,8 +1405,8 @@ WEP 40/128-bit ASCII 1 2 - 7 - 8 + 8 + 9 fill @@ -1433,8 +1433,8 @@ WEP 40/128-bit ASCII 0 1 - 6 - 7 + 7 + 8 fill @@ -1462,8 +1462,8 @@ WEP 40/128-bit ASCII 1 2 - 6 - 7 + 7 + 8 fill @@ -1489,8 +1489,8 @@ WEP 40/128-bit ASCII 0 1 - 5 - 6 + 6 + 7 fill @@ -1517,8 +1517,8 @@ WEP 40/128-bit ASCII 1 2 - 5 - 6 + 6 + 7 fill @@ -1545,8 +1545,8 @@ WEP 40/128-bit ASCII 0 1 - 4 - 5 + 5 + 6 fill @@ -1573,8 +1573,8 @@ WEP 40/128-bit ASCII 1 2 - 4 - 5 + 5 + 6 fill @@ -1598,6 +1598,63 @@ WEP 40/128-bit ASCII False 0 + + 0 + 1 + 4 + 5 + fill + + + + + + + True + True + + False + False + GTK_JUSTIFY_LEFT + False + True + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 1 + 2 + 4 + 5 + fill + + + + + + + True + Speed: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + 0 1 @@ -1609,7 +1666,7 @@ WEP 40/128-bit ASCII - + True True @@ -1665,7 +1722,7 @@ WEP 40/128-bit ASCII True - wep_key_subwindow + wep_key_subwindow GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False @@ -1854,7 +1911,7 @@ Shared Key True - leap_subwindow + leap_subwindow GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False @@ -2046,7 +2103,7 @@ Shared Key True - wpa_psk_subwindow + wpa_psk_subwindow GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False @@ -2234,7 +2291,7 @@ Shared Key True - wpa_eap_subwindow + wpa_eap_subwindow GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False @@ -2712,7 +2769,7 @@ Shared Key True - wep_passphrase_subwindow + wep_passphrase_subwindow GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False diff --git a/gnome/applet/nm-device.c b/gnome/applet/nm-device.c index 5b06aadca5..69d29c7b2e 100644 --- a/gnome/applet/nm-device.c +++ b/gnome/applet/nm-device.c @@ -51,6 +51,7 @@ struct NetworkDevice char * primary_dns; char * secondary_dns; gint strength; + gint speed; GSList * networks; NMActStage act_stage; }; @@ -678,6 +679,23 @@ void network_device_set_link (NetworkDevice *dev, gboolean link) dev->link = link; } +/* + * Accessors for speed (in Mb/s) + */ +int network_device_get_speed (NetworkDevice *dev) +{ + g_return_val_if_fail (dev != NULL, FALSE); + + return (dev->speed); +} + +void network_device_set_speed (NetworkDevice *dev, int speed) +{ + g_return_if_fail (dev != NULL); + + dev->speed = speed; +} + /* * Accessors for active */ diff --git a/gnome/applet/nm-device.h b/gnome/applet/nm-device.h index 9925ccdf08..d8ab40b387 100644 --- a/gnome/applet/nm-device.h +++ b/gnome/applet/nm-device.h @@ -97,6 +97,9 @@ void network_device_set_hal_udi (NetworkDevice *dev, const char *hal_udi) gboolean network_device_get_link (NetworkDevice *dev); void network_device_set_link (NetworkDevice *dev, gboolean link); +int network_device_get_speed (NetworkDevice *dev); +void network_device_set_speed (NetworkDevice *dev, int speed); + gboolean network_device_get_active (NetworkDevice *dev); void network_device_set_active (NetworkDevice *dev, gboolean active); diff --git a/src/nm-dbus-device.c b/src/nm-dbus-device.c index 4cb0a844e3..850074d3d6 100644 --- a/src/nm-dbus-device.c +++ b/src/nm-dbus-device.c @@ -367,6 +367,7 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D char * hw_addr_buf_ptr = &hw_addr_buf[0]; dbus_int32_t mode = -1; dbus_int32_t strength = -1; + dbus_int32_t speed = 0; char * active_network_path = NULL; dbus_bool_t link_active = (dbus_bool_t) nm_device_has_active_link (dev); dbus_uint32_t capabilities = (dbus_uint32_t) nm_device_get_capabilities (dev); @@ -419,8 +420,9 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D NMAccessPointList * ap_list; NMAPListIter * iter; - strength = (dbus_int32_t) nm_device_802_11_wireless_get_signal_strength (wdev); - mode = (dbus_int32_t) nm_device_802_11_wireless_get_mode (wdev); + strength = nm_device_802_11_wireless_get_signal_strength (wdev); + mode = nm_device_802_11_wireless_get_mode (wdev); + speed = nm_device_802_11_wireless_get_bitrate (wdev); if (req && (ap = nm_act_request_get_ap (req))) { @@ -450,6 +452,9 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D } } } + else + speed = nm_device_802_3_ethernet_get_speed (NM_DEVICE_802_3_ETHERNET (dev)); + if (!active_network_path) active_network_path = g_strdup (""); @@ -469,6 +474,7 @@ static DBusMessage *nm_dbus_device_get_properties (DBusConnection *connection, D DBUS_TYPE_INT32, &mode, DBUS_TYPE_INT32, &strength, DBUS_TYPE_BOOLEAN,&link_active, + DBUS_TYPE_INT32, &speed, DBUS_TYPE_UINT32, &capabilities, DBUS_TYPE_UINT32, &type_capabilities, DBUS_TYPE_STRING, &active_network_path, diff --git a/src/nm-device-802-11-wireless.c b/src/nm-device-802-11-wireless.c index 7ba962ddab..cdafc846b5 100644 --- a/src/nm-device-802-11-wireless.c +++ b/src/nm-device-802-11-wireless.c @@ -1412,10 +1412,10 @@ nm_device_802_11_wireless_set_frequency (NMDevice80211Wireless *self, * nm_device_get_bitrate * * For wireless devices, get the bitrate to broadcast/receive at. - * Returned value is rate in KHz. + * Returned value is rate in Mb/s. * */ -static int +int nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *self) { NMSock * sk; @@ -1435,7 +1435,7 @@ nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *self) nm_dev_sock_close (sk); } - return ((err >= 0) ? wrq.u.bitrate.value / 1000 : 0); + return ((err >= 0) ? wrq.u.bitrate.value / 1000000 : 0); } @@ -3086,6 +3086,8 @@ process_scan_results (NMDevice80211Wireless *dev, char *pos, *end, *custom, *genie, *gpos, *gend; NMAccessPoint *ap = NULL; size_t clen; + struct iw_param iwp; + int maxrate; struct iw_event iwe_buf, *iwe = &iwe_buf; g_return_val_if_fail (dev != NULL, FALSE); @@ -3174,7 +3176,7 @@ process_scan_results (NMDevice80211Wireless *dev, } break; case SIOCGIWFREQ: - nm_ap_set_freq (ap, iw_freq2float(&(iwe->u.freq))); + nm_ap_set_freq (ap, iw_freq2float(&(iwe->u.freq))); break; case IWEVQUAL: nm_ap_set_strength (ap, wireless_qual_to_percent (&(iwe->u.qual), @@ -3191,25 +3193,22 @@ process_scan_results (NMDevice80211Wireless *dev, nm_ap_add_capabilities_for_wep (ap); } break; -#if 0 case SIOCGIWRATE: - custom = pos + IW_EV_LCP_LEN; clen = iwe->len; if (custom + clen > end) break; maxrate = 0; - while (((ssize_t) clen) >= sizeof(struct iw_param)) { - /* Note: may be misaligned, make a local, - * aligned copy */ - memcpy(&p, custom, sizeof(struct iw_param)); - if (p.value > maxrate) - maxrate = p.value; - clen -= sizeof(struct iw_param); - custom += sizeof(struct iw_param); + while (((ssize_t) clen) >= sizeof(struct iw_param)) + { + /* the payload may be unaligned, so we align it */ + memcpy(&iwp, custom, sizeof (struct iw_param)); + if (iwp.value > maxrate) + maxrate = iwp.value; + clen -= sizeof (struct iw_param); + custom += sizeof (struct iw_param); } - results[ap_num].maxrate = maxrate; + nm_ap_set_rate (ap, maxrate); break; -#endif case IWEVGENIE: gpos = genie = custom; gend = genie + iwe->u.data.length; diff --git a/src/nm-device-802-11-wireless.h b/src/nm-device-802-11-wireless.h index 6c766317b7..d5d32f5f18 100644 --- a/src/nm-device-802-11-wireless.h +++ b/src/nm-device-802-11-wireless.h @@ -92,6 +92,8 @@ const char * nm_device_802_11_wireless_get_essid (NMDevice80211Wireless *self); gboolean nm_device_802_11_wireless_set_mode (NMDevice80211Wireless *self, const int mode); +int nm_device_802_11_wireless_get_bitrate (NMDevice80211Wireless *self); + NMAccessPoint * nm_device_802_11_wireless_get_best_ap (NMDevice80211Wireless *dev); NMAccessPoint * nm_device_802_11_wireless_get_activation_ap (NMDevice80211Wireless *dev, diff --git a/src/nm-device-802-3-ethernet.c b/src/nm-device-802-3-ethernet.c index f91373d096..3355646584 100644 --- a/src/nm-device-802-3-ethernet.c +++ b/src/nm-device-802-3-ethernet.c @@ -332,8 +332,8 @@ supports_ethtool_carrier_detect (NMDevice8023Ethernet *self) iface = nm_device_get_iface (NM_DEVICE (self)); if ((sk = nm_dev_sock_open (NM_DEVICE (self), DEV_GENERAL, __func__, NULL)) == NULL) { - nm_warning ("cannot open socket on interface %s for ethtool detect; errno=%d", - iface, errno); + nm_warning ("cannot open socket on interface %s for ethtool detect: %s", + iface, strerror (errno)); return FALSE; } @@ -357,6 +357,37 @@ out: } +int +nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *self) +{ + NMSock * sk; + struct ifreq ifr; + struct ethtool_cmd edata; + const char * iface; + int speed = 0; + + g_return_val_if_fail (self != NULL, FALSE); + + iface = nm_device_get_iface (NM_DEVICE (self)); + if ((sk = nm_dev_sock_open (NM_DEVICE (self), DEV_GENERAL, __func__, NULL)) == NULL) + { + nm_warning ("cannot open socket on interface %s for ethtool: %s", + iface, strerror (errno)); + return FALSE; + } + + strncpy (ifr.ifr_name, iface, sizeof (ifr.ifr_name) - 1); + edata.cmd = ETHTOOL_GSET; + ifr.ifr_data = (char *) &edata; + if (ioctl (nm_dev_sock_get_fd (sk), SIOCETHTOOL, &ifr) == -1) + goto out; + speed = edata.speed; + +out: + nm_dev_sock_close (sk); + return speed; +} + /**************************************/ /* MII capability detection */ diff --git a/src/nm-device-802-3-ethernet.h b/src/nm-device-802-3-ethernet.h index da098c2809..f976ab4cc1 100644 --- a/src/nm-device-802-3-ethernet.h +++ b/src/nm-device-802-3-ethernet.h @@ -73,6 +73,8 @@ void nm_device_802_3_ethernet_get_address (NMDevice8023Ethernet *dev, void nm_device_802_3_ethernet_set_address (NMDevice8023Ethernet *dev); +int nm_device_802_3_ethernet_get_speed (NMDevice8023Ethernet *self); + G_END_DECLS #endif /* NM_DEVICE_802_3_ETHERNET_H */ diff --git a/test/nm-tool.c b/test/nm-tool.c index 601c26608e..4c13ac3021 100644 --- a/test/nm-tool.c +++ b/test/nm-tool.c @@ -184,8 +184,13 @@ static void detail_network (DBusConnection *connection, const char *path, const enc_string = g_string_append (enc_string, ")"); } - temp = g_strdup_printf ("%s Mode, Freq %.3f MHz, Strength %d%%%s%s", (mode == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc", - flt_freq, strength, (enc_string && strlen (enc_string->str)) ? enc_string->str : "", !broadcast ? ", Hidden" : ""); + temp = g_strdup_printf ("%s Mode, Freq %.3f MHz, Rate %d Mb/s, Strength %d%%%s%s", + (mode == IW_MODE_INFRA) ? "Infrastructure" : "Ad-Hoc", + flt_freq, + rate / 1024, + strength, + (enc_string && strlen (enc_string->str)) ? enc_string->str : "", + !broadcast ? ", Hidden" : ""); temp_essid = g_strdup_printf (" %s%s", active ? "*" : "", essid); print_string (temp_essid, temp); g_string_free (enc_string, TRUE); @@ -251,6 +256,7 @@ static void detail_device (DBusConnection *connection, const char *path) dbus_int32_t strength = -1; char * active_network_path = NULL; dbus_bool_t link_active = FALSE; + dbus_int32_t speed = 0; dbus_uint32_t caps = NM_DEVICE_CAP_NONE; dbus_uint32_t type_caps = NM_DEVICE_CAP_NONE; char ** networks = NULL; @@ -287,9 +293,10 @@ static void detail_device (DBusConnection *connection, const char *path) DBUS_TYPE_STRING, &route, DBUS_TYPE_STRING, &primary_dns, DBUS_TYPE_STRING, &secondary_dns, - DBUS_TYPE_INT32, &mode, + DBUS_TYPE_INT32, &mode, DBUS_TYPE_INT32, &strength, DBUS_TYPE_BOOLEAN,&link_active, + DBUS_TYPE_INT32, &speed, DBUS_TYPE_UINT32, &caps, DBUS_TYPE_UINT32, &type_caps, DBUS_TYPE_STRING, &active_network_path, @@ -328,6 +335,15 @@ static void detail_device (DBusConnection *connection, const char *path) if (caps & NM_DEVICE_CAP_CARRIER_DETECT) print_string (" Carrier Detect", "yes"); + if (speed) + { + char *speed_string; + + speed_string = g_strdup_printf ("%d Mb/s", speed); + print_string (" Speed", speed_string); + g_free (speed_string); + } + /* Wireless specific information */ if (type == DEVICE_TYPE_802_11_WIRELESS) {