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

📄 btsdp.h

📁 三星2440原版bsp
💻 H
📖 第 1 页 / 共 2 页
字号:
    //
    // The destructor for this object is behaving oddly, removing for now
    //
    CancelableQue clientQueue;
    static VOID _QueueCancelRoutine(PVOID Context, PIRP Irp);
#endif

    union {
        struct {
            //
            // Entire request sent to the server, including the PDU.  It saved
            // off in case we multiple PDUs are required for the entire response.
            //
            PVOID pRequest;

            //
            // Size of all the parameters in the reuqest except for the 
            // continuation state
            //
            USHORT rawParametersLength;

            UCHAR lastPduRequest;

            //
            // Last client request.  If the response was too large for the 
            // requestor's buffer, we will save off the result and if the 
            // requestor sends down the same request w/the appropriately sized
            // buffer, the response will be sent back up.  For service searches,
            // we do not store off any results b/c we send the server the max amount
            // of data we can handle
            //
            SdpQueryUuid lastUuid[MAX_UUIDS_IN_QUERY];
            SdpAttributeRange *pLastRange;  
            ULONG numRange;

            struct {
                //
                // Total number of records in the response
                //
                USHORT totalRecordCount;
            } ServiceSearch;

            struct {
                //
                // The response from either an attribute of service + attribute
                // search
                //
                PUCHAR pResponse;
                ULONG responseLength;
            } AttributeSearch;
        } Client;

        struct {
            //
            // The original request sent by the client.  We store this off so that
            // when we receive another request w/a continuation state, we can match
            // up the requests
            //
            PVOID pClientRequest;
            ULONG clientRequestLength;     
            UCHAR lastPduRequest;

            //
            // Some search responses have a response pointer plus a pointer which
            // should be free (and not the response), but for simplicity, always put
            // the pointer that needs to be freed here.
            //
            PVOID pOriginalAlloc;

            //
            // Cached search results
            //
            union {
                struct {
                    PUCHAR pSearchResults;
                    ULONG resultsSize;
                } StreamSearch;

                struct {
                    PULONG pRecordsNext;
                    USHORT recordCount;
                    USHORT totalRecordCount;
                } ServiceSearch;
            };
        } Server;
    } u;

#if ! (defined (UNDER_CE) || defined (WINCE_EMULATION))
protected:

    SdpChannelState GetChannelState()
    {
        KIRQL irql;
        LockState(&irql);
        SdpChannelState state = channelState;
        UnlockState(irql);
        return state;
    }
#endif
    void CompleteClientRequest(ULONG_PTR info, NTSTATUS status);
    void CleanUpServerSearchResults();

    BOOLEAN IsRequestContinuation(
        SdpPDU *pPdu,
        PUCHAR pRequest, 
        ContinuationState *pConStateReq,
        BOOLEAN &cleanUpRequired,
        BOOLEAN &contError);

#if ! (defined (UNDER_CE) || defined (WINCE_EMULATION))
    NTSTATUS SendBrb(PBRB pBrb, PIRP pIrp = NULL);

    NTSTATUS SendBrbAsync(
        PBRB pBrb, 
        PIO_COMPLETION_ROUTINE Routine,
        PIRP pIrp = NULL,
        PVOID pContext = NULL,
        PVOID pArg1 = NULL,
        PVOID pArg2 = NULL,
        PVOID pArg3 = NULL,
        PVOID pArg4 = NULL);

    //
    // Cannot have a global struct with a constructor in a kernel mode driver so
    // CList< ... > is out of the question.  Do it the old fashioned way.
    //
    static LIST_ENTRY _TimeoutListHead;
    static KSPIN_LOCK _TimeoutListLock;
    static KTIMER _TimeoutTimer;
    static KDPC _TimeoutTimerDpc;

    static BOOLEAN _RegisterConnectionOnTimer(SdpConnection *, ULONG maxTimeout);
    static void _TimeoutTimerDpcProc(IN PKDPC Dpc, IN PVOID DeviceObject, IN PVOID Context1, IN PVOID Context2);
