⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdpns.cxx

📁 三星2440原版bsp
💻 CXX
📖 第 1 页 / 共 4 页
字号:
		if ((type == SDP_SERVICE_SEARCH_REQUEST) || (type == SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST)) {
			if (pResBlob) {
				pUUIDs = pResBlob->uuids;
			}
			else {
				memcpy(&UUID[0].u.uuid128,&pBthNsHandle->ServiceClassId,sizeof(GUID));
				UUID[0].uuidType = SDP_ST_UUID128;
				// This is so SdpInterface::VerifyServiceSearch knows where to stop
				memset(&UUID[1],0,sizeof(SdpQueryUuid));
				pUUIDs = UUID;
			}
		}

		if (type == SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST) {
			if (pResBlob) {
				pRange = pResBlob->pRange;
				numAttributes = pResBlob->numRange;
			}
			else {
				SVSUTIL_ASSERT(pBthNsHandle->fXPCompatMode);
				Range.minAttribute = 0;
				Range.maxAttribute = 0xffff;
				pRange = &Range;
				numAttributes = 1;
			}
		}

		switch (type) {
			case SDP_SERVICE_SEARCH_REQUEST:  {
				if (ERROR_SUCCESS != (iRes = ServiceSearchBlocking(pCall,cid, pUUIDs, MAX_SEARCH_HANDLES)))
					iRes = MapErrorCodeToWinsockErr(iRes);
			}
			break;

			case SDP_SERVICE_ATTRIBUTE_REQUEST: {
				numAttributes = pResBlob->numRange;
				if (ERROR_SUCCESS != (iRes = AttributeSearchBlocking(pCall, cid, pResBlob->serviceHandle,pResBlob->pRange,numAttributes)))
					iRes = MapErrorCodeToWinsockErr(iRes);
			}
			break;

			case SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST: {
				if (ERROR_SUCCESS != (iRes = ServiceAttributeSearchBlocking(pCall, cid, pUUIDs,pRange,numAttributes)))
					iRes = MapErrorCodeToWinsockErr(iRes);
			}
			break;

			default:
				SVSUTIL_ASSERT(0);
		}
		SVSUTIL_ASSERT(gpBthNS->IsLocked());

		if (iRes != ERROR_SUCCESS)
			goto done;

		if (NULL == (pCall = FindCall(pCall)) || pCall->iResult != ERROR_SUCCESS || 
		    NULL == (pBthNsHandle = FindBthNsHandle(pBthNsHandle)))  {
			iRes = MapErrorCodeToWinsockErr((pCall && pBthNsHandle) ? pCall->iResult : ERROR_OPERATION_ABORTED);
			goto done;
		}

		pBthNsHandle->pClientBuf = pCall->pClientBuf;
		pBthNsHandle->cClientBuf = pCall->cClientBuf;
		pBthNsHandle->fNetSearchComplete  = TRUE;
		pCall->pClientBuf      = NULL;
		pCall->cClientBuf      = 0;
	}

	if (!pBthNsHandle->cClientBuf) {
		SVSUTIL_ASSERT(!pBthNsHandle->pClientBuf);
		iRes = WSA_E_NO_MORE;
		goto done;
	}
	cbRequired = pBthNsHandle->cClientBuf + sizeof(WSAQUERYSET) + sizeof(BLOB);

	if (*lpdwBufferLength < cbRequired || !pResults) {
		IFDBG(DebugOut(DEBUG_ERROR,L"BthNsLookupServiceNext: WSA_NOT_ENOUGH_MEMORY.  *lpdwBufferLength=%d,cbRequired=%d\r\n",*lpdwBufferLength,cbRequired));
		*lpdwBufferLength = cbRequired;
		iRes =  WSA_NOT_ENOUGH_MEMORY;
		goto done;
	}

	*lpdwBufferLength = cbRequired;
	pBthNsHandle->fNoMoreData = TRUE;

#if defined (UNDER_CE)
    memset(pResults,0,sizeof(WSAQUERYSETA));
	pResults->dwSize      = sizeof(WSAQUERYSETA);
	pResults->dwNameSpace = NS_BTH;
	pResults->lpBlob = (LPBLOB) ((char*)pResults + sizeof(WSAQUERYSET));
	pResults->lpBlob->cbSize    = pBthNsHandle->cClientBuf;
	pResults->lpBlob->pBlobData = (PBYTE) ((char*)pResults->lpBlob + sizeof(BLOB));

	if (pBthNsHandle->pClientBuf)
		memcpy(pResults->lpBlob->pBlobData,pBthNsHandle->pClientBuf,pBthNsHandle->cClientBuf);
