14 #error TnbCeBluetoothApi.h is only supported on Windows CE platforms.
24#pragma comment(lib,"bthguid.lib")
25#pragma comment(lib,"Ws2.lib")
37#define IOCTL_AG_OPEN_AUDIO 0x01
38#define IOCTL_AG_CLOSE_AUDIO 0x02
39#define IOCTL_AG_CLOSE_CONTROL 0x03
40#define IOCTL_AG_SET_SPEAKER_VOL 0x04
41#define IOCTL_AG_SET_MIC_VOL 0x05
42#define IOCTL_AG_GET_SPEAKER_VOL 0x06
43#define IOCTL_AG_GET_MIC_VOL 0x07
44#define IOCTL_AG_GET_POWER_MODE 0x08
45#define IOCTL_AG_SET_POWER_MODE 0x09
46#define IOCTL_AG_OPEN_CONTROL 0x0A
47#define IOCTL_AG_SET_USE_HF_AUDIO 0x0B
48#define IOCTL_AG_SET_INBAND_RING 0x0C
51#define BTHHID_IOCTL_HIDConnect 1
52#define BTHHID_IOCTL_HIDVerify 2
53#define BTHHID_IOCTL_HIDDisconnect 3
54#define BTHHID_IOCTL_HidSendControl 4
55#define BTHHID_IOCTL_HidSendInterrupt 5
67 static CModule s_module;
73 int BthActivatePAN(BOOL fActivate)
75 int (*P)(BOOL fActivate) = NULL;
76 P = Func(P, _T(
"BthActivatePAN"));
77 return (P == NULL) ? ERROR_FUNCTION_FAILED : P(fActivate);
81 int BthAuthenticate(
BT_ADDR* pba)
const
84 return Func(P, _T(
"BthAuthenticate"))(pba);
88 int BthAnswerPairRequest(
BT_ADDR* pba,
int cPinLength,
unsigned char *ppin)
90 int (*P)(
BT_ADDR* pba,
int cPinLength,
unsigned char *ppin) = NULL;
91 return Func(P, _T(
"BthAnswerPairRequest"))(pba, cPinLength, ppin);
95 int BthCancelInquiry(
void)
97 int (*P)(void) = NULL;
98 return Func(P, _T(
"BthCancelInquiry"))();
102 int BthClearInquiryFilter(
void)
104 int (*P)(void) = NULL;
105 return Func(P, _T(
"BthClearInquiryFilter"))();
109 int BthCloseConnection(
unsigned short handle)
111 int (*P)(
unsigned short handle) = NULL;
112 return Func(P, _T(
"BthCloseConnection"))(handle);
116 int BthCreateACLConnection(
BT_ADDR* pbt,
unsigned short* phandle)
118 int (*P)(
BT_ADDR* pbt,
unsigned short* phandle) = NULL;
119 return Func(P, _T(
"BthCreateACLConnection"))(pbt, phandle);
123 int BthCreateSCOConnection(
BT_ADDR* pbt,
unsigned short* phandle)
125 int (*P)(
BT_ADDR* pbt,
unsigned short* phandle) = NULL;
126 return Func(P, _T(
"BthCreateSCOConnection"))(pbt, phandle);
130 int BthEnterHoldMode(
BT_ADDR* pba,
unsigned short hold_mode_max,
unsigned short hold_mode_min,
unsigned short* pinterval)
132 int (*P)(
BT_ADDR* pba,
unsigned short hold_mode_max,
unsigned short hold_mode_min,
unsigned short* pinterval) = NULL;
133 return Func(P, _T(
"BthEnterHoldMode"))(pba, hold_mode_max, hold_mode_min, pinterval);
137 int BthEnterParkMode(
BT_ADDR* pba,
unsigned short beacon_max,
unsigned short beacon_min,
unsigned short* pinterval)
139 int (*P)(
BT_ADDR* pba,
unsigned short beacon_max,
unsigned short beacon_min,
unsigned short* pinterval) = NULL;
140 return Func(P, _T(
"BthEnterParkMode"))(pba, beacon_max, beacon_min, pinterval);
144 int BthEnterSniffMode(
BT_ADDR* pba,
unsigned short sniff_mode_max,
unsigned short sniff_mode_min,
unsigned short sniff_attempt,
unsigned short sniff_timeout,
unsigned short* pinterval)
146 int (*P)(
BT_ADDR* pba,
unsigned short sniff_mode_max,
unsigned short sniff_mode_min,
unsigned short sniff_attempt,
unsigned short sniff_timeout,
unsigned short* pinterval) = NULL;
147 return Func(P, _T(
"BthEnterSniffMode"))(pba, sniff_mode_max, sniff_mode_min, sniff_attempt, sniff_timeout, pinterval);
151 int BthExitParkMode(
BT_ADDR* pba)
154 return Func(P, _T(
"BthExitParkMode"))(pba);
158 int BthExitSniffMode(
BT_ADDR* pba)
161 return Func(P, _T(
"BthExitSniffMode"))(pba);
165 int BthGetAddress(
unsigned short handle,
BT_ADDR* pba)
const
167 int (*P)(
unsigned short handle,
BT_ADDR* pba) = NULL;
168 return Func(P, _T(
"BthGetAddress"))(handle, pba);
172 int BthGetBasebandConnections(
int cConnections, BASEBAND_CONNECTION* pConnections,
int* pcConnectionsReturned)
174 int (*P)(
int cConnections, BASEBAND_CONNECTION* pConnections,
int* pcConnectionsReturned) = NULL;
175 return Func(P, _T(
"BthGetBasebandConnections"))(cConnections, pConnections, pcConnectionsReturned);
179 int BthGetCurrentMode(
BT_ADDR* pba,
unsigned char* pmode)
const
181 int (*P)(
BT_ADDR* pba,
unsigned char* pmode) = NULL;
182 return Func(P, _T(
"BthGetCurrentMode"))(pba, pmode);
186 int BthGetHardwareStatus(
int* pistatus)
const
188 int (*P)(
int* pistatus) = NULL;
189 return Func(P, _T(
"BthGetHardwareStatus"))(pistatus);
193 int BthGetLinkKey(
BT_ADDR* pba,
unsigned char key[16])
const
195 int (*P)(
BT_ADDR* pba,
unsigned char key[16]) = NULL;
196 return Func(P, _T(
"BthGetLinkKey"))(pba, key);
200 int BthGetPINRequest(
BT_ADDR* pbt)
const
203 return Func(P, _T(
"BthGetPINRequest"))(pbt);
207 int BthGetRemoteCOD(
BT_ADDR* pbt,
unsigned int* pcod)
const
209 int (*P)(
BT_ADDR* pbt,
unsigned int* pcod) = NULL;
210 return Func(P, _T(
"BthGetRemoteCOD"))(pbt, pcod);
215 int BthGetRole(
BT_ADDR* pbt, USHORT* pusRole)
217 int (*P)(
BT_ADDR* pbt, USHORT* pusRole) = NULL;
218 P = Func(P, _T(
"BthGetRole"));
219 return (P == NULL) ? ERROR_FUNCTION_FAILED : P(pbt, pusRole);
223 int BthNsLookupServiceBegin(LPWSAQUERYSET pQuerySet, DWORD dwFlags, LPHANDLE lphLookup)
const
225 int (*P)(LPWSAQUERYSET pQuerySet, DWORD dwFlags, LPHANDLE lphLookup) = NULL;
226 return Func(P, _T(
"BthNsLookupServiceBegin"))(pQuerySet, dwFlags, lphLookup);
230 int BthNsLookupServiceEnd(HANDLE hLookup)
const
232 int (*P)(HANDLE hLookup) = NULL;
233 return Func(P, _T(
"BthNsLookupServiceEnd"))(hLookup);
237 int BthNsLookupServiceNext(HANDLE hLookup, DWORD dwFlags, LPDWORD lpdwBufferLength, LPWSAQUERYSET pResults)
const
239 int (*P)(HANDLE hLookup, DWORD dwFlags, LPDWORD lpdwBufferLength, LPWSAQUERYSET pResults) = NULL;
240 return Func(P, _T(
"BthNsLookupServiceNext"))(hLookup, dwFlags, lpdwBufferLength, pResults);
244 int BthNsSetService(LPWSAQUERYSET pSet, WSAESETSERVICEOP op, DWORD dwFlags)
246 int (*P)(LPWSAQUERYSET pSet, WSAESETSERVICEOP op, DWORD dwFlags) = NULL;
247 return Func(P, _T(
"BthNsSetService"))(pSet, op, dwFlags);
251 int BthPairRequest(
BT_ADDR* pba,
int cPinLength,
unsigned char *ppin)
253 int (*P)(
BT_ADDR* pba,
int cPinLength,
unsigned char *ppin) = NULL;
254 return Func(P, _T(
"BthPairRequest"))(pba, cPinLength, ppin);
258 int BthPerformInquiry(
unsigned int LAP,
unsigned char length,
unsigned char num_responses,
unsigned int cBuffer,
unsigned int* pcDiscoveredDevices, BthInquiryResult* InquiryList)
const
260 int (*P)(
unsigned int LAP,
unsigned char length,
unsigned char num_responses,
unsigned int cBuffer,
unsigned int* pcDiscoveredDevices, BthInquiryResult* InquiryList) = NULL;
261 return Func(P, _T(
"BthPerformInquiry"))(LAP, length, num_responses, cBuffer, pcDiscoveredDevices, InquiryList);
265 int BthReadAuthenticationEnable(
unsigned char* pae)
const
267 int (*P)(
unsigned char* pae) = NULL;
268 return Func(P, _T(
"BthReadAuthenticationEnable"))(pae);
272 int BthReadCOD(
unsigned int* pcod)
const
274 int (*P)(
unsigned int* pcod) = NULL;
275 return Func(P, _T(
"BthReadCOD"))(pcod);
279 int BthReadLocalAddr(
BT_ADDR* pba)
const
282 return Func(P, _T(
"BthReadLocalAddr"))(pba);
286 int BthReadPageTimeout(
unsigned short* ptimeout)
const
288 int (*P)(
unsigned short* ptimeout) = NULL;
289 return Func(P, _T(
"BthReadPageTimeout"))(ptimeout);
293 int BthReadRemoteVersion(
BT_ADDR* pba,
unsigned char* plmp_version,
unsigned short* plmp_subversion,
unsigned short* pmanufacturer,
unsigned char* plmp_features)
const
295 int (*P)(
BT_ADDR* pba,
unsigned char* plmp_version,
unsigned short* plmp_subversion,
unsigned short* pmanufacturer,
unsigned char* plmp_features) = NULL;
296 return Func(P, _T(
"BthReadRemoteVersion"))(pba, plmp_version, plmp_subversion, pmanufacturer, plmp_features);
300 int BthReadScanEnableMask(
unsigned char* pmask)
const
302 int (*P)(
unsigned char* pmask) = NULL;
303 return Func(P, _T(
"BthReadScanEnableMask"))(pmask);
307 int BthRefusePINRequest(
BT_ADDR* pbt)
310 return Func(P, _T(
"BthRefusePINRequest"))(pbt);
314 int BthRemoteNameQuery(
BT_ADDR* pba,
unsigned int cBuffer,
unsigned int* pcRequired, WCHAR* szString)
const
316 int (*P)(
BT_ADDR* pba,
unsigned int cBuffer,
unsigned int* pcRequired, WCHAR* szString) = NULL;
317 return Func(P, _T(
"BthRemoteNameQuery"))(pba, cBuffer, pcRequired, szString);
321 int BthRevokeLinkKey(
BT_ADDR* pba)
324 return Func(P, _T(
"BthRevokeLinkKey"))(pba);
331 return Func(P, _T(
"BthRevokePIN"))(pba);
335 int BthSetCODInquiryFilter (
unsigned int cod,
unsigned int codMask)
337 int (*P)(
unsigned int cod,
unsigned int codMask) = NULL;
338 return Func(P, _T(
"BthSetCODInquiryFilter"))(cod, codMask);
342 int BthSetEncryption(
BT_ADDR* pba,
int fOn)
344 int (*P)(
BT_ADDR* pba,
int fOn) = NULL;
345 return Func(P, _T(
"BthSetEncryption"))(pba, fOn);
349 int BthSetInquiryFilter(
BT_ADDR* pba)
352 return Func(P, _T(
"BthSetInquiryFilter"))(pba);
356 int BthSetLinkKey(
BT_ADDR* pba,
unsigned char key[16])
358 int (*P) (
BT_ADDR* pba,
unsigned char key[16]) = NULL;
359 return Func(P, _T(
"BthSetLinkKey"))(pba, key);
363 int BthSetPIN(
BT_ADDR* pba,
int cPinLength,
unsigned char* ppin)
365 int (*P)(
BT_ADDR* pba,
int cPinLength,
unsigned char* ppin) = NULL;
366 return Func(P, _T(
"BthSetPIN"))(pba, cPinLength, ppin);
370 int BthSetSecurityUI(HANDLE hEvent, DWORD dwStoreTimeout, DWORD dwProcTimeout)
372 int (*P)(HANDLE hEvent, DWORD dwStoreTimeout, DWORD dwProcTimeout) = NULL;
373 return Func(P, _T(
"BthSetSecurityUI"))(hEvent, dwStoreTimeout, dwProcTimeout);
378 int BthSwitchRole(
BT_ADDR* pbt, USHORT usRole)
380 int (*P)(
BT_ADDR* pbt, USHORT usRole) = NULL;
381 P = Func(P, _T(
"BthSwitchRole"));
382 return (P == NULL) ? ERROR_FUNCTION_FAILED : P(pbt, usRole);
386 int BthTerminateIdleConnections(
void)
388 int (*P)(void) = NULL;
389 return Func(P, _T(
"BthTerminateIdleConnections"))();
393 int BthWriteAuthenticationEnable(
unsigned char ae)
395 int (*P)(
unsigned char ae) = NULL;
396 return Func(P, _T(
"BthWriteAuthenticationEnable"))(ae);
400 int BthWriteCOD(
unsigned int cod)
402 int (*P)(
unsigned int cod) = NULL;
403 return Func(P, _T(
"BthWriteCOD"))(cod);
407 int BthReadLinkPolicySettings(
BT_ADDR* pba,
unsigned short* plps)
const
409 int (*P)(
BT_ADDR* pba,
unsigned short* plps) = 0;
410 return Func(P, _T(
"BthReadLinkPolicySettings"))(pba, plps);
414 int BthWriteLinkPolicySettings(
BT_ADDR* pba,
unsigned short lps)
416 int (*P)(
BT_ADDR* pba,
unsigned short lps) = 0;
417 return Func(P, _T(
"BthWriteLinkPolicySettings"))(pba, lps);
421 int BthWritePageTimeout(
unsigned short timeout)
423 int (*P)(
unsigned short timeout) = NULL;
424 return Func(P, _T(
"BthWritePageTimeout"))(timeout);
428 int BthWriteScanEnableMask(
unsigned char mask)
430 int (*P)(
unsigned char mask) = NULL;
431 return Func(P, _T(
"BthWriteScanEnableMask"))(mask);
445 int BthSetMode(DWORD mode)
447 int ret=ERROR_SUCCESS;
451 ms_BtdStartStop(
false);
453 case BTH_CONNECTABLE:
454 ms_BtdStartStop(
true);
455 BthWriteScanEnableMask(2);
457 case BTH_DISCOVERABLE:
458 ms_BtdStartStop(
true);
459 BthWriteScanEnableMask(3);
464 return ERROR_SUCCESS;
468 int BthGetMode(DWORD* pMode)
const
471 if ( BthReadScanEnableMask(&mask) != ERROR_SUCCESS )
473 *pMode = BTH_POWER_OFF;
477 if ( (mask & 0x0001) != 0 )
479 *pMode = BTH_DISCOVERABLE;
483 *pMode = BTH_CONNECTABLE;
486 return ERROR_SUCCESS;
492 template<
typename TYP>
493 TYP* Func(TYP* typ, LPCTSTR lpsz)
const
495 ForceSet(typ, ::GetProcAddress(m_module, lpsz));
496 ASSERT1( typ != NULL,
"CBluetoothApi::Func",
"[%s]が見つかwareりませんでした", lpsz );
501 bool m_Ret(
int r)
const
504 return r == ERROR_SUCCESS;
509 static bool ms_BtdStartStop(
bool isEnable)
511 HANDLE hDev = ::CreateFile (L
"BTD0:", GENERIC_READ | GENERIC_WRITE,
512 FILE_SHARE_READ | FILE_SHARE_WRITE,
513 NULL, OPEN_EXISTING, 0, NULL);
514 if ( hDev == INVALID_HANDLE_VALUE )
518 const DWORD IOCTL_SERVICE_START = CTL_CODE(FILE_DEVICE_SERVICE, 1, METHOD_BUFFERED, FILE_ANY_ACCESS);
519 const DWORD IOCTL_SERVICE_STOP = CTL_CODE(FILE_DEVICE_SERVICE, 2, METHOD_BUFFERED, FILE_ANY_ACCESS);
520 DWORD ioctl = (isEnable) ? IOCTL_SERVICE_START : IOCTL_SERVICE_STOP;
523 WCHAR* pArgPtr = L
"card";
524 ::DeviceIoControl (hDev, ioctl, pArgPtr,
sizeof(WCHAR) * (4 + 1), NULL, outSize, &outBuffer, NULL);
534 CModule(
void) : m_module(::LoadLibrary(_T(
"btdrt.dll")))
536 ASSERT( m_module != NULL );
541 if ( m_module != NULL )
543 ::FreeLibrary(m_module);
548 operator HMODULE(
void)
const
ULONGLONG BT_ADDR
Bluetooth(CE) アドレス.