#endif        
};

#define SetMaxUuidsInIrp(_irp, _maxuuids) (_irp)->Tail.Overlay.DriverContext[SDP_IRP_STORAGE_UUID_MAX] = UlongToPtr(_maxuuids)
#define SetMaxRangeInIrp(_irp, _maxrange) (_irp)->Tail.Overlay.DriverContext[SDP_IRP_STORAGE_RANGE_MAX] = UlongToPtr(_maxrange)

#define GetMaxUuidsFromIrp(_irp) (UCHAR) PtrToUlong((_irp)->Tail.Overlay.DriverContext[SDP_IRP_STORAGE_UUID_MAX])
#define GetMaxRangeFromIrp(_irp) PtrToUlong((_irp)->Tail.Overlay.DriverContext[SDP_IRP_STORAGE_RANGE_MAX])


class SdpInterface {
public:
    friend SdpConnection;

    SELF_DESTRUCT

    SdpInterface();
    ~SdpInterface();

#if (defined (UNDER_CE) || defined (WINCE_EMULATION))
	static NTSTATUS ServiceSearch(SdpConnection *pCon, SdpServiceSearch *pSearch, BOOL fLocal);
	static NTSTATUS AttributeSearch(SdpConnection *pCon, SdpAttributeSearch *pSearch, BOOL fLocal);
    static NTSTATUS ServiceAndAttributeSearch(SdpConnection *pCon, SdpServiceAttributeSearch *pSearch, BOOL fLocal);

#endif // UNDER_CE

#if ! (defined (UNDER_CE) || defined (WINCE_EMULATION))
    NTSTATUS Start(BThDevice *pBthDevice);
    NTSTATUS Stop();

    //
    // BThPort DDI interface callbacks and associated member functions
    //
    static NTSTATUS Sdp_IndicationCallback(
        IN PVOID ContextIF,
        IN IndicationCode Indication,
        IN IndicationParameters * Parameters);

    NTSTATUS RemoteConnectCallback(IndicationParameters *Parameters);
    NTSTATUS EnterConfigStateCallback(IndicationParameters *Parameters,
                                      SdpConnection *pConnection);
    NTSTATUS RemoteConfigCallback(IndicationParameters *Parameters,
                                  SdpConnection *pConnection);
    NTSTATUS ConfigResponseCallback(IndicationParameters *Parameters);
    NTSTATUS EnterOpenStateCallback(IndicationParameters *Parameters,
                                    SdpConnection *pConnection);
    NTSTATUS RemoteDisconnectCallback(IndicationParameters *Parameters,
                                      SdpConnection *pConnection);
    NTSTATUS FinalCleanupCallback(IndicationParameters *Parameters,
                                  SdpConnection *pConnection);

    NTSTATUS SendConfigRequest(PIRP Irp,
                               BRB* Brb,
                               SdpConnection *Con,
                               USHORT Mtu
                               );

    void SendDisconnect(SdpConnection *pCon, PIRP pIrp, PBRB pBrb);

    static NTSTATUS ConnectRequestComplete(PDEVICE_OBJECT DeviceObject,
                                       PIRP Irp,
                                       PVOID Context);

    static NTSTATUS ConfigRequestComplete(PDEVICE_OBJECT DeviceObject,
                                          PIRP Irp,
                                          PVOID Context);

    static NTSTATUS DisconnectRequestComplete(PDEVICE_OBJECT DeviceObject,
                                              PIRP Irp,
                                              PVOID Context);



    //
    // Close cleanup
    //
    void CloseConnections(PIRP pIrp);

    //
    // IOCTL handlers
    //                              
    NTSTATUS Connect(PIRP pIrp, ULONG_PTR& info);
    NTSTATUS ServiceSearch(PIRP pIrp, ULONG_PTR& info);
    NTSTATUS AttributeSearch(PIRP pIrp, ULONG_PTR& info);
    NTSTATUS ServiceAndAttributeSearch(PIRP pIrp, ULONG_PTR& info);
    NTSTATUS Disconnect(PIRP pIrp, ULONG_PTR& info);

#endif

