' ########################################################################################
' Microsoft Windows
' File: Traffic.inc
' Contents: API definitions for the traffic control interface.
' Copyright (c) 2011 Jos? Roca
' Portions Copyright (c) Microsoft Corporation.
' All Rights Reserved.
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
' EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
' MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
' ########################################################################################
#IF NOT %DEF(PBX_Traffic_PBI)
#DEFINE PBX_Traffic_PBI
%EQUATE `TRADDIC_INC = 1
#INCLUDE ONCE "Legacy/Platform/NtDDNdis.inc"
#INCLUDE ONCE "Legacy/Network/qosobjs.inc"
'//---------------------------------------------------------------------------
'//
'// Define's
'//
%EQUATE `CURRENT_TCI_VERSION = &H0002
'//
'// Definitions of notification events. These may be passed
'// to the client's notification handler, to identify the
'// notification type
'//
'//
'// A TC interface has come up
'//
%EQUATE `TC_NOTIFY_IFC_UP = 1
'//
'// A TC interface has come down
'//
%EQUATE `TC_NOTIFY_IFC_CLOSE = 2
'//
'// A change on a TC interface, typically a change in the
'// list of supported network addresses
'//
%EQUATE `TC_NOTIFY_IFC_CHANGE = 3
'//
'// A TC parameter has changed
'//
%EQUATE `TC_NOTIFY_PARAM_CHANGED = 4
'//
'// A flow has been closed by the TC interface
'// for example: after a remote call close, or the whole interface
'// is going down
'//
%EQUATE `TC_NOTIFY_FLOW_CLOSE = 5
%EQUATE `TC_INVALID_HANDLE = 0 ' ((HANDLE)0)
%EQUATE `MAX_STRING_LENGTH = 256
'//---------------------------------------------------------------------------
'//
'// Typedef's and structures
'//
'//
'// Handlers registered by the TCI client
'//
'typedef
'VOID (CALLBACK * TCI_NOTIFY_HANDLER)(
' );
'SUB TCI_NOTIFY_HANDLER ( ' BYVAL ClRegCtx AS DWORD ' , BYVAL ClIfcCtx AS DWORD ' , BYVAL dwEevent AS DWORD ' , BYVAL SubCode AS DWORD ' , BYVAL BufSize AS DWORD ' , BYVAL Buffer AS DWORD ' )
'typedef
'VOID (CALLBACK * TCI_ADD_FLOW_COMPLETE_HANDLER)(
' );
'SUB TCI_ADD_FLOW_COMPLETE_HANDLER ( ' BYVAL ClFlowCtx AS DWORD ' , BYVAL dwStatus AS DWORD ' )
'typedef
'VOID (CALLBACK * TCI_MOD_FLOW_COMPLETE_HANDLER)(
' );
'SUB TCI_MOD_FLOW_COMPLETE_HANDLER ( ' BYVAL ClFlowCtx AS DWORD ' , BYVAL dwStatus AS DWORD ' )
'typedef
'VOID (CALLBACK * TCI_DEL_FLOW_COMPLETE_HANDLER)(
' );
'SUB TCI_DEL_FLOW_COMPLETE_HANDLER ( ' BYVAL ClFlowCtx AS DWORD ' , BYVAL dwStatus AS DWORD ' )
' // Size = 16 bytes
TYPE TCI_CLIENT_FUNC_LIST DWORD
 ClNotifyHandler AS DWORD ' TCI_NOTIFY_HANDLER
 ClAddFlowCompleteHandler AS DWORD ' TCI_ADD_FLOW_COMPLETE_HANDLER
 ClModifyFlowCompleteHandler AS DWORD ' TCI_MOD_FLOW_COMPLETE_HANDLER
 ClDeleteFlowCompleteHandler AS DWORD ' TCI_DEL_FLOW_COMPLETE_HANDLER
END TYPE
'//
'// Network address descriptor
'//
' // Size = 16 bytes
TYPE ADDRESS_LIST_DESCRIPTOR DWORD
 MediaType AS DWORD ' ULONG
 AddressList AS NETWORK_ADDRESS_LIST
END TYPE
'//
'// An interface ID that is returned by the enumerator
'//
' // Size = 28 bytes
TYPE TC_IFC_DESCRIPTOR DWORD
 Length AS DWORD ' ULONG
 pInterfaceName AS WSTRINGZ PTR
 pInterfaceID AS WSTRINGZ PTR
 AddressListDesc AS ADDRESS_LIST_DESCRIPTOR
END TYPE
'//
'// This structure is returned by a QoS data provider in reply to
'// GUID_QOS_SUPPORTED query or with an interface UP notification
'//
' // Size = 544 bytes
TYPE TC_SUPPORTED_INFO_BUFFER QWORD FILL ' Must be 8 byte aligned
 InstanceIDLength AS WORD ' USHORT
 ' // device or interface ID
 InstanceID AS WSTRINGZ * %MAX_STRING_LENGTH ' WCHAR
 ' // the NET_LUID for the interface
 InterfaceLuid AS QUAD ' ULONG64
 ' // address list
 AddrListDesc AS ADDRESS_LIST_DESCRIPTOR
END TYPE
'//
'// Filters are used to match packets. The Pattern field
'// indicates the values to which bits in corresponding
'// positions in candidate packets should be compared. The
'// Mask field indicates which bits are to be compared and
'// which bits are don't cares.
'//
'// Different filters can be submitted on the TCI interface.
'// The generic filter structure is defined to include an
'// AddressType, which indicates the specific type of filter to
'// follow.
'//
' // Size = 16 bytes
TYPE TC_GEN_FILTER DWORD
 AddressType AS WORD ' USHORT // IP, IPX, etc.
 PatternSize AS DWORD ' ULONG // byte count of the pattern
 Pattern AS DWORD ' PVOID // specific format, e.g. IP_PATTERN
 Mask AS DWORD ' PVOID // same type as Pattern
END TYPE
'//
'// A generic flow includes two flowspecs and a freeform
'// buffer which contains flow specific TC objects.
'//
' // Size = 76 bytes
TYPE TC_GEN_FLOW DWORD
 SendingFlowspec AS FLOWSPEC
 ReceivingFlowspec AS FLOWSPEC
 TcObjectsLength AS DWORD ' ULONG // number of optional bytes
 TcObjects(0) AS QOS_OBJECT_HDR
END TYPE
'//
'// Format of specific pattern or mask used by GPC for the IP protocol
'//
'typedef struct _IP_PATTERN {
' ULONG Reserved1;
' ULONG Reserved2;
' ULONG SrcAddr;
' ULONG DstAddr;
' union {
' struct { USHORT s_srcport,s_dstport; } S_un_ports;
' struct { UCHAR s_type,s_code; USHORT filler; } S_un_icmp;
' ULONG S_Spi;
' } S_un;
' UCHAR ProtocolId;
' UCHAR Reserved3[3];
'#define tcSrcPort S_un.S_un_ports.s_srcport
'#define tcDstPort S_un.S_un_ports.s_dstport
'#define tcIcmpType S_un.S_un_icmp.s_type
'#define tcIcmpCode S_un.S_un_icmp.s_code
'#define tcSpi S_un.S_Spi
'} IP_PATTERN, *PIP_PATTERN;
' // Size = 4 bytes
TYPE S_un_ports BYTE
 s_srcport AS WORD ' USHORT
 s_dstport AS WORD ' USHORT
END TYPE
' // Size = 4 bytes
TYPE S_un_icmp BYTE
 s_type AS BYTE ' UCHAR
 s_code AS BYTE ' UCHAR
 filler AS WORD ' USHORT
END TYPE
' // Size = 4 bytes
UNION IP_PATTERN_UNION BYTE
 S_un_ports
 S_un_icmp
 S_Spi AS DWORD ' ULONG
END UNION
' // Size = 24 bytes
TYPE IP_PATTERN BYTE
 Reserved1 AS DWORD ' ULONG
 Reserved2 AS DWORD ' ULONG
 SrcAddr AS DWORD ' ULONG
 DstAddr AS DWORD ' ULONG
 IP_PATTERN_UNION
 ProtocolId AS BYTE ' UCHAR
 Reserved3(2) AS BYTE ' UCHAR[3]
END TYPE
'//
'// Format of specific pattern or mask used by GPC for the IPX protocol
'//
'typedef struct _IPX_PATTERN {
' struct {
' ULONG NetworkAddress;
' UCHAR NodeAddress[6];
' USHORT Socket;
' } Src, Dest;
'} IPX_PATTERN, *PIPX_PATTERN;
' // Size = 12 bytes
TYPE IPX_PATTERN_STRUCT BYTE
 NetworkAddress AS DWORD ' ULONG
 NodeAddress(5) AS BYTE ' UCHAR[6]
 Socket AS WORD ' USHORT
END TYPE
' // Size = 24 bytes
TYPE IPX_PATTERN BYTE
 Src AS IPX_PATTERN_STRUCT
 Dest AS IPX_PATTERN_STRUCT
END TYPE
'//
'// The enumeration buffer is the flow parameters + a list of filters
'//
' // Size = 548 bytes
TYPE ENUMERATION_BUFFER DWORD FILL
 Length AS DWORD ' ULONG
 OwnerProcessId AS DWORD ' ULONG
 FlowNameLength AS WORD ' USHORT
 FlowName AS WSTRINGZ * %MAX_STRING_LENGTH ' WCHAR
 pFlow AS TC_GEN_FLOW PTR ' PTC_GEN_FLOW
 NumberOfFilters AS DWORD ' ULONG
 GenericFilter(0) AS TC_GEN_FILTER ' // one for each filter
END TYPE
'//---------------------------------------------------------------------------
'//
'// Interface Function Definitions
'//
DECLARE FUNCTION TcRegisterClient LIB "traffic.dll" ALIAS "TcRegisterClient" ( BYVAL TciVersion AS QUAD , BYVAL ClRegCtx AS QUAD , BYREF ClientHandlerList AS TCI_CLIENT_FUNC_LIST , BYREF pClientHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcEnumerateInterfaces LIB "traffic.dll" ALIAS "TcEnumerateInterfaces" ( BYVAL ClientHandle AS QUAD , BYREF pBufferSize AS QUAD , BYREF InterfaceBuffer AS TC_IFC_DESCRIPTOR ) AS QUAD ' ULONG
DECLARE FUNCTION TcOpenInterfaceA LIB "traffic.dll" ALIAS "TcOpenInterfaceA" ( BYREF pInterfaceName AS ASCIIZ , BYVAL ClientHandle AS QUAD , BYVAL ClIfcCtx AS QUAD , BYREF pIfcHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcOpenInterfaceW LIB "traffic.dll" ALIAS "TcOpenInterfaceW" ( BYREF pInterfaceName AS WSTRINGZ , BYVAL ClientHandle AS QUAD , BYVAL ClIfcCtx AS QUAD , BYREF pIfcHandle AS QUAD ) AS QUAD ' ULONG
#IF %DEF(%UNICODE)
 MACRO TcOpenInterface = TcOpenInterfaceW
#ELSE
 MACRO TcOpenInterface = TcOpenInterfaceA
#ENDIF
DECLARE FUNCTION TcCloseInterface LIB "traffic.dll" ALIAS "TcCloseInterface" ( BYVAL IfcHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcQueryInterface LIB "traffic.dll" ALIAS "TcQueryInterface" ( BYVAL IfcHandle AS QUAD , BYREF pGuidParam AS GUID , BYVAL NotifyChange AS BYTE , BYREF pBufferSize AS QUAD , BYREF Buffer AS ANY ) AS QUAD ' ULONG
DECLARE FUNCTION TcSetInterface LIB "traffic.dll" ALIAS "TcSetInterface" ( BYVAL IfcHandle AS QUAD , BYREF pGuidParam AS GUID , BYREF pBufferSize AS QUAD , BYREF Buffer AS ANY ) AS QUAD ' ULONG
DECLARE FUNCTION TcQueryFlowA LIB "traffic.dll" ALIAS "TcQueryFlowA" ( BYREF pFlowName AS ASCIIZ , BYREF pGuidParam AS GUID , BYREF pBufferSize AS QUAD , BYREF Buffer AS ANY ) AS QUAD ' ULONG
DECLARE FUNCTION TcQueryFlowW LIB "traffic.dll" ALIAS "TcQueryFlowW" ( BYREF pFlowName AS WSTRINGZ , BYREF pGuidParam AS GUID , BYREF pBufferSize AS QUAD , BYREF Buffer AS ANY ) AS QUAD ' ULONG
#IF %DEF(%UNICODE)
 MACRO TcQueryFlow = TcQueryFlowW
#ELSE
 MACRO TcQueryFlow = TcQueryFlowA
#ENDIF
DECLARE FUNCTION TcSetFlowA LIB "traffic.dll" ALIAS "TcSetFlowA" ( BYREF pFlowName AS ASCIIZ , BYREF pGuidParam AS GUID , BYREF pBufferSize AS QUAD , BYREF Buffer AS ANY ) AS QUAD ' ULONG
DECLARE FUNCTION TcSetFlowW LIB "traffic.dll" ALIAS "TcSetFlowW" ( BYREF pFlowName AS WSTRINGZ , BYREF pGuidParam AS GUID , BYREF pBufferSize AS QUAD , BYREF Buffer AS ANY ) AS QUAD ' ULONG
#IF %DEF(%UNICODE)
 MACRO TcSetFlow = TcSetFlowW
#ELSE
 MACRO TcSetFlow = TcSetFlowA
#ENDIF
DECLARE FUNCTION TcAddFlow LIB "traffic.dll" ALIAS "TcAddFlow" ( BYVAL IfcHandle AS QUAD , BYVAL ClFlowCtx AS QUAD , BYVAL Flags AS QUAD , BYREF pGenericFlow AS TC_GEN_FLOW , BYREF pFlowHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcGetFlowNameA LIB "traffic.dll" ALIAS "TcGetFlowNameA" ( BYVAL FlowHandle AS QUAD , BYVAL StrSize AS QUAD , BYREF pFlowName AS ASCIIZ ) AS QUAD ' ULONG
DECLARE FUNCTION TcGetFlowNameW LIB "traffic.dll" ALIAS "TcGetFlowNameW" ( BYVAL FlowHandle AS QUAD , BYVAL StrSize AS QUAD , BYREF pFlowName AS WSTRINGZ ) AS QUAD ' ULONG
#IF %DEF(%UNICODE)
 MACRO TcGetFlowName = TcGetFlowNameW
#ELSE
 MACRO TcGetFlowName = TcGetFlowNameA
#ENDIF
DECLARE FUNCTION TcModifyFlow LIB "traffic.dll" ALIAS "TcModifyFlow" ( BYVAL FlowHandle AS QUAD , BYREF pGenericFlow AS TC_GEN_FLOW ) AS QUAD ' ULONG
DECLARE FUNCTION TcAddFilter LIB "traffic.dll" ALIAS "TcAddFilter" ( BYVAL FlowHandle AS QUAD , BYREF pGenericFilter AS TC_GEN_FILTER , BYREF pFilterHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcDeregisterClient LIB "traffic.dll" ALIAS "TcDeregisterClient" ( BYVAL ClientHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcDeleteFlow LIB "traffic.dll" ALIAS "TcDeleteFlow" ( BYVAL FlowHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcDeleteFilter LIB "traffic.dll" ALIAS "TcDeleteFilter" ( BYVAL FilterHandle AS QUAD ) AS QUAD ' ULONG
DECLARE FUNCTION TcEnumerateFlows LIB "traffic.dll" ALIAS "TcEnumerateFlows" ( BYVAL IfcHandle AS QUAD , BYREF pEnumHandle AS QUAD , BYREF pFlowCount AS QUAD , BYREF pBufSize AS QUAD , BYREF Buffer AS ENUMERATION_BUFFER ) AS QUAD ' ULONG
#ENDIF
