' ########################################################################################
' Microsoft Windows
' File: ws2bth.inc
' Contents: Winsock 2 Bluetooth Annex definitions
' 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_ws2bth_PBI)
#DEFINE PBX_ws2bth_PBI
%WS2BTH_INC = 1
#include once "bthdef.inc"
'#include <pshpack1.h>
%BT_PORT_ANY = -1
%BT_PORT_MIN = &H1
%BT_PORT_MAX = &Hffff
%BT_PORT_DYN_FIRST = &H1001
'//
'// These three definitions are duplicated in winsock2.h to reserve ordinals
'//
#IF NOT %DEF(%AF_BTH)
%AF_BTH = 32
#ENDIF
#IF NOT %DEF(%PF_BTH)
%PF_BTH = %AF_BTH
#ENDIF
#IF NOT %DEF(%NS_BTH)
%NS_BTH = 16
#ENDIF
' // Size = 30 bytes
TYPE SOCKADDR_BTH BYTE
 addressFamily AS WORD ' USHORT // Always AF_BTH
 btAddr AS QUAD ' BTH_ADDR // Bluetooth device address
 serviceClassId AS GUID ' GUID // [OPTIONAL] system will query SDP for port
 port AS DWORD ' ULONG // RFCOMM channel or L2CAP PSM
END TYPE
$SVCID_BTH_PROVIDER = GUID$("{06AA63E0-7D60-41FF-AFB2-3EE6D2D9392D}")
%BTH_ADDR_STRING_SIZE = 12 ' // max size from WSAAddressToString
'//
'// Bluetooth protocol #s are assigned according to the Bluetooth
'// Assigned Numbers portion of the Bluetooth Specification
'//
%BTHPROTO_RFCOMM = &H0003
%BTHPROTO_L2CAP = &H0100
%SOL_RFCOMM = %BTHPROTO_RFCOMM
%SOL_L2CAP = %BTHPROTO_L2CAP
%SOL_SDP = &H0101
'//
'// SOCKET OPTIONS
'//
%SO_BTH_AUTHENTICATE = &H80000001 ' // optlen=sizeof(ULONG), optval = &(ULONG)TRUE/FALSE
%SO_BTH_ENCRYPT = &H00000002 ' // optlen=sizeof(ULONG), optval = &(ULONG)TRUE/FALSE
%SO_BTH_MTU = &H80000007 ' // optlen=sizeof(ULONG), optval = &mtu
%SO_BTH_MTU_MAX = &H80000008 ' // optlen=sizeof(ULONG), optval = &max. mtu
%SO_BTH_MTU_MIN = &H8000000A ' // optlen=sizeof(ULONG), optval = &min. mtu
' //
' // Socket option parameters
' //
%RFCOMM_MAX_MTU = &H0000029A ' // L2CAP MTU (672) - RFCOMM header size (6)
%RFCOMM_MIN_MTU = &H00000017 ' // RFCOMM spec sec 5.3 table 5.1
'//
'// NAME SERVICE PROVIDER DEFINITIONS
'// For calling WSASetService
'// and WSALookupServiceBegin, WSALookupServiceNext, WSALookupServiceEnd
'// with Bluetooth-specific extensions
'//
%BTH_SDP_VERSION = 1
'//
'// [OPTIONAL] passed in BLOB member of WSAQUERYSET
'// QUERYSET and its lpBlob member are copied & converted
'// to unicode in the system for non-unicode applications.
'// However, nothing is copied back upon return. In
'// order for the system to return data such as pRecordHandle,
'// it much have an extra level of indirection from lpBlob
'//
'typedef struct _BTH_SET_SERVICE {
' //
' // This version number will change when/if the binary format of
' // SDP records change, affecting the format of pRecord.
' // Set to BTH_SDP_VERSION by client, and returned by system
' //
' PULONG pSdpVersion;
' //
' // Handle to SDP record. When BTH_SET_SERVICE structure is later
' // passed to WSASetService RNRSERVICE_DELETE, this handle identifies the
' // record to delete.
' //
' HANDLE *pRecordHandle;
' //
' // COD_SERVICE_* bit(s) associated with this SDP record, which will be
' // advertised when the local radio is found during device inquiry.
' // When the last SDP record associated with a bit is deleted, that
' // service bit is no longer reported in repsonse to inquiries
' //
' ULONG fCodService; // COD_SERVICE_* bits
' ULONG Reserved[5]; // Reserved by system. Must be zero.
' ULONG ulRecordLength; // length of pRecord which follows
' UCHAR pRecord[1]; // SDP record as defined by bluetooth spec
'} BTH_SET_SERVICE, *PBTH_SET_SERVICE;
' // Size = 37 bytes
TYPE BTH_SET_SERVICE BYTE
 pSdpVersion AS DWORD PTR
 pRecordHandle AS DWORD ' HANDLE *
 fCodService AS DWORD ' ULONG // COD_SERVICE_* bits
 Reserved(4) AS DWORD ' ULONG // Reserved by system. Must be zero.
 ulRecordLength AS DWORD ' ULONG // length of pRecord which follows
 pRecord(0) AS BYTE ' UCHAR // SDP record as defined by bluetooth spec
