📄 sdptest.cxx
字号:
if (0 == memcmp(&bt,&zeroAddr,sizeof(BD_ADDR)))
dwFlags = LUP_RES_SERVICE;
SKIP_WHITESPACE(szCmd);
if (NULL == (pFile = SdpOpenFile(szCmd)))
return;
memset(UUIDs,0,sizeof(UUIDs));
BOOL fRead = ReadUUIDs(pFile,UUIDs,&cUUIDs,TRUE);
fclose(pFile);
if (!fRead)
return;
// Setup Query
WSAQUERYSET wsaQuery;
BTHNS_RESTRICTIONBLOB rBlob;
BLOB blob;
memset(&rBlob,0,sizeof(rBlob));
rBlob.type = SDP_SERVICE_SEARCH_REQUEST;
memcpy(rBlob.uuids,UUIDs,cUUIDs*sizeof(SdpQueryUuid));
blob.cbSize = sizeof(BTHNS_RESTRICTIONBLOB);
blob.pBlobData = (BYTE*)&rBlob;
CSADDR_INFO csAddr;
SOCKADDR_BTH sockBT;
InitWSAQuerySet(&wsaQuery,&bt,&csAddr,&sockBT,&blob);
HANDLE hLookup;
SetLastError(0);
int iRet = BthNsLookupServiceBegin(&wsaQuery,dwFlags,&hLookup);
wprintf(L"BthNsLookupServiceBegin returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
if (ERROR_SUCCESS != iRet) {
return;
}
// Get Results
CHAR buf[BUFFER_SIZE];
LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET) buf;
DWORD dwSize = sizeof(buf);
SetLastError(0);
iRet = BthNsLookupServiceNext(hLookup,0,&dwSize,pwsaResults);
wprintf(L"BthNsLookupServiceNext returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
#if defined (UNDER_CE)
unsigned long *pHandles;
unsigned long ulReturnedHandles;
if (ERROR_SUCCESS == iRet) {
ulReturnedHandles = (pwsaResults->lpBlob->cbSize) / sizeof(DWORD);
pHandles = (unsigned long *) pwsaResults->lpBlob->pBlobData;
wprintf(L"BthNsLookupServiceNext returned %d handles\r\n",ulReturnedHandles);
for (unsigned long i = 0; i < ulReturnedHandles; i++) {
wprintf(L"rec[%d] = 0x%08x\t",i,pHandles[i]);
if (i && (i % 3 == 0))
wprintf(L"\r\n");
}
iRet = BthNsLookupServiceNext(hLookup,0,&dwSize,pwsaResults);
if (iRet != SOCKET_ERROR || GetLastError() != WSA_E_NO_MORE)
wprintf(L"ERROR: 2nd call to BthNsLookupServiceNext should've returned SOCKET_ERROR,setGLE=WSA_E_NO_MORE. iRet=0x%08x,GLE=0x%08x",iRet,GetLastError());
}
if ((ulReturnedHandles==1) || ((ulReturnedHandles-1) % 3 != 0))
wprintf(L"\r\n");
#endif
SetLastError(0);
iRet = BthNsLookupServiceEnd(hLookup);
wprintf(L"BthNsLookupServiceEnd returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
}
/************************************************************
TestSdpAttribSearch
File format
Service Record Handle
[(Attribute ranges, 2 16 bit #'s, ordered least->smallest)]
All values are in hex.
Example file:
10000
1 5
8 8
100 FFFF
************************************************************/
void TestSdpAttribSearch(WCHAR *szCmd) {
FILE *pFile;
SdpAttributeRange attribRange[MAX_ATTRIBUTES];
unsigned long ulHandle;
unsigned long cAttributes;
BT_ADDR bt;
DWORD dwFlags = 0;
// Read Input
SKIP_WHITESPACE(szCmd);
if (! GetBA(&szCmd, &bt)) {
wprintf (L"Syntax: BD_ADDR\n");
return;
}
if (0 == memcmp(&bt,&zeroAddr,sizeof(BD_ADDR)))
dwFlags = LUP_RES_SERVICE;
SKIP_WHITESPACE(szCmd);
if (NULL == (pFile = SdpOpenFile(szCmd)))
return;
BOOL fRead = ReadAttributes(pFile,&ulHandle,attribRange,&cAttributes);
fclose(pFile);
if (!fRead)
return;
// Setup Query
WSAQUERYSET wsaQuery;
PBTHNS_RESTRICTIONBLOB prBlob;
BLOB blob;
CHAR buf2[BUFFER_SIZE];
memset(buf2,0,sizeof(buf2));
unsigned long ulBlobLen = sizeof(BTHNS_RESTRICTIONBLOB) + (cAttributes-1)* sizeof(SdpAttributeRange);
prBlob = (PBTHNS_RESTRICTIONBLOB) buf2;
prBlob->type = SDP_SERVICE_ATTRIBUTE_REQUEST;
prBlob->serviceHandle = ulHandle;
prBlob->numRange = cAttributes;
memcpy(prBlob->pRange,attribRange,cAttributes*sizeof(SdpAttributeRange));
blob.cbSize = ulBlobLen;
blob.pBlobData = (BYTE*)prBlob;
CSADDR_INFO csAddr;
SOCKADDR_BTH sockBT;
InitWSAQuerySet(&wsaQuery,&bt,&csAddr,&sockBT,&blob);
HANDLE hLookup;
SetLastError(0);
int iRet = BthNsLookupServiceBegin(&wsaQuery,dwFlags,&hLookup);
wprintf(L"BthNsLookupServiceBegin returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
if (ERROR_SUCCESS != iRet) {
return;
}
// Get Results
CHAR buf[BUFFER_SIZE];
LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET) buf;
DWORD dwSize = sizeof(buf);
SetLastError(0);
iRet = BthNsLookupServiceNext(hLookup,0,&dwSize,pwsaResults);
wprintf(L"BthNsLookupServiceNext returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
#if defined (UNDER_CE)
if (ERROR_SUCCESS == iRet) {
wprintf(L"BthNsLookupServiceNext return buf size = %d bytes\r\n",pwsaResults->lpBlob->cbSize);
PrintStream(pwsaResults->lpBlob->pBlobData,pwsaResults->lpBlob->cbSize);
wprintf(L"\r\n");
iRet = BthNsLookupServiceNext(hLookup,0,&dwSize,pwsaResults);
if (iRet != SOCKET_ERROR || GetLastError() != WSA_E_NO_MORE)
wprintf(L"ERROR: 2nd call to BthNsLookupServiceNext should've returned SOCKET_ERROR,setGLE=WSA_E_NO_MORE. iRet=0x%08x,GLE=0x%08x",iRet,GetLastError());
}
#endif
SetLastError(0);
iRet = BthNsLookupServiceEnd(hLookup);
wprintf(L"BthNsLookupServiceEnd returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
}
/************************************************************
TestSdpServAttribSearch. All values are in hex.
Example file:
UUID16 FFF
UUID16 3000
END
1 4
5 42
256 FFFF
************************************************************/
void TestSdpServAttribSearch(WCHAR *szCmd) {
FILE *pFile;
SdpAttributeRange attribRange[MAX_ATTRIBUTES];
unsigned long cAttributes;
BT_ADDR bt;
SdpQueryUuid UUIDs[MAX_UUIDS_IN_QUERY];
unsigned short cUUIDs;
DWORD dwFlags = 0;
BOOL fRead;
// Read Input
SKIP_WHITESPACE(szCmd);
if (! GetBA(&szCmd, &bt)) {
wprintf (L"Syntax: BD_ADDR\n");
return;
}
if (0 == memcmp(&bt,&zeroAddr,sizeof(BD_ADDR)))
dwFlags = LUP_RES_SERVICE;
SKIP_WHITESPACE(szCmd);
if (NULL == (pFile = SdpOpenFile(szCmd)))
return;
fRead = ReadUUIDs(pFile,UUIDs,&cUUIDs,FALSE);
if (fRead)
ReadAttributes(pFile,NULL,attribRange,&cAttributes);
fclose(pFile);
if (!fRead)
return;
// Setup Query
WSAQUERYSET wsaQuery;
PBTHNS_RESTRICTIONBLOB prBlob;
BLOB blob;
unsigned long ulBlobLen = sizeof(BTHNS_RESTRICTIONBLOB) + (cAttributes-1)* sizeof(SdpAttributeRange);
CHAR buf2[BUFFER_SIZE];
prBlob = (PBTHNS_RESTRICTIONBLOB) buf2;
memset(buf2,0,sizeof(buf2));
prBlob->type = SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST;
prBlob->numRange = cAttributes;
memcpy(prBlob->pRange,attribRange,cAttributes*sizeof(SdpAttributeRange));
memcpy(prBlob->uuids,UUIDs,cUUIDs*sizeof(SdpQueryUuid));
blob.cbSize = ulBlobLen;
blob.pBlobData = (BYTE*)prBlob;
CSADDR_INFO csAddr;
SOCKADDR_BTH sockBT;
InitWSAQuerySet(&wsaQuery,&bt,&csAddr,&sockBT,&blob);
HANDLE hLookup;
SetLastError(0);
int iRet = BthNsLookupServiceBegin(&wsaQuery,dwFlags,&hLookup);
wprintf(L"BthNsLookupServiceBegin returned 0x%08x\r\n",iRet);
if (ERROR_SUCCESS != iRet) {
return;
}
CHAR buf[BUFFER_SIZE];
LPWSAQUERYSET pwsaResults = (LPWSAQUERYSET) buf;
DWORD dwSize = sizeof(buf);
SetLastError(0);
iRet = BthNsLookupServiceNext(hLookup,0,&dwSize,pwsaResults);
wprintf(L"BthNsLookupServiceNext returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
#if defined (UNDER_CE)
if (ERROR_SUCCESS == iRet) {
wprintf(L"BthNsLookupServiceNext return buf size = %d bytes\r\n",pwsaResults->lpBlob->cbSize);
PrintStream(pwsaResults->lpBlob->pBlobData,pwsaResults->lpBlob->cbSize);
wprintf(L"\r\n");
iRet = BthNsLookupServiceNext(hLookup,0,&dwSize,pwsaResults);
if (iRet != SOCKET_ERROR || GetLastError() != WSA_E_NO_MORE)
wprintf(L"ERROR: 2nd call to BthNsLookupServiceNext should've returned SOCKET_ERROR,setGLE=WSA_E_NO_MORE. iRet=0x%08x,GLE=0x%08x",iRet,GetLastError());
}
#endif
SetLastError(0);
iRet = BthNsLookupServiceEnd(hLookup);
wprintf(L"BthNsLookupServiceEnd returned 0x%08x,GLE=0x%08x\r\n",iRet,GetLastError());
}
// *************************************************************************
// Code below is used only by TestSdpAddRecord, it creates a record out
// of a file and returns a string.
// *************************************************************************
IClassFactory *pCFRecord = NULL;
IClassFactory *pCFContainer = NULL;
struct NDW : public NodeData {
inline void Z() { ZeroMemory(&u, sizeof(u)); }
NDW()
{
type = SDP_TYPE_NIL;
specificType = SDP_ST_NONE;
ZeroMemory(&u, sizeof(u));
}
NDW(UCHAR val, UCHAR b)
{
type= SDP_TYPE_BOOLEAN;
specificType = SDP_ST_NONE;
u.booleanVal = val;
}
void Boolean(UCHAR val)
{
Z();
type= SDP_TYPE_BOOLEAN;
specificType = SDP_ST_NONE;
u.booleanVal = val;
}
NDW(UCHAR uint8)
{
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT8;
u.uint8 = uint8;
}
void Uint8(UCHAR uint8)
{
Z();
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT8;
u.uint8 = uint8;
}
NDW(USHORT uint16)
{
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT16;
u.uint16 = uint16;
}
void Uint16(USHORT uint16)
{
Z();
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT16;
u.uint16 = uint16;
}
NDW(ULONG uint32)
{
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT32;
u.uint32 = uint32;
}
void Uint32(ULONG uint32)
{
Z();
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT32;
u.uint32 = uint32;
}
NDW(ULONGLONG uint64)
{
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT64;
u.uint64 = uint64;
}
void Uint64(ULONGLONG uint64)
{
Z();
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT64;
u.uint64 = uint64;
}
NDW(PSDP_ULARGE_INTEGER_16 uint128)
{
type= SDP_TYPE_UINT;
specificType = SDP_ST_UINT128;
u.uint128 = *uint128;
}
NDW(CHAR int8)
{
type=SDP_TYPE_INT;
specificType = SDP_ST_INT8;
u.int8 = int8;
}
NDW(SHORT int16)
{
type= SDP_TYPE_INT;
specificType = SDP_ST_INT16;
u.int16 = int16;
}
NDW(LONG int32)
{
type= SDP_TYPE_INT;
specificType = SDP_ST_INT32;
u.int32 = int32;
}
NDW(LONGLONG int64)
{
type= SDP_TYPE_INT;
specificType = SDP_ST_INT64;
u.int64 = int64;
}
NDW(PSDP_LARGE_INTEGER_16 int128)
{
type= SDP_TYPE_INT;
specificType = SDP_ST_INT128;
u.int128 = *int128;
}
NDW(CHAR *str, ULONG length, UCHAR IsString = TRUE)
{
if (IsString) {
type=SDP_TYPE_STRING;
u.str.val = str;
u.str.length = length;
}
else {
type=SDP_TYPE_URL;
u.url.val = str;
u.url.length = length;
}
specificType = SDP_ST_NONE;
}
NDW(ISdpNodeContainer *c)
{
type=SDP_TYPE_CONTAINER;
specificType=SDP_ST_NONE;
u.container = c;
}
NDW(USHORT uuid16, UCHAR d)
{
type=SDP_TYPE_UUID;
specificType=SDP_ST_UUID16;
u.uuid16 = uuid16;
}
void Uuid16(USHORT uuid16)
{
Z();
type=SDP_TYPE_UUID;
specificType=SDP_ST_UUID16;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -