Exemple #1
0
DWORD SetInterface(WLAN_INTF_OPCODE opcode, PVOID* pData, GUID* InterfaceGuid)
{
	DWORD dwResult = 0;
	HANDLE hClient = NULL;
	DWORD dwCurVersion = 0;
	DWORD outsize = 0;

	// Open Handle for the set operation
	dwResult = WlanOpenHandle(WLAN_CLIENT_VERSION_VISTA, NULL, &dwCurVersion, &hClient);
	dwResult = WlanSetInterface(hClient, InterfaceGuid, opcode, sizeof(ULONG), pData, NULL);
	WlanCloseHandle(hClient, NULL);

	return dwResult;
}
Exemple #2
0
int TestWlanApi(int argc, _TCHAR* argv[])
{
	// init_lib( &cs );
	// return 0;
	HANDLE hClient = NULL;
	WLAN_INTERFACE_INFO sInfo[64];
	RPC_CSTR strGuid = NULL;

	TCHAR szBuffer[256];
	DWORD dwRead;
	if( OpenHandleAndCheckVersion( &hClient ) != ERROR_SUCCESS )
		return -1;

	UINT nCount = EnumInterface( hClient, sInfo );
	for( UINT i = 0; i < nCount; ++i )
	{
		if (UuidToStringA( &sInfo[i].InterfaceGuid, &strGuid) == RPC_S_OK)
		{
			printf( ("%d. %s\n\tDescription: %S\n\tState: %S\n"), 
				i, 
				strGuid, 
				sInfo[i].strInterfaceDescription, 
				GetInterfaceStateString(sInfo[i].isState) );

			RpcStringFreeA(&strGuid);
		}
	}

	UINT nChoice = 0;
	printf( "for choice wireless card:" );

	if( ReadConsole( GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL ) == FALSE )
	{
		puts( "error input" );
		return -1;
	}
	szBuffer[dwRead] = 0;
	nChoice = _ttoi( szBuffer );

	if( nChoice > nCount )
	{
		puts( "error input." );
		return -1;
	}

	ULONG ulOperatorCode = DOT11_OPERATION_MODE_NETWORK_MONITOR;
	if( ERROR_SUCCESS != WlanSetInterface( 
		hClient, 
		&sInfo[nChoice].InterfaceGuid, 
		wlan_intf_opcode_current_operation_mode,
		sizeof(ULONG),
		&ulOperatorCode,
		NULL ) )
	{
		puts( "enter monitor mode failed!" );
		return -1;
	}

	BOOL bRet = ReadFile( hClient, szBuffer, sizeof(szBuffer), &dwRead, NULL );

	_getch();
	ulOperatorCode = DOT11_OPERATION_MODE_EXTENSIBLE_STATION;
	if( ERROR_SUCCESS != WlanSetInterface( 
		hClient, 
		&sInfo[nChoice].InterfaceGuid, 
		wlan_intf_opcode_current_operation_mode,
		sizeof(ULONG),
		&ulOperatorCode,
		NULL ) )
	{
		puts( "enter monitor mode failed!" );
		return -1;
	}

	WlanCloseHandle( hClient, NULL );
	return 0;
}
Exemple #3
0
DWORD PMD::stopMonitorMode() {

	DWORD rtn = 0;
	ULONG ulSize = 0;
	dNegotiatedVersion = 0;
	dClientVersion = 1;

	// get connected AP info from WLAN API
	dwSize = 0;

	
	ULONG pulresult = DOT11_OPERATION_MODE_EXTENSIBLE_STATION;
	PULONG mode = &pulresult;

	printf ("I want to change dwIndex, %d\n", pInterfaceList->dwIndex);
	rtn = WlanSetInterface(hClientHandle,
					&pInterfaceList->InterfaceInfo[pInterfaceList->dwIndex].InterfaceGuid,
					wlan_intf_opcode_current_operation_mode,
					sizeof(mode),
					mode,
					NULL);

	if(rtn == ERROR_INVALID_STATE) {

		// that means not connected to any AP
		rtn = ERROR_SUCCESS;

		printf("Not connected to any AP\n");
		return rtn;
	} 
	else if(rtn != ERROR_SUCCESS)
	{
		switch (rtn) {
		case ERROR_ACCESS_DENIED:
			printf ("WlanSetInterface [ERROR_ACCESS_DENIED]\n");
			break;
		case ERROR_GEN_FAILURE:
			printf ("WlanSetInterface [ERROR_GEN_FAILURE]\n");
			break;
		case ERROR_INVALID_HANDLE:
			printf ("WlanSetInterface [ERROR_INVALID_HANDLE]\n");
			break;
		case ERROR_INVALID_PARAMETER:
			printf ("WlanSetInterface [ERROR_INVALID_PARAMETER]\n");
			break;
		/*
		case RPC_STATUS:
			printf ("WlanSetInterface [RPC_STATUS]\n");
			break;
		*/
		default:
			printf ("WlanSetInterface [SHOULD_NOT]\n");
			break;
		}

		printf("Error occured in WlanSetInterface: %d\n", rtn);
		return rtn;
	}
	

	return rtn;
}