Scan WiFi access point

Scan WiFi access point

Postby Daniel Garcia-Gil » Sun Jul 04, 2010 3:52 pm

Hello

thanks to Otto for share original code, was adapted to FWPPC

Download from here: http://www.sitasoft.net/fivewin/samples/fwppc/wifi.zip

sample
Code: Select all  Expand view
#include "FWCE.ch"


FUNCTION Main()
   LOCAL oWnd
   LOCAL oWifi
   LOCAL aAdapters, cAdapter
   LOCAL n
   LOCAL aInfo
   LOCAL ctext
   LOCAL oBrw
   
   
   DEFINE DIALOG oWnd TITLE "Wifi Search" SIZE 220, 210
   
   oWifi = TWifiScan():New()

   aInfo = GetInfo( oWifi )
   
   /*
   MacAddress ( string )              
   Ssid       ( string )        
   Channel    ( numeric )        
   Auth       ( string )        
   InfrastructureMode  ( string )
   Signal( numeric )   */


   @ 1, 1 LISTBOX oBrw ;
      FIELDS aInfo[ oBrw:nAt, 2 ], Transform(aInfo[ oBrw:nAt, 6 ], "9999" ),;
             Transform( aInfo[ oBrw:nAt, 3 ], "999" ), aInfo[ oBrw:nAt, 5 ], ;
             aInfo[ oBrw:nAt, 4 ], aInfo[ oBrw:nAt, 1 ] ;
      HEADERS "Name", "Sig", "Ch", "Type", "Sec", "Mac";
      COLSIZES  100, 30, 30, 60, 60, 150 ;
      SIZE 100, 82
   
   oBrw:SetArray( aInfo )
   
   ACTIVATE DIALOG oWnd CENTERED;
            ON CLICK( aInfo := GetInfo( oWifi, cAdapter ),;
                      oBrw:SetArray( aInfo ),;
                      oBrw:Refresh() )

   oWifi:End()
     
RETURN NIL


FUNCTION GetInfo( oWifi )
   local aInfo
   local cAdapter
   
   cAdapter = GetAdapter( oWifi )
   
   if ! Empty( cAdapter )
      oWifi:RefreshBSSIDs( cAdapter )
      aInfo = oWifi:GetBBSIDs( cAdapter )
   endif
   if Len( aInfo ) == 0
      aInfo := { { , , 0, , , 0 } }
   endif

return aInfo

FUNCTION GetAdapter( oWifi )
   local aAdapters := oWifi:GetAdapters()
   local cAdapter := ""
   if Len( aAdapters ) > 0
      cAdapter = aAdapters[ 1 ]
   endif
return cAdapter  

 


CLASS
Code: Select all  Expand view

#include "fivewin.ch"

CLASS TWifiScan

   DATA hHandle
   
   METHOD New()
   METHOD GetAdapters  INLINE GetAdapters( ::hHandle )
   METHOD GetBBSIDs( cAdapter )  INLINE GetBBSIDs( ::hHandle, cAdapter )
                                 /*Return Array 6 position
                                   MacAddress ( string )              
                                   Ssid       ( string )        
                                   Channel    ( numeric )        
                                   Auth       ( string )        
                                   InfrastructureMode  ( string )
                                   Signal( numeric ) */


   
   METHOD RefreshBSSIDs( cAdapter ) INLINE RefreshBSSIDs( ::hHandle, cAdapter )

   METHOD End()   INLINE EndWifi( ::hHandle )

ENDCLASS

METHOD New() CLASS TWifiScan

   ::hHandle = InitWifi()

RETURN Self
 


C code
Code: Select all  Expand view

#include <windows.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <ntddndis.h>
#include <nuiouser.h>
#include <winioctl.h>

typedef struct tagWifiPeek{
    CRITICAL_SECTION m_Lock;
    HANDLE m_hNDUIO;
} WIFIPEEK;
typedef WIFIPEEK  *PFWIFIPEEK;

void CloseWifi( PFWIFIPEEK );
BOOL OpenWifi( PFWIFIPEEK );
LPWSTR AnsiToWide( LPSTR );
LPSTR WideToAnsi( LPWSTR );
const char cSep = '-';
static char * sAuth_Mode[] = { "Open System",
                              "Wep" };
                             
