コード例 #1
0
ファイル: wlanapi.c プロジェクト: reactos/reactos
static void WlanScan_test(void)
{
    DWORD ret;
    DOT11_SSID Ssid;
    WLAN_RAW_DATA RawData;
    
    /* invalid pReserved */
    ret = WlanScan((HANDLE) -1, &InterfaceGuid, &Ssid, &RawData, (PVOID) 1);
    ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n");
    
    /* invalid InterfaceGuid */
    ret = WlanScan((HANDLE) -1, NULL, &Ssid, &RawData, NULL);
    ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n");

    /* invalid hClientHandle */
    ret = WlanScan(NULL, &InterfaceGuid, &Ssid, &RawData, NULL);
    ok(ret == ERROR_INVALID_PARAMETER, "expected failure\n");
}
コード例 #2
0
// Initiate a scan of Wifi Networks on the given interface
boolean scanWifiNetworks(HANDLE hClient, GUID ifGuid) {
	DWORD dwResult;
	dwResult = WlanScan(hClient, &ifGuid, NULL, NULL, NULL);
	if (dwResult != ERROR_SUCCESS) {
		return false;
	}
	else {
		return true;
	}
}
コード例 #3
0
ファイル: wifi_info_windows.cpp プロジェクト: DINKIN/omim
void WiFiInfo::Impl::RequestWiFiBSSIDs(WifiRequestCallbackT callback)
{
  m_callback = callback;
  // if it's XP without necessary api... use gateway instead
  if (!pWlanGetNetworkBssList)
  {
    vector<WiFiInfo::AccessPoint> apns;
    GatewaysInfo(apns);
    callback(apns);
    return;
  }

  if (!m_isNotificationSupported)
  { // request timer after 4 seconds, when scanning completes
    CreateTimerQueueTimer(&m_timer, NULL, &WaitOrTimerCallback, this,
                          4100, 0, WT_EXECUTEONLYONCE);
  }
  else
  { // subscribe to notification when scanning is completed
    WlanRegisterNotification(m_hClient,
                             WLAN_NOTIFICATION_SOURCE_ACM,
                             TRUE,
                             &OnWlanScanCompleted,
                             this,
                             NULL,
                             NULL);
  }
  // start scanning
  PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
  DWORD dwResult = WlanEnumInterfaces(m_hClient, NULL, &pIfList);
  if (dwResult == ERROR_SUCCESS)
  {
    for (int ifIndex = 0; ifIndex < static_cast<int>(pIfList->dwNumberOfItems); ++ifIndex)
    {
      PWLAN_INTERFACE_INFO pIfInfo = (PWLAN_INTERFACE_INFO)&pIfList->InterfaceInfo[ifIndex];
      WlanScan(m_hClient, &pIfInfo->InterfaceGuid, NULL, NULL, NULL);
    }
    WlanFreeMemory(pIfList);
  }
}
コード例 #4
0
ファイル: wlanscan.c プロジェクト: hammackj/wintools
int main(int argc, char *argv[])
{
HANDLE hWlan = NULL;

	DWORD dwError = 0;
	DWORD dwSupportedVersion = 0;
	DWORD dwClientVersion = (IsVistaOrHigher() ? 2 : 1);

	GUID guidInterface; ZeroMemory(&guidInterface, sizeof(GUID));

	WLAN_INTERFACE_INFO_LIST *wlanInterfaceList = (WLAN_INTERFACE_INFO_LIST*)WlanAllocateMemory(sizeof(WLAN_INTERFACE_INFO_LIST));
	ZeroMemory(wlanInterfaceList, sizeof(WLAN_INTERFACE_INFO_LIST));

	WLAN_AVAILABLE_NETWORK_LIST *wlanNetworkList = (WLAN_AVAILABLE_NETWORK_LIST*)WlanAllocateMemory(sizeof(WLAN_AVAILABLE_NETWORK_LIST));
	ZeroMemory(wlanNetworkList, sizeof(WLAN_AVAILABLE_NETWORK_LIST));

	try
	{
		if(dwError = WlanOpenHandle(dwClientVersion, NULL, &dwSupportedVersion, &hWlan) != ERROR_SUCCESS)
			throw("[x] Unable access wireless interface");

		if(dwError = WlanEnumInterfaces(hWlan, NULL, &wlanInterfaceList) != ERROR_SUCCESS)
			throw("[x] Unable to enum wireless interfaces");

		wprintf(L"[!] Found adapter %s\n", wlanInterfaceList->InterfaceInfo[0].strInterfaceDescription);

		if(dwError = wlanInterfaceList->InterfaceInfo[0].isState != wlan_interface_state_not_ready)
		{
				if(wlanInterfaceList->dwNumberOfItems > 1)
				{
					// TODO: Add processing for multiple wireless cards here
					printf("[!] Detected multiple wireless adapters, using default\n");
					guidInterface = wlanInterfaceList->InterfaceInfo[0].InterfaceGuid;
				}
				else
				{
					guidInterface = wlanInterfaceList->InterfaceInfo[0].InterfaceGuid;
				}
		}
		else
			throw("[x] Default wireless adapter disabled");

		DWORD dwPrevNotif = 0;

		// Scan takes awhile so we need to register a callback
		if(dwError = WlanRegisterNotification(hWlan, WLAN_NOTIFICATION_SOURCE_ACM, TRUE,
		  (WLAN_NOTIFICATION_CALLBACK)WlanNotification, NULL, NULL, &dwPrevNotif) != ERROR_SUCCESS)
			throw("[x] Unable to register for notifications");

		printf("[i] Scanning for nearby networks...\n");
		if(dwError = WlanScan(hWlan, &guidInterface, NULL, NULL, NULL) != ERROR_SUCCESS)
			throw("[x] Scan failed, check adapter is enabled");

		// Yawn...
		while(bWait)
			Sleep(100);

		// Unregister callback, don't care if it succeeds or not
		WlanRegisterNotification(hWlan, WLAN_NOTIFICATION_SOURCE_NONE, TRUE, NULL, NULL, NULL, &dwPrevNotif);

		if(dwError = WlanGetAvailableNetworkList(hWlan, &guidInterface, NULL, NULL, &wlanNetworkList) != ERROR_SUCCESS)
			throw("[x] Unable to obtain network list");

		for(unsigned int i = 0; i < wlanNetworkList->dwNumberOfItems; i++)
		{
				printf("\nSSID:\t\t\t%s\nSIGNAL:\t\t\t%d%%\n",
						wlanNetworkList->Network[i].dot11Ssid.ucSSID,
						wlanNetworkList->Network[i].wlanSignalQuality);

				printf("SECURITY:\t\t");
				switch(wlanNetworkList->Network[i].dot11DefaultAuthAlgorithm)
				{
						case DOT11_AUTH_ALGO_80211_OPEN:
						case DOT11_AUTH_ALGO_80211_SHARED_KEY:
							printf("WEP");
						break;

						case DOT11_AUTH_ALGO_WPA:
						case DOT11_AUTH_ALGO_WPA_PSK:
						case DOT11_AUTH_ALGO_WPA_NONE:
							printf("WPA");
						break;

						case DOT11_AUTH_ALGO_RSNA:
						case DOT11_AUTH_ALGO_RSNA_PSK:
							printf("WPA2");
						break;

						default:
							printf("UNKNOWN");
						break;
				}
				printf("\n");
		}
	}
	catch(char *szError)
	{
		printf("%s (0x%X)\nQuitting...\n", szError);
	}

	if(wlanNetworkList)
		WlanFreeMemory(wlanNetworkList);
	if(wlanInterfaceList)
		WlanFreeMemory(wlanInterfaceList);
	if(hWlan)
		WlanCloseHandle(hWlan, NULL);

	return dwError;
}
コード例 #5
0
ファイル: wifis.cpp プロジェクト: garvankeeley/wifiscanner
int foo() {

  WindowsNdisApi* w = WindowsNdisApi::Create();
  std::vector<AccessPoint> apData;
  w->GetAccessPointData(apData);


  ///////////////////////////////////////////////////////////
	HANDLE hClient;
	PWLAN_INTERFACE_INFO_LIST pIfList = NULL;
	PWLAN_INTERFACE_INFO pIfConnInfo = NULL;
	PWLAN_CONNECTION_ATTRIBUTES pConnectInfo = NULL;

	PWLAN_BSS_LIST pBssList=NULL;
	PWLAN_BSS_ENTRY  pBssEntry=NULL;
	WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;

	DWORD dwResult = 0;
	DWORD dwMaxClient = 2;         
	DWORD dwCurVersion = 0;
	DWORD connectInfoSize = sizeof(WLAN_CONNECTION_ATTRIBUTES);

	int i;

	// Initialise the Handle
	dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
	if (dwResult != ERROR_SUCCESS) 
	{    
		return 0;
	}

	// Get the Interface List
	dwResult = WlanEnumInterfaces(hClient, NULL, &pIfList);
	if (dwResult != ERROR_SUCCESS) 
	{    
		return 0;
	}

	//Loop through the List to find the connected Interface
	PWLAN_INTERFACE_INFO pIfInfo = NULL;
	for (i = 0; i < (int) pIfList->dwNumberOfItems; i++) 
	{
		pIfInfo = (WLAN_INTERFACE_INFO *) & pIfList->InterfaceInfo[i];    
		if (pIfInfo->isState == wlan_interface_state_connected) 
		{
			pIfConnInfo = pIfInfo;
			break;
		}
	}

	if ( pIfConnInfo == NULL )
		return 0;

	// Query the Interface
	dwResult = WlanQueryInterface(hClient,&pIfConnInfo->InterfaceGuid,wlan_intf_opcode_current_connection,NULL,&connectInfoSize,(PVOID *) &pConnectInfo,&opCode);
	if (dwResult != ERROR_SUCCESS) 
	{    
		return 0;
	}

	// Scan the connected SSID
	dwResult = WlanScan(hClient, &pIfConnInfo->InterfaceGuid,
		                NULL/*&pConnectInfo->wlanAssociationAttributes.dot11Ssid*/,
						NULL, NULL);
	if (dwResult != ERROR_SUCCESS) 
	{    
		return 0;
	}

	// Get the BSS Entry
	dwResult = WlanGetNetworkBssList(hClient, &pIfConnInfo->InterfaceGuid,
		NULL /*&pConnectInfo->wlanAssociationAttributes.dot11Ssid */,
		dot11_BSS_type_any,
		TRUE, NULL, &pBssList);

	if (dwResult != ERROR_SUCCESS) 
	{    
		return 0;
	}

	// Get the RSSI value
	pBssEntry=&pBssList->wlanBssEntries[0];
	return pBssEntry->lRssi;
}