here's a patch for nm-applet to show channel info



Hi,

The attached patch modifies nm-applet to display which channel each wireless network is on which is useful if you're in an area with lots of wireless networks and you want to set your AP to a channel in a range far enough away from all of the others that you can actually connect to your own AP.

Hopefully you'll find this useful.

Katie

diff -upr nm-applet-0.6.5/ChangeLog nm-applet-0.6.5-kg/ChangeLog
--- nm-applet-0.6.5/ChangeLog	2007-04-19 14:01:22.000000000 -0400
+++ nm-applet-0.6.5-kg/ChangeLog	2007-10-20 14:38:32.000000000 -0400
@@ -1,3 +1,21 @@
+2007-10-20  Katelin Ganzer
+
+	* src/menu-items.c (network_menu_item_update): Set the channel #
+	text on the GtkProgressBar for the wireless network item.
+
+	* src/applet-dbus-devices.c (nma_dbus_net_properties_cb): Store
+	the channel info using the new wireless_network_set_channel()
+	function.
+	(channel_from_frequency): New function to map a frequency to a
+	channel.
+
+	* src/wireless-network.c (wireless_network_get_channel): New
+	function to get the stored channel # that his wireles network is
+	using.
+	(wireless_network_set_channel): New function to store the channel
+	# that this network is using.
+	(wireless_network_copy): Copy the channel #.
+
 2007-03-21  Pema Geyleg <pema geyleg gmail com>
 
 	* configure.ac: Added 'dz' to ALL_LINGUAS
diff -upr nm-applet-0.6.5/src/applet-dbus-devices.c nm-applet-0.6.5-kg/src/applet-dbus-devices.c
--- nm-applet-0.6.5/src/applet-dbus-devices.c	2007-04-19 14:01:13.000000000 -0400
+++ nm-applet-0.6.5-kg/src/applet-dbus-devices.c	2007-10-20 14:45:04.000000000 -0400
@@ -504,6 +504,67 @@ static void free_net_prop_cb_data (NetPr
 	g_free (data);
 }
 
