Add FreeBSD Aironet support to the wireless applet. This uses code

borrowed from ancontrol.  It was tested with PC340 and PC350 Aironet cards.
Since I don't own any wi-driven cards, I was not able to add support
for those.  Contributions welcome...
This commit is contained in:
Joe Marcus Clarke 2003-02-16 23:32:35 +00:00
parent 3f5c794385
commit 5e94494e9c
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=75669
4 changed files with 466 additions and 0 deletions

View File

@ -7,6 +7,7 @@
PORTNAME= gnomeapplets2
PORTVERSION= 2.2.0
PORTREVISION= 1
CATEGORIES= x11 gnome
MASTER_SITES= ${MASTER_SITE_GNOME}
MASTER_SITE_SUBDIR= sources/gnome-applets/2.2

View File

@ -0,0 +1,232 @@
--- wireless/wireless-applet.c.orig Sun Feb 16 00:12:42 2003
+++ wireless/wireless-applet.c Sun Feb 16 18:19:34 2003
@@ -30,12 +30,24 @@
#include <math.h>
#include <dirent.h>
+#ifdef __FreeBSD__
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <dev/an/if_aironet_ieee.h>
+#endif
+
#include <gnome.h>
#include <panel-applet.h>
#include <panel-applet-gconf.h>
#include <glade/glade.h>
+#ifdef __FreeBSD__
+#define CFG_DEVICE "an0"
+#else
#define CFG_DEVICE "eth0"
+#endif
#define CFG_UPDATE_INTERVAL 2
typedef enum {
@@ -93,6 +105,10 @@
WirelessApplet *applet);
static void wireless_applet_about_cb (BonoboUIComponent *uic,
WirelessApplet *applet);
+#ifdef __FreeBSD__
+static int an_getval(WirelessApplet *applet, char *device, struct an_req *areq);
+static void get_an_data(WirelessApplet *applet, char *device, long int *level);
+#endif
static const BonoboUIVerb wireless_menu_verbs [] = {
BONOBO_UI_UNSAFE_VERB ("WirelessProperties",
@@ -150,7 +166,9 @@
g_free (tmp);
/* Update the image */
+#ifndef __FreeBSD__
percent = CLAMP (percent, 0, 100);
+#endif
if (applet->pixmaps[percent] != applet->current_pixmap)
{
@@ -234,6 +252,7 @@
int percent;
/* Calculate the percentage based on the link quality */
+#ifndef __FreeBSD__
if (level < 0) {
percent = -1;
} else {
@@ -244,6 +263,9 @@
percent = CLAMP (percent, 0, 100);
}
}
+#else
+ percent = (int)level;
+#endif
if (percent < 0) {
applet->state = BUSTED_LINK;
@@ -387,22 +409,107 @@
applet->show_dialogs = show;
}
+#ifdef __FreeBSD__
+static int
+an_getval(WirelessApplet *applet, char *device, struct an_req *areq)
+{
+ struct ifreq ifr;
+ int s;
+
+ bzero((char *)&ifr, sizeof(ifr));
+
+ strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+ ifr.ifr_data = (caddr_t)areq;
+
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (s == -1) {
+ gtk_tooltips_set_tip (applet->tips,
+ GTK_WIDGET (applet),
+ "Socket Error",
+ NULL);
+ return 0;
+ }
+
+ if (ioctl(s, SIOCGAIRONET, &ifr) == -1) {
+ gtk_tooltips_set_tip (applet->tips,
+ GTK_WIDGET (applet),
+ "ioctl Error",
+ NULL);
+ return 0;
+ }
+
+ close(s);
+ return 1;
+}
+
+static void
+get_an_data (WirelessApplet *applet, char *device, long int *level)
+{
+ struct an_req areq;
+ struct an_ltv_status *sts;
+ struct an_ltv_rssi_map an_rssimap;
+ long int signal_strength;
+ int rssimap_valid = 0;
+
+ an_rssimap.an_len = sizeof(an_rssimap);
+ an_rssimap.an_type = AN_RID_RSSI_MAP;
+ rssimap_valid = an_getval(applet, device, (struct an_req*)&an_rssimap);
+
+ areq.an_len = sizeof(areq);
+ areq.an_type = AN_RID_STATUS;
+
+ (void)an_getval(applet, device, &areq);
+
+ sts = (struct an_ltv_status *)&areq;
+ if (rssimap_valid)
+ signal_strength = (long int)(an_rssimap.an_entries[
+ sts->an_normalized_strength].an_rss_pct);
+ else
+ signal_strength = (long int)(sts->an_normalized_strength);
+
+ memcpy(level, &signal_strength, sizeof(level));
+}
+#endif
+
/* check stats, modify the state attribute */
static void
wireless_applet_read_device_state (WirelessApplet *applet)
{
- long int level, noise;
- double link;
+ long int level;
char device[256];
+#ifdef __FreeBSD__
+ struct if_nameindex *ifstart, *ifs;
+#else
+ long int noise;
+ double link;
char line[256];
+#endif
/* resest list of available wireless devices */
g_list_foreach (applet->devices, (GFunc)g_free, NULL);
g_list_free (applet->devices);
applet->devices = NULL;
+#ifdef __FreeBSD__
+ ifs = ifstart = if_nameindex();
+#endif
/* Here we begin to suck... */
do {
+#ifdef __FreeBSD__
+ if (ifs == NULL || ifs->if_name == NULL) {
+ break;
+ }
+ strlcpy(device, ifs->if_name, 6);
+ if (g_strncasecmp(device, "an", 2)==0) {
+ applet->devices = g_list_prepend (applet->devices, g_strdup (device));
+ if (g_strcasecmp(applet->device, device)==0) {
+ get_an_data(applet, device, &level);
+ wireless_applet_update_state (applet, device, 0, level, 0);
+ }
+ }
+ ifs++;
+#else
char *ptr;
fgets (line, 256, applet->file);
@@ -435,6 +542,7 @@
wireless_applet_update_state (applet, device, link, level, noise);
}
}
+#endif
} while (1);
if (g_list_length (applet->devices)==1) {
@@ -446,15 +554,21 @@
}
/* rewind the /proc/net/wireless file */
+#ifdef __FreeBSD__
+ if_freenameindex(ifstart);
+#else
rewind (applet->file);
+#endif
}
static int
wireless_applet_timeout_handler (WirelessApplet *applet)
{
+#ifndef __FreeBSD__
if (applet->file == NULL) {
return FALSE;
}
+#endif
wireless_applet_read_device_state (applet);
@@ -517,6 +631,7 @@
static void
start_file_read (WirelessApplet *applet)
{
+#ifndef __FreeBSD__
applet->file = fopen ("/proc/net/wireless", "rt");
if (applet->file == NULL) {
gtk_tooltips_set_tip (applet->tips,
@@ -525,6 +640,7 @@
NULL);
show_error_dialog (_("There doesn't seem to be any wireless devices configured on your system.\nPlease verify your configuration if you think this is incorrect."));
}
+#endif
}
static void
@@ -766,7 +882,9 @@
applet->prefs = NULL;
}
+#ifndef __FreeBSD__
fclose (applet->file);
+#endif
}
static GtkWidget *

