' ########################################################################################
' Microsoft Windows
' File: madcapcl.inc
' 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_madcapcl_PBI)
#DEFINE PBX_madcapcl_PBI
%EQUATE `MADCAPCL_INC = 1
'#INCLUDE ONCE "time.inc"
' Not included in Windows 7 SDK, but needed here.
#IF NOT %DEF(%UNICODE_STRING_DEFINED)
%EQUATE `UNICODE_STRING_DEFINED = 1
' // Size = 8 bytes
TYPE UNICODE_STRING WORD
 Length AS WORD ' USHORT Length
 MaximumLength AS WORD ' USHORT MaximumLength
 Buffer AS WSTRINGZ PTR ' PWSTR Buffer
END TYPE
#ENDIF
%EQUATE `MCAST_CLIENT_ID_LEN = 17
%EQUATE `MCAST_API_VERSION_0 = 0
%EQUATE `MCAST_API_VERSION_1 = 1
%EQUATE `MCAST_API_CURRENT_VERSION = %MCAST_API_VERSION_1
'typedef unsigned short IP_ADDR_FAMILY;
' // Size = 16 bytes
UNION IPNG_ADDRESS BYTE
 IpAddrV4 AS DWORD
 IpAddrV6(15) AS BYTE ' BYTE [16]
END UNION
'/*++
'Description:
' This union is used to pass both IPv4 and IPv6 style address.
'Members:
' IpAddrV4 - IPv4 style address
' IpAddrV6 - IPv6 style address
'--*/
' // Size = 8 bytes
TYPE MCAST_CLIENT_UID DWORD
 ClientUID AS BYTE PTR
 ClientUIDLength AS DWORD
END TYPE
'/*++
'Description:
' This describes the unique clientID for each request.
'Members:
' ClientUID - Buffer containing the clientID
' ClientUIDLength - The size of the above buffer in bytes.
'--*/
' // Size = 48 bytes
TYPE MCAST_SCOPE_CTX DWORD FILL
 ScopeID AS IPNG_ADDRESS
 Interface AS IPNG_ADDRESS
 ServerID AS IPNG_ADDRESS
END TYPE
'/*++
'Description:
' This defines the handle of the scope from which the address
' is to be allocated/renewed/released.
'Members:
' ScopeID - Scope ID is essentially first ip of the scope
' Interface - Interface on which this scope was found
' ServerID - IPAddress of the MADCAP server
'--*/
' // Size = 76 bytes
TYPE MCAST_SCOPE_ENTRY DWORD FILL
 ScopeCtx AS MCAST_SCOPE_CTX
 LastAddr AS IPNG_ADDRESS
 TTL AS DWORD
 ScopeDesc AS UNICODE_STRING
END TYPE
'/*++
'Description:
' This structure contains all the info pertaining to a given multicast
' scope.
'Members:
' ScopeCtx - the handle for this scope
' LastAddr - last addr of the scope
' TTL - TTL value of this scope.
' ScopeDesc - user friendly description of scope
'--*/
' // Size = 40 bytes
TYPE MCAST_LEASE_REQUEST DWORD FILL
 LeaseStartTime AS LONG
 MaxLeaseStartTime AS LONG
 LeaseDuration AS DWORD
 MinLeaseDuration AS DWORD
 ServerAddress AS IPNG_ADDRESS
 MinAddrCount AS WORD ' WORD
 AddrCount AS WORD ' WORD
 pAddrBuf AS BYTE PTR