+static struct ChanFreqRange {
+	guint8 chan_min;
+	guint8 chan_max;
+	guint8 chan_step;
+	double freq_min;
+	double freq_max;
+	double freq_step;
+} chan_freq_ranges[] = {
+	{   1,  11, 1, 2.412f, 2.462f, 0.005f },
+	{  36,  64, 4, 5.18f,  5.320f, 0.020f },
+	{ 149, 165, 4, 5.745f, 5.825f, 0.020f }
+};
+
+/**
+ * channel_from_frequency:
+ * @freq: Frequency in Hz
+ *
+ * Maps the provided frequency with a channel.
+ *
+ * Returns the channel on success or 0 if unknown.
+ **/
+static guint8
+channel_from_frequency (double freq)
+{
+	struct ChanFreqRange *range = chan_freq_ranges;
+	double min, max;
+	guint8 chan;
+	int i;
+	
+	freq /= 1000000000.0;
+	
+	for (i = 0; i < G_N_ELEMENTS (chan_freq_ranges); i++, range++) {
+		max = range->freq_max + range->freq_step;
+		
+		if (freq > max) {
+			/* frequency not in this range, maybe in the next range? */
+			continue;
+		}
+		
+		min = range->freq_min - range->freq_step;
+		
+		if (freq < min) {
+			/* ranges go up in frequency, so if this is too high then later ranges won't match either */
+			break;
+		}
+		
+		max = range->freq_min + range->freq_step;
+		for (chan = range->chan_min; chan <= range->chan_max; chan += range->chan_step) {
+			if (freq > min && freq < max)
+				return chan;
+			
+			min += range->freq_step;
+			max += range->freq_step;
+		}
+	}
+	
+	/* unknown channel frequency */
+	
+	return 0;
+}
+
 
 /*
  * nma_dbus_net_properties_cb
@@ -566,7 +627,7 @@ static void nma_dbus_net_properties_cb (
 									DBUS_TYPE_INVALID))
 	{
 		NetworkDevice *	dev;
-
+		
 		if ((dev = nma_get_device_for_nm_path (applet->device_list, cb_data->dev_op)))
 		{
 			WirelessNetwork *	net = wireless_network_new (essid, op);
@@ -584,6 +645,7 @@ static void nma_dbus_net_properties_cb (
 			wireless_network_set_mode (net, mode);
 			wireless_network_set_capabilities (net, capabilities);
 			wireless_network_set_strength (net, strength);
+			wireless_network_set_channel (net, channel_from_frequency (freq));
 			if (act_net && strlen (act_net) && (strcmp (act_net, op) == 0))
 				wireless_network_set_active (net, TRUE);
 			g_free (act_net);
diff -upr nm-applet-0.6.5/src/menu-items.c nm-applet-0.6.5-kg/src/menu-items.c
--- nm-applet-0.6.5/src/menu-items.c	2007-04-19 14:01:13.000000000 -0400
+++ nm-applet-0.6.5-kg/src/menu-items.c	2007-10-20 14:35:29.000000000 -0400
@@ -242,7 +242,7 @@ GtkCheckMenuItem *network_menu_item_get_
 void network_menu_item_update (NMApplet *applet, NMNetworkMenuItem *item,
 						 WirelessNetwork *network, const gboolean is_encrypted)
 {
-	char *	display_essid;
+	char *	display_essid, *channel = NULL;
 	gdouble	percent;
 	gboolean	encrypted = FALSE;
 	gboolean	adhoc = FALSE;
@@ -253,6 +253,11 @@ void network_menu_item_update (NMApplet 
 	display_essid = nm_menu_network_escape_essid_for_display (wireless_network_get_essid (network));
 	gtk_label_set_text (GTK_LABEL (item->label), display_essid);
 	g_free (display_essid);
+	
+	if (wireless_network_get_channel (network) != 0)
+		channel = g_strdup_printf (_("Channel %d"), (int) wireless_network_get_channel (network));
+	gtk_progress_bar_set_text (GTK_PROGRESS_BAR (item->progress), channel);
+	g_free (channel);
 
 	percent = (double) CLAMP (wireless_network_get_strength (network), 0, 100) / 100.0;
 	gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (item->progress), percent);
diff -upr nm-applet-0.6.5/src/wireless-network.c nm-applet-0.6.5-kg/src/wireless-network.c
--- nm-applet-0.6.5/src/wireless-network.c	2007-04-19 14:01:12.000000000 -0400
+++ nm-applet-0.6.5-kg/src/wireless-network.c	2007-10-20 14:31:47.000000000 -0400
@@ -37,6 +37,7 @@ struct WirelessNetwork
 	char *	essid;
 	gboolean	active;
 	gint8	strength;
+	guint8    channel;
 	int		mode;
 	int		capabilities;
 };
@@ -82,6 +83,7 @@ WirelessNetwork *wireless_network_copy (
 	net->active = src->active;
 	net->capabilities = src->capabilities;
 	net->strength = src->strength;
+	net->channel = src->channel;
 
 	return net;
 }
@@ -210,3 +212,19 @@ void wireless_network_set_strength (Wire
 	net->strength = strength;
 }
 
+/*
+ * Accesors for channel
+ */
+guint8 wireless_network_get_channel (WirelessNetwork *net)
+{
+	g_return_val_if_fail (net != NULL, FALSE);
+
+	return net->channel;
+}
+
+void wireless_network_set_channel (WirelessNetwork *net, guint8 channel)
+{
+	g_return_if_fail (net != NULL);
+
+	net->channel = channel;
+}
diff -upr nm-applet-0.6.5/src/wireless-network.h nm-applet-0.6.5-kg/src/wireless-network.h
--- nm-applet-0.6.5/src/wireless-network.h	2007-04-19 14:01:12.000000000 -0400
+++ nm-applet-0.6.5-kg/src/wireless-network.h	2007-10-20 14:32:07.000000000 -0400
@@ -47,4 +47,7 @@ void				wireless_network_set_mode		(Wire
 gint8			wireless_network_get_strength		(WirelessNetwork *net);
 void				wireless_network_set_strength		(WirelessNetwork *net, gint8 strength);
 
+guint8			wireless_network_get_channel		(WirelessNetwork *net);
+void				wireless_network_set_channel		(WirelessNetwork *net, guint8 channel);
+
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]