View File

@ -7,6 +7,7 @@
PORTNAME= gnomeapplets2
PORTVERSION= 2.2.0
PORTREVISION= 1
CATEGORIES= x11 gnome
MASTER_SITES= ${MASTER_SITE_GNOME}
MASTER_SITE_SUBDIR= sources/gnome-applets/2.2

View File

@ -0,0 +1,232 @@
--- wireless/wireless-applet.c.orig Sun Feb 16 00:12:42 2003
+++ wireless/wireless-applet.c Sun Feb 16 18:19:34 2003
@@ -30,12 +30,24 @@
#include <math.h>
#include <dirent.h>
+#ifdef __FreeBSD__
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/if_var.h>
+#include <dev/an/if_aironet_ieee.h>
+#endif
+
#include <gnome.h>
#include <panel-applet.h>
#include <panel-applet-gconf.h>
#include <glade/glade.h>
+#ifdef __FreeBSD__
+#define CFG_DEVICE "an0"
+#else
#define CFG_DEVICE "eth0"
+#endif
#define CFG_UPDATE_INTERVAL 2
typedef enum {
@@ -93,6 +105,10 @@
WirelessApplet *applet);
static void wireless_applet_about_cb (BonoboUIComponent *uic,
WirelessApplet *applet);
+#ifdef __FreeBSD__
+static int an_getval(WirelessApplet *applet, char *device, struct an_req *areq);
+static void get_an_data(WirelessApplet *applet, char *device, long int *level);
+#endif
static const BonoboUIVerb wireless_menu_verbs [] = {
BONOBO_UI_UNSAFE_VERB ("WirelessProperties",
@@ -150,7 +166,9 @@
g_free (tmp);
/* Update the image */
+#ifndef __FreeBSD__
percent = CLAMP (percent, 0, 100);
+#endif
if (applet->pixmaps[percent] != applet->current_pixmap)
{
@@ -234,6 +252,7 @@
int percent;
/* Calculate the percentage based on the link quality */
+#ifndef __FreeBSD__
if (level < 0) {
percent = -1;
} else {
@@ -244,6 +263,9 @@
percent = CLAMP (percent, 0, 100);
}
}
+#else
+ percent = (int)level;
+#endif
if (percent < 0) {
applet->state = BUSTED_LINK;
@@ -387,22 +409,107 @@
applet->show_dialogs = show;
}
+#ifdef __FreeBSD__
+static int
+an_getval(WirelessApplet *applet, char *device, struct an_req *areq)
+{
+ struct ifreq ifr;
+ int s;
+
+ bzero((char *)&ifr, sizeof(ifr));
+
+ strlcpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+ ifr.ifr_data = (caddr_t)areq;
+
+ s = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (s == -1) {
+ gtk_tooltips_set_tip (applet->tips,
+ GTK_WIDGET (applet),
+ "Socket Error",
+ NULL);
+ return 0;
+ }
+
+ if (ioctl(s, SIOCGAIRONET, &ifr) == -1) {
+ gtk_tooltips_set_tip (applet->tips,
+ GTK_WIDGET (applet),
+ "ioctl Error",
+ NULL);
+ return 0;
+ }
+
+ close(s);
+ return 1;
+}
+
+static void
+get_an_data (WirelessApplet *applet, char *device, long int *level)
+{
+ struct an_req areq;
+ struct an_ltv_status *sts;
+ struct an_ltv_rssi_map an_rssimap;
+ long int signal_strength;
+ int rssimap_valid = 0;
+
+ an_rssimap.an_len = sizeof(an_rssimap);
+ an_rssimap.an_type = AN_RID_RSSI_MAP;
+ rssimap_valid = an_getval(applet, device, (struct an_req*)&an_rssimap);
+
+ areq.an_len = sizeof(areq);
+ areq.an_type = AN_RID_STATUS;
+
+ (void)an_getval(applet, device, &areq);
+
+ sts = (struct an_ltv_status *)&areq;
+ if (rssimap_valid)
+ signal_strength = (long int)(an_rssimap.an_entries[
+ sts->an_normalized_strength].an_rss_pct);
+ else
+ signal_strength = (long int)(sts->an_normalized_strength);
+
+ memcpy(level, &signal_strength, sizeof(level));
+}
+#endif
+
/* check stats, modify the state attribute */
static void
wireless_applet_read_device_state (WirelessApplet *applet)
{
- long int level, noise;
- double link;
+ long int level;
char device[256];
+#ifdef __FreeBSD__
+ struct if_nameindex *ifstart, *ifs;
+#else
+ long int noise;
+ double link;
char line[256];
+#endif
/* resest list of available wireless devices */
g_list_foreach (applet->devices, (GFunc)g_free, NULL);
g_list_free (applet->devices);
applet->devices = NULL;
+#ifdef __FreeBSD__
+ ifs = ifstart = if_nameindex();
+#endif
/* Here we begin to suck... */
do {
+#ifdef __FreeBSD__
+ if (ifs == NULL || ifs->if_name == NULL) {
+ break;
+ }
+ strlcpy(device, ifs->if_name, 6);
+ if (g_strncasecmp(device, "an", 2)==0) {
+ applet->devices = g_list_prepend (applet->devices, g_strdup (device));
+ if (g_strcasecmp(applet->device, device)==0) {
+ get_an_data(applet, device, &level);
+ wireless_applet_update_state (applet, device, 0, level, 0);
+ }
+ }
+ ifs++;
+#else
char *ptr;
fgets (line, 256, applet->file);
@@ -435,6 +542,7 @@
wireless_applet_update_state (applet, device, link, level, noise);
}
}
+#endif
} while (1);
if (g_list_length (applet->devices)==1) {
@@ -446,15 +554,21 @@
}
/* rewind the /proc/net/wireless file */
+#ifdef __FreeBSD__
+ if_freenameindex(ifstart);
+#else
rewind (applet->file);
+#endif
}
static int
wireless_applet_timeout_handler (WirelessApplet *applet)
{
+#ifndef __FreeBSD__
if (applet->file == NULL) {
return FALSE;
}
+#endif
wireless_applet_read_device_state (applet);
@@ -517,6 +631,7 @@
static void
start_file_read (WirelessApplet *applet)
{
+#ifndef __FreeBSD__
applet->file = fopen ("/proc/net/wireless", "rt");
if (applet->file == NULL) {
gtk_tooltips_set_tip (applet->tips,
@@ -525,6 +640,7 @@
NULL);
show_error_dialog (_("There doesn't seem to be any wireless devices configured on your system.\nPlease verify your configuration if you think this is incorrect."));
}
+#endif
}
static void
@@ -766,7 +882,9 @@
applet->prefs = NULL;
}
+#ifndef __FreeBSD__
fclose (applet->file);
+#endif
}
static GtkWidget *