    //
    // PDU request crackers
    //
    static NTSTATUS CrackClientServiceSearchRequest(
        IN UCHAR *pServiceSearchRequestStream,
        IN ULONG streamSize,
        OUT UCHAR **ppSequenceStream,
        OUT ULONG *pSequenceStreamSize,
        OUT USHORT *pMaxRecordCount,
        OUT ContinuationState *pContState,
        OUT PSDP_ERROR pSdpError);

    static NTSTATUS CrackClientServiceAttributeRequest(
        IN UCHAR *pServiceAttributeRequestStream,
        IN ULONG streamSize,
        OUT ULONG *pRecordHandle,
        OUT USHORT *pMaxAttribByteCount,
        OUT UCHAR **ppAttribIdListStream,
        OUT ULONG *pAttribIdListStreamSize,
        OUT ContinuationState *pContState,
        OUT PSDP_ERROR pSdpError);

    static NTSTATUS CrackClientServiceSearchAttributeRequest(
        IN UCHAR *pServiceSearchAttributeRequestStream,
        IN ULONG streamSize,
        OUT UCHAR **ppServiceSearchSequence,
        OUT ULONG *pServiceSearchSequenceSize,
        OUT USHORT *pMaxAttributeByteCount,
        OUT UCHAR **ppAttributeIdSequence,
        OUT ULONG *pAttributeIdSequenceSize,
        OUT ContinuationState *pContState,
        OUT PSDP_ERROR pSdpError);

    //
    // PDU response crackers
    //
    static NTSTATUS CrackServerServiceSearchResponse(
        IN UCHAR *pResponseStream,
        IN ULONG streamSize,
        OUT USHORT *pTotalCount,
        OUT USHORT *pCurrentCount,
        OUT ULONG **ppHandleList,
        OUT ContinuationState *pContState,
        OUT PSDP_ERROR pSdpError);

    static NTSTATUS CrackServerServiceAttributeResponse(
        IN UCHAR *pResponseStream,
        IN ULONG streamSize,
        OUT USHORT *pByteCount,
        OUT UCHAR **ppAttributeList,
        OUT ContinuationState *pContState,
        OUT PSDP_ERROR pSdpError);

    //
    // PDU creators
    //
    static NTSTATUS CreateServiceSearchResponsePDU(
        ULONG *pRecordHandles,
        USHORT recordCount,
        USHORT totalRecordCount,
        IN ContinuationState *pContState,
        IN USHORT mtu,
        OUT UCHAR **ppResponse,
        OUT ULONG *pResponseSize,
        OUT ULONG **ppNextRecordHandles,
        OUT USHORT *pNextRecordCount,
        OUT PSDP_ERROR pSdpError
        );

    static NTSTATUS CreateServiceAttributePDU(
        IN UCHAR *pResult,
        IN ULONG resultSize,
        IN ContinuationState *pContState,
        IN USHORT maxAttribByteCount,
        IN ULONG mtu,
        OUT UCHAR **ppResponse,
        OUT ULONG *pResponseSize,
        OUT UCHAR **ppNextResult,
        OUT ULONG *pNextResultSize,
        OUT PSDP_ERROR pSdpError
        );

    static NTSTATUS CreateServiceSearchAttributePDU(
        IN UCHAR *pResult,
        IN ULONG resultSize,
        IN ContinuationState *pContState,
        IN USHORT maxAttribByteCount,
        IN USHORT mtu,
        OUT UCHAR **ppResponse,
        OUT ULONG *pResponseSize,
        OUT UCHAR **ppNextResult,
        OUT ULONG *pNextResultSize,
        OUT PSDP_ERROR pSdpError
        );