END TYPE
'//
'// Default device inquiry duration in seconds
'//
'// The application thread will be blocked in WSALookupServiceBegin
'// for the duration of the device inquiry, so this value needs to
'// be balanced against the chance that a device that is actually
'// present might not being found by Bluetooth in this time
'//
'// Paging improvements post-1.1 will cause devices to be
'// found generally uniformly in the 0-6 sec timeperiod
'//
%SDP_DEFAULT_INQUIRY_SECONDS = 6
%SDP_MAX_INQUIRY_SECONDS = 60
'//
'// Default maximum number of devices to search for
'//
%SDP_DEFAULT_INQUIRY_MAX_RESPONSES = 255
%SDP_SERVICE_SEARCH_REQUEST = 1
%SDP_SERVICE_ATTRIBUTE_REQUEST = 2
%SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST = 3
'//
'// [OPTIONAL] input restrictions on device inquiry
'// Passed in BLOB of LUP_CONTAINERS (device) search
'//
' // Size = 5 bytes
TYPE BTH_QUERY_DEVICE BYTE
 LAP AS DWORD ' ULONG // reserved: must be 0 (GIAC inquiry only)
 length AS BYTE ' UCHAR // requested length of inquiry (seconds)
END TYPE
'//
'// [OPTIONAL] Restrictions on searching for a particular service
'// Passed in BLOB of !LUP_CONTAINERS (service) search
'//
' // Size = 256 bytes
TYPE BTH_QUERY_SERVICE BYTE
 type AS DWORD ' ULONG // one of SDP_SERVICE_*
 serviceHandle AS DWORD ' ULONG
 uuids(%MAX_UUIDS_IN_QUERY - 1) AS SdpQueryUuid ' SdpQueryUuid
 numRange AS DWORD ' ULONG
 pRange(0) AS SdpAttributeRange ' SdpAttributeRange