#endif

	iRes = ERROR_SUCCESS;
done:

#if defined (DEBUG) || defined (_DEBUG)
	if (iRes != ERROR_SUCCESS)
		IFDBG(DebugOut(DEBUG_ERROR,L"BthNsLookupServiceNext:: fails, err=0x%08x\r\n",iRes));
#endif

	if (fDisconnect) {
		SDPDisconnect(pCall,cid);
		SVSUTIL_ASSERT(gpBthNS->IsLocked());
	}

	if (pBthNsHandle)
		pBthNsHandle->pCall = NULL;

	if (pCall)
		DeleteCall(pCall);

	if (iRes != ERROR_SUCCESS) {
		SetLastError(iRes);
		iRes = SOCKET_ERROR;
	}

	gpBthNS->Unlock();
	return iRes;
}

int BthNsLookupServiceEnd(HANDLE hLookup)  {
	IFDBG(DebugOut(DEBUG_SDP_TRACE,L"BthNsLookupServiceEnd entered\r\n"));

	if (!gpBthNS) {
		IFDBG(DebugOut(DEBUG_ERROR,L"BthNsLookupServiceNext:: ERROR_SERVICE_DOES_NOT_EXIST\r\n"));
		SetLastError(WSASERVICE_NOT_FOUND);
		return SOCKET_ERROR;
	}

	gpBthNS->Lock();

	if (gpBthNS->eStage != Running) {
		IFDBG(DebugOut(DEBUG_ERROR,L"BthNsLookupServiceNext:: ERROR_SERVICE_NOT_ACTIVE\r\n"));
		gpBthNS->Unlock();
		SetLastError(WSASERVICE_NOT_FOUND);
		return SOCKET_ERROR;
	}

	int fCancelInquiry = ((DWORD)hLookup == BTHNS_ABORT_CURRENT_INQUIRY);

	if (fCancelInquiry) {
		gpBthNS->Unlock();
		BthCancelInquiry ();

		return ERROR_SUCCESS;
	}

	BthNsHandle *pBthNsHandle = FindBthNsHandle((BthNsHandle *) hLookup);

	if (pBthNsHandle) {
		if (pBthNsHandle->fInquiryStatus == INQUIRY_INPROGRESS)
			fCancelInquiry = TRUE;

		// If the call is currently executing then terminate it.
		if (pBthNsHandle->pCall)
			SetEvent(pBthNsHandle->pCall->hEvent);

		DeleteBthNsHandle(pBthNsHandle);
	}

	gpBthNS->Unlock();

	if (!pBthNsHandle) {
		SetLastError(WSA_INVALID_HANDLE);
		return SOCKET_ERROR;
	}

	if (fCancelInquiry)
		BthCancelInquiry ();

	return ERROR_SUCCESS;
}

// BthNsHandleback functions
static int bthns_Connect_Out(void *pBthNsHandleContext, unsigned long status, unsigned short cid)  {
	if (!gpBthNS) {
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_Connect_Out:: ERROR_SERVICE_DOES_NOT_EXIST\r\n"));
		return ERROR_SERVICE_DOES_NOT_EXIST;
	}
	gpBthNS->Lock();

	if (gpBthNS->eStage != Running) {
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_Connect_Out:: ERROR_SERVICE_NOT_ACTIVE\r\n"));
		gpBthNS->Unlock();
		return ERROR_SERVICE_NOT_ACTIVE;
	}
	
	Call *pCall = FindCall ((Call*) pBthNsHandleContext);
	if (pCall) {
		pCall->iResult = status;
		pCall->cid     = cid;
		SetEvent(pCall->hEvent);
	}

	gpBthNS->Unlock();
	return ERROR_SUCCESS;
}