    static PSDP_NODE CreateAttributeSearchTree(SdpAttributeRange *pRange, ULONG maxRange);
    static PSDP_NODE CreateServiceSearchTree(SdpQueryUuid *pUuid, UCHAR maxUuids);

protected:
#if ! (defined (UNDER_CE) || defined (WINCE_EMULATION))
    NTSTATUS SendBrb(PBRB pBrb);

    NTSTATUS SendBrbAsync(
        PIRP pIrp,
        PBRB pBrb, 
        PIO_COMPLETION_ROUTINE Routine,
        PVOID pContext = NULL,
        PVOID pArg1 = NULL,
        PVOID pArg2 = NULL,
        PVOID pArg3 = NULL,
        PVOID pArg4 = NULL);

    NTSTATUS SendConfigRequest(PIRP pIrp,
                               BRB* pBrb,
                               SdpConnection *Con,
                               USHORT Mtu,
                               PIO_COMPLETION_ROUTINE Routine = L2CA_ConnectInd_ConfigReqComplete
                               );

    void SendDisconnect(SdpConnection *pCon,
                        PIRP pIrp,
                        PBRB pBrb,
                        PIO_COMPLETION_ROUTINE pRoutine,
                        PVOID Tag
                        );


    //
    // Naming scheme for these completion routines:
    // {Indication in which the request was sent from}{type of BRB sent}Complete
    //
    // For instance, L2CA_ConnectInd_ConnectResponseComplete means:
    //
    // the brb was sent async while processing L2CA_ConnectInd
    // the brb type that is completing is a ConnectionResponse
    //

    static NTSTATUS L2CA_ConnectInd_ConnectResponseComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);
    static NTSTATUS L2CA_ConnectInd_ConfigReqComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);
    static NTSTATUS L2CA_ConnectInd_DisconnectComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);

    static NTSTATUS L2CA_ConfigInd_ConfigComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);
    static NTSTATUS L2CA_ConfigInd_DisconnectComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);

    static NTSTATUS L2CA_DisconnectInd_DisconnectRspComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);

    static NTSTATUS ConnectRequest_ConfigReqComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);
    static NTSTATUS ConnectRequest_DisconnectComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context);

    BOOLEAN RemoveConnectionAtDpc(SdpConnection *pCon,
                                  BOOLEAN SendDisconnectRsp = FALSE,
                                  PVOID FinalTag = REASON(AcquireConnectInd));

    static void RemoveConnectionWorker(PDEVICE_OBJECT DeviceObject, PVOID Context);

    SdpConnection * FindConnection(PVOID hConnection);
    SdpConnection * FindConnection(const bt_addr& address, BOOLEAN onlyServer = FALSE);
    NTSTATUS AcquireConnection(PVOID hConnection,
                               SdpConnection** ppCon,
                               PVOID tag = NULL);
    NTSTATUS AcquireConnection(const bt_addr& btAddress,
                               SdpConnection** ppCon,
                               PVOID tag = NULL);
    NTSTATUS AcquireConnectionInternal(SdpConnection *pCon, PVOID tag);
#endif

    static NTSTATUS VerifyServiceSearch(SdpQueryUuid *pUuids, UCHAR *pMaxUuids);
    static NTSTATUS VerifyAttributeSearch(SdpAttributeRange *pRange, ULONG *pMaxRange, ULONG_PTR bufferLength);

    void FireWmiEvent(SDP_SERVER_LOG_TYPE Type, BD_ADDR *pAddress = NULL, USHORT Mtu = 0);

#if ! (defined (UNDER_CE) || defined (WINCE_EMULATION))   
    BThDevice *m_pDevice;

    CList<SdpConnection, FIELD_OFFSET(SdpConnection, entry), CSemaphore> m_SdpConnectionList;
#endif
};

NTSTATUS VerifyProtocolList(PUCHAR pStream, ULONG size, ULONG flags);

#endif // __BTSDP_H__

⌨️ 快捷键说明

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