static char * sInfra_Mode[] = { "Ad Hoc",
                                "Access Point",
                                "Auto or unknown" };

//----------------------------------

HB_FUNC( ENDWIFI )
{
  PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
 
    if( pWifi->m_hNDUIO != NULL)
    {
        CloseWifi( pWifi );
    }
    DeleteCriticalSection(&pWifi->m_Lock);
    hb_xfree( pWifi );
}

//----------------------------------

HB_FUNC( INITWIFI )
{
  PFWIFIPEEK pWifi = hb_xgrab( sizeof( WIFIPEEK ) );
   
    pWifi->m_hNDUIO=NULL;
    InitializeCriticalSection(&pWifi->m_Lock);
    if( OpenWifi( pWifi ) )
       hb_retnl( ( LONG ) pWifi );
    else
    {
       hb_xfree( pWifi );
       hb_retnl( 0 );
    }
   
}

//----------------------------------


void CloseWifi( PFWIFIPEEK pWifi )
{
    CloseHandle( pWifi->m_hNDUIO );
    pWifi->m_hNDUIO=NULL;
}

//----------------------------------

BOOL OpenWifi( PFWIFIPEEK pWifi )
{
HANDLE hDev;

    //already opened?
    if( pWifi->m_hNDUIO != NULL)
    {
        return TRUE;
    }

    hDev=CreateFile(NDISUIO_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, INVALID_HANDLE_VALUE);
    if(hDev == INVALID_HANDLE_VALUE)
    {
        return FALSE;
    }
    else
    {
        pWifi->m_hNDUIO=hDev;
        return TRUE;
    }
}

