ws2bth.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. ws2bth.h
  5. Abstract:
  6. Winsock 2 Bluetooth Annex definitions.
  7. Notes:
  8. Change BT_* to BTH_*
  9. --*/
  10. #ifndef __WS2BTH__H
  11. #define __WS2BTH__H
  12. #include <bthdef.h>
  13. #include <pshpack1.h>
  14. #define BT_PORT_ANY -1
  15. #define BT_PORT_MIN 0x1
  16. #define BT_PORT_MAX 0xffff
  17. #define BT_PORT_DYN_FIRST 0x1001
  18. //
  19. // These three definitions are duplicated in winsock2.h to reserve ordinals
  20. //
  21. #ifndef AF_BTH
  22. #define AF_BTH 32
  23. #endif
  24. #ifndef PF_BTH
  25. #define PF_BTH AF_BTH
  26. #endif
  27. #ifndef NS_BTH
  28. #define NS_BTH 16
  29. #endif
  30. typedef struct _SOCKADDR_BTH
  31. {
  32. USHORT addressFamily; // Always AF_BTH
  33. BTH_ADDR btAddr; // Bluetooth device address
  34. GUID serviceClassId; // [OPTIONAL] system will query SDP for port
  35. ULONG port; // RFCOMM channel or L2CAP PSM
  36. } SOCKADDR_BTH, *PSOCKADDR_BTH;
  37. DEFINE_GUID(SVCID_BTH_PROVIDER, 0x6aa63e0, 0x7d60, 0x41ff, 0xaf, 0xb2, 0x3e, 0xe6, 0xd2, 0xd9, 0x39, 0x2d);
  38. #define BTH_ADDR_STRING_SIZE 12 // max size from WSAAddressToString
  39. //
  40. // Bluetooth protocol #s are assigned according to the Bluetooth
  41. // Assigned Numbers portion of the Bluetooth Specification
  42. //
  43. #define BTHPROTO_RFCOMM 0x0003
  44. #define BTHPROTO_L2CAP 0x0100
  45. #define SOL_RFCOMM BTHPROTO_RFCOMM
  46. #define SOL_L2CAP BTHPROTO_L2CAP
  47. #define SOL_SDP 0x0101
  48. //
  49. // SOCKET OPTIONS
  50. //
  51. #define SO_BTH_AUTHENTICATE 0x80000001 // optlen=sizeof(ULONG), optval = &(ULONG)TRUE/FALSE
  52. #define SO_BTH_ENCRYPT 0x00000002 // optlen=sizeof(ULONG), optval = &(ULONG)TRUE/FALSE
  53. #define SO_BTH_MTU 0x80000007 // optlen=sizeof(ULONG), optval = &mtu
  54. #define SO_BTH_MTU_MAX 0x80000008 // optlen=sizeof(ULONG), optval = &max. mtu
  55. #define SO_BTH_MTU_MIN 0x8000000a // optlen=sizeof(ULONG), optval = &min. mtu
  56. //
  57. // Socket option parameters
  58. //
  59. #define RFCOMM_MAX_MTU 0x0000029a // L2CAP MTU (672) - RFCOMM header size (6)
  60. #define RFCOMM_MIN_MTU 0x00000017 // RFCOMM spec sec 5.3 table 5.1
  61. //
  62. // NAME SERVICE PROVIDER DEFINITIONS
  63. // For calling WSASetService
  64. // and WSALookupServiceBegin, WSALookupServiceNext, WSALookupServiceEnd
  65. // with Bluetooth-specific extensions
  66. //
  67. #define BTH_SDP_VERSION 1
  68. //
  69. // [OPTIONAL] passed in BLOB member of WSAQUERYSET
  70. // QUERYSET and its lpBlob member are copied & converted
  71. // to unicode in the system for non-unicode applications.
  72. // However, nothing is copied back upon return. In
  73. // order for the system to return data such as pRecordHandle,
  74. // it much have an extra level of indirection from lpBlob
  75. //
  76. typedef struct _BTH_SET_SERVICE {
  77. //
  78. // This version number will change when/if the binary format of
  79. // SDP records change, affecting the format of pRecord.
  80. // Set to BTH_SDP_VERSION by client, and returned by system
  81. //
  82. PULONG pSdpVersion;
  83. //
  84. // Handle to SDP record. When BTH_SET_SERVICE structure is later
  85. // passed to WSASetService RNRSERVICE_DELETE, this handle identifies the
  86. // record to delete.
  87. //
  88. HANDLE *pRecordHandle;
  89. //
  90. // COD_SERVICE_* bit(s) associated with this SDP record, which will be
  91. // advertised when the local radio is found during device inquiry.
  92. // When the last SDP record associated with a bit is deleted, that
  93. // service bit is no longer reported in repsonse to inquiries
  94. //
  95. ULONG fCodService; // COD_SERVICE_* bits
  96. ULONG Reserved[5]; // Reserved by system. Must be zero.
  97. ULONG ulRecordLength; // length of pRecord which follows
  98. UCHAR pRecord[1]; // SDP record as defined by bluetooth spec
  99. } BTH_SET_SERVICE, *PBTH_SET_SERVICE;
  100. //
  101. // Default device inquiry duration in seconds
  102. //
  103. // The application thread will be blocked in WSALookupServiceBegin
  104. // for the duration of the device inquiry, so this value needs to
  105. // be balanced against the chance that a device that is actually
  106. // present might not being found by Bluetooth in this time
  107. //
  108. // Paging improvements post-1.1 will cause devices to be
  109. // found generally uniformly in the 0-6 sec timeperiod
  110. //
  111. #define SDP_DEFAULT_INQUIRY_SECONDS 6
  112. #define SDP_MAX_INQUIRY_SECONDS 60
  113. //
  114. // Default maximum number of devices to search for
  115. //
  116. #define SDP_DEFAULT_INQUIRY_MAX_RESPONSES 255
  117. #define SDP_SERVICE_SEARCH_REQUEST 1
  118. #define SDP_SERVICE_ATTRIBUTE_REQUEST 2
  119. #define SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST 3
  120. //
  121. // [OPTIONAL] input restrictions on device inquiry
  122. // Passed in BLOB of LUP_CONTAINERS (device) search
  123. //
  124. typedef struct _BTH_QUERY_DEVICE {
  125. ULONG LAP; // reserved: must be 0 (GIAC inquiry only)
  126. UCHAR length; // requested length of inquiry (seconds)
  127. } BTH_QUERY_DEVICE, *PBTH_QUERY_DEVICE;
  128. //
  129. // [OPTIONAL] Restrictions on searching for a particular service
  130. // Passed in BLOB of !LUP_CONTAINERS (service) search
  131. //
  132. typedef struct _BTH_QUERY_SERVICE {
  133. ULONG type; // one of SDP_SERVICE_*
  134. ULONG serviceHandle;
  135. SdpQueryUuid uuids[MAX_UUIDS_IN_QUERY];
  136. ULONG numRange;
  137. SdpAttributeRange pRange[1];
  138. } BTH_QUERY_SERVICE, *PBTH_QUERY_SERVICE;
  139. //
  140. // BTHNS_RESULT_*
  141. //
  142. // Bluetooth specific flags returned from WSALookupServiceNext
  143. // in WSAQUERYSET.dwOutputFlags in response to device inquiry
  144. //
  145. //
  146. // Local device is paired with remote device
  147. //
  148. #define BTHNS_RESULT_DEVICE_CONNECTED 0x00010000
  149. #define BTHNS_RESULT_DEVICE_REMEMBERED 0x00020000
  150. #define BTHNS_RESULT_DEVICE_AUTHENTICATED 0x00040000
  151. //
  152. // SOCKET IOCTLs
  153. //
  154. #define SIO_RFCOMM_SEND_COMMAND _WSAIORW (IOC_VENDOR, 101)
  155. #define SIO_RFCOMM_WAIT_COMMAND _WSAIORW (IOC_VENDOR, 102)
  156. //
  157. // These IOCTLs are for test/validation/conformance and may only be
  158. // present in debug/checked builds of the system
  159. //
  160. #define SIO_BTH_PING _WSAIORW (IOC_VENDOR, 8)
  161. #define SIO_BTH_INFO _WSAIORW (IOC_VENDOR, 9)
  162. #define SIO_RFCOMM_SESSION_FLOW_OFF _WSAIORW (IOC_VENDOR, 103)
  163. #define SIO_RFCOMM_TEST _WSAIORW (IOC_VENDOR, 104)
  164. #define SIO_RFCOMM_USECFC _WSAIORW (IOC_VENDOR, 105)
  165. //
  166. // SOCKET IOCTL DEFINITIONS
  167. //
  168. #ifndef BIT
  169. #define BIT(b) (1<<(b))
  170. #endif
  171. //
  172. // Structure definition from Bluetooth RFCOMM spec, TS 07.10 5.4.6.3.7
  173. //
  174. typedef struct _RFCOMM_MSC_DATA {
  175. UCHAR Signals;
  176. #define MSC_EA_BIT EA_BIT
  177. #define MSC_FC_BIT BIT(1) // Flow control, clear if we can receive
  178. #define MSC_RTC_BIT BIT(2) // Ready to communicate, set when ready
  179. #define MSC_RTR_BIT BIT(3) // Ready to receive, set when ready
  180. #define MSC_RESERVED (BIT(4)|BIT(5))// Reserved by spec, must be 0
  181. #define MSC_IC_BIT BIT(6) // Incoming call
  182. #define MSC_DV_BIT BIT(7) // Data valid
  183. UCHAR Break;
  184. #define MSC_BREAK_BIT BIT(1) // Set if sending break
  185. #define MSC_SET_BREAK_LENGTH(b, l) ((b) = ((b)&0x3) | (((l)&0xf) << 4))
  186. } RFCOMM_MSC_DATA, *PRFCOMM_MSC_DATA;
  187. //
  188. // Structure definition from Bluetooth RFCOMM spec, TS 07.10 5.4.6.3.10
  189. //
  190. typedef struct _RFCOMM_RLS_DATA {
  191. UCHAR LineStatus;
  192. #define RLS_ERROR 0x01
  193. #define RLS_OVERRUN 0x02
  194. #define RLS_PARITY 0x04
  195. #define RLS_FRAMING 0x08
  196. } RFCOMM_RLS_DATA, *PRFCOMM_RLS_DATA;
  197. //
  198. // Structure definition from Bluetooth RFCOMM spec, TS 07.10 5.4.6.3.9
  199. //
  200. typedef struct _RFCOMM_RPN_DATA {
  201. UCHAR Baud;
  202. #define RPN_BAUD_2400 0
  203. #define RPN_BAUD_4800 1
  204. #define RPN_BAUD_7200 2
  205. #define RPN_BAUD_9600 3
  206. #define RPN_BAUD_19200 4
  207. #define RPN_BAUD_38400 5
  208. #define RPN_BAUD_57600 6
  209. #define RPN_BAUD_115200 7
  210. #define RPN_BAUD_230400 8
  211. UCHAR Data;
  212. #define RPN_DATA_5 0x0
  213. #define RPN_DATA_6 0x1
  214. #define RPN_DATA_7 0x2
  215. #define RPN_DATA_8 0x3
  216. #define RPN_STOP_1 0x0
  217. #define RPN_STOP_1_5 0x4
  218. #define RPN_PARITY_NONE 0x00
  219. #define RPN_PARITY_ODD 0x08
  220. #define RPN_PARITY_EVEN 0x18
  221. #define RPN_PARITY_MARK 0x28
  222. #define RPN_PARITY_SPACE 0x38
  223. UCHAR FlowControl;
  224. #define RPN_FLOW_X_IN 0x01
  225. #define RPN_FLOW_X_OUT 0x02
  226. #define RPN_FLOW_RTR_IN 0x04
  227. #define RPN_FLOW_RTR_OUT 0x08
  228. #define RPN_FLOW_RTC_IN 0x10
  229. #define RPN_FLOW_RTC_OUT 0x20
  230. UCHAR XonChar;
  231. UCHAR XoffChar;
  232. UCHAR ParameterMask1;
  233. #define RPN_PARAM_BAUD 0x01
  234. #define RPN_PARAM_DATA 0x02
  235. #define RPN_PARAM_STOP 0x04
  236. #define RPN_PARAM_PARITY 0x08
  237. #define RPN_PARAM_P_TYPE 0x10
  238. #define RPN_PARAM_XON 0x20
  239. #define RPN_PARAM_XOFF 0x40
  240. UCHAR ParameterMask2;
  241. #define RPN_PARAM_X_IN 0x01
  242. #define RPN_PARAM_X_OUT 0x02
  243. #define RPN_PARAM_RTR_IN 0x04
  244. #define RPN_PARAM_RTR_OUT 0x08
  245. #define RPN_PARAM_RTC_IN 0x10
  246. #define RPN_PARAM_RTC_OUT 0x20
  247. } RFCOMM_RPN_DATA, *PRFCOMM_RPN_DATA;
  248. #define RFCOMM_CMD_NONE 0
  249. #define RFCOMM_CMD_MSC 1
  250. #define RFCOMM_CMD_RLS 2
  251. #define RFCOMM_CMD_RPN 3
  252. #define RFCOMM_CMD_RPN_REQUEST 4
  253. #define RFCOMM_CMD_RPN_RESPONSE 5
  254. typedef struct _RFCOMM_COMMAND
  255. {
  256. ULONG CmdType; // one of RFCOMM_CMD_*
  257. union
  258. {
  259. RFCOMM_MSC_DATA MSC;
  260. RFCOMM_RLS_DATA RLS;
  261. RFCOMM_RPN_DATA RPN;
  262. } Data;
  263. } RFCOMM_COMMAND, *PRFCOMM_COMMAND;
  264. //
  265. // These structures are for test/validation/conformance and may only be
  266. // present in debug/checked builds of the system
  267. //
  268. typedef struct _BTH_PING_REQ {
  269. BTH_ADDR btAddr;
  270. UCHAR dataLen;
  271. UCHAR data[MAX_L2CAP_PING_DATA_LENGTH];
  272. } BTH_PING_REQ, *PBTH_PING_REQ;
  273. typedef struct _BTH_PING_RSP {
  274. UCHAR dataLen;
  275. UCHAR data[MAX_L2CAP_PING_DATA_LENGTH];
  276. } BTH_PING_RSP, *PBTH_PING_RSP;
  277. typedef struct _BTH_INFO_REQ {
  278. BTH_ADDR btAddr;
  279. USHORT infoType;
  280. } BTH_INFO_REQ, *PBTH_INFO_REQ;
  281. typedef struct _BTH_INFO_RSP {
  282. USHORT result;
  283. UCHAR dataLen;
  284. union {
  285. USHORT connectionlessMTU;
  286. UCHAR data[MAX_L2CAP_INFO_DATA_LENGTH];
  287. };
  288. } BTH_INFO_RSP, *PBTH_INFO_RSP;
  289. //
  290. // WinCE compatible struct names
  291. //
  292. typedef struct _BTH_SET_SERVICE BTHNS_SETBLOB, *PBTHNS_SETBLOB;
  293. typedef struct _BTH_QUERY_DEVICE BTHNS_INQUIRYBLOB, *PBTHNS_INQUIRYBLOB;
  294. typedef struct _BTH_QUERY_SERVICE BTHNS_RESTRICTIONBLOB, *PBTHNS_RESTRICTIONBLOB;
  295. #include <poppack.h>
  296. #endif // __WS2BTH__H