dockapps/wmifinfo/nwn.c

81 lines
1.3 KiB
C
Raw Normal View History

/*
* This code reads the /proc/driver/poldhu/eth# file for the No Wires Needed poldhu
* cards. Since there seems to be no official range for the 'Quality' value I assume
* it's between 0 and 15, and multiply by 4 to get the range 0-63...
*
2014-07-29 03:50:59 +00:00
* $Id: nwn.c,v 1.2 2002/09/15 14:31:41 ico Exp $
*
*/
#ifdef ENABLE_NWN_SUPPORT
#include <stdio.h>
#include <string.h>
#define POLDHUPATH "/proc/driver/poldhu/%s"
#define SWALLOWPATH "/proc/driver/swallow/%s"
int nwn_get_link(char *ifname)
{
FILE *f;
char buf[256];
char *key, *val;
char *p;
char bssid[32] = "";
int inbssid = 0;
int link = 0;
sprintf(buf, POLDHUPATH, ifname);
f = fopen(buf, "r");
2014-10-05 15:29:59 +00:00
if(f == NULL) {
sprintf(buf, SWALLOWPATH, ifname);
f = fopen(buf, "r");
}
2014-10-05 15:29:59 +00:00
if(f == NULL) {
return(0);
}
2014-10-05 15:29:59 +00:00
while(fgets(buf, sizeof(buf), f)) {
p = strchr(buf, '\n');
if(p) *p=0;
p = strchr(buf, ':');
2014-10-05 15:29:59 +00:00
if(p) {
*p=0;
key = buf;
val = p+2;
p--;
while((*p == ' ') || (*p == '\t')) {
*p=0;
p--;
}
2014-10-05 15:29:59 +00:00
if(strcmp(key, "Current BSSID") == 0) {
strcpy(bssid, val);
}
2014-10-05 15:29:59 +00:00
if((strcmp(key, "BSSID") == 0) &&
(strcmp(val, bssid) == 0)) {
inbssid = 1;
}
2014-10-05 15:29:59 +00:00
if((inbssid == 1) &&
(strcmp(key, "Quality") == 0)) {
sscanf(val, "%X", &link);
link *= 4;
inbssid = 0;
}
}
}
2014-10-05 15:29:59 +00:00
fclose(f);
2014-10-05 15:29:59 +00:00
return(link);
}
#endif