34typedef ULONGLONG BT_ADDR;
46 #define BT_HANDLE unsigned short
107 ASSERT( index < 16 );
180 operator DWORD(
void)
const
200 return m_class.serviceClass;
209 m_class.serviceClass = c;
218 return m_class.majorDeviceClass;
227 m_class.majorDeviceClass = c;
239 case Computer:
return _T(
"Computer");
240 case Phone:
return _T(
"Phone");
241 case Network:
return _T(
"Network");
242 case AV:
return _T(
"Audio/Video");
244 case Imaging:
return _T(
"Imaging");
255 return m_class.minorDeviceClass;
264 m_class.minorDeviceClass = c;
275 case Computer:
return m_ComputerDeviceClassName();
276 case Phone:
return m_PhoneDeviceClassName();
277 case AV:
return m_AvDeviceClassName();
278 case Peripheral:
return m_PeripheralDeviceClassName();
279 case Imaging:
return m_ImagingDeviceClassName();
289 LPCTSTR m_ComputerDeviceClassName(
void)
const
294 case 0:
return _T(
"Unclassified");
295 case 1:
return _T(
"Desktop Computer");
296 case 2:
return _T(
"Server Computer");
297 case 3:
return _T(
"Laptop Computer");
298 case 4:
return _T(
"Handled Computer");
299 case 5:
return _T(
"Palm Computer");
300 case 6:
return _T(
"Wearable Computer");
308 LPCTSTR m_PhoneDeviceClassName(
void)
const
313 case 0:
return _T(
"Unclassified");
314 case 1:
return _T(
"Cellular Phone");
315 case 2:
return _T(
"Cordless Phone");
316 case 3:
return _T(
"Smartphone");
317 case 4:
return _T(
"Modem");
318 case 5:
return _T(
"ISDN Phone");
326 LPCTSTR m_AvDeviceClassName(
void)
const
331 case 0:
return _T(
"Unclassified");
332 case 1:
return _T(
"Headset");
333 case 2:
return _T(
"Handsfree");
334 case 4:
return _T(
"Microphone");
335 case 5:
return _T(
"Loudspeaker");
336 case 6:
return _T(
"Headphone");
337 case 7:
return _T(
"Portable Audio");
338 case 8:
return _T(
"Car Audio");
339 case 9:
return _T(
"Set Top Box");
340 case 10:
return _T(
"Hifi Audio");
341 case 11:
return _T(
"VCR");
342 case 12:
return _T(
"Video Camera");
343 case 13:
return _T(
"Camcoder");
344 case 14:
return _T(
"Video Monitor");
345 case 15:
return _T(
"Video Display & Loundspeaker");
346 case 16:
return _T(
"Video Conferencing");
347 case 18:
return _T(
"Gaiming Toy");
355 LPCTSTR m_PeripheralDeviceClassName(
void)
const
362 case 1:
return _T(
"Joystick");
363 case 2:
return _T(
"Gamepad");
365 case 4:
return _T(
"Sensing Device");
366 case 5:
return _T(
"Digitizer Tablet");
367 case 6:
return _T(
"Card Reader");
371 case 0x00:
return _T(
"Unclassified");
372 case 0x40:
return _T(
"Keyboard");
373 case 0x80:
return _T(
"Pointer");
374 case 0xC0:
return _T(
"Combo Device");
382 LPCTSTR m_ImagingDeviceClassName(
void)
const
388 #define RX_COD_MINOR_IMAJING_DISPLAY_MASK 0x10
389 #define RX_COD_MINOR_IMAJING_CAMERA_MASK 0x20
390 #define RX_COD_MINOR_IMAJING_SCANNER_MASK 0x40
391 #define RX_COD_MINOR_IMAJING_PRINTER_MASK 0x80
463 TValue(SDP_TYPE t = SDP_TYPE_NIL, SDP_SPECIFICTYPE s = SDP_ST_NONE) :
type(t),
spec(s)
488 typeName = _T(
"UINT8");
492 typeName = _T(
"UINT16");
496 typeName = _T(
"UINT32");
500 typeName = _T(
"UINT64");
504 typeName = _T(
"UINT128");
508 typeName = _T(
"INT8");
512 typeName = _T(
"INT16");
516 typeName = _T(
"INT32");
520 typeName = _T(
"INT64");
524 typeName = _T(
"INT128");
528 typeName = _T(
"UUID16");
532 typeName = _T(
"UUID32");
535 value.
Format(_T(
"%08X-%04X-%04X-%02X%02X%02X%02X%02X%02X%02X%02X")
539 typeName = _T(
"UUID128");
546 case SDP_TYPE_BOOLEAN:
547 value =
booleanVal ? _T(
"true") : _T(
"false");
548 typeName = _T(
"BOOL");
550 case SDP_TYPE_STRING:
552 typeName = _T(
"STRING");
556 typeName = _T(
"URL");
582 ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
597 if ( m_ppSdpRecords != NULL )
599 loop ( i, m_numRecords )
601 m_ppSdpRecords[i]->Release();
603 BYTE* B =
reinterpret_cast<BYTE*
>(m_ppSdpRecords);
605 m_ppSdpRecords = NULL;
618 return m_ppSdpRecords != NULL;
650 raw.
Reset(size,
static_cast<const BYTE*
>(lpRawData));
652 ISdpStream* pIStream = NULL;
653 HRESULT hr = ::CoCreateInstance(__uuidof(SdpStream), NULL, CLSCTX_INPROC_SERVER
654 , __uuidof(ISdpStream),
reinterpret_cast<LPVOID*
>(&pIStream));
658 hr = pIStream->Validate(raw.
Ref(), raw.
GetSize(), &ulError);
661 hr = pIStream->VerifySequenceOf(raw.
Ref(), raw.
GetSize(), SDP_TYPE_SEQUENCE, NULL, &m_numRecords);
664 ASSERT( m_numRecords > 0 );
665 BYTE* B =
new BYTE[
sizeof(ISdpRecord*) * m_numRecords];
666 m_ppSdpRecords =
reinterpret_cast<ISdpRecord**
>(B);
667 ASSERT( m_ppSdpRecords != NULL );
668 hr = pIStream->RetrieveRecords(raw.
Ref(), raw.
GetSize(), m_ppSdpRecords, &m_numRecords);
679 if ( m_numRecords == 0 )
681 return m_Res(E_FAIL);
697 if ( record < m_numRecords )
699 return m_CheckRecord(m_ppSdpRecords[record]);
702 m_attrDetails.RemoveAll();
714 return m_attrIds.
Find(attributeId) != INVALID_INDEX;
757 INDEX f = m_attrIds.
Find(attributeId);
758 if ( f != INVALID_INDEX )
760 return m_attrDetails[f];
773 loop ( i, m_attrDetails )
778 SDP_TYPE s = list[i].type;
779 if ( s == SDP_TYPE_STRING || s == SDP_TYPE_URL )
792 ISdpRecord** m_ppSdpRecords;
794 HRESULT m_lastResult;
796 bool m_CheckRecord(ISdpRecord* pRecord)
802 HRESULT hr = pRecord->GetAttributeList(&pList, &listSize);
805 m_attrIds.SetSize(listSize);
806 m_attrDetails.
SetSize(listSize);
809 BYTE* pStream = NULL;
813 hr = pRecord->GetAttributeAsStream(aid, &pStream, &size);
816 TTRACE1(
"Attrib ID %04X\n", aid);
817 hr = m_CheckSub(m_attrDetails[i], pStream, size);
819 if ( pStream != NULL )
821 ::CoTaskMemFree(pStream);
823 if ( ! SUCCEEDED(hr) )
831 ::CoTaskMemFree(pList);
836 void m_CheckSubUint(TValue& _val, SDP_SPECIFICTYPE specType, BYTE* pSubElement, ISdpStream* pSdpStream)
841 _val.uint8 = *pSubElement;
844 pSdpStream->RetrieveUint16(pSubElement, &_val.uint16);
848 pSdpStream->RetrieveUint32(pSubElement, &_val.uint32);
852 pSdpStream->RetrieveUint64(pSubElement, &_val.uint64);
856 pSdpStream->RetrieveUint128(pSubElement, &_val.uint128);
857 _val.uint128.LowPart =
SwapEndian(_val.uint128.LowPart);
858 _val.uint128.HighPart =
SwapEndian(_val.uint128.HighPart);
866 void m_CheckSubInt(TValue& _val, SDP_SPECIFICTYPE specType, BYTE* pSubElement, ISdpStream* pSdpStream)
871 _val.int8 = *pSubElement;
874 pSdpStream->RetrieveInt16(pSubElement, &_val.int16);
875 _val.int16 =
SwapEndian(
static_cast<WORD
>(_val.int16));
878 pSdpStream->RetrieveInt32(pSubElement, &_val.int32);
879 _val.int32 =
SwapEndian(
static_cast<DWORD
>(_val.int32));
882 pSdpStream->RetrieveInt64(pSubElement, &_val.int64);
883 _val.int64 =
SwapEndian(
static_cast<ULONGLONG
>(_val.int64));
886 pSdpStream->RetrieveInt128(pSubElement, &_val.int128);
887 _val.int128.LowPart =
SwapEndian(
static_cast<ULONGLONG
>(_val.int128.LowPart));
888 _val.int128.HighPart =
SwapEndian(
static_cast<ULONGLONG
>(_val.int128.HighPart));
896 void m_CheckSubUuid(TValue& _val, SDP_SPECIFICTYPE specType, BYTE* pSubElement, ISdpStream* pSdpStream)
901 pSdpStream->RetrieveUint16(pSubElement, &_val.uuid16);
905 pSdpStream->RetrieveUint32(pSubElement, &_val.uuid32);
909 pSdpStream->RetrieveUuid128(pSubElement, &_val.uuid128);
910 _val.uuid128.Data1 =
SwapEndian(_val.uuid128.Data1);
911 _val.uuid128.Data2 =
SwapEndian(_val.uuid128.Data2);
912 _val.uuid128.Data3 =
SwapEndian(_val.uuid128.Data3);
920 bool m_CheckSub(
TValuesList& _list, BYTE* pStream, ULONG size)
922 ISdpStream* pSdpStream = NULL;
923 if ( ! m_LoadAndValidate(&pSdpStream, &pStream, &size) )
931 SDP_SPECIFICTYPE specType;
934 BYTE* pSubElement = NULL;
935 hr = pSdpStream->RetrieveElementInfo(pStream, &type, &specType, &recordSize, &storageSize, &pSubElement);
936 ASSERT( SUCCEEDED(hr) );
937 if ( type == SDP_TYPE_SEQUENCE || type == SDP_TYPE_ALTERNATIVE )
939 if ( ! m_CheckSub(_list, pSubElement, recordSize) )
946 TValue val(type, specType);
952 m_CheckSubUint(val, specType, pSubElement, pSdpStream);
955 m_CheckSubInt(val, specType, pSubElement, pSdpStream);
958 m_CheckSubUuid(val, specType, pSubElement, pSdpStream);
960 case SDP_TYPE_BOOLEAN:
961 val.booleanVal = ((*pSubElement) != 0);
963 case SDP_TYPE_STRING:
964 val.str.SetFromLeft(
reinterpret_cast<LPCSTR
>(pSubElement), recordSize);
967 val.str.SetFromLeft(
reinterpret_cast<LPCSTR
>(pSubElement), recordSize);
970 val.type = SDP_TYPE_NIL;
973 if ( val.type != SDP_TYPE_NIL )
977 CStr va = val.ToString(&type);
978 TTRACE2(
" %s: %s\n", type, va);
983 recordSize += 1 + storageSize;
984 pStream += recordSize;
987 pSdpStream->Release();
991 bool m_LoadAndValidate(ISdpStream **ppSdpStream, BYTE **ppStream, ULONG *pSize)
993 HRESULT hr = ::CoCreateInstance(__uuidof(SdpStream), NULL, CLSCTX_INPROC_SERVER
994 , __uuidof(ISdpStream),
reinterpret_cast<LPVOID*
>(ppSdpStream));
998 ASSERT( *ppSdpStream != NULL );
999 hr = (*ppSdpStream)->Validate(*ppStream, *pSize, &sdpError);
1004 bool m_Res(HRESULT hr)
1007 return SUCCEEDED(hr);
1117 if ( lpszAddress[i * 3 + 2] !=
':' )
1124 LONGLONG r = m_ToInt(&lpszAddress[i * 3]);
1125 if ( r < 0 || r > 255 )
1129 a += r << ((5 - i) * 8);
1142 int m_ToInt(LPCTSTR lpsz)
const
1146 if ( i1 >= 0 && i2 >= 0 )
1148 return i1 << 4 | i2;
1168 DEFSUPER(CBluetoothApi);
1185 bool r = m_Ret(BthReadLocalAddr(&ba));
1201 return reg[_T(
"Ident")].QueryString(_T(
"Name"));
1213 return reg[_T(
"Ident")].WriteString(_T(
"Name"), lpszName);
1225 bool r = m_Ret(BthReadCOD(&cl));
1239 return m_Ret(BthWriteCOD(cl));
1250 return m_Ret(BthWriteAuthenticationEnable(isEnable ? 1 : 0));
1262 bool r = m_Ret(BthReadAuthenticationEnable(&ae));
1265 _isEnabled = (ae != 0);
1290 int r = BthGetMode(&mode);
1291 if ( r == ERROR_SUCCESS )
1293 if ( mode == BTH_POWER_OFF )
1299 r = BthReadScanEnableMask(&mask);
1300 if ( r == ERROR_SUCCESS )
1302 ASSERT( mask >= 0 && mask <= 3 );
1303 _mode =
static_cast<EMode>(mask);
1320 int e = ERROR_SUCCESS;
1323 e = BthSetMode(BTH_POWER_OFF);
1328 e = BthGetHardwareStatus(&status);
1329 if ( e == ERROR_SUCCESS && status == HCI_HARDWARE_NOT_PRESENT )
1331 e = ERROR_DEVICE_NOT_CONNECTED;
1333 if ( e == ERROR_SUCCESS )
1335 e = BthSetMode(BTH_DISCOVERABLE);
1337 if ( e == ERROR_SUCCESS )
1343 int e1 = BthGetHardwareStatus(&status);
1344 if ( e1 != ERROR_SUCCESS )
1349 if ( status == HCI_HARDWARE_RUNNING )
1351 e = BthWriteScanEnableMask(mode);
1371 bool r = m_Ret(BthReadPageTimeout(&ot));
1387 WORD ot =
static_cast<WORD
>(timeout);
1388 return m_Ret(BthWritePageTimeout(ot));
1405 _timeout =
static_cast<DWORD
>(d * .625);
1419 double d =
static_cast<double>(timeout);
1437 int s = HCI_HARDWARE_UNKNOWN;
1438 int e = BthGetHardwareStatus(&s);
1439 if ( e == ERROR_SUCCESS && s == HCI_HARDWARE_UNKNOWN )
1441 e = ERROR_SERVICE_NOT_ACTIVE;
1454 return m_Ret(BthTerminateIdleConnections());
1468 return m_Ret(BthSetInquiryFilter(&ba));
1480 return m_Ret(BthClearInquiryFilter());
1492 const UINT LAP = 0x9e8b33;
1493 DWORD length = timeout / 1280;
1498 if ( length > 0x30 )
1504 bool r = m_Ret(BthPerformInquiry(LAP,
static_cast<BYTE
>(length), 0, 256, &got, ir));
1553 if ( BthGetAddress(btHandle, &
m_btAddr) != ERROR_SUCCESS )
1597 int e = BthReadRemoteVersion(&
m_btAddr,
1628 bool r = m_Ret(BthGetRemoteCOD(&ba, &cl));
1643 if ( ! r && ::GetLastError() == ERROR_NOT_FOUND )
1661 const int len = 1024;
1663 bool r = m_Ret(BthRemoteNameQuery(&ba, len, &requ, str.
GetBuffer(len)));
1665 return r ? str : _T(
"");
1676 return m_Ret(BthAuthenticate(&ba));
1693 if ( ! m_Ret(BthCreateSCOConnection(&
m_btAddr, &h)) )
1714 if ( ! m_Ret(BthCreateACLConnection(&
m_btAddr, &h)) )
1741 bool r = m_Ret(BthGetCurrentMode(&ba, &m));
1742 _mode =
static_cast<EMode>(m);
1757 return m_Ret(BthEnterHoldMode(&
m_btAddr, hold_mode_max, hold_mode_min, &_interval));
1771 return m_Ret(BthEnterParkMode(&
m_btAddr, beacon_max, beacon_min, &_interval));
1785 bool EnterSniffMode(WORD& _interval, WORD sniff_mode_max, WORD sniff_mode_min, WORD sniff_attempt, WORD sniff_timeout)
1787 return m_Ret(BthEnterSniffMode(&
m_btAddr, sniff_mode_max, sniff_mode_min, sniff_attempt, sniff_timeout, &_interval));
1797 return m_Ret(BthExitParkMode(&
m_btAddr));
1807 return m_Ret(BthExitSniffMode(&
m_btAddr));
1820 return m_Ret(BthGetLinkKey(&ba, _key.
Refer()));
1831 return m_Ret(BthRefusePINRequest(&ba));
1848 return m_Ret(BthPairRequest(&
m_btAddr, 1, &b));
1850 return m_Ret(BthPairRequest(&
m_btAddr, len,
reinterpret_cast<BYTE*
>(pin.
GetBuffer())));
1861 return m_Ret(BthRevokeLinkKey(&
m_btAddr));
1872 return m_Ret(BthRevokePIN(&
m_btAddr));
1884 return m_Ret(BthSetEncryption(&
m_btAddr, isEnable ? 1 : 0));
1914 return m_Ret(BthSetPIN(&
m_btAddr, 1, &b));
1916 return m_Ret(BthSetPIN(&
m_btAddr, len,
reinterpret_cast<BYTE*
>(pin.
GetBuffer())));
1932 SdpAttributeRange range = { 0, 0x200 };
1933 if ( m_QueryService(_raw, range, uuid16) )
1992 v[d++] = i + 0x1100;
1999 v[d++] = i + 0x1200;
2002 _list.
Reset(d, v.Ref());
2038 if ( baseListLength == 0 || pBaseList == NULL )
2043 ASSERT ( ! ::IsBadReadPtr(pBaseList,
sizeof(WORD) * baseListLength) );
2046 loop ( i, baseListLength )
2050 v[d++] = pBaseList[i];
2066 int r = api.BthCloseConnection(handle);
2068 return r == ERROR_SUCCESS;
2080 const int WORKLEN = 1000;
2083 int r = api.BthGetBasebandConnections(WORKLEN, w.
Ref(), &len);
2084 if ( r == ERROR_SUCCESS )
2101 switch ( serviceUuid16 )
2115 case PublicBrowseGroupServiceClassID_UUID16:
2116 s = _T(
"Public Browse Group");
2118 case SerialPortServiceClassID_UUID16:
2119 s = _T(
"Serial Port");
2121 case LANAccessUsingPPPServiceClassID_UUID16:
2122 s = _T(
"LAN Access Using PPP");
2124 case DialupNetworkingServiceClassID_UUID16:
2125 s = _T(
"Dialup Net working");
2127 case IrMCSyncServiceClassID_UUID16:
2128 s = _T(
"IrMC Sync");
2130 case OBEXObjectPushServiceClassID_UUID16:
2131 s = _T(
"OBEX Object Push");
2133 case OBEXFileTransferServiceClassID_UUID16:
2134 s = _T(
"OBEX File Transfer");
2136 case IrMcSyncCommandServiceClassID_UUID16:
2137 s = _T(
"IrMc Sync Command");
2139 case HeadsetServiceClassID_UUID16:
2142 case CordlessServiceClassID_UUID16:
2145 case AudioSourceServiceClassID_UUID16:
2146 s = _T(
"Audio Source");
2148 case AudioSinkServiceClassID_UUID16:
2149 s = _T(
"Audio Sink");
2151 case AV_RemoteControlTargetServiceClassID_UUID16:
2152 s = _T(
"A/V Remote Control Target");
2154 case AdvancedAudioDistributionServiceClassID_UUID16:
2155 s = _T(
"Advanced Audio Distribution");
2157 case AV_RemoteControlServiceClassID_UUID16:
2158 s = _T(
"A/V Remote Control");
2160 case VideoConferencingServiceClassID_UUID16:
2161 s = _T(
"Video Conferencing");
2163 case IntercomServiceClassID_UUID16:
2166 case FaxServiceClassID_UUID16:
2169 case HeadsetAudioGatewayServiceClassID_UUID16:
2170 s = _T(
"Headset Audio Gateway");
2172 case PANUServiceClassID_UUID16:
2175 case NAPServiceClassID_UUID16:
2178 case GNServiceClassID_UUID16:
2181 case HandsfreeServiceClassID_UUID16:
2182 s = _T(
"Handsfree");
2184 case HandsfreeAudioGatewayServiceClassID_UUID16:
2185 s = _T(
"Handsfree Audio Gateway");
2187 case PnPInformationServiceClassID_UUID16:
2188 s = _T(
"PnP Information");
2190 case GenericNetworkingServiceClassID_UUID16:
2191 s = _T(
"Generic Networking");
2193 case GenericFileTransferServiceClassID_UUID16:
2194 s = _T(
"Generic File Transfer");
2196 case GenericAudioServiceClassID_UUID16:
2197 s = _T(
"Generic Audio");
2199 case GenericTelephonyServiceClassID_UUID16:
2200 s = _T(
"Generic Telephony");
2206 s = _T(
"WAP Client");
2209 s = _T(
"Direct Printing");
2212 s = _T(
"Reference Printing");
2218 s = _T(
"Imaging Responder");
2221 s = _T(
"Imaging Automatic Archive");
2224 s = _T(
"Imaging Reference Objects");
2239 bool m_QueryService(
CWorkMem& _sdp,
const SdpAttributeRange& range, WORD uuid16)
const
2242 BTHNS_RESTRICTIONBLOB resb = { 0 };
2243 resb.type = SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST;
2245 resb.pRange[0] = range;
2246 resb.uuids[0].uuidType = SDP_ST_UUID16;
2247 resb.uuids[0].u.uuid16 = uuid16;
2250 blob.cbSize =
sizeof(BTHNS_RESTRICTIONBLOB);
2251 blob.pBlobData =
reinterpret_cast<BYTE*
>(&resb);
2253 SOCKADDR_BTH sa = { 0 };
2255 sa.addressFamily = AF_BT;
2256 CSADDR_INFO csai = { 0 };
2257 csai.RemoteAddr.lpSockaddr =
reinterpret_cast<sockaddr*
>(&sa);
2258 csai.RemoteAddr.iSockaddrLength =
sizeof(sa);
2260 WSAQUERYSET wsaq = { 0 };
2261 wsaq.dwSize =
sizeof(wsaq);
2262 wsaq.dwNameSpace = NS_BTH;
2263 wsaq.lpBlob = &blob;
2264 wsaq.lpcsaBuffer = &csai;
2266 HANDLE hLookup = NULL;
2267 int ret = BthNsLookupServiceBegin(&wsaq, 0, &hLookup);
2268 if ( ret == ERROR_SUCCESS )
2273 DWORD dwSize = work.GetSize();
2275 WSAQUERYSET* pResults =
reinterpret_cast<WSAQUERYSET*
>(work.Ref());
2276 pResults->dwSize =
sizeof(WSAQUERYSET);
2277 pResults->dwNameSpace = NS_BTH;
2278 int ret = BthNsLookupServiceNext(hLookup, 0, &dwSize, pResults);
2279 int ec = ::GetLastError();
2280 if ( ret != ERROR_SUCCESS && ec == ERROR_NOT_ENOUGH_MEMORY )
2283 work.Resize(dwSize);
2285 pResults =
reinterpret_cast<WSAQUERYSET*
>(work.Ref());
2286 pResults->dwSize =
sizeof(WSAQUERYSET);
2287 pResults->dwNameSpace = NS_BTH;
2288 ret = BthNsLookupServiceNext(hLookup, 0, &dwSize, pResults);
2289 ec = ::GetLastError();
2291 BthNsLookupServiceEnd(hLookup);
2292 if ( ret == ERROR_SUCCESS )
2294 if ( (pResults->lpBlob->cbSize) >= 4 )
2296 _sdp.
Reset(pResults->lpBlob->cbSize, pResults->lpBlob->pBlobData);
2299 ::SetLastError(WSASERVICE_NOT_FOUND);
2303 _GetLastError(
"BthNsLookupServiceNext");
2306 _GetLastError(
"BthNsLookupServiceBegin");
2330 DEFSUPER(CBluetoothApi);
2354 int r = BthSetInquiryFilter(&ba);
2356 return r == ERROR_SUCCESS;
2368 int r = BthClearInquiryFilter();
2370 return r == ERROR_SUCCESS;
2382 WSAQUERYSET wsaq = { 0 };
2383 wsaq.dwSize =
sizeof(WSAQUERYSET);
2384 wsaq.dwNameSpace = NS_BTH;
2385 int ret = BthNsLookupServiceBegin(&wsaq, LUP_CONTAINERS, &m_hLookup);
2386 if ( ret != ERROR_SUCCESS )
2405 DWORD dwSize = work.
GetSize();
2407 DWORD flag = LUP_RETURN_NAME | LUP_RETURN_ADDR | LUP_RETURN_BLOB;
2408 WSAQUERYSET* pResults =
reinterpret_cast<WSAQUERYSET*
>(work.
Ref());
2409 pResults->dwSize =
sizeof(WSAQUERYSET);
2410 pResults->dwNameSpace = NS_BTH;
2411 int ret = BthNsLookupServiceNext(m_hLookup, flag, &dwSize, pResults);
2412 if ( ret != ERROR_SUCCESS && ::GetLastError() == ERROR_NOT_ENOUGH_MEMORY )
2417 pResults =
reinterpret_cast<WSAQUERYSET*
>(work.
Ref());
2418 pResults->dwSize =
sizeof(WSAQUERYSET);
2419 pResults->dwNameSpace = NS_BTH;
2420 ret = BthNsLookupServiceNext(m_hLookup, flag, &dwSize, pResults);
2422 if ( ret != ERROR_SUCCESS )
2424 if ( ::GetLastError() != WSA_E_NO_MORE )
2426 _GetLastError(
"BthNsLookupServiceNext");
2431 if ( pResults->dwNumberOfCsAddrs == 1 )
2433 LPSOCKADDR lpszAddr = pResults->lpcsaBuffer->RemoteAddr.lpSockaddr;
2434 SOCKADDR_BTH* P =
reinterpret_cast<SOCKADDR_BTH*
>(lpszAddr);
2437 ASSERT( pResults->lpBlob->cbSize ==
sizeof(BthInquiryResult) );
2438 BthInquiryResult* pInqRes =
reinterpret_cast<BthInquiryResult*
>(pResults->lpBlob->pBlobData);
2441 m_foundName = pResults->lpszServiceInstanceName;
2442 m_foundClass = pInqRes->
cod;
2443 return m_foundDevice.
IsValid();
2449 if ( m_hLookup != NULL )
2451 BthNsLookupServiceEnd(m_hLookup);
2463 return m_foundDevice;
2473 return m_foundClass;
2515 return ag.Control(IOCTL_AG_CLOSE_CONTROL);
2526 return ag.Control(IOCTL_AG_OPEN_CONTROL);
2538 return ag.Control(IOCTL_AG_SET_USE_HF_AUDIO, &dwData,
sizeof(dwData));
2549 return ag.Control(IOCTL_AG_OPEN_AUDIO);
2560 return ag.Control(IOCTL_AG_CLOSE_AUDIO);
2572 DWORD dwData = isOn ? 1 : 0;
2573 return ag.Control(IOCTL_AG_SET_INBAND_RING, &dwData,
sizeof(dwData));
2585 DWORD dwData = isOn ? 1 : 0;
2586 return ag.Control(IOCTL_AG_SET_POWER_MODE, &dwData,
sizeof(dwData));
2599 bool r = ag.Control(IOCTL_AG_GET_POWER_MODE, NULL, 0, &dwData,
sizeof(dwData));
2600 _isOn = (dwData != 0);
2613 return ag.Control(IOCTL_AG_SET_SPEAKER_VOL, &vol,
sizeof(vol));
2625 return ag.Control(IOCTL_AG_GET_SPEAKER_VOL, NULL, 0, &_vol,
sizeof(_vol));
2637 return ag.Control(IOCTL_AG_SET_MIC_VOL, &vol,
sizeof(vol));
2649 return ag.Control(IOCTL_AG_GET_MIC_VOL, NULL, 0, &_vol,
sizeof(_vol));
2658 CBag(
void) : m_handle(::CreateFile(_T(
"BAG0:"), 0, 0, NULL, OPEN_EXISTING, 0, NULL))
2664 if ( m_handle != INVALID_HANDLE_VALUE )
2666 ::CloseHandle(m_handle);
2667 m_handle = INVALID_HANDLE_VALUE;
2671 bool Control(DWORD dwIoControlCode, LPVOID lpInBuffer = NULL, DWORD nInBufferSize = 0, LPVOID lpOutBuffer = NULL, DWORD nOutBufferSize = 0, LPDWORD lpBytesReturned = NULL, LPOVERLAPPED lpOverlapped = NULL)
2673 bool r = !! ::DeviceIoControl(m_handle, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped);
2676 _GetLastError(
"DeviceIoControl");
2689 CE の SDP は、一個ずつしか検索できない。
#define loop(VAR, CNT)
loop構文.
const BT_ADDR & GetAddress(void) const
[取得] アドレス取得.
CBluetoothAddress & operator=(const CBluetoothAddress &other)
コピーオペレータ.
bool IsValid(void) const
[確認] 有効確認.
CStr GetAddressString(void) const
[取得] アドレス文字列取得.
bool SetAddressString(LPCTSTR lpszAddress)
[設定] アドレス文字列設定.
CBluetoothAddress(BT_ADDR btAddr=0)
コンストラクタ.
CBluetoothAddress(const CBluetoothAddress &other)
コピーコンストラクタ.
Bluetooth(CE) Audio Gateway Service 管理.
bool SetInbandRing(bool isOn=true)
[設定] Turning on/off inband ring tones.
bool Disconnect(void)
[処理] Closing Bluetooth control connection.
bool GetSpeakerVolume(int &_vol)
[取得] Getting speaker volume.
bool GetMicVolume(int &_vol)
[取得] Getting microphone volume.
bool AutoAnswer(void)
[処理] Setting auto-answer option.
bool GetPowerSaveMode(bool &_isOn)
[取得] Getting Power-save mode.
bool CloseAudio(void)
[処理] Closing Bluetooth audio.
bool OpenAudio(void)
[処理] Opening Bluetooth audio.
bool SetSpeakerVolume(int vol)
[設定] Setting speaker volume.
bool SetMicVolume(int vol)
[設定] Setting microphone volume.
bool Connect(void)
[処理] Opening Bluetooth control connection.
bool SetPowerSaveMode(bool isOn=true)
[設定] Turning on/off Power-save mode.
DWORD serviceClass
サービスクラス
DWORD majorDeviceClass
メジャーデバイスクラス
DWORD GetMajorDeviceClass(void) const
[取得] メジャーデバイスクラス取得.
void SetServiceClass(DWORD c)
[設定] サービスクラス設定.
LPCTSTR GetMinorDeviceClassName(void) const
[取得] マイナーデバイスクラス文字列取得.
DWORD GetServiceClass(void) const
[取得] サービスクラス取得.
DWORD formatType
フォーマットタイプ
void SetMajorDeviceClass(DWORD c)
[設定] メジャーデバイスクラス設定.
LPCTSTR GetMajorDeviceClassName(void) const
[取得] メジャーデバイスクラス文字列取得.
EMajorDeviceClass
メジャーデバイスクラス種類.
@ Imaging
Imaging (printing, scanner, camera, display, ...)
@ Network
LAN /Network Access point
@ Miscellaneous
Miscellaneous
@ Peripheral
Peripheral (mouse, joystick, keyboards, ..... )
@ AV
Audio/Video (headset,speaker,stereo, video display, vcr.....
@ Phone
Phone (cellular, cordless, payphone, modem, ...)
@ Computer
Computer (desktop,notebook, PDA, organizers, .... )
@ Positioning
Positioning (Location identification)
@ ObjectTransfer
Object Transfer (v-Inbox, v-Folder, ...)
@ Rendering
Rendering (Printing, Speaker, ...)
@ Networking
Networking (LAN, Ad hoc, ...)
@ Information
Information (WEB-server, WAP-server, ...)
@ Telephony
Telephony (Cordless telephony, Modem, Headset service, ...)
@ Audio
Audio (Speaker, Microphone, Headset service, ...)
@ Capturing
Capturing (Scanner, Microphone, ...)
DWORD GetMinorDeviceClass(void) const
[取得] マイナーデバイスクラス取得.
DWORD GetDeviceClass(void) const
[取得] デバイスクラス取得.
void SetMinorDeviceClass(DWORD c)
[設定] マイナーデバイスクラス設定.
CBluetoothClass(DWORD cod=0)
コンストラクタ.
DWORD minorDeviceClass
マイナーデバイスクラス
bool RefusePinRequest(void)
[処理] PIN リクエスト辞退.
bool GetClassEx(CBluetoothClass &_class)
[取得] デバイスクラス取得.
bool GetVersion(TVersion &_version)
[取得] バージョン取得.
bool IsExist(void) const
[確認] 存在確認.
CBluetoothDevice(const BT_ADDR &btAddr=0)
コンストラクタ.
bool HasService(WORD uuid16) const
[確認] サービス確認.
bool ExitParkMode(void)
[設定] パークモード終了
bool GetServicesList(CWorkMemT< WORD > &_list, size_t baseListLength, const WORD *pBaseList) const
[取得] サービス一覧取得.
CBluetoothDevice(BT_HANDLE btHandle)
コンストラクタ.
bool ExitSniffMode(void)
[設定] スニフモード終了
bool HasService(CWorkMem &_raw, WORD uuid16) const
[確認] サービス確認.
static bool GetBasebandConnections(CWorkMemT< BASEBAND_CONNECTION > &_connections)
[取得] ベースバンド接続一覧取得.
bool PairRequest(LPCTSTR lpszPin)
[処理] ペアリクエスト.
bool EnterHoldMode(WORD &_interval, WORD hold_mode_max, WORD hold_mode_min)
[設定] ホールドモード開始.
CBluetoothDevice(const CBluetoothDevice &other)
コピーコンストラクタ.
bool Authenticate(void) const
[処理] 認証.
CBluetoothDevice & operator=(const CBluetoothDevice &other)
コピーオペレータ.
bool GetCurrentMode(EMode &_mode) const
[取得] .ACLモード取得.
static CStr ServiceToString(WORD serviceUuid16)
[取得] サービス名取得.
BT_HANDLE CreateAclConnection(void)
[処理] データ通信用パケットオープン.
bool SetEncryption(bool isEnable)
[設定] 暗号設定.
bool EnterParkMode(WORD &_interval, WORD beacon_max, WORD beacon_min)
[設定] パークモード開始.
bool SetPin(LPCTSTR lpszPin)
[設定] PIN コード設定.
bool EnterSniffMode(WORD &_interval, WORD sniff_mode_max, WORD sniff_mode_min, WORD sniff_attempt, WORD sniff_timeout)
[設定] スニフモード開始.
bool GetClass(CBluetoothClass &_class) const
[取得] デバイスクラス取得.
bool SetLinkKey(const CBluetoothLinkKey &key)
[設定] LINKキー設定.
bool HasService(CBluetoothServiceAttribute &_attr, WORD uuid16) const
[確認] サービス確認.
CStr GetName(void) const
[取得] デバイス名取得.
static bool CloseConnection(BT_HANDLE handle)
[処理] コネクションクローズ.
bool GetLinkKey(CBluetoothLinkKey &_key) const
[取得] LINKキー取得.
bool RevokePin(void)
[破棄] PINコード破棄.
BT_HANDLE CreateScoConnection(void)
[処理] 音声用パケットオープン.
bool RevokeLinkKey(void)
[破棄] LINKキー破棄.
const CBluetoothClass & GetFoundDeviceClass(void) const
[取得] 発見デバイスクラス取得.
CBluetoothFinder(void)
コンストラクタ
void Finish(void)
[検索] 検索終了
bool SetFilter(const CBluetoothAddress &addr)
[設定] フィルタ設定.
const CBluetoothDevice & GetFoundDevice(void) const
[取得] 発見デバイス取得.
bool Start(void)
[検索] 検索開始.
LPCTSTR GetFoundDeviceName(void) const
[取得] 発見デバイス名取得.
~CBluetoothFinder(void)
デストラクタ
bool ResetFilter(void)
[設定] フィルタ設定解除.
const BYTE * Refer(void) const
[参照] アドレス参照.
const BYTE & operator[](INDEX index) const
[参照] 要素参照.
CBluetoothLinkKey(void)
コンストラクタ.
BYTE * Refer(void)
[参照] アドレス参照.
BYTE & operator[](INDEX index)
[参照] 要素参照.
bool IsEnabledAuthentication(bool &_isEnabled) const
[取得] 認証状態取得.
bool SetPageTimeout(DWORD timeout)
[設定] ページタイムアウト時間設定.
bool TerminateIdleConnections(void)
[設定] アイドル接続切断.
bool ClearInquiryFilter(void)
[設定] Inquiryフィルタ設定解除.
bool SetInquiryFilter(const CBluetoothAddress &addr)
[設定] Inquiryフィルタ設定.
bool GetPageTimeoutMs(DWORD &_timeout) const
[取得] ページタイムアウト時間取得.
bool GetPageTimeout(DWORD &_timeout) const
[取得] ページタイムアウト時間取得.
bool GetAddress(CBluetoothAddress &_addr) const
[取得] アドレス取得.
int GetStatus(void) const
[取得] 状態取得.
bool SetMode(EMode mode, DWORD timeout=3000)
[設定] モード設定.
bool SetName(LPCTSTR lpszName)
[設定] 名前設定.
@ EnabledPageScan
Power ON。Inquiry は Disable、 Page Scan は Enable。
@ EnabledAll
Power ON。Inquiry は Enable、 Page Scan は Enable。
@ DisabledAll
Power ON。Inquiry は Disable、 Page Scan は Disable。
@ EnabledInquiry
Power ON。Inquiry は Enable、 Page Scan は Disable。
bool GetMode(EMode &_mode) const
[取得] モード取得.
CVectorT< BthInquiryResult > Inquiry(DWORD timeout=1000) const
[検索] Inquiry実行.
bool GetClass(CBluetoothClass &_class) const
[取得] デバイスクラス取得.
CStr GetName(void) const
[取得] 名前取得.
bool EnableAuthentication(bool isEnable)
[設定] 認証有効無効.
CBluetoothLocal(void)
コンストラクタ
bool SetPageTimeoutMs(DWORD timeout)
[設定] ページタイムアウト時間設定.
bool SetClass(const CBluetoothClass &clas)
[設定] デバイスクラス設定.
~CBluetoothServiceAttribute(void)
デストラクタ
const TIdsList & GetAttributeIdList(void) const
[取得] 属性ID一覧取得.
bool HasAttribute(WORD attributeId) const
[確認] 属性データ確認.
bool Analyze(size_t size, LPCVOID lpRawData)
[解析] 解析.
CVectorT< WORD > TIdsList
ID配列.
bool IsValid(void) const
[確認] 有効確認.
CVectorT< TValue > TValuesList
値配列.
HRESULT GetLastResult(void) const
[取得] 最終リザルト取得.
CStrVector GetAttributeString(void) const
[取得] 属性文字列取得.
const TValuesList & GetAttributeData(WORD attributeId) const
[取得] 属性IDデータ取得.
bool SearchRecord(INDEX record)
[検索] レコード検索.
size_t GetRecordCount(void) const
[取得] 保持レコード数.
CBluetoothServiceAttribute(void)
コンストラクタ
bool IsEmpty(void) const
[確認] 空チェック
void ReleaseBuffer(void)
[操作] 割り当てたバッファを開放.
size_t GetLength(void) const
[取得] 文字列長
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
void Format(const TYP *lpszFormat,...)
[代入] 書式付き文字列代入.
TYP * GetBuffer(size_t iLength=0)
[操作] 書き込みバッファ要求.
bool IsPassed(DWORD dwTime) const
[確認] 経過確認.
void OutputDebugPassedCount(void) const
[出力] 経過時間表示.
void Invalid(void)
[操作] 無効状態にする
virtual bool SetSize(size_t size)
[操作] サイズ指定
virtual bool RemoveAll(void)
[削除] 空化
virtual INDEX Add(const TYP &t)
[追加] 要素一つ追加.
size_t GetSize(void) const
[取得] サイズ取得
void Fill(const TYP &other)
[設定] 全情報代入.
void Resize(size_t l)
[設定] サイズ再設定
void Reset(size_t l, const TYP *P)
[設定] 再設定
const TYP * Ref(void) const
[取得] ポインタ取得
size_t GetLen(LPCSTR lpsz)
[計算] 文字列長計算(ASCII/SJIS用)
int HexCharToInt(int c)
[変換] HEX文字数値変換
TNB::CStrT< TCHAR > CStr
文字列クラス
void Zero(V &value)
[設定] ゼロクリア.
WORD SwapEndian(WORD val)
[変換] エンディアン変換.
unsigned short BT_HANDLE
Bluetooth(CE) ハンドル.
ULONGLONG BT_ADDR
Bluetooth(CE) アドレス.
Bluetooth(CE) デバイスのバージョン管理
ULONGLONG uint64
spec = SDP_ST_UINT64 の場合の値
GUID uuid128
spec = SDP_ST_UUID128 の場合の値
LONGLONG int64
spec = SDP_ST_INT64 の場合の値
BYTE uint8
spec = SDP_ST_UINT8 の場合の値
WORD uint16
spec = SDP_ST_UINT16 の場合の値
bool booleanVal
type = SDP_TYPE_BOOLEAN / SDP_TYPE_STRING の場合の値
SDP_SPECIFICTYPE spec
詳細タイプ
SDP_ULARGE_INTEGER_16 uint128
spec = SDP_ST_UINT128 の場合の値
CHAR int8
spec = SDP_ST_INT8 の場合の値
TValue(SDP_TYPE t=SDP_TYPE_NIL, SDP_SPECIFICTYPE s=SDP_ST_NONE)
コンストラクタ.
CStr ToString(CStr *pType=NULL) const
[取得] 文字列化.
CAscii str
type = SDP_TYPE_URL の場合の値
DWORD uint32
spec = SDP_ST_UINT32 の場合の値
SDP_LARGE_INTEGER_16 int128
spec = SDP_ST_INT128 の場合の値
DWORD uuid32
spec = SDP_ST_UUID32 の場合の値
WORD uuid16
spec = SDP_ST_UUID16 の場合の値
LONG int32
spec = SDP_ST_INT32 の場合の値
SHORT int16
spec = SDP_ST_INT16 の場合の値
virtual size_t CopyElements(size_t size, const TYP *P=NULL)
[設定] コピー.
INDEX Find(const IChecker &checker, INDEX startIndex=0, bool boIsReverse=false) const
[検索] 条件一致要素の検索.