Skip to content

Commit

Permalink
Added PacketGetMonitorMode() function to Packet.dll.
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed May 25, 2016
1 parent 3d4b3dd commit 00c6471
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Common/Packet32.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ extern "C"
BOOLEAN PacketIsLoopbackAdapter(LPADAPTER AdapterObject);
BOOLEAN PacketIsMonitorModeSupported(PCHAR AdapterName);
BOOLEAN PacketSetMonitorMode(PCHAR AdapterName, int mode);
int PacketGetMonitorMode(PCHAR AdapterName);
LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject, LPPACKET pPacket, BOOLEAN Sync);
INT PacketSendPackets(LPADAPTER AdapterObject, PVOID PacketBuff, ULONG Size, BOOLEAN Sync);
Expand Down
1 change: 1 addition & 0 deletions packetWin7/Dll/Packet.def
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ EXPORTS
PacketIsLoopbackAdapter
PacketIsMonitorModeSupported
PacketSetMonitorMode
PacketGetMonitorMode
PacketSetReadTimeout
PacketSetMode
PacketSetNumWrites
Expand Down
58 changes: 58 additions & 0 deletions packetWin7/Dll/Packet32.c
Original file line number Diff line number Diff line change
Expand Up @@ -4834,6 +4834,22 @@ DWORD SetInterface(WLAN_INTF_OPCODE opcode, PVOID* pData, GUID* InterfaceGuid)
return dwResult;
}

DWORD GetInterface(WLAN_INTF_OPCODE opcode, PVOID* pData, GUID* InterfaceGuid)
{
DWORD dwResult = 0;
HANDLE hClient = NULL;
DWORD dwCurVersion = 0;
DWORD outsize = 0;
WLAN_OPCODE_VALUE_TYPE opCode = wlan_opcode_value_type_invalid;

// Open Handle for the set operation
dwResult = WlanOpenHandle(WLAN_CLIENT_VERSION_VISTA, NULL, &dwCurVersion, &hClient);
dwResult = WlanQueryInterface(hClient, InterfaceGuid, opcode, NULL, &outsize, pData, &opCode);
WlanCloseHandle(hClient, NULL);

return dwResult;
}

/*!
\brief Sets the operation mode of an adapter.
\param AdapterObject Pointer to an _ADAPTER structure.
Expand Down Expand Up @@ -4867,6 +4883,48 @@ BOOLEAN PacketSetMonitorMode(PCHAR AdapterName, int mode)
}
}

/*!
\brief Determine if the operation mode of an adapter is monitor mode.
\param AdapterObject Pointer to an _ADAPTER structure.
\param mode The new operation mode of the adapter, 1 for monitor mode, 0 for managed mode.
\return 1 if it's monitor mode, 0 if it's not monitor mode, -1 if the function fails.
*/
int PacketGetMonitorMode(PCHAR AdapterName)
{
GUID ChoiceGUID;
TRACE_ENTER("PacketGetMonitorMode");

if (myGUIDFromString(AdapterName + sizeof(DEVICE_PREFIX) - 1 + sizeof(NPF_DEVICE_NAMES_PREFIX) - 1, &ChoiceGUID) != TRUE)
{
TRACE_PRINT("PacketGetMonitorMode failed, myGUIDFromString error");
return FALSE;
}

ULONG ulOperationMode = -1;
PULONG pOperationMode;
DWORD dwResult = GetInterface(wlan_intf_opcode_current_operation_mode, (PVOID*)&pOperationMode, &ChoiceGUID);
if (dwResult != ERROR_SUCCESS)
{
TRACE_PRINT("PacketGetMonitorMode failed, GetInterface error");
TRACE_EXIT("PacketGetMonitorMode");
return -1;
}
else
{
ulOperationMode = *pOperationMode;
WlanFreeMemory(pOperationMode);
TRACE_EXIT("PacketGetMonitorMode");
if (ulOperationMode == DOT11_OPERATION_MODE_NETWORK_MONITOR)
{
return 1;
}
else
{
return 0;
}
}
}

/*!
\brief Returns the AirPcap handler associated with an adapter. This handler can be used to change
the wireless-related settings of the CACE Technologies AirPcap wireless capture adapters.
Expand Down

0 comments on commit 00c6471

Please sign in to comment.