]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2003-11-14 05:59:37 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Fri, 14 Nov 2003 05:59:37 +0000 (05:59 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Fri, 14 Nov 2003 05:59:37 +0000 (05:59 +0000)
added wifi.c wifi.h which have been forgotten at the last checkin

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@273 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

wifi.c [new file with mode: 0644]
wifi.h [new file with mode: 0644]

diff --git a/wifi.c b/wifi.c
new file mode 100644 (file)
index 0000000..9a9b136
--- /dev/null
+++ b/wifi.c
@@ -0,0 +1,122 @@
+/* $Id: wifi.c,v 1.1 2003/11/14 05:59:37 reinelt Exp $
+ *
+ * WIFI specific functions
+ *
+ * Copyright 2003 Xavier Vello <xavier66@free.fr>
+ * 
+ * based on lcd4linux/isdn.c which is
+ * Copyright 1999, 2000 by Michael Reinelt (reinelt@eunet.at)
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: wifi.c,v $
+ * Revision 1.1  2003/11/14 05:59:37  reinelt
+ * added wifi.c wifi.h which have been forgotten at the last checkin
+ *
+ */
+
+/* 
+ * exported functions:
+ *
+ * Wifi (int *signal, int *link, int *noise)
+ *   returns 0 if ok, -1 if error
+ *   sets *signal to signal level (which determines the rate)
+ *   sets *link to link quality
+ *   sets *noise to noise level (reverse of link quality)
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+
+#include "debug.h"
+#include "wifi.h"
+#include "filter.h"
+
+typedef struct {
+  int signal;
+  int link;
+  int noise;
+} CPS;
+
+int Wifi (int *signal, int *link, int *noise)
+{
+  *signal=0;
+  *link=0;
+  *noise=0;
+  int ws, wl, wn;
+  static int fd=-2;
+  char buffer[4096];  
+  char *p;
+  if (fd==-1) return -1;       
+       
+  if (fd==-2) {
+    fd = open("/proc/net/wireless", O_RDONLY);   // the real procfs file
+    // fd = open("/wireless", O_RDONLY);         // a fake file for testing
+    if (fd==-1) {
+      error ("open(/proc/net/wireless) failed: %s", strerror(errno));
+      return -1;
+    }
+    debug ("open(/proc/net/wireless)=%d", fd);
+  }
+  
+  if (lseek(fd, 0L, SEEK_SET)!=0) {
+    error ("lseek(/proc/net/wireless) failed: %s", strerror(errno));
+    fd=-1;
+    return -1;
+  }  
+
+  if (read (fd, &buffer, sizeof(buffer)-1)==-1) {
+    error("read(/proc/net/wireless) failed: %s", strerror(errno));
+    fd=-1;
+    return -1;
+  }
+  
+  p=strstr(buffer, "wlan0");
+  if (p!=NULL) {
+    if (sscanf(p+13, "%d", &wl)!=1) { 
+      error ("parse(/proc/net/wireless) failed: unknown format");
+      fd=-1;
+      return -1;
+    }            
+    if (sscanf(p+19, "%d", &ws)!=1) { 
+      error ("parse(/proc/net/wireless) failed: unknown format");
+      fd=-1;
+      return -1;
+    } 
+    if (sscanf(p+25, "%d", &wn)!=1) { 
+      error ("parse(/proc/net/wireless) failed: unknown format");
+      fd=-1;
+      return -1;
+    }  
+  } else {
+    error("read(/proc/net/wireless) failed: %s", strerror(errno));
+    fd=-1;
+    return -1;
+  }      
+  *signal=ws;
+  *link=wl;
+  *noise=wn;
+  return 0; 
+}
diff --git a/wifi.h b/wifi.h
new file mode 100644 (file)
index 0000000..871a44b
--- /dev/null
+++ b/wifi.h
@@ -0,0 +1,38 @@
+/* $Id: wifi.h,v 1.1 2003/11/14 05:59:37 reinelt Exp $
+ *
+ * WIFI specific functions
+ *
+ * Copyright 2003 Xavier Vello <xavier66@free.fr>
+ * 
+ * based on lcd4linux/isdn.c which is
+ * Copyright 1999, 2000 by Michael Reinelt <reinelt@eunet.at>
+ *
+ * This file is part of LCD4Linux.
+ *
+ * LCD4Linux is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * LCD4Linux is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * $Log: wifi.h,v $
+ * Revision 1.1  2003/11/14 05:59:37  reinelt
+ * added wifi.c wifi.h which have been forgotten at the last checkin
+ *
+ */
+
+#ifndef _WIFI_H_
+#define _WIFI_H_
+
+int Wifi (int *signal, int *link, int *noise);
+
+#endif