HB_FUNC( GETADAPTERS )
{
HANDLE hFile;
BYTE Buffer[2048];
VOID *pvBuf;
DWORD dwRet;
PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
PHB_ITEM  pAdapters = hb_itemArrayNew( 0 );

    if(pWifi == NULL || pWifi->m_hNDUIO == NULL)
    {
        hb_retnl( 0 );
    }
    EnterCriticalSection(&pWifi->m_Lock);
    //open NDIS driver
    hFile=CreateFile(L"NDS0:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
    if(hFile != INVALID_HANDLE_VALUE)
    {
        pvBuf=(void *)(&Buffer[0]);
        dwRet=sizeof(Buffer);
        if(DeviceIoControl(hFile, IOCTL_NDIS_GET_ADAPTER_NAMES, NULL, 0, pvBuf, sizeof(Buffer), &dwRet, NULL))
        {
            //adapter list ok.
            LPWSTR pszStr;
            dwRet=0;

            //no string classes used, so no MFC or ATL dependency.
            for(pszStr=(LPWSTR)pvBuf; *pszStr; pszStr+=wcslen(pszStr)+1)
            {
                //check if adapter name is ok, skip infrared, gprs, ActiveSync etc.
                if(wcsicmp(pszStr, L"ASYNCMAC1") && \
                    wcsicmp(pszStr, L"IRSIR1") && \
                    wcsicmp(pszStr, L"L2TP1") && \
                    wcsicmp(pszStr, L"PPTP1") && \
                    wcsicmp(pszStr, L"RNDISFN1") && \
                    wcsicmp(pszStr, L"WWAN1") && \
                    wcsicmp(pszStr, L"XSC1_IRDA1"))
                    {              
                  LPSTR psStr;
                  PHB_ITEM pSubarray;
                psStr = WideToAnsi( ( LPWSTR ) pszStr );
                pSubarray = hb_itemPutC( NULL, psStr );
                hb_arrayAddForward( pAdapters, pSubarray );
                hb_itemRelease( pSubarray );
             }

            }
        }
        CloseHandle(hFile);
    }
    LeaveCriticalSection(&pWifi->m_Lock);
  hb_itemReturnRelease( pAdapters );

}


BOOL RefreshBSSIDs( PFWIFIPEEK pWifi, LPWSTR pAdapter )
{
NDISUIO_SET_OID nso;
DWORD dwBytesRet;
BOOL retval;

    EnterCriticalSection(&pWifi->m_Lock);
    nso.ptcDeviceName = pAdapter;
    nso.Oid = OID_802_11_BSSID_LIST_SCAN;

    dwBytesRet=0;
    if(!DeviceIoControl(pWifi->m_hNDUIO, IOCTL_NDISUIO_SET_OID_VALUE, (void *)&nso, sizeof(NDISUIO_SET_OID), NULL, 0, &dwBytesRet, NULL))
    {
        retval=FALSE;
    }
    else
    {
        retval=TRUE;
    }
    LeaveCriticalSection(&pWifi->m_Lock);
    return retval;
}

HB_FUNC( REFRESHBSSIDS )
{
   PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
   LPSTR psStr = hb_parc( 2 );
   LPWSTR pAdapter = AnsiToWide( psStr );
   
   hb_retl( RefreshBSSIDs( pWifi, pAdapter ) );
   
   hb_xfree( pAdapter );
}  
   

//----------------------------------------------



char *MacToChar(char *pszMACAddress,
                unsigned char *pbyMacAddressInBytes)
{
    sprintf(pszMACAddress, "%02x%c%02x%c%02x%c%02x%c%02x%c%02x",
                        pbyMacAddressInBytes[0] & 0xff,
                        cSep,
                        pbyMacAddressInBytes[1]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[2]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[3]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[4]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[5]& 0xff);

    return pszMACAddress;
}   


CHAR * Get_Auth_Mode( int );

HB_FUNC( GETBBSIDS )
{
   PNDISUIO_QUERY_OID pNQO;
   DWORD dwBytesRet;
   BYTE Buffer[8192], *pByte;
   PNDIS_802_11_BSSID_LIST pList;
   PNDIS_WLAN_BSSID pItem;
   int i, iChannel;
   PHB_ITEM pItemDest;
     PHB_ITEM pitemField = hb_itemNew( NULL );
     ULONG dwReturnedItems;
     CHAR BSSID[64] = "";
     PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
     LPWSTR pAdapter  = AnsiToWide( ( LPSTR ) hb_parc( 2 ) );
   
     EnterCriticalSection(&pWifi->m_Lock)
     pNQO=(PNDISUIO_QUERY_OID)Buffer;
   
     pNQO->ptcDeviceName = pAdapter;
     pNQO->Oid=OID_802_11_BSSID_LIST;
   
     // Run query
     dwBytesRet = 0;
     if(!DeviceIoControl(pWifi->m_hNDUIO, IOCTL_NDISUIO_QUERY_OID_VALUE, (void *)pNQO, 8192, (void *)pNQO, 8192, &dwBytesRet, NULL))
     {
        LeaveCriticalSection(&pWifi->m_Lock);
        hb_retl( FALSE );
     }
   
     pList=(PNDIS_802_11_BSSID_LIST)&pNQO->Data;
     dwReturnedItems = pList->NumberOfItems;
   
    pItemDest = hb_itemArrayNew( 0 );
   
     //first item in array
     pItem=pList->Bssid;
   
     for(i=0; i<( INT )dwReturnedItems; i++)
     {
        MacToChar( BSSID,  pItem->MacAddress );
   
         if(pItem->Configuration.DSConfig > 14)
         {
              iChannel=(pItem->Configuration.DSConfig - 2407000) / 5000;
        }else
         {
            iChannel=pItem->Configuration.DSConfig;
         }     
   
         hb_arrayNew( pitemField, 6 );
       hb_arraySetC( pitemField, 1, BSSID );            //MacAddress
       hb_arraySetC( pitemField, 2, pItem->Ssid.Ssid ); // Ssid
       hb_arraySetNI( pitemField, 3, iChannel );        // Channel
       hb_arraySetC( pitemField, 4, sAuth_Mode[ pItem->Privacy ] );  // Auth
       hb_arraySetC( pitemField, 5, sInfra_Mode[ pItem->InfrastructureMode ] ); //InfrastructureMode
       hb_arraySetNI( pitemField, 6, pItem->Rssi );     //Signal
       hb_arrayAddForward( pItemDest, pitemField );
        
        //some pointer magic...actually pItem->Length was not sizeof(NDIS_WLAN_BSSID)
        //so use returned length
        pByte=(BYTE *)pItem;
        pByte+=pItem->Length;
        pItem=(PNDIS_WLAN_BSSID)pByte;
     }//for
   
     LeaveCriticalSection(&pWifi->m_Lock);
    
   hb_itemRelease( pitemField );
   hb_itemReturnRelease( pItemDest );
}
 
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: Scan WiFi access point

Postby toddevans » Wed Sep 01, 2010 1:52 am

Thanks for porting/sharing this. This a nice example of how to query NDIS for WiFi status. After running on our Elf model (Windows Mobile 6.5), I noticed that the channel map didn't account for 802.11a and 5GHz channel conversion. The Elf has an a/b/g radio from Summit Data. I modified WIFIPK.C and added frequency to channel conversions for the channels my AP supports.

Here's WIRE running on a Datalogic Elf. Notice channel 149 in the middle there.

Image

I also defined UNDER_CE at the top of WIFIPK.C for those who haven't specified this setting in their make file. Otherwise you'll get a page full of errors.
I compiled and linked WIRE as a CE5 application with CE5 libs.

Code: Select all  Expand view

#ifndef UNDER_CE
    #define UNDER_CE
#endif

#include <windows.h>
#include <hbapi.h>
#include <hbapiitm.h>
#include <ntddndis.h>
#include <nuiouser.h>
#include <winioctl.h>

typedef struct tagWifiPeek{
    CRITICAL_SECTION m_Lock;
    HANDLE m_hNDUIO;
} WIFIPEEK;
typedef WIFIPEEK  *PFWIFIPEEK;

void CloseWifi( PFWIFIPEEK );
BOOL OpenWifi( PFWIFIPEEK );
LPWSTR AnsiToWide( LPSTR );
LPSTR WideToAnsi( LPWSTR );
const char cSep = '-';
static char * sAuth_Mode[] = { "Open System",
                              "Wep" };
                             
static char * sInfra_Mode[] = { "Ad Hoc",
                                "Access Point",
                                "Auto or unknown" };


int Freq2Channel( ULONG ulLongFreq, INT * piChannel  );

//----------------------------------

HB_FUNC( ENDWIFI )
{
  PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
 
    if( pWifi->m_hNDUIO != NULL)
    {
        CloseWifi( pWifi );
    }
    DeleteCriticalSection(&pWifi->m_Lock);
    hb_xfree( pWifi );
}

//----------------------------------

HB_FUNC( INITWIFI )
{
  PFWIFIPEEK pWifi = hb_xgrab( sizeof( WIFIPEEK ) );
   
    pWifi->m_hNDUIO=NULL;
    InitializeCriticalSection(&pWifi->m_Lock);

    if( OpenWifi( pWifi ) )
       hb_retnl( ( LONG ) pWifi );
    else
    {
       hb_xfree( pWifi );
       hb_retnl( 0 );
    }
   
}

//----------------------------------


void CloseWifi( PFWIFIPEEK pWifi )
{
    CloseHandle( pWifi->m_hNDUIO );
    pWifi->m_hNDUIO=NULL;
}

//----------------------------------

BOOL OpenWifi( PFWIFIPEEK pWifi )
{
    HANDLE hDev;

    //already opened?
    if( pWifi->m_hNDUIO != NULL)
    {
        return TRUE;
    }

    hDev=CreateFile(NDISUIO_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, INVALID_HANDLE_VALUE);
    if(hDev == INVALID_HANDLE_VALUE)
    {
        return FALSE;
    }
    else
    {
        pWifi->m_hNDUIO=hDev;
        return TRUE;
    }
}

HB_FUNC( GETADAPTERS )
{
HANDLE hFile;
BYTE Buffer[2048];
VOID *pvBuf;
DWORD dwRet;
PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
PHB_ITEM  pAdapters = hb_itemArrayNew( 0 );

    if(pWifi == NULL || pWifi->m_hNDUIO == NULL)
    {
        hb_retnl( 0 );
    }
    EnterCriticalSection(&pWifi->m_Lock);

    //open NDIS driver
    hFile=CreateFile(L"NDS0:", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, INVALID_HANDLE_VALUE);
    if(hFile != INVALID_HANDLE_VALUE)
    {
        pvBuf=(void *)(&Buffer[0]);
        dwRet=sizeof(Buffer);
        if(DeviceIoControl(hFile, IOCTL_NDIS_GET_ADAPTER_NAMES, NULL, 0, pvBuf, sizeof(Buffer), &dwRet, NULL))
        {
            //adapter list ok.
            LPWSTR pszStr;
            dwRet=0;

            //no string classes used, so no MFC or ATL dependency.
            for(pszStr=(LPWSTR)pvBuf; *pszStr; pszStr+=wcslen(pszStr)+1)
            {
                //check if adapter name is ok, skip infrared, gprs, ActiveSync etc.
                if(wcsicmp(pszStr, L"ASYNCMAC1") && \
                    wcsicmp(pszStr, L"IRSIR1") && \
                    wcsicmp(pszStr, L"L2TP1") && \
                    wcsicmp(pszStr, L"PPTP1") && \
                    wcsicmp(pszStr, L"RNDISFN1") && \
                    wcsicmp(pszStr, L"WWAN1") && \
                    wcsicmp(pszStr, L"XSC1_IRDA1"))
                    {              
                  LPSTR psStr;
                  PHB_ITEM pSubarray;
                psStr = WideToAnsi( ( LPWSTR ) pszStr );
                pSubarray = hb_itemPutC( NULL, psStr );
                hb_arrayAddForward( pAdapters, pSubarray );
                hb_itemRelease( pSubarray );
             }

            }
        }
        CloseHandle(hFile);
    }
    LeaveCriticalSection(&pWifi->m_Lock);
  hb_itemReturnRelease( pAdapters );

}


BOOL RefreshBSSIDs( PFWIFIPEEK pWifi, LPWSTR pAdapter )
{
NDISUIO_SET_OID nso;
DWORD dwBytesRet;
BOOL retval;

    EnterCriticalSection(&pWifi->m_Lock);
    nso.ptcDeviceName = pAdapter;
    nso.Oid = OID_802_11_BSSID_LIST_SCAN;

    dwBytesRet=0;
    if(!DeviceIoControl(pWifi->m_hNDUIO, IOCTL_NDISUIO_SET_OID_VALUE, (void *)&nso, sizeof(NDISUIO_SET_OID), NULL, 0, &dwBytesRet, NULL))
    {
        retval=FALSE;
    }
    else
    {
        retval=TRUE;
    }
    LeaveCriticalSection(&pWifi->m_Lock);
    return retval;
}

HB_FUNC( REFRESHBSSIDS )
{
   PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
   LPSTR psStr = hb_parc( 2 );
   LPWSTR pAdapter = AnsiToWide( psStr );
   
   hb_retl( RefreshBSSIDs( pWifi, pAdapter ) );
   
   hb_xfree( pAdapter );
}  
   

//----------------------------------------------



char *MacToChar(char *pszMACAddress,
                unsigned char *pbyMacAddressInBytes)
{
    sprintf(pszMACAddress, "%02x%c%02x%c%02x%c%02x%c%02x%c%02x",
                        pbyMacAddressInBytes[0] & 0xff,
                        cSep,
                        pbyMacAddressInBytes[1]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[2]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[3]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[4]& 0xff,
                        cSep,
                        pbyMacAddressInBytes[5]& 0xff);

    return pszMACAddress;
}   


CHAR * Get_Auth_Mode( int );

HB_FUNC( GETBBSIDS )
{
   PNDISUIO_QUERY_OID pNQO;
   DWORD dwBytesRet;
   BYTE Buffer[8192], *pByte;
   PNDIS_802_11_BSSID_LIST pList;
   PNDIS_WLAN_BSSID pItem;
   int i, iChannel;
   PHB_ITEM pItemDest;
     PHB_ITEM pitemField = hb_itemNew( NULL );
     ULONG dwReturnedItems;
     CHAR BSSID[64] = "";
     PFWIFIPEEK pWifi = ( PFWIFIPEEK ) hb_parnl( 1 );
     LPWSTR pAdapter  = AnsiToWide( ( LPSTR ) hb_parc( 2 ) );
   
     EnterCriticalSection(&pWifi->m_Lock)
     pNQO=(PNDISUIO_QUERY_OID)Buffer;
   
     pNQO->ptcDeviceName = pAdapter;
     pNQO->Oid=OID_802_11_BSSID_LIST;
   
     // Run query
     dwBytesRet = 0;
     if(!DeviceIoControl(pWifi->m_hNDUIO, IOCTL_NDISUIO_QUERY_OID_VALUE, (void *)pNQO, 8192, (void *)pNQO, 8192, &dwBytesRet, NULL))
     {
        LeaveCriticalSection(&pWifi->m_Lock);
        hb_retl( FALSE );
     }
   
     pList=(PNDIS_802_11_BSSID_LIST)&pNQO->Data;
     dwReturnedItems = pList->NumberOfItems;
   
   pItemDest = hb_itemArrayNew( 0 );
   
     //first item in array
     pItem=pList->Bssid;
   
     for(i=0; i<( INT )dwReturnedItems; i++)
     {
        MacToChar( BSSID,  pItem->MacAddress );

            Freq2Channel( pItem->Configuration.DSConfig, &iChannel );

/*
         if(pItem->Configuration.DSConfig > 14)
         {
              iChannel=(pItem->Configuration.DSConfig - 2407000) / 5000;
        }else
         {
            iChannel=pItem->Configuration.DSConfig;
         }     
*/

   
         hb_arrayNew( pitemField, 6 );
       hb_arraySetC( pitemField, 1, BSSID );            //MacAddress
       hb_arraySetC( pitemField, 2, pItem->Ssid.Ssid ); // Ssid
       hb_arraySetNI( pitemField, 3, iChannel );        // Channel
       hb_arraySetC( pitemField, 4, sAuth_Mode[ pItem->Privacy ] );  // Auth
       hb_arraySetC( pitemField, 5, sInfra_Mode[ pItem->InfrastructureMode ] ); //InfrastructureMode
       hb_arraySetNI( pitemField, 6, pItem->Rssi );     //Signal
       hb_arrayAddForward( pItemDest, pitemField );
        
            //some pointer magic...actually pItem->Length was not sizeof(NDIS_WLAN_BSSID)
            //so use returned length
            pByte=(BYTE *)pItem;
            pByte+=pItem->Length;
            pItem=(PNDIS_WLAN_BSSID)pByte;
    
     }//for
   
     LeaveCriticalSection(&pWifi->m_Lock);
    
   hb_itemRelease( pitemField );
   hb_itemReturnRelease( pItemDest );
}

#define FREQ_24GHZ_BOTTOM           2412000
#define FREQ_24GHZ_TOP              2484000  
#define FREQ_5GHZ_LOW_BOTTOM    5180000
#define FREQ_5GHZ_LOW_TOP       5240000
#define FREQ_5GHZ_HIGH_BOTTOM   5680000
#define FREQ_5GHZ_HIGH_TOP      5825000

/*----------------------------------------------------------------------------
*
* Freq2Channel() - Convert frequency to WiFi Channel
*
*/

int Freq2Channel( ULONG ulLongFreq, INT * piChannel  )
{
    // no channel
  *piChannel = 0;

  // Hz?
  if( ulLongFreq <=14 )
  {
        *piChannel = ulLongFreq;
    }
    // 2.4 GHz
  else if( ulLongFreq <= FREQ_24GHZ_TOP )
  {
            *piChannel = ( (ulLongFreq - FREQ_24GHZ_BOTTOM )/5000 ) + 1;
    }
    // 5.0 GHz
    else if ( ulLongFreq <= FREQ_5GHZ_HIGH_TOP )
    {
        ULONG uShortFreq = ulLongFreq / 1000;
        switch ( uShortFreq ) {
        case 5825:
            *piChannel = 165;
            break;
        case 5805:
            *piChannel = 161;
            break;
        case 5785:
            *piChannel = 157;
            break;
        case 5765:
            *piChannel = 153;
            break;
        case 5745:
            *piChannel = 149;
            break;
        case 5240:
            *piChannel = 48;
            break;
        case 5220:
            *piChannel = 44;
            break;
        case 5200:
            *piChannel = 40;
            break;
        case 5180:
            *piChannel = 36;
            break;
        default:
            *piChannel = 999;
        }                          
    }   

    return ( 0 );
}
 
toddevans
 
Posts: 6
Joined: Wed Feb 04, 2009 9:33 pm
Location: US

Re: Scan WiFi access point

Postby Antonio Linares » Wed Sep 01, 2010 9:21 am

Todd,

Many thanks for your changes and feedback! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 8 guests