static int bthns_Disconnect_Out(void *pBthNsHandleContext, unsigned long status) {
	if (!gpBthNS) {
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_Connect_Out:: ERROR_SERVICE_DOES_NOT_EXIST\r\n"));
		return ERROR_SERVICE_DOES_NOT_EXIST;
	}
	gpBthNS->Lock();

	if (gpBthNS->eStage != Running) {
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_Connect_Out:: ERROR_SERVICE_NOT_ACTIVE\r\n"));
		gpBthNS->Unlock();
		return ERROR_SERVICE_NOT_ACTIVE;
	}
	
	Call *pCall = FindCall ((Call*) pBthNsHandleContext);
	if (pCall)
		SetEvent(pCall->hEvent);

	gpBthNS->Unlock();
	return ERROR_SUCCESS;
}

static int bthns_ServiceSearch_Out(void *pBthNsHandleContext, unsigned long status, unsigned short cReturnedHandles, unsigned long *pHandles)  {
	IFDBG(DebugOut(DEBUG_SDP_TRACE,L"bthns_ServiceSearch_Out pContext=0x%08x, status=%d, cRetHandles=%d, pHandles=0x%08x\r\n",
	                              pBthNsHandleContext, status, cReturnedHandles, pHandles));

	int iRet = ERROR_INTERNAL_ERROR;
	BOOL fFreeLock = FALSE;
	Call *pCall;

#if defined (DEBUG) || defined (_DEBUG)
	if (pHandles && cReturnedHandles)  {
		int i;

		for (i = 0; i < cReturnedHandles; i++)
			IFDBG(DebugOut(DEBUG_SDP_PACKETS,L"SDP Handle[%d] = 0x%08x\r\n",i,pHandles[i]));
	}
#endif

	if (!gpBthNS) {
		iRet = ERROR_SERVICE_DOES_NOT_EXIST;
		goto done;
	}

	gpBthNS->Lock();
	fFreeLock = TRUE;

	if (gpBthNS->eStage != Running) {
		iRet = ERROR_SERVICE_NOT_ACTIVE;
		goto done;
	}

	if (NULL == (pCall = FindCall ((Call*) pBthNsHandleContext)))  {
		iRet = ERROR_INVALID_PARAMETER;
		goto done;
	}
	pCall->iResult    = status;
	pCall->cClientBuf = cReturnedHandles * sizeof (DWORD);
	pCall->pClientBuf = (unsigned char*) pHandles;
	SetEvent(pCall->hEvent);
	iRet = ERROR_SUCCESS;
done:

#if defined (DEBUG) || defined (_DEBUG)
	if (iRet != ERROR_SUCCESS)
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_ServiceSearch_Out: 0x%08x\r\n",iRet));
#endif

	if (iRet != ERROR_SUCCESS && pHandles) {
		ExFreePool(pHandles);
	}
	if (fFreeLock)
		gpBthNS->Unlock();
	
	return iRet;
}

static int bthns_AttributeSearch_Out(void *pBthNsHandleContext, unsigned long status, unsigned char *pOutBuf, unsigned long cOutBuf) {
	IFDBG(DebugOut(DEBUG_SDP_TRACE,L"bthns_AttributeSearch_Out pContext=0x%08x, status=%d, pOutBuf=0x%08x, cOutBuf=0x%08x\r\n",
	                              pBthNsHandleContext, status, pOutBuf, cOutBuf));


	int iRet = ERROR_INTERNAL_ERROR;
	BOOL fFreeLock = FALSE;
	Call *pCall;

	if (!gpBthNS) {
		iRet = ERROR_SERVICE_DOES_NOT_EXIST;
		goto done;
	}
	gpBthNS->Lock();
	fFreeLock = TRUE;

	if (gpBthNS->eStage != Running) {
		iRet = ERROR_SERVICE_NOT_ACTIVE;
		goto done;
	}

	if (NULL == (pCall = FindCall((Call*) pBthNsHandleContext)))  {
		iRet = ERROR_INVALID_PARAMETER;
		goto done;
	}
	pCall->iResult    = status;
	pCall->pClientBuf = pOutBuf;
	pCall->cClientBuf = cOutBuf;
	SetEvent(pCall->hEvent);
	iRet = ERROR_SUCCESS;
done:

#if defined (DEBUG) || defined (_DEBUG)
	if (iRet != ERROR_SUCCESS)
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_AttributeSearch_Out: 0x%08x\r\n",iRet));
#endif

	if (iRet != ERROR_SUCCESS && pOutBuf) {
		ExFreePool(pOutBuf);
	}
	if (fFreeLock)
		gpBthNS->Unlock();	
	
	return iRet;
}

