BluetoothAPIs.h 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539
  1. //
  2. // Copyright 2002 - Microsoft Corporation
  3. //
  4. // Created By:
  5. // Geoff Pease (GPease) 12-JAN-2002
  6. //
  7. //////////////////////////////////////////////////////////////////////////////
  8. #pragma once
  9. #define BLUETOOTH_MAX_NAME_SIZE (248)
  10. #define BLUETOOTH_MAX_PASSKEY_SIZE (16)
  11. #define BLUETOOTH_MAX_PASSKEY_BUFFER_SIZE (BLUETOOTH_MAX_PASSKEY_SIZE + 1)
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. // ***************************************************************************
  16. //
  17. // Bluetooth Address
  18. //
  19. // ***************************************************************************
  20. typedef ULONGLONG BTH_ADDR;
  21. typedef struct _BLUETOOTH_ADDRESS {
  22. union {
  23. BTH_ADDR ullLong; // easier to compare again BLUETOOTH_NULL_ADDRESS
  24. BYTE rgBytes[ 6 ]; // easier to format when broken out
  25. };
  26. } BLUETOOTH_ADDRESS_STRUCT;
  27. #define BLUETOOTH_ADDRESS BLUETOOTH_ADDRESS_STRUCT
  28. #define BLUETOOTH_NULL_ADDRESS ( (ULONGLONG) 0x0 )
  29. // ***************************************************************************
  30. //
  31. // Radio Enumeration
  32. //
  33. // Description:
  34. // This group of APIs enumerates the installed Bluetooth radios.
  35. //
  36. // Sample Usage:
  37. // HANDLE hRadio;
  38. // BLUETOOTH_FIND_RADIO_PARAMS btfrp = { sizeof(btfrp) };
  39. //
  40. // HBLUETOOTH_RADIO_FIND hFind = BluetoothFindFirstRadio( &btfrp, &hRadio );
  41. // if ( NULL != hFind )
  42. // {
  43. // do
  44. // {
  45. // //
  46. // // TODO: Do something with the radio handle.
  47. // //
  48. //
  49. // CloseHandle( hRadio );
  50. //
  51. // } while( BluetoothFindNextRadio( hFind, &hRadio ) );
  52. //
  53. // BluetoothFindRadioClose( hFind );
  54. // }
  55. //
  56. // ***************************************************************************
  57. typedef struct _BLUETOOTH_FIND_RADIO_PARAMS {
  58. DWORD dwSize; // IN sizeof this structure
  59. } BLUETOOTH_FIND_RADIO_PARAMS;
  60. typedef HANDLE HBLUETOOTH_RADIO_FIND;
  61. //
  62. // Description:
  63. // Begins the enumeration of local Bluetooth radios.
  64. //
  65. // Parameters:
  66. // pbtfrp
  67. // A pointer to a BLUETOOTH_FIND_RADIO_PARAMS structure. The dwSize
  68. // member of this structure must match the sizeof the of the structure.
  69. //
  70. // phRadio
  71. // A pointer where the first radio HANDLE enumerated will be returned.
  72. //
  73. // Return Values:
  74. // NULL
  75. // Error opening radios or no devices found. Use GetLastError() for
  76. // more info.
  77. //
  78. // ERROR_INVALID_PARAMETER
  79. // pbtfrp parameter is NULL.
  80. //
  81. // ERROR_REVISION_MISMATCH
  82. // The pbtfrp structure is not the right length.
  83. //
  84. // ERROR_OUTOFMEMORY
  85. // Out of memory.
  86. //
  87. // other Win32 errors.
  88. //
  89. // any other
  90. // Success. The return handle is valid and phRadio points to a valid handle.
  91. //
  92. HBLUETOOTH_RADIO_FIND
  93. WINAPI
  94. BluetoothFindFirstRadio(
  95. BLUETOOTH_FIND_RADIO_PARAMS * pbtfrp,
  96. HANDLE * phRadio
  97. );
  98. //
  99. // Description:
  100. // Finds the next installed Bluetooth radio.
  101. //
  102. // Parameters:
  103. // hFind
  104. // The handle returned by BluetoothFindFirstRadio().
  105. //
  106. // phRadio
  107. // A pointer where the next radio HANDLE enumerated will be returned.
  108. //
  109. // Return Values:
  110. // TRUE
  111. // Next device succesfully found. pHandleOut points to valid handle.
  112. //
  113. // FALSE
  114. // No device found. pHandleOut points to an invalid handle. Call
  115. // GetLastError() for more details.
  116. //
  117. // ERROR_INVALID_HANDLE
  118. // The handle is NULL.
  119. //
  120. // ERROR_NO_MORE_ITEMS
  121. // No more radios found.
  122. //
  123. // ERROR_OUTOFMEMORY
  124. // Out of memory.
  125. //
  126. // other Win32 errors
  127. //
  128. BOOL
  129. WINAPI
  130. BluetoothFindNextRadio(
  131. HBLUETOOTH_RADIO_FIND hFind,
  132. HANDLE * phRadio
  133. );
  134. //
  135. // Description:
  136. // Closes the enumeration handle.
  137. //
  138. // Parameters
  139. // hFind
  140. // The handle returned by BluetoothFindFirstRadio().
  141. //
  142. // Return Values:
  143. // TRUE
  144. // Handle succesfully closed.
  145. //
  146. // FALSE
  147. // Failure. Check GetLastError() for details.
  148. //
  149. // ERROR_INVALID_HANDLE
  150. // The handle is NULL.
  151. //
  152. BOOL
  153. WINAPI
  154. BluetoothFindRadioClose(
  155. HBLUETOOTH_RADIO_FIND hFind
  156. );
  157. // ***************************************************************************
  158. //
  159. // Radio Information
  160. //
  161. // ***************************************************************************
  162. typedef struct _BLUETOOTH_RADIO_INFO {
  163. DWORD dwSize; // Size, in bytes, of this entire data structure
  164. BLUETOOTH_ADDRESS address; // Address of the local radio
  165. WCHAR szName[ BLUETOOTH_MAX_NAME_SIZE ]; // Name of the local radio
  166. ULONG ulClassofDevice; // Class of device for the local radio
  167. USHORT lmpSubversion; // lmpSubversion, manufacturer specifc.
  168. USHORT manufacturer; // Manufacturer of the radio, BTH_MFG_Xxx value. For the most up to date
  169. // list, goto the Bluetooth specification website and get the Bluetooth
  170. // assigned numbers document.
  171. } BLUETOOTH_RADIO_INFO, *PBLUETOOTH_RADIO_INFO;
  172. //
  173. // Description:
  174. // Retrieves the information about the radio represented by the handle.
  175. //
  176. // Parameters:
  177. // hRadio
  178. // Handle to a local radio retrieved through BluetoothFindFirstRadio()
  179. // et al or SetupDiEnumerateDeviceInterfaces()
  180. //
  181. // pRadioInfo
  182. // Radio information to be filled in. The dwSize member must match the
  183. // size of the structure.
  184. //
  185. // Return Values:
  186. // ERROR_SUCCESS
  187. // The information was retrieved successfully.
  188. //
  189. // ERROR_INVALID_PARAMETER
  190. // pRadioInfo or hRadio is NULL.
  191. //
  192. // ERROR_REVISION_MISMATCH
  193. // pRadioInfo->dwSize is invalid.
  194. //
  195. // other Win32 error codes.
  196. //
  197. DWORD
  198. WINAPI
  199. BluetoothGetRadioInfo(
  200. HANDLE hRadio,
  201. PBLUETOOTH_RADIO_INFO pRadioInfo
  202. );
  203. // ***************************************************************************
  204. //
  205. // Device Information Stuctures
  206. //
  207. // ***************************************************************************
  208. typedef struct _BLUETOOTH_DEVICE_INFO {
  209. DWORD dwSize; // size, in bytes, of this structure - must be the sizeof(BLUETOOTH_DEVICE_INFO)
  210. BLUETOOTH_ADDRESS Address; // Bluetooth address
  211. ULONG ulClassofDevice; // Bluetooth "Class of Device"
  212. BOOL fConnected; // Device connected/in use
  213. BOOL fRemembered; // Device remembered
  214. BOOL fAuthenticated; // Device authenticated/paired/bonded
  215. SYSTEMTIME stLastSeen; // Last time the device was seen
  216. SYSTEMTIME stLastUsed; // Last time the device was used for other than RNR, inquiry, or SDP
  217. WCHAR szName[ BLUETOOTH_MAX_NAME_SIZE ]; // Name of the device
  218. } BLUETOOTH_DEVICE_INFO_STRUCT;
  219. #define BLUETOOTH_DEVICE_INFO BLUETOOTH_DEVICE_INFO_STRUCT
  220. typedef BLUETOOTH_DEVICE_INFO * PBLUETOOTH_DEVICE_INFO;
  221. // ***************************************************************************
  222. //
  223. // Device Enumeration
  224. //
  225. // Description:
  226. // Enumerates the Bluetooth devices. The types of returned device depends
  227. // on the flags set in the BLUETOOTH_DEVICE_SEARCH_PARAMS (see structure
  228. // definition for details).
  229. //
  230. // Sample Usage:
  231. // HBLUETOOTH_DEVICE_FIND hFind;
  232. // BLUETOOTH_DEVICE_SEARCH_PARAMS btsp = { sizeof(btsp) };
  233. // BLUETOOTH_DEVICE_INFO btdi = { sizeof(btdi) };
  234. //
  235. // btsp.fReturnAuthenticated = TRUE;
  236. // btsp.fReturnRemembered = TRUE;
  237. //
  238. // hFind = BluetoothFindFirstDevice( &btsp, &btdi );
  239. // if ( NULL != hFind )
  240. // {
  241. // do
  242. // {
  243. // //
  244. // // TODO: Do something useful with the device info.
  245. // //
  246. //
  247. // } while( BluetoothFindNextDevice( hFind, &btdi ) );
  248. //
  249. // BluetoothFindDeviceClose( hFind );
  250. // }
  251. //
  252. // ***************************************************************************
  253. typedef struct _BLUETOOTH_DEVICE_SEARCH_PARAMS {
  254. DWORD dwSize; // IN sizeof this structure
  255. BOOL fReturnAuthenticated; // IN return authenticated devices
  256. BOOL fReturnRemembered; // IN return remembered devices
  257. BOOL fReturnUnknown; // IN return unknown devices
  258. BOOL fReturnConnected; // IN return connected devices
  259. BOOL fIssueInquiry; // IN issue a new inquiry
  260. UCHAR cTimeoutMultiplier; // IN timeout for the inquiry
  261. HANDLE hRadio; // IN handle to radio to enumerate - NULL == all radios will be searched
  262. } BLUETOOTH_DEVICE_SEARCH_PARAMS;
  263. typedef HANDLE HBLUETOOTH_DEVICE_FIND;
  264. //
  265. // Description:
  266. // Begins the enumeration of Bluetooth devices.
  267. //
  268. // Parameters:
  269. // pbtsp
  270. // A pointer to a BLUETOOTH_DEVICE_SEARCH_PARAMS structure. This
  271. // structure contains the flags and inputs used to conduct the search.
  272. // See BLUETOOTH_DEVICE_SEARCH_PARAMS for details.
  273. //
  274. // pbtdi
  275. // A pointer to a BLUETOOTH_DEVICE_INFO structure to return information
  276. // about the first Bluetooth device found. Note that the dwSize member
  277. // of the structure must be the sizeof(BLUETOOTH_DEVICE_INFO) before
  278. // calling because the APIs hast to know the size of the buffer being
  279. // past in. The dwSize member must also match the exact
  280. // sizeof(BLUETOOTH_DEVICE_INFO) or the call will fail.
  281. //
  282. // Return Values:
  283. // NULL
  284. // Error opening radios or not devices found. Use GetLastError for more info.
  285. //
  286. // ERROR_INVALID_PARAMETER
  287. // pbtsp parameter or pbtdi parameter is NULL.
  288. //
  289. // ERROR_REVISION_MISMATCH
  290. // The pbtfrp structure is not the right length.
  291. //
  292. // other Win32 errors
  293. //
  294. // any other value
  295. // Success. The return handle is valid and pbtdi points to valid data.
  296. //
  297. HBLUETOOTH_DEVICE_FIND
  298. WINAPI
  299. BluetoothFindFirstDevice(
  300. BLUETOOTH_DEVICE_SEARCH_PARAMS * pbtsp,
  301. BLUETOOTH_DEVICE_INFO * pbtdi
  302. );
  303. //
  304. // Description:
  305. // Finds the next Bluetooth device in the enumeration.
  306. //
  307. // Parameters:
  308. // hFind
  309. // The handle returned from BluetoothFindFirstDevice().
  310. //
  311. // pbtdi
  312. // A pointer to a BLUETOOTH_DEVICE_INFO structure to return information
  313. // about the first Bluetooth device found. Note that the dwSize member
  314. // of the structure must be the sizeof(BLUETOOTH_DEVICE_INFO) before
  315. // calling because the APIs hast to know the size of the buffer being
  316. // past in. The dwSize member must also match the exact
  317. // sizeof(BLUETOOTH_DEVICE_INFO) or the call will fail.
  318. //
  319. // Return Values:
  320. // TRUE
  321. // Next device succesfully found. pHandleOut points to valid handle.
  322. //
  323. // FALSE
  324. // No device found. pHandleOut points to an invalid handle. Call
  325. // GetLastError() for more details.
  326. //
  327. // ERROR_INVALID_HANDLE
  328. // The handle is NULL.
  329. //
  330. // ERROR_NO_MORE_ITEMS
  331. // No more radios found.
  332. //
  333. // ERROR_OUTOFMEMORY
  334. // Out of memory.
  335. //
  336. // other Win32 errors
  337. //
  338. BOOL
  339. WINAPI
  340. BluetoothFindNextDevice(
  341. HBLUETOOTH_DEVICE_FIND hFind,
  342. BLUETOOTH_DEVICE_INFO * pbtdi
  343. );
  344. //
  345. // Description:
  346. // Closes the enumeration handle.
  347. //
  348. // Parameters:
  349. // hFind
  350. // The handle returned from BluetoothFindFirstDevice().
  351. //
  352. // Return Values:
  353. // TRUE
  354. // Handle succesfully closed.
  355. //
  356. // FALSE
  357. // Failure. Check GetLastError() for details.
  358. //
  359. // ERROR_INVALID_HANDLE
  360. // The handle is NULL.
  361. //
  362. BOOL
  363. WINAPI
  364. BluetoothFindDeviceClose(
  365. HBLUETOOTH_DEVICE_FIND hFind
  366. );
  367. //
  368. // Description:
  369. // Retrieves information about a remote device.
  370. //
  371. // Fill in the dwSize and the Address members of the pbtdi structure
  372. // being passed in. On success, the rest of the members will be filled
  373. // out with the information that the system knows.
  374. //
  375. // Parameters:
  376. // hRadio
  377. // Handle to a local radio retrieved through BluetoothFindFirstRadio()
  378. // et al or SetupDiEnumerateDeviceInterfaces()
  379. //
  380. // pbtdi
  381. // A pointer to a BLUETOOTH_DEVICE_INFO structure to return information
  382. // about the first Bluetooth device found. The dwSize member of the
  383. // structure must be the sizeof the structure in bytes. The Address
  384. // member must be filled out with the Bluetooth address of the remote
  385. // device.
  386. //
  387. // Return Values:
  388. // ERROR_SUCCESS
  389. // Success. Information returned.
  390. //
  391. // ERROR_REVISION_MISMATCH
  392. // The size of the BLUETOOTH_DEVICE_INFO isn't compatible. Check
  393. // the dwSize member of the BLUETOOTH_DEVICE_INFO structure you
  394. // passed in.
  395. //
  396. // ERROR_NOT_FOUND
  397. // The radio is not known by the system or the Address field of
  398. // the BLUETOOTH_DEVICE_INFO structure is all zeros.
  399. //
  400. // ERROR_INVALID_PARAMETER
  401. // pbtdi is NULL.
  402. //
  403. // other error codes
  404. //
  405. DWORD
  406. WINAPI
  407. BluetoothGetDeviceInfo(
  408. HANDLE hRadio,
  409. BLUETOOTH_DEVICE_INFO * pbtdi
  410. );
  411. //
  412. // Description:
  413. // Updates the computer local cache about the device.
  414. //
  415. // Parameters:
  416. // pbtdi
  417. // A pointer to the BLUETOOTH_DEVICE_INFO structure to be updated.
  418. // The following members must be valid:
  419. // dwSize
  420. // Must match the size of the structure.
  421. // Address
  422. // Must be a previously found radio address.
  423. // szName
  424. // New name to be stored.
  425. //
  426. // Return Values:
  427. // ERROR_SUCCESS
  428. // The device information was updated successfully.
  429. //
  430. // ERROR_INVALID_PARAMETER
  431. // pbtdi is NULL.
  432. //
  433. // ERROR_REVISION_MISMATCH
  434. // pbtdi->dwSize is invalid.
  435. //
  436. // other Win32 error codes.
  437. //
  438. DWORD
  439. WINAPI
  440. BluetoothUpdateDeviceRecord(
  441. BLUETOOTH_DEVICE_INFO * pbtdi
  442. );
  443. //
  444. // Description:
  445. // Delete the authentication (aka "bond") between the computer and the
  446. // device. Also purges any cached information about the device.
  447. //
  448. // Return Values:
  449. // ERROR_SUCCESS
  450. // The device was removed successfully.
  451. //
  452. // ERROR_NOT_FOUND
  453. // The device was not found. If no Bluetooth radio is installed,
  454. // the devices could not be enumerated or removed.
  455. //
  456. DWORD
  457. WINAPI
  458. BluetoothRemoveDevice(
  459. BLUETOOTH_ADDRESS * pAddress
  460. );
  461. // ***************************************************************************
  462. //
  463. // Device Picker Dialog
  464. //
  465. // Description:
  466. // Invokes a common dialog for selecting Bluetooth devices. The list
  467. // of devices displayed to the user is determined by the flags and
  468. // settings the caller specifies in the BLUETOOTH_SELECT_DEVICE_PARAMS
  469. // (see structure definition for more details).
  470. //
  471. // If BluetoothSelectDevices() returns TRUE, the caller must call
  472. // BluetoothSelectDevicesFree() or memory will be leaked within the
  473. // process.
  474. //
  475. // Sample Usage:
  476. //
  477. // BLUETOOTH_SELECT_DEVICE_PARAMS btsdp = { sizeof(btsdp) };
  478. //
  479. // btsdp.hwndParent = hDlg;
  480. // btsdp.fShowUnknown = TRUE;
  481. // btsdp.fAddNewDeviceWizard = TRUE;
  482. //
  483. // BOOL b = BluetoothSelectDevices( &btsdp );
  484. // if ( b )
  485. // {
  486. // BLUETOOTH_DEVICE_INFO * pbtdi = btsdp.pDevices;
  487. // for ( ULONG cDevice = 0; cDevice < btsdp.cNumDevices; cDevice ++ )
  488. // {
  489. // if ( pbtdi->fAuthenticated || pbtdi->fRemembered )
  490. // {
  491. // //
  492. // // TODO: Do something usefull with the device info
  493. // //
  494. // }
  495. //
  496. // pbtdi = (BLUETOOTH_DEVICE_INFO *) ((LPBYTE)pbtdi + pbtdi->dwSize);
  497. // }
  498. //
  499. // BluetoothSelectDevicesFree( &btsdp );
  500. // }
  501. //
  502. // ***************************************************************************
  503. typedef struct _BLUETOOTH_COD_PAIRS {
  504. ULONG ulCODMask; // ClassOfDevice mask to compare
  505. LPCWSTR pcszDescription; // Descriptive string of mask
  506. } BLUETOOTH_COD_PAIRS;
  507. typedef BOOL (WINAPI *PFN_DEVICE_CALLBACK)(LPVOID pvParam, PBLUETOOTH_DEVICE_INFO pDevice);
  508. typedef struct _BLUETOOTH_SELECT_DEVICE_PARAMS {
  509. DWORD dwSize; // IN sizeof this structure
  510. ULONG cNumOfClasses; // IN Number in prgClassOfDevice - if ZERO search for all devices
  511. BLUETOOTH_COD_PAIRS * prgClassOfDevices; // IN Array of CODs to find.
  512. LPWSTR pszInfo; // IN If not NULL, sets the "information" text
  513. HWND hwndParent; // IN parent window - NULL == no parent
  514. BOOL fForceAuthentication; // IN If TRUE, authenication will be forced before returning
  515. BOOL fShowAuthenticated; // IN If TRUE, authenticated devices will be shown in the picker
  516. BOOL fShowRemembered; // IN If TRUE, remembered devices will be shown in the picker
  517. BOOL fShowUnknown; // IN If TRUE, unknown devices that are not authenticated or "remember" will be shown.
  518. BOOL fAddNewDeviceWizard; // IN If TRUE, invokes the add new device wizard.
  519. BOOL fSkipServicesPage; // IN If TRUE, skips the "Services" page in the wizard.
  520. PFN_DEVICE_CALLBACK pfnDeviceCallback; // IN If non-NULL, a callback that will be called for each device. If the
  521. // the callback returns TRUE, the item will be added. If the callback is
  522. // is FALSE, the item will not be shown.
  523. LPVOID pvParam; // IN Parameter to be passed to pfnDeviceCallback as the pvParam.
  524. DWORD cNumDevices; // IN number calles wants - ZERO == no limit.
  525. // OUT the number of devices returned.
  526. PBLUETOOTH_DEVICE_INFO pDevices; // OUT pointer to an array for BLUETOOTH_DEVICE_INFOs.
  527. // call BluetoothSelectDevicesFree() to free
  528. } BLUETOOTH_SELECT_DEVICE_PARAMS;
  529. //
  530. // Description:
  531. // (See header above)
  532. //
  533. // Return Values:
  534. // TRUE
  535. // User selected a device. pbtsdp->pDevices points to valid data.
  536. // Caller should check the fAuthenticated && fRemembered flags to
  537. // determine which devices we successfuly authenticated or valid
  538. // selections by the user.
  539. //
  540. // Use BluetoothSelectDevicesFree() to free the nessecary data
  541. // such as pDevices only if this function returns TRUE.
  542. //
  543. // FALSE
  544. // No valid data returned. Call GetLastError() for possible details
  545. // of the failure. If GLE() is:
  546. //
  547. // ERROR_CANCELLED
  548. // The user cancelled the request.
  549. //
  550. // ERROR_INVALID_PARAMETER
  551. // The pbtsdp is NULL.
  552. //
  553. // ERROR_REVISION_MISMATCH
  554. // The structure passed in as pbtsdp is of an unknown size.
  555. //
  556. // other WIN32 errors
  557. //
  558. BOOL
  559. WINAPI
  560. BluetoothSelectDevices(
  561. BLUETOOTH_SELECT_DEVICE_PARAMS * pbtsdp
  562. );
  563. //
  564. // Description:
  565. // This function should only be called if BluetoothSelectDevices() returns
  566. // TRUE. This function will free any memory and resource returned by the
  567. // BluetoothSelectDevices() in the BLUETOOTH_SELECT_DEVICE_PARAMS
  568. // structure.
  569. //
  570. // Return Values:
  571. // TRUE
  572. // Success.
  573. //
  574. // FALSE
  575. // Nothing to free.
  576. //
  577. BOOL
  578. WINAPI
  579. BluetoothSelectDevicesFree(
  580. BLUETOOTH_SELECT_DEVICE_PARAMS * pbtsdp
  581. );
  582. // ***************************************************************************
  583. //
  584. // Device Property Sheet
  585. //
  586. // ***************************************************************************
  587. //
  588. // Description:
  589. // Invokes the CPLs device info property sheet.
  590. //
  591. // Parameters:
  592. // hwndParent
  593. // HWND to parent the property sheet.
  594. //
  595. // pbtdi
  596. // A pointer to a BLUETOOTH_DEVICE_INFO structure of the device
  597. // to be displayed.
  598. //
  599. // Return Values:
  600. // TRUE
  601. // The property page was successfully displayed.
  602. //
  603. // FALSE
  604. // Failure. The property page was not displayed. Check GetLastError
  605. // for more details.
  606. //
  607. BOOL
  608. WINAPI
  609. BluetoothDisplayDeviceProperties(
  610. HWND hwndParent,
  611. BLUETOOTH_DEVICE_INFO * pbtdi
  612. );
  613. // ***************************************************************************
  614. //
  615. // Radio Authentication
  616. //
  617. // ***************************************************************************
  618. //
  619. // Description:
  620. // Sends an authentication request to a remote device.
  621. //
  622. // There are two modes of operation. "Wizard mode" and "Blind mode."
  623. //
  624. // "Wizard mode" is invoked when the pszPasskey is NULL. This will cause
  625. // the "Bluetooth Connection Wizard" to be invoked. The user will be
  626. // prompted to enter a passkey during the wizard after which the
  627. // authentication request will be sent. The user will see the success
  628. // or failure of the authentication attempt. The user will also be
  629. // given the oppurtunity to try to fix a failed authentication.
  630. //
  631. // "Blind mode" is invoked when the pszPasskey is non-NULL. This will
  632. // cause the computer to send a authentication request to the remote
  633. // device. No UI is ever displayed. The Bluetooth status code will be
  634. // mapped to a Win32 Error code.
  635. //
  636. // Parameters:
  637. //
  638. // hwndParent
  639. // The window to parent the authentication wizard. If NULL, the
  640. // wizard will be parented off the desktop.
  641. //
  642. // hRadio
  643. // A valid local radio handle or NULL. If NULL, then all radios will
  644. // be tired. If any of the radios succeed, then the call will
  645. // succeed.
  646. //
  647. // pbtdi
  648. // BLUETOOTH_DEVICE_INFO record of the device to be authenticated.
  649. //
  650. // pszPasskey
  651. // PIN to be used to authenticate the device. If NULL, then UI is
  652. // displayed and the user steps through the authentication process.
  653. // If not NULL, no UI is shown. The passkey is NOT NULL terminated.
  654. //
  655. // ulPasskeyLength
  656. // Length of szPassKey in bytes. The length must be less than or
  657. // equal to BLUETOOTH_MAX_PASSKEY_SIZE * sizeof(WCHAR).
  658. //
  659. // Return Values:
  660. //
  661. // ERROR_SUCCESS
  662. // Success.
  663. //
  664. // ERROR_CANCELLED
  665. // User aborted the operation.
  666. //
  667. // ERROR_INVALID_PARAMETER
  668. // The device structure in pbtdi is invalid.
  669. //
  670. // ERROR_NO_MORE_ITEMS
  671. // The device in pbtdi is already been marked as authenticated.
  672. //
  673. // other WIN32 error
  674. // Failure. Return value is the error code.
  675. //
  676. // For "Blind mode," here is the current mapping of Bluetooth status
  677. // code to Win32 error codes:
  678. //
  679. // { BTH_ERROR_SUCCESS, ERROR_SUCCESS },
  680. // { BTH_ERROR_NO_CONNECTION, ERROR_DEVICE_NOT_CONNECTED },
  681. // { BTH_ERROR_PAGE_TIMEOUT, WAIT_TIMEOUT },
  682. // { BTH_ERROR_HARDWARE_FAILURE, ERROR_GEN_FAILURE },
  683. // { BTH_ERROR_AUTHENTICATION_FAILURE, ERROR_NOT_AUTHENTICATED },
  684. // { BTH_ERROR_MEMORY_FULL, ERROR_NOT_ENOUGH_MEMORY },
  685. // { BTH_ERROR_CONNECTION_TIMEOUT, WAIT_TIMEOUT },
  686. // { BTH_ERROR_LMP_RESPONSE_TIMEOUT, WAIT_TIMEOUT },
  687. // { BTH_ERROR_MAX_NUMBER_OF_CONNECTIONS, ERROR_REQ_NOT_ACCEP },
  688. // { BTH_ERROR_PAIRING_NOT_ALLOWED, ERROR_ACCESS_DENIED },
  689. // { BTH_ERROR_UNSPECIFIED_ERROR, ERROR_NOT_READY },
  690. // { BTH_ERROR_LOCAL_HOST_TERMINATED_CONNECTION, ERROR_VC_DISCONNECTED },
  691. //
  692. DWORD
  693. WINAPI
  694. BluetoothAuthenticateDevice(
  695. HWND hwndParent,
  696. HANDLE hRadio,
  697. BLUETOOTH_DEVICE_INFO * pbtbi,
  698. PWCHAR pszPasskey,
  699. ULONG ulPasskeyLength
  700. );
  701. //
  702. // Description:
  703. // Allows the caller to prompt for multiple devices to be authenticated
  704. // within a single instance of the "Bluetooth Connection Wizard."
  705. //
  706. // Parameters:
  707. //
  708. // hwndParent
  709. // The window to parent the authentication wizard. If NULL, the
  710. // wizard will be parented off the desktop.
  711. //
  712. // hRadio
  713. // A valid local radio handle or NULL. If NULL, then all radios will
  714. // be tired. If any of the radios succeed, then the call will
  715. // succeed.
  716. //
  717. // cDevices
  718. // Number of devices in the rgbtdi array.
  719. //
  720. // rgbtdi
  721. // An array BLUETOOTH_DEVICE_INFO records of the devices to be
  722. // authenticated.
  723. //
  724. // Return Values:
  725. //
  726. // ERROR_SUCCESS
  727. // Success. Check the fAuthenticate flag on each of the devices.
  728. //
  729. // ERROR_CANCELLED
  730. // User aborted the operation. Check the fAuthenticate flags on
  731. // each device to determine if any of the devices were authenticated
  732. // before the user cancelled the operation.
  733. //
  734. // ERROR_INVALID_PARAMETER
  735. // One of the items in the array of devices is invalid.
  736. //
  737. // ERROR_NO_MORE_ITEMS
  738. // All the devices in the array of devices are already been marked as
  739. // being authenticated.
  740. //
  741. // other WIN32 error
  742. // Failure. Return value is the error code.
  743. //
  744. DWORD
  745. WINAPI
  746. BluetoothAuthenticateMultipleDevices(
  747. HWND hwndParent,
  748. HANDLE hRadio,
  749. DWORD cDevices,
  750. BLUETOOTH_DEVICE_INFO * pbtdi
  751. );
  752. // ***************************************************************************
  753. //
  754. // Bluetooth Services
  755. //
  756. // ***************************************************************************
  757. #define BLUETOOTH_SERVICE_DISABLE 0x00
  758. #define BLUETOOTH_SERVICE_ENABLE 0x01
  759. #define BLUETOOTH_SERVICE_MASK ( BLUETOOTH_ENABLE_SERVICE | BLUETOOTH_DISABLE_SERVICE )
  760. //
  761. // Description:
  762. // Enables/disables the services for a particular device.
  763. //
  764. // The system maintains a mapping of service guids to supported drivers for
  765. // Bluetooth-enabled devices. Enabling a service installs the corresponding
  766. // device driver. Disabling a service removes the corresponding device driver.
  767. //
  768. // If a non-supported service is enabled, a driver will not be installed.
  769. //
  770. // Parameters
  771. // hRadio
  772. // Handle of the local Bluetooth radio device.
  773. //
  774. // pbtdi
  775. // Pointer to a BLUETOOTH_DEVICE_INFO record.
  776. //
  777. // pGuidService
  778. // The service GUID on the remote device.
  779. //
  780. // dwServiceFlags
  781. // Flags to adjust the service.
  782. // BLUETOOTH_SERVICE_DISABLE - disable the service
  783. // BLUETOOTH_SERVICE_ENABLE - enables the service
  784. //
  785. // Return Values:
  786. // ERROR_SUCCESS
  787. // The call was successful.
  788. //
  789. // ERROR_INVALID_PARAMETER
  790. // dwServiceFlags are invalid.
  791. //
  792. // ERROR_SERVICE_DOES_NOT_EXIST
  793. // The GUID in pGuidService is not supported.
  794. //
  795. // other WIN32 error
  796. // The call failed.
  797. //
  798. DWORD
  799. WINAPI
  800. BluetoothSetServiceState(
  801. HANDLE hRadio,
  802. BLUETOOTH_DEVICE_INFO * pbtdi,
  803. GUID * pGuidService,
  804. DWORD dwServiceFlags
  805. );
  806. //
  807. // Description:
  808. // Enumerates the services guids enabled on a particular device. If hRadio
  809. // is NULL, all device will be searched for the device and all the services
  810. // enabled will be returned.
  811. //
  812. // Parameters:
  813. // hRadio
  814. // Handle of the local Bluetooth radio device. If NULL, it will search
  815. // all the radios for the address in the pbtdi.
  816. //
  817. // pbtdi
  818. // Pointer to a BLUETOOTH_DEVICE_INFO record.
  819. //
  820. // pcService
  821. // On input, the number of records pointed to by pGuidServices.
  822. // On output, the number of valid records return in pGuidServices.
  823. //
  824. // pGuidServices
  825. // Pointer to memory that is at least *pcService in length.
  826. //
  827. // Return Values:
  828. // ERROR_SUCCESS
  829. // The call succeeded. pGuidServices is valid.
  830. //
  831. // ERROR_MORE_DATA
  832. // The call succeeded. pGuidService contains an incomplete list of
  833. // enabled service GUIDs.
  834. //
  835. // other WIN32 errors
  836. // The call failed.
  837. //
  838. DWORD
  839. WINAPI
  840. BluetoothEnumerateInstalledServices(
  841. HANDLE hRadio,
  842. BLUETOOTH_DEVICE_INFO * pbtdi,
  843. DWORD * pcServices,
  844. GUID * pGuidServices
  845. );
  846. //
  847. // Description:
  848. // Change the discovery state of the local radio(s).
  849. // If hRadio is NULL, all the radios will be set.
  850. //
  851. // Use BluetoothIsDiscoverable() to determine the radios current state.
  852. //
  853. // The system ensures that a discoverable system is connectable, thus
  854. // the radio must allow incoming connections (see
  855. // BluetoothEnableIncomingConnections) prior to making a radio
  856. // discoverable. Failure to do so will result in this call failing
  857. // (returns FALSE).
  858. //
  859. // Parameters:
  860. // hRadio
  861. // If not NULL, changes the state of a specific radio.
  862. // If NULL, the API will interate through all the radios.
  863. //
  864. // fEnabled
  865. // If FALSE, discovery will be disabled.
  866. //
  867. // Return Values
  868. // TRUE
  869. // State was successfully changed. If the caller specified NULL for
  870. // hRadio, at least of the radios accepted the state change.
  871. //
  872. // FALSE
  873. // State was not changed. If the caller specified NULL for hRadio, all
  874. // of the radios did not accept the state change.
  875. //
  876. BOOL
  877. WINAPI
  878. BluetoothEnableDiscovery(
  879. HANDLE hRadio,
  880. BOOL fEnabled
  881. );
  882. //
  883. // Description:
  884. // Determines if the Bluetooth radios are discoverable. If there are
  885. // multiple radios, the first one to say it is discoverable will cause
  886. // this function to return TRUE.
  887. //
  888. // Parameters:
  889. // hRadio
  890. // Handle of the radio to check. If NULL, it will check all local
  891. // radios.
  892. //
  893. // Return Values:
  894. // TRUE
  895. // A least one radio is discoverable.
  896. //
  897. // FALSE
  898. // No radios are discoverable.
  899. //
  900. BOOL
  901. WINAPI
  902. BluetoothIsDiscoverable(
  903. HANDLE hRadio
  904. );
  905. //
  906. // Description:
  907. // Enables/disables the state of a radio to accept incoming connections.
  908. // If hRadio is NULL, all the radios will be set.
  909. //
  910. // Use BluetoothIsConnectable() to determine the radios current state.
  911. //
  912. // The system enforces that a radio that is not connectable is not
  913. // discoverable too. The radio must be made non-discoverable (see
  914. // BluetoothEnableDiscovery) prior to making a radio non-connectionable.
  915. // Failure to do so will result in this call failing (returns FALSE).
  916. //
  917. // Parameters:
  918. // hRadio
  919. // If not NULL, changes the state of a specific radio.
  920. // If NULL, the API will interate through all the radios.
  921. //
  922. // fEnabled
  923. // If FALSE, incoming connection will be disabled.
  924. //
  925. // Return Values
  926. // TRUE
  927. // State was successfully changed. If the caller specified NULL for
  928. // hRadio, at least of the radios accepted the state change.
  929. //
  930. // FALSE
  931. // State was not changed. If the caller specified NULL for hRadio, all
  932. // of the radios did not accept the state change.
  933. //
  934. BOOL
  935. WINAPI
  936. BluetoothEnableIncomingConnections(
  937. HANDLE hRadio,
  938. BOOL fEnabled
  939. );
  940. //
  941. // Description:
  942. // Determines if the Bluetooth radios are connectable. If there are
  943. // multiple radios, the first one to say it is connectable will cause
  944. // this function to return TRUE.
  945. //
  946. // Parameters:
  947. // hRadio
  948. // Handle of the radio to check. If NULL, it will check all local
  949. // radios.
  950. //
  951. // Return Values:
  952. // TRUE
  953. // A least one radio is allowing incoming connections.
  954. //
  955. // FALSE
  956. // No radios are allowing incoming connections.
  957. //
  958. BOOL
  959. WINAPI
  960. BluetoothIsConnectable(
  961. HANDLE hRadio
  962. );
  963. // ***************************************************************************
  964. //
  965. // Authentication Registration
  966. //
  967. // ***************************************************************************
  968. typedef HANDLE HBLUETOOTH_AUTHENTICATION_REGISTRATION;
  969. typedef BOOL (*PFN_AUTHENTICATION_CALLBACK)(LPVOID pvParam, PBLUETOOTH_DEVICE_INFO pDevice);
  970. //
  971. // Description:
  972. // Registers a callback function to be called when a particular device
  973. // requests authentication. The request is sent to the last application
  974. // that requested authentication for a particular device.
  975. //
  976. // Parameters:
  977. // pbtdi
  978. // A pointer to a BLUETOOTH_DEVICE_INFO structure. The Bluetooth
  979. // address will be used for comparision.
  980. //
  981. // phRegHandle
  982. // A pointer to where the registration HANDLE value will be
  983. // stored. Call BluetoothUnregisterAuthentication() to close
  984. // the handle.
  985. //
  986. // pfnCallback
  987. // The function that will be called when the authentication event
  988. // occurs. This function should match PFN_AUTHENTICATION_CALLBACK's
  989. // prototype.
  990. //
  991. // pvParam
  992. // Optional parameter to be past through to the callback function.
  993. // This can be anything the application was to define.
  994. //
  995. // Return Values:
  996. // ERROR_SUCCESS
  997. // Success. A valid registration handle was returned.
  998. //
  999. // ERROR_OUTOFMEMORY
  1000. // Out of memory.
  1001. //
  1002. // other Win32 error.
  1003. // Failure. The registration handle is invalid.
  1004. //
  1005. DWORD
  1006. WINAPI
  1007. BluetoothRegisterForAuthentication(
  1008. BLUETOOTH_DEVICE_INFO * pbtdi,
  1009. HBLUETOOTH_AUTHENTICATION_REGISTRATION * phRegHandle,
  1010. PFN_AUTHENTICATION_CALLBACK pfnCallback,
  1011. PVOID pvParam
  1012. );
  1013. //
  1014. // Description:
  1015. // Unregisters an authentication callback and closes the handle. See
  1016. // BluetoothRegisterForAuthentication() for more information about
  1017. // authentication registration.
  1018. //
  1019. // Parameters:
  1020. // hRegHandle
  1021. // Handle returned by BluetoothRegisterForAuthentication().
  1022. //
  1023. // Return Value:
  1024. // TRUE
  1025. // The handle was successfully closed.
  1026. //
  1027. // FALSE
  1028. // The handle was not successfully closed. Check GetLastError for
  1029. // more details.
  1030. //
  1031. // ERROR_INVALID_HANDLE
  1032. // The handle is NULL.
  1033. //
  1034. // other Win32 errors.
  1035. //
  1036. BOOL
  1037. WINAPI
  1038. BluetoothUnregisterAuthentication(
  1039. HBLUETOOTH_AUTHENTICATION_REGISTRATION hRegHandle
  1040. );
  1041. //
  1042. // Description:
  1043. // This function should be called after receiving an authentication request
  1044. // to send the passkey response.
  1045. //
  1046. // Parameters:
  1047. //
  1048. // hRadio
  1049. // Optional handle to the local radio. If NULL, the function will try
  1050. // each radio until one succeeds.
  1051. //
  1052. // pbtdi
  1053. // A pointer to a BLUETOOTH_DEVICE_INFO structure describing the device
  1054. // being authenticated. This can be the same structure passed to the
  1055. // callback function.
  1056. //
  1057. // pszPasskey
  1058. // A pointer to UNICODE zero-terminated string of the passkey response
  1059. // that should be sent back to the authenticating device.
  1060. //
  1061. // Return Values:
  1062. // ERROR_SUCESS
  1063. // The device accepted the passkey response. The device is authenticated.
  1064. //
  1065. // ERROR_CANCELED
  1066. // The device denied the passkey reponse. This also will returned if there
  1067. // is a communications problem with the local radio.
  1068. //
  1069. // E_FAIL
  1070. // The device returned a failure code during authentication.
  1071. //
  1072. // other Win32 error codes
  1073. //
  1074. DWORD
  1075. WINAPI
  1076. BluetoothSendAuthenticationResponse(
  1077. HANDLE hRadio,
  1078. BLUETOOTH_DEVICE_INFO * pbtdi,
  1079. LPWSTR pszPasskey
  1080. );
  1081. // ***************************************************************************
  1082. //
  1083. // SDP Parsing Functions
  1084. //
  1085. // ***************************************************************************
  1086. typedef struct _SDP_ELEMENT_DATA {
  1087. //
  1088. // Enumeration of SDP element types. Generic element types will have a
  1089. // specificType value other then SDP_ST_NONE. The generic types are:
  1090. // o SDP_TYPE_UINT
  1091. // o SDP_TYPE_INT
  1092. // o SDP_TYPE_UUID
  1093. //
  1094. SDP_TYPE type;
  1095. //
  1096. // Specific types for the generic SDP element types.
  1097. //
  1098. SDP_SPECIFICTYPE specificType;
  1099. //
  1100. // Union of all possible data types. type and specificType will indicate
  1101. // which field is valid. For types which do not have a valid specificType,
  1102. // specific type will be SDP_ST_NONE.
  1103. //
  1104. union {
  1105. // type == SDP_TYPE_INT
  1106. SDP_LARGE_INTEGER_16 int128; // specificType == SDP_ST_INT128
  1107. LONGLONG int64; // specificType == SDP_ST_INT64
  1108. LONG int32; // specificType == SDP_ST_INT32
  1109. SHORT int16; // specificType == SDP_ST_INT16
  1110. CHAR int8; // specificType == SDP_ST_INT8
  1111. // type == SDP_TYPE_UINT
  1112. SDP_ULARGE_INTEGER_16 uint128; // specificType == SDP_ST_UINT128
  1113. ULONGLONG uint64; // specificType == SDP_ST_UINT64
  1114. ULONG uint32; // specificType == SDP_ST_UINT32
  1115. USHORT uint16; // specificType == SDP_ST_UINT16
  1116. UCHAR uint8; // specificType == SDP_ST_UINT8
  1117. // type == SDP_TYPE_BOOLEAN
  1118. UCHAR booleanVal;
  1119. // type == SDP_TYPE_UUID
  1120. GUID uuid128; // specificType == SDP_ST_UUID128
  1121. ULONG uuid32; // specificType == SDP_ST_UUID32
  1122. USHORT uuid16; // specificType == SDP_ST_UUID32
  1123. // type == SDP_TYPE_STRING
  1124. struct {
  1125. // raw string buffer, may not be encoded as ANSI, use
  1126. // BluetoothSdpGetString to convert the value if it is described
  1127. // by the base language attribute ID list
  1128. LPBYTE value;
  1129. // raw length of the string, may not be NULL terminuated
  1130. ULONG length;
  1131. } string;
  1132. // type == SDP_TYPE_URL
  1133. struct {
  1134. LPBYTE value;
  1135. ULONG length;
  1136. } url;
  1137. // type == SDP_TYPE_SEQUENCE
  1138. struct {
  1139. // raw sequence, starts at sequence element header
  1140. LPBYTE value;
  1141. // raw sequence length
  1142. ULONG length;
  1143. } sequence;
  1144. // type == SDP_TYPE_ALTERNATIVE
  1145. struct {
  1146. // raw alternative, starts at alternative element header
  1147. LPBYTE value;
  1148. // raw alternative length
  1149. ULONG length;
  1150. } alternative;
  1151. } data;
  1152. } SDP_ELEMENT_DATA, *PSDP_ELEMENT_DATA;
  1153. //
  1154. // Description:
  1155. // Retrieves and parses the element found at pSdpStream
  1156. //
  1157. // Parameters:
  1158. // IN pSdpStream
  1159. // pointer to valid SDP stream
  1160. //
  1161. // IN cbSdpStreamLength
  1162. // length of pSdpStream in bytes
  1163. //
  1164. // OUT pData
  1165. // pointer to be filled in with the data of the SDP element at the
  1166. // beginning of pSdpStream
  1167. //
  1168. // Return Values:
  1169. // ERROR_INVALID_PARAMETER
  1170. // one of required parameters is NULL or the pSdpStream is invalid
  1171. //
  1172. // ERROR_SUCCESS
  1173. // the sdp element was parsed correctly
  1174. //
  1175. DWORD
  1176. WINAPI
  1177. BluetoothSdpGetElementData(
  1178. LPBYTE pSdpStream,
  1179. ULONG cbSdpStreamLength,
  1180. PSDP_ELEMENT_DATA pData
  1181. );
  1182. typedef HANDLE HBLUETOOTH_CONTAINER_ELEMENT;
  1183. //
  1184. // Description:
  1185. // Iterates over a container stream, returning each elemetn contained with
  1186. // in the container element at the beginning of pContainerStream
  1187. //
  1188. // Parameters:
  1189. // IN pContainerStream
  1190. // pointer to valid SDP stream whose first element is either a sequence
  1191. // or alternative
  1192. //
  1193. // IN cbContainerlength
  1194. // length in bytes of pContainerStream
  1195. //
  1196. // IN OUT pElement
  1197. // Value used to keep track of location within the stream. The first
  1198. // time this function is called for a particular container, *pElement
  1199. // should equal NULL. Upon subsequent calls, the value should be
  1200. // unmodified.
  1201. //
  1202. // OUT pData
  1203. // pointer to be filled in with the data of the SDP element at the
  1204. // current element of pContainerStream
  1205. //
  1206. // Return Values:
  1207. // ERROR_SUCCESS
  1208. // The call succeeded, pData contains the data
  1209. //
  1210. // ERROR_NO_MORE_ITEMS
  1211. // There are no more items in the list, the caller should cease calling
  1212. // BluetoothSdpGetContainerElementData for this container.
  1213. //
  1214. // ERROR_INVALID_PARAMETER
  1215. // A required pointer is NULL or the container is not a valid SDP
  1216. // stream
  1217. //
  1218. // Usage example:
  1219. //
  1220. // HBLUETOOTH_CONTAINER_ELEMENT element;
  1221. // SDP_ELEMENT_DATA data;
  1222. // ULONG result;
  1223. //
  1224. // element = NULL;
  1225. //
  1226. // while (TRUE) {
  1227. // result = BluetoothSdpGetContainerElementData(
  1228. // pContainer, ulContainerLength, &element, &data);
  1229. //
  1230. // if (result == ERROR_NO_MORE_ITEMS) {
  1231. // // We are done
  1232. // break;
  1233. // }
  1234. // else if (result != ERROR_SUCCESS) {
  1235. // // error
  1236. // }
  1237. //
  1238. // // do something with data ...
  1239. // }
  1240. //
  1241. //
  1242. DWORD
  1243. WINAPI
  1244. BluetoothSdpGetContainerElementData(
  1245. LPBYTE pContainerStream,
  1246. ULONG cbContainerLength,
  1247. HBLUETOOTH_CONTAINER_ELEMENT* pElement,
  1248. PSDP_ELEMENT_DATA pData
  1249. );
  1250. //
  1251. // Description:
  1252. // Retrieves the attribute value for the given attribute ID. pRecordStream
  1253. // must be an SDP stream that is formatted as an SDP record, a SEQUENCE
  1254. // containing UINT16 + element pairs.
  1255. //
  1256. // Parameters:
  1257. // IN pRecordStream
  1258. // pointer to a valid SDP stream which is formatted as a singl SDP
  1259. // record
  1260. //
  1261. // IN cbRecordlnegh
  1262. // length of pRecordStream in bytes
  1263. //
  1264. // IN usAttributeId
  1265. // the attribute ID to search for. see bthdef.h for SDP_ATTRIB_Xxx
  1266. // values.
  1267. //
  1268. // OUT pAttributeData
  1269. // pointer that will contain the attribute ID's value
  1270. //
  1271. // Return Values:
  1272. // ERRROR_SUCCESS
  1273. // Call succeeded, pAttributeData contains the attribute value
  1274. //
  1275. // ERROR_INVALID_PARAMETER
  1276. // One of the required pointers was NULL, pRecordStream was not a valid
  1277. // SDP stream, or pRecordStream was not a properly formatted SDP record
  1278. //
  1279. // ERROR_FILE_NOT_FOUND
  1280. // usAttributeId was not found in the record
  1281. //
  1282. // Usage:
  1283. //
  1284. // ULONG result;
  1285. // SDP_DATA_ELEMENT data;
  1286. //
  1287. // result = BluetoothSdpGetAttributeValue(
  1288. // pRecordStream, cbRecordLength, SDP_ATTRIB_RECORD_HANDLE, &data);
  1289. // if (result == ERROR_SUCCESS) {
  1290. // printf("record handle is 0x%x\n", data.data.uint32);
  1291. // }
  1292. //
  1293. DWORD
  1294. WINAPI
  1295. BluetoothSdpGetAttributeValue(
  1296. LPBYTE pRecordStream,
  1297. ULONG cbRecordLength,
  1298. USHORT usAttributeId,
  1299. PSDP_ELEMENT_DATA pAttributeData
  1300. );
  1301. //
  1302. // These three fields correspond one to one with the triplets defined in the
  1303. // SDP specification for the language base attribute ID list.
  1304. //
  1305. typedef struct _SDP_STRING_TYPE_DATA {
  1306. //
  1307. // How the string is encoded according to ISO 639:1988 (E/F): "Code
  1308. // for the representation of names of languages".
  1309. //
  1310. USHORT encoding;
  1311. //
  1312. // MIBE number from IANA database
  1313. //
  1314. USHORT mibeNum;
  1315. //
  1316. // The base attribute where the string is to be found in the record
  1317. //
  1318. USHORT attributeId;
  1319. } SDP_STRING_TYPE_DATA, *PSDP_STRING_TYPE_DATA;
  1320. //
  1321. // Description:
  1322. // Converts a raw string embedded in the SDP record into a UNICODE string
  1323. //
  1324. // Parameters:
  1325. // IN pRecordStream
  1326. // a valid SDP stream which is formatted as an SDP record
  1327. //
  1328. // IN cbRecordLength
  1329. // length of pRecordStream in bytes
  1330. //
  1331. // IN pStringData
  1332. // if NULL, then the calling thread's locale will be used to search
  1333. // for a matching string in the SDP record. If not NUL, the mibeNum
  1334. // and attributeId will be used to find the string to convert.
  1335. //
  1336. // IN usStringOffset
  1337. // the SDP string type offset to convert. usStringOffset is added to
  1338. // the base attribute id of the string. SDP specification defined
  1339. // offsets are: STRING_NAME_OFFSET, STRING_DESCRIPTION_OFFSET, and
  1340. // STRING_PROVIDER_NAME_OFFSET (found in bthdef.h).
  1341. //
  1342. // OUT pszString
  1343. // if NULL, pcchStringLength will be filled in with the required number
  1344. // of characters (not bytes) to retrieve the converted string.
  1345. //
  1346. // IN OUT pcchStringLength
  1347. // Upon input, if pszString is not NULL, will contain the length of
  1348. // pszString in characters. Upon output, it will contain either the
  1349. // number of required characters including NULL if an error is returned
  1350. // or the number of characters written to pszString (including NULL).
  1351. //
  1352. // Return Values:
  1353. // ERROR_SUCCES
  1354. // Call was successful and pszString contains the converted string
  1355. //
  1356. // ERROR_MORE_DATA
  1357. // pszString was NULL or too small to contain the converted string,
  1358. // pccxhStringLength contains the required length in characters
  1359. //
  1360. // ERROR_INVALID_DATA
  1361. // Could not perform the conversion
  1362. //
  1363. // ERROR_NO_SYSTEM_RESOURCES
  1364. // Could not allocate memory internally to perform the conversion
  1365. //
  1366. // ERROR_INVALID_PARAMETER
  1367. // One of the rquired pointers was NULL, pRecordStream was not a valid
  1368. // SDP stream, pRecordStream was not a properly formatted record, or
  1369. // the desired attribute + offset was not a string.
  1370. //
  1371. // Other HRESULTs returned by COM
  1372. //
  1373. DWORD
  1374. WINAPI
  1375. BluetoothSdpGetString(
  1376. LPBYTE pRecordStream,
  1377. ULONG cbRecordLength,
  1378. PSDP_STRING_TYPE_DATA pStringData,
  1379. USHORT usStringOffset,
  1380. PWCHAR pszString,
  1381. PULONG pcchStringLength
  1382. );
  1383. // ***************************************************************************
  1384. //
  1385. // Raw Attribute Enumeration
  1386. //
  1387. // ***************************************************************************
  1388. typedef BOOL (CALLBACK *PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK)(
  1389. ULONG uAttribId,
  1390. LPBYTE pValueStream,
  1391. ULONG cbStreamSize,
  1392. LPVOID pvParam
  1393. );
  1394. //
  1395. // Description:
  1396. // Enumerates through the SDP record stream calling the Callback function
  1397. // for each attribute in the record. If the Callback function returns
  1398. // FALSE, the enumeration is stopped.
  1399. //
  1400. // Return Values:
  1401. // TRUE
  1402. // Success! Something was enumerated.
  1403. //
  1404. // FALSE
  1405. // Failure. GetLastError() could be one of the following:
  1406. //
  1407. // ERROR_INVALID_PARAMETER
  1408. // pSDPStream or pfnCallback is NULL.
  1409. //
  1410. // ERROR_INVALID_DATA
  1411. // The SDP stream is corrupt.
  1412. //
  1413. // other Win32 errors.
  1414. //
  1415. #define BluetoothEnumAttributes BluetoothSdpEnumAttributes
  1416. BOOL
  1417. WINAPI
  1418. BluetoothSdpEnumAttributes(
  1419. LPBYTE pSDPStream,
  1420. ULONG cbStreamSize,
  1421. PFN_BLUETOOTH_ENUM_ATTRIBUTES_CALLBACK pfnCallback,
  1422. LPVOID pvParam
  1423. );
  1424. #ifdef __cplusplus
  1425. }
  1426. #endif