END TYPE
'/*++
'Description:
' This structure is used to describe the request parameters for
' requesting/renewing/releasing multicast addresses
'Members:
' LeaseStartTime - desired start time of the lease, pass 0 if desired start time
' is current time. The desired time is specified in the number of seconds elapsed
' since midnight (00:00:00), January 1, 1970, coordinated universal time.
' MaxLeaseStartTime - the maximum start time that the client is willing to accept.
' Where time is the number of seconds elapsed since midnight (00:00:00),
' January 1, 1970, coordinated universal time.
' LeaseDuration - desired lease time for the request, pass 0 if default
' lease time is requested.
' MinLeaseDuration - the minimum lease time that the client is willing
' to accept
' ServerAddress - server's ip address where this lease whas renewed/requested.
' pass 0 if unknown (e.g in McastRequestAddress)
' MinAddrCount - minimum number of addresses that the client is willing
' to accept
' AddrCount - the desired number of addresses requested/allocated/renewed.
' This also specifies the size of the array specified by Addr.
' pAddrBuf - buffer containing specific addresses being requested/renewed/released.
' For IPv4 it is a pointer to 4 byte addresses and for IPv6 it
' points to 16 byte chunks. Pass NULL if no specific addresses
' are requested.
'Remarks:
' In MCAST_API_VERSION_1 version, the MaxLeaseStartTime, MinLeaseDuration and
' MinAddrCount are ignored by the API implementation. However, the clients should
' set appropriate desired values for these members so as when the OS update brings
' new implementation of the APIs then the clients can take advantage of it.
'--*/
' // Size = 32 bytes
TYPE MCAST_LEASE_RESPONSE DWORD FILL
 LeaseStartTime AS LONG
 LeaseEndTime AS LONG
 ServerAddress AS IPNG_ADDRESS
 AddrCount AS WORD ' WORD
 pAddrBuf AS BYTE PTR
END TYPE
'/*++
'Description:
' This structure is used to pass the response of the operation of
' requesting/renewing/releasing multicast addresses.
'Members:
' LeaseStartTime - start time of the lease in number of seconds elapsed since
' midnight (00:00:00), January 1, 1970, coordinated universal time.
' LeaseEndTime - time when lease ends, where time is the number of seconds elapsed
' since midnight (00:00:00), January 1, 1970, coordinated universal time.
' ServerAddress - server's ip address where this lease is renewed/requested.
' AddrCount - number of addresses requested/allocated/renewed.
' This also specifies the size of the array specified by Addr.
' Addr - buffer containing addresses being requested/renewed/released. For IPv4
' it is a pointer to 4 byte addresses and for IPv6 it points to 16 byte chunks
'--*/
DECLARE FUNCTION McastApiStartup LIB "dhcpcsvc.dll" ALIAS "McastApiStartup" ( BYVAL Version AS QUAD ) AS QUAD
DECLARE SUB McastApiCleanup LIB "dhcpcsvc.dll" ALIAS "McastApiCleanup" ()
DECLARE FUNCTION McastGenUID LIB "dhcpcsvc.dll" ALIAS "McastGenUID" ( BYREF pRequestID AS MCAST_CLIENT_UID ) AS QUAD
DECLARE FUNCTION McastEnumerateScopes LIB "dhcpcsvc.dll" ALIAS "McastEnumerateScopes" ( BYREF AddrFamily AS WORD
 , BYVAL ReQuery AS LONG
 , BYREF pScopeList AS MCAST_SCOPE_ENTRY
 , BYREF pScopeLen AS DWORD
 , BYREF pScopeCount AS DWORD
 ) AS DWORD
DECLARE FUNCTION McastRequestAddress LIB "dhcpcsvc.dll" ALIAS "McastRequestAddress" ( BYREF AddrFamily AS WORD
 , BYREF pRequestID AS MCAST_CLIENT_UID
 , BYREF pScopeCtx AS MCAST_SCOPE_CTX
 , BYREF pAddrRequest AS MCAST_LEASE_REQUEST
 , BYREF pAddrResponse AS MCAST_LEASE_RESPONSE
 ) AS DWORD
DECLARE FUNCTION McastRenewAddress LIB "dhcpcsvc.dll" ALIAS "McastRenewAddress" ( BYREF AddrFamily AS WORD
 , BYREF pRequestID AS MCAST_CLIENT_UID
 , BYREF pRenewRequest AS MCAST_LEASE_REQUEST
 , BYREF pRenewResponse AS MCAST_LEASE_RESPONSE
 ) AS DWORD
DECLARE FUNCTION McastReleaseAddress LIB "dhcpcsvc.dll" ALIAS "McastReleaseAddress" ( BYREF AddrFamily AS WORD
 , BYREF pRequestID AS MCAST_CLIENT_UID
 , BYREF pReleaseRequest AS MCAST_LEASE_REQUEST
 ) AS DWORD
#ENDIF