END TYPE
'//
'// BTHNS_RESULT_*
'//
'// Bluetooth specific flags returned from WSALookupServiceNext
'// in WSAQUERYSET.dwOutputFlags in response to device inquiry
'//
'//
'// Local device is paired with remote device
'//
%BTHNS_RESULT_DEVICE_CONNECTED = &H00010000
%BTHNS_RESULT_DEVICE_REMEMBERED = &H00020000
%BTHNS_RESULT_DEVICE_AUTHENTICATED = &H00040000
'//
'// SOCKET IOCTLs
'//
'#define SIO_RFCOMM_SEND_COMMAND _WSAIORW (IOC_VENDOR, 101)
'#define SIO_RFCOMM_WAIT_COMMAND _WSAIORW (IOC_VENDOR, 102)
%SIO_RFCOMM_SEND_COMMAND = &HD8000065
%SIO_RFCOMM_WAIT_COMMAND = &HD8000066
'//
'// These IOCTLs are for test/validation/conformance and may only be
'// present in debug/checked builds of the system
'//
'#define SIO_BTH_PING _WSAIORW (IOC_VENDOR, 8)
'#define SIO_BTH_INFO _WSAIORW (IOC_VENDOR, 9)
'#define SIO_RFCOMM_SESSION_FLOW_OFF _WSAIORW (IOC_VENDOR, 103)
'#define SIO_RFCOMM_TEST _WSAIORW (IOC_VENDOR, 104)
'#define SIO_RFCOMM_USECFC _WSAIORW (IOC_VENDOR, 105)
%SIO_BTH_PING = &HD8000008
%SIO_BTH_INFO = &HD8000009
%SIO_RFCOMM_SESSION_FLOW_OFF = &HD8000067
%SIO_RFCOMM_TEST = &HD8000068
%SIO_RFCOMM_USECFC = &HD8000069
'//
'// SOCKET IOCTL DEFINITIONS
'//
'#ifndef BIT
'#define BIT(b) (1<<(b))
'#endif
'//
'// Structure definition from Bluetooth RFCOMM spec, TS 07.10 5.4.6.3.7
'//
'typedef struct _RFCOMM_MSC_DATA {
' UCHAR Signals;
' #define MSC_EA_BIT EA_BIT
' #define MSC_FC_BIT BIT(1) // Flow control, clear if we can receive
' #define MSC_RTC_BIT BIT(2) // Ready to communicate, set when ready
' #define MSC_RTR_BIT BIT(3) // Ready to receive, set when ready
' #define MSC_RESERVED (BIT(4)|BIT(5))// Reserved by spec, must be 0
' #define MSC_IC_BIT BIT(6) // Incoming call
' #define MSC_DV_BIT BIT(7) // Data valid
' UCHAR Break;
' #define MSC_BREAK_BIT BIT(1) // Set if sending break
' #define MSC_SET_BREAK_LENGTH(b, l) ((b) = ((b)&0x3) | (((l)&0xf) << 4))
'} RFCOMM_MSC_DATA, *PRFCOMM_MSC_DATA;
'%MSC_EA_BIT = %EA_BIT ' Note: EA_BIT isn't defined in any header
%MSC_EA_BIT = &H01?
%MSC_FC_BIT = &H02? ' // Flow control, clear if we can receive
%MSC_RTC_BIT = &H04? ' // Ready to communicate, set when ready
%MSC_RTR_BIT = &H08? ' // Ready to receive, set when ready
%MSC_RESERVED = &H10? OR &H20? ' // Reserved by spec, must be 0
%MSC_IC_BIT = &H40? ' // Incoming call
%MSC_DV_BIT = &H80? ' // Data valid
' // Size = 2 bytes
TYPE RFCOMM_MSC_DATA BYTE
 Signals AS BYTE ' UCHAR
 Break AS BYTE ' UCHAR
END TYPE
'//
'// Structure definition from Bluetooth RFCOMM spec, TS 07.10 5.4.6.3.10
'//
%RLS_ERROR = &H01?
%RLS_OVERRUN = &H02?
%RLS_PARITY = &H04?
%RLS_FRAMING = &H08?
' // Size = 1 byte
TYPE RFCOMM_RLS_DATA BYTE
 LineStatus AS BYTE ' UCHAR
