1 #ifndef _HCI_H_
2 #define _HCI_H_
3 
4 #include <windows.h>
5 
6 #include "fbthw.h"
7 #include "fbtHciDefs.h"
8 
9 // Number of overlapped requests to have pending in the driver
10 #define HCI_NUMBER_OF_OVERLAPPED_LISTENS	MAXIMUM_WAIT_OBJECTS-1
11 
12 // HCI Abstraction layer
13 class CHci;
14 typedef struct
15 {
16 	PFBT_HCI_EVENT_HEADER		pEvent;
17 	DWORD						dwLength;
18 	CHci						*pThis;
19 
20 } HCI_EVENT, *PHCI_EVENT;
21 
22 class CHci : public CBTHW
23 {
24 public:
25 	CHci(void);
26 	virtual ~CHci(void);
27 
28 	virtual DWORD StartEventListener(void);
29 	virtual DWORD StopEventListener(void);
30     virtual DWORD OnEvent(PFBT_HCI_EVENT_HEADER pEvent, DWORD Length);
31 
32 	static LPCTSTR GetEventText(BYTE Event);
33 	static LPCTSTR GetStatusText(BYTE Status);
34 	static LPCTSTR GetManufacturerName(USHORT Company);
35 
36     virtual DWORD OnCommandComplete(BYTE NumHCICommandPackets, USHORT CommandOpcode, BYTE *Parameters, DWORD ParameterLength);
37     virtual DWORD OnCommandStatus(BYTE Status, BYTE NumHCICommandPackets, USHORT CommandOpcode);
38 
39     virtual DWORD OnConnectionRequest(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], ULONG ClassOfDevice[FBT_HCI_DEVICE_CLASS_SIZE], BYTE LinkType);
40     virtual DWORD OnConnectionComplete(BYTE Status, USHORT ConnectionHandle, BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE LinkType, BYTE EncryptionMode);
41     virtual DWORD OnDisconnectionComplete(BYTE Status, USHORT ConnectionHandle, BYTE Reason);
42 
43     virtual DWORD OnInquiryComplete(BYTE Status, BYTE NumResponses);
44     virtual DWORD OnInquiryResult(BYTE NumResponses, BYTE BD_ADDR[FBT_HCI_VARIABLE_SIZE][FBT_HCI_BDADDR_SIZE], BYTE PageScanRepetitionMode[FBT_HCI_VARIABLE_SIZE], BYTE PageScanPeriodMode[FBT_HCI_VARIABLE_SIZE], BYTE PageScanMode[FBT_HCI_VARIABLE_SIZE], BYTE ClassOfDevice[FBT_HCI_VARIABLE_SIZE][FBT_HCI_DEVICE_CLASS_SIZE], USHORT ClockOffset[FBT_HCI_VARIABLE_SIZE]);
45 
46     virtual DWORD OnRemoteNameRequestComplete(BYTE Status, BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE RemoteName[FBT_HCI_NAME_SIZE]);
47 
48     virtual DWORD OnRoleChange(BYTE Status, BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE Role);
49 
50     virtual DWORD OnPINCodeRequest(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE]);
51 
52 	virtual DWORD OnLinkKeyNotification(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE LinkKey[FBT_HCI_LINK_KEY_SIZE]);
53     virtual DWORD OnLinkKeyRequest(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE]);
54 
55 	virtual DWORD OnAuthenticationComplete(BYTE Status, USHORT ConnectionHandle);
56 
57 	virtual DWORD OnReadLocalNameComplete(BYTE Status, BYTE Name[FBT_HCI_NAME_SIZE]);
58 
59     virtual DWORD OnUnknown(PFBT_HCI_EVENT_HEADER pEvent, DWORD Length);
60 
61     virtual DWORD SendReset(void);
62 
63     virtual DWORD SendInquiry(ULONG LAP, BYTE InquiryLength, BYTE NumResponses);
64     virtual DWORD SendInquiryCancel(void);
65 
66     virtual DWORD SendReadBDADDR(void);
67 
68     virtual DWORD SendWriteScanEnable(BYTE ScanEnable);
69 
70     virtual DWORD SendWriteAuthenticationEnable(BYTE ScanEnable);
71 
72     virtual DWORD SendSetEventFilter(BYTE FilterType,
73                                      BYTE FilterConditionType,
74                                      BYTE Condition[FBT_HCI_MAX_CONDITION_SIZE],
75 									 BYTE ConditionBytes);
76 
77     virtual DWORD SendReadClassOfDevice(void);
78 
79     virtual DWORD SendWriteClassOfDevice(BYTE ClassOfDevice[FBT_HCI_DEVICE_CLASS_SIZE]);
80 
81     virtual DWORD SendCreateConnection(BYTE		BD_ADDR[FBT_HCI_BDADDR_SIZE],
82                                        USHORT	PacketType,
83                                        BYTE		PageScanRepetitionMode,
84                                        BYTE		PageScanMode,
85                                        USHORT	ClockOffset,
86                                        BYTE		AllowRoleSwitch);
87 
88     virtual DWORD SendAcceptConnectionRequest(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE RoleSwitch);
89 
90     virtual DWORD SendDisconnect(USHORT ConnectionHandle, BYTE  Reason);
91 
92     virtual DWORD SendWriteLinkSupervisionTimeout(USHORT ConnectionHandle, USHORT LinkSupervisionTimeout);
93 
94     virtual DWORD SendWritePageTimeout(USHORT PageTimeout);
95 
96     virtual DWORD SendRemoteNameRequest(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE PageScanRepetitionMode, BYTE PageScanMode, USHORT ClockOffset);
97 
98     virtual DWORD SendReadLocalName(void);
99 
100     virtual DWORD SendChangeLocalName(BYTE Name[FBT_HCI_NAME_SIZE]);
101 
102 	virtual DWORD SendSwitchRole(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE Role);
103 
104 	virtual DWORD SendPINCodeRequestReply(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE PINCodeLength, BYTE PINCode[FBT_HCI_PIN_CODE_SIZE]);
105 	virtual DWORD SendPINCodeRequestNegativeReply(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE]);
106 
107 	virtual DWORD SendLinkKeyRequestReply(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE LinkKey[FBT_HCI_LINK_KEY_SIZE]);
108 	virtual DWORD SendLinkKeyRequestNegativeReply(BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE]);
109 
110 	virtual DWORD SendReadLocalVersionInformation(void);
111 
112 	DWORD CompareBDADDRs(BYTE BD_ADDR1[FBT_HCI_BDADDR_SIZE], BYTE BD_ADDR2[FBT_HCI_BDADDR_SIZE]);
113 
114 protected:
115 	friend static DWORD CALLBACK Listener(LPVOID pContext);
116 	friend static DWORD EventHandler(PFBT_HCI_EVENT_HEADER pEvent, DWORD Length);
117 
118 	virtual DWORD SendHciCommand(PFBT_HCI_CMD_HEADER lpCommand, DWORD dwBufferSize);
119 
120     DWORD SendListenForEvent(OVERLAPPED *pOverlapped, BYTE *pEventBuffer);
121 
122     HANDLE	m_hStopListeningEvent;
123     HANDLE	m_hListenerReadyEvent;
124     HANDLE	m_hListenerThread;
125 
126     DWORD	m_dwListenerThreadId;
127 
128     OVERLAPPED  m_Overlappeds[HCI_NUMBER_OF_OVERLAPPED_LISTENS];
129     BYTE		m_pEventBuffers[HCI_NUMBER_OF_OVERLAPPED_LISTENS][FBT_HCI_EVENT_MAX_SIZE];
130 
131 };
132 
133 
134 #endif // _HCI_H_
135