Author: ks156
Date: 2009-01-15 16:11:01 +0100 (Thu, 15 Jan 2009)
New Revision: 3469

Modified:
   software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_win32.c
Log:
* Added the Vista part (with netsh).
  The code should work with all languages. If the channel cannot
  be found, the program stops and return -1

Modified: software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_win32.c
===================================================================
--- software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_win32.c      
2009-01-15 11:15:26 UTC (rev 3468)
+++ software_suite_v2/software/tux_wifi_channel/trunk/wifi_channel_win32.c      
2009-01-15 15:11:01 UTC (rev 3469)
@@ -506,6 +506,90 @@
 
         printf("[XP] Channel found : %d\n", channel);
     }
+    /* Version is vista or more recently */
+    else
+    {
+               /*
+                * This way to retrieve the Wifi channel currently used is a 
bit tricky.
+                * Previously, an easiest code was written, but was parsing 
directly the
+                * strings. 
+                * The major problem is that netsh return translated strings. 
So it's
+                * it's almost impossible to do it working for all languages !
+                *
+                * This maner search for string untralsted, like SSID or BSSID, 
and count
+                * the lines to retrieve the channel.
+                */
+        FILE *pcmd;
+        char buff[80];
+        char connected_SSID[32];
+               char current_SSID[32];
 
-    return channel;
+        /* If no SSID specified then attempt to retrieve the current
+         * used SSID */
+        if (strcmp("", requested_SSID) == 0)
+        {
+            pcmd = popen("netsh wlan show interface", "r");
+
+            if (pcmd != NULL)
+            {
+                while(fgets(buff, 80, pcmd))
+                {
+                                       /* Parse the string : Be sure to 
considere the SSID line,
+                                        * and not BSSID */
+                    if ((strstr(buff, "SSID") != NULL) &&
+                        (strstr(buff, "BSSID") == NULL))
+                    {
+                        sscanf(strrchr(buff, ':'), ": %s", &connected_SSID[0]);
+                                               /* Assign the active SSID */
+                        requested_SSID = connected_SSID;
+                        break;
+                    }
+                }
+                fclose(pcmd);
+            }
+        }
+               
+               /* Search the channel */
+        pcmd = popen("netsh wlan show network mode=BSSID", "r");
+               
+        if (pcmd != NULL)
+        {
+            while(fgets(buff, 80, pcmd))
+            {
+                               /* Search for the correct SSID */
+                               if ((strstr(buff, "SSID") != NULL) &&
+                     (strstr(buff, "BSSID") == NULL))
+                {
+                    sscanf(strrchr(buff, ':'), ": %s", &current_SSID[0]);
+                                       /* If the current scanned SSID is the 
requested one, continue */
+                                       if (strcmp(current_SSID,requested_SSID) 
== 0)
+                                       {
+                                               break;
+                                       }
+                               }
+                       }
+                       while (fgets(buff, 80, pcmd))
+                       {
+                               /* Search for BSSID */
+                               if (strstr(buff, "BSSID") != NULL)
+                               {
+                                       /* Dummy reads :
+                                          - Signal
+                                          - RF type
+                                       */
+                                       fgets(buff, 80, pcmd);
+                                       fgets(buff, 80, pcmd);
+                                                               
+                                       /* Retrive the channel */
+                                       fgets(buff, 80, pcmd);
+                                       sscanf(strrchr(buff, ':'), ": %d", 
&channel);
+                                       
+                                       break;
+                               }
+                       }
+                       fclose(pcmd);
+               }
+               printf("[VISTA] Channel found : %d\n", channel);
+       }
+       return channel;
 }


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to