END TYPE
'//
'// Structure definition from Bluetooth RFCOMM spec, TS 07.10 5.4.6.3.9
'//
%RPN_BAUD_2400 = 0?
%RPN_BAUD_4800 = 1?
%RPN_BAUD_7200 = 2?
%RPN_BAUD_9600 = 3?
%RPN_BAUD_19200 = 4?
%RPN_BAUD_38400 = 5?
%RPN_BAUD_57600 = 6?
%RPN_BAUD_115200 = 7?
%RPN_BAUD_230400 = 8?
%RPN_DATA_5 = &H0?
%RPN_DATA_6 = &H1?
%RPN_DATA_7 = &H2?
%RPN_DATA_8 = &H3?
%RPN_STOP_1 = &H0?
%RPN_STOP_1_5 = &H4?
%RPN_PARITY_NONE = &H00?
%RPN_PARITY_ODD = &H08?
%RPN_PARITY_EVEN = &H18?
%RPN_PARITY_MARK = &H28?
%RPN_PARITY_SPACE = &H38?
%RPN_FLOW_X_IN = &H01?
%RPN_FLOW_X_OUT = &H02?
%RPN_FLOW_RTR_IN = &H04?
%RPN_FLOW_RTR_OUT = &H08?
%RPN_FLOW_RTC_IN = &H10?
%RPN_FLOW_RTC_OUT = &H20?
%RPN_PARAM_BAUD = &H01?
%RPN_PARAM_DATA = &H02?
%RPN_PARAM_STOP = &H04?
%RPN_PARAM_PARITY = &H08?
%RPN_PARAM_P_TYPE = &H10?
%RPN_PARAM_XON = &H20?
%RPN_PARAM_XOFF = &H40?
%RPN_PARAM_X_IN = &H01?
%RPN_PARAM_X_OUT = &H02?
%RPN_PARAM_RTR_IN = &H04?
%RPN_PARAM_RTR_OUT = &H08?
%RPN_PARAM_RTC_IN = &H10?
%RPN_PARAM_RTC_OUT = &H20?
' // Size = 7 bytes
TYPE RFCOMM_RPN_DATA BYTE
 Baud AS BYTE ' UCHAR
 Data AS BYTE ' UCHAR
 FlowControl AS BYTE ' UCHAR
 XonChar AS BYTE ' UCHAR
 XoffChar AS BYTE ' UCHAR
 ParameterMask1 AS BYTE ' UCHAR
 ParameterMask2 AS BYTE ' UCHAR
END TYPE
%RFCOMM_CMD_NONE = 0
%RFCOMM_CMD_MSC = 1
%RFCOMM_CMD_RLS = 2
%RFCOMM_CMD_RPN = 3
%RFCOMM_CMD_RPN_REQUEST = 4
%RFCOMM_CMD_RPN_RESPONSE = 5
' // Size = 7 bytes
UNION RFCOMM_COMMAND_DATA_UNION BYTE
 MSC AS RFCOMM_MSC_DATA
 RLS AS RFCOMM_RLS_DATA
 RPN AS RFCOMM_RPN_DATA
END UNION
' // Size = 11 bytes
TYPE RFCOMM_COMMAND BYTE
 CmdType AS DWORD ' ULONG // one of RFCOMM_CMD_*
 Data AS RFCOMM_COMMAND_DATA_UNION
END TYPE
'//
'// These structures are for test/validation/conformance and may only be
'// present in debug/checked builds of the system
'//
' // Size = 53 bytes
TYPE BTH_PING_REQ BYTE
 btAddr AS QUAD ' BTH_ADDR
 dataLen AS BYTE ' UCHAR
 data(%MAX_L2CAP_PING_DATA_LENGTH - 1) AS BYTE ' UCHAR
END TYPE
' // Size = 45 bytes
TYPE BTH_PING_RSP BYTE
 dataLen AS BYTE ' UCHAR
 data(%MAX_L2CAP_PING_DATA_LENGTH - 1) AS BYTE ' UCHAR
END TYPE
' // Size = 10 bytes
TYPE BTH_INFO_REQ BYTE
 btAddr AS QUAD ' BTH_ADDR
 infoType AS WORD ' USHORT
END TYPE
' // Size = 44 bytes
UNION BTH_INFO_RSP_UNION BYTE
 connectionlessMTU AS WORD ' USHORT
 data(%MAX_L2CAP_INFO_DATA_LENGTH - 1) AS BYTE ' UCHAR
END UNION
' // Size = 47 bytes
TYPE BTH_INFO_RSP BYTE
 result AS WORD ' WORD
 dataLen AS BYTE ' UCHAR
 BTH_INFO_RSP_UNION
END TYPE
'//
'#include <poppack.h>