static int bthns_ServiceAttributeSearch_Out(void *pBthNsHandleContext, unsigned long status, unsigned char *pOutBuf, unsigned long cOutBuf) {
	IFDBG(DebugOut(DEBUG_SDP_TRACE,L"bthns_ServiceAttributeSearch_Out pContext=0x%08x, status=%d, pOutBuf=0x%08x, cOutBuf=0x%08x\r\n",
	                              pBthNsHandleContext, status, pOutBuf, cOutBuf));

	int iRet = ERROR_INTERNAL_ERROR;
	BOOL fFreeLock = FALSE;
	Call *pCall;

	if (!gpBthNS) {
		iRet = ERROR_SERVICE_DOES_NOT_EXIST;
		goto done;
	}
	gpBthNS->Lock();
	fFreeLock = TRUE;

	if (gpBthNS->eStage != Running) {
		iRet = ERROR_SERVICE_NOT_ACTIVE;
		goto done;
	}
	if (NULL == (pCall = FindCall((Call*) pBthNsHandleContext)))  {
		iRet = ERROR_INVALID_PARAMETER;
		goto done;
	}
	pCall->iResult    = status;
	pCall->pClientBuf = pOutBuf;
	pCall->cClientBuf = cOutBuf;
	SetEvent(pCall->hEvent);
	iRet = ERROR_SUCCESS;
done:

#if defined (DEBUG) || defined (_DEBUG)
	if (iRet != ERROR_SUCCESS)
		IFDBG(DebugOut(DEBUG_ERROR,L"bthns_AttributeSearch_Out: 0x%08x\r\n",iRet));
#endif

	if (iRet != ERROR_SUCCESS && pOutBuf) {
		ExFreePool(pOutBuf);
	}

	if (fFreeLock)
		gpBthNS->Unlock();
	
	return iRet;
}

#if defined (UNDER_CE)

BOOL       g_fNameSpaceInstalled = FALSE;
HINSTANCE  g_hWS2Lib             = NULL;
typedef int (WINAPI *PFN_WSCINSTALLNAMESPACE) (LPWSTR lpszIdentifier, LPWSTR lpszPathName, DWORD dwNameSpace, DWORD dwVersion, LPGUID lpProviderId);
typedef int (WINAPI *PFN_WSCUNINSTALLNAMESPACE) (LPGUID lpProviderId);


// {371AE22A-2144-4b26-94D8-90C47DD240D0}
static const GUID NsId = {0x371ae22a, 0x2144, 0x4b26, {0x94, 0xd8, 0x90, 0xc4, 0x7d, 0xd2, 0x40, 0xd0}};

// to install in the 1st place, WCSInstallNameSpace().  Only if ws2.dll is installed.
WCHAR szProviderName[] = L"Windows CE Bluetooth Name Space Provider";
WCHAR szProviderPath[] = L"btdrt.dll";

// Installs BTHNS as a Winsock 2 name space provider if Winsock 2 is installed.
void sdp_LoadWSANameSpaceProvider(void) {
	if (g_fNameSpaceInstalled)
		return;

	// wether we suceeed or fail, never run through this code again.
	g_fNameSpaceInstalled = TRUE;

	g_hWS2Lib = LoadLibrary(L"ws2.dll");
	if (!g_hWS2Lib)
		return;

	PFN_WSCINSTALLNAMESPACE pfnInstall = (PFN_WSCINSTALLNAMESPACE) GetProcAddress(g_hWS2Lib,L"WSCInstallNameSpace");
	if (!pfnInstall) {
		SVSUTIL_ASSERT(0);
		return;
	}

	pfnInstall(szProviderName,szProviderPath,NS_BTH,0,(GUID*)&NsId);
}

void sdp_UnLoadWSANameSpaceProvider(void) {
	if (!g_hWS2Lib)
		return;

	PFN_WSCUNINSTALLNAMESPACE pfnUnInstall = (PFN_WSCUNINSTALLNAMESPACE) GetProcAddress(g_hWS2Lib,L"WSCUninstallNameSpace");
	if (!pfnUnInstall) {
		SVSUTIL_ASSERT(0);
		return;
	}

	pfnUnInstall((GUID*)&NsId);
	FreeLibrary(g_hWS2Lib);

	g_hWS2Lib                = NULL;
	g_fNameSpaceInstalled    = FALSE;
}
#endif // UNDER_CE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -