Author: ks156
Date: 2009-02-11 14:50:06 +0100 (Wed, 11 Feb 2009)
New Revision: 3605
Modified:
software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_unix.c
Log:
* Fixed a bug with the wireless channel detection on unix systems :
The iface name is not alway wlan0. It can be wlan1, 2, ... or even ath0 for
the atheros cards.
The detection is now done by scanning the wireless ifaces in
/proc/net/wireless.
Modified: software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_unix.c
===================================================================
--- software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_unix.c
2009-02-11 13:26:39 UTC (rev 3604)
+++ software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_unix.c
2009-02-11 13:50:06 UTC (rev 3605)
@@ -23,6 +23,7 @@
#include <stdbool.h>
#include <string.h>
+static int find_channel(char * iface);
/**
* \brief Program entry point.
* Return the current used channel or -1.
@@ -30,14 +31,62 @@
int main(int argc, char *argv[])
{
int channel = -1;
+ int chan = 0;
FILE *pcmd;
char buff[80];
+ char iface[80];
+
+ /* Try to read the file containing the wireless card informations */
+ pcmd = popen("cat /proc/net/wireless", "r");
+
+ /* If the command is done without problem, read the output stream */
+ if (pcmd != NULL)
+ {
+ while (fgets(buff, 80, pcmd))
+ {
+ /* Try to find ":" which indicate a new iface line */
+ if (strstr(buff, ":") != NULL)
+ {
+ sscanf(strtok(buff, ":"), "%s", iface);
+ /* And try to determine the channel */
+ chan = find_channel(iface);
+ /* If the channel has been found, break the loop.
+ * Otherwise, continue with the next iface (if exists) */
+ if (chan > 0)
+ {
+ channel = chan;
+ break;
+ }
+ }
+ }
+ }
+ printf("[UNIX] Channel found : %d\n", channel);
+ fclose(pcmd);
+
+ return channel;
+}
+
+/**
+ * Find the channel of the current wireless interface.
+ * @param iface : the interface name.
+ * @return the channel, or -1 if no channels has been found.
+ */
+static int find_channel(char * iface)
+{
+ FILE *pcmd;
+ char buff[80];
+ char cmd[80];
float frequency;
- pcmd = popen("iwconfig wlan0", "r");
+ /* Include the iface to the command */
+ memcpy(cmd, "iwconfig ", 9);
+ strcat(cmd, iface);
+ /* Send the command */
+ pcmd = popen(cmd , "r");
if (pcmd != NULL)
{
+ /* And search for the frequency used by the iface */
while(fgets(buff, 80, pcmd))
{
if ((strstr(buff, "Mode:") != NULL) &&
@@ -45,16 +94,11 @@
{
sscanf(strstr(buff, "Frequency:"), "Frequency: %f GHz",
&frequency);
frequency *= 1000.01;
- channel = (int)(frequency - 2407.) / 5;
- break;
+ fclose(pcmd);
+ return (int)(frequency - 2407.) / 5;
}
}
-
fclose(pcmd);
}
-
- printf("[UNIX] Channel found : %d\n", channel);
-
- return channel;
+ return -1;
}
-
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn