|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Generic functions for direct HCI access (licensee-specific) |
|
15 // |
|
16 // |
|
17 |
|
18 #include "HCIDirectAccess.h" |
|
19 |
|
20 #include <bt_sock.h> |
|
21 #include <bluetooth/hci/hciipc.h> |
|
22 |
|
23 # include <bluetooth/hciserverclient.h> |
|
24 #include <bthci.h> |
|
25 |
|
26 /** |
|
27 Constructor |
|
28 */ |
|
29 EXPORT_C RHCIDirectAccess::RHCIDirectAccess() |
|
30 : iHCIServerSession(NULL) |
|
31 , iSocketAccess(NULL) |
|
32 { |
|
33 } |
|
34 |
|
35 /** |
|
36 Close the HCIDirectAccess. |
|
37 */ |
|
38 EXPORT_C void RHCIDirectAccess::Close() |
|
39 { |
|
40 if(iHCIServerSession) |
|
41 { |
|
42 iHCIServerSession->Close(); |
|
43 delete iHCIServerSession; |
|
44 iHCIServerSession = NULL; |
|
45 } |
|
46 } |
|
47 |
|
48 /** |
|
49 Open a direct interface between the application layer and the HCI for |
|
50 custom messages. |
|
51 @return Error code |
|
52 @publishedAll |
|
53 @released |
|
54 @capability LocalServices |
|
55 */ |
|
56 EXPORT_C TInt RHCIDirectAccess::Open() |
|
57 { |
|
58 TInt err = KErrNoMemory; |
|
59 iHCIServerSession = new RHCIServerSession; |
|
60 if(iHCIServerSession) |
|
61 { |
|
62 err = iHCIServerSession->Open(KHCIDirectAccessManagerUid); |
|
63 if(err != KErrNone) |
|
64 { |
|
65 delete iHCIServerSession; |
|
66 iHCIServerSession = NULL; |
|
67 } |
|
68 } |
|
69 return err; |
|
70 } |
|
71 |
|
72 /** |
|
73 Open a direct interface between the application layer and the HCI for |
|
74 custom messages. This method exists for backwards compatability. The |
|
75 ESock session is not used. |
|
76 @param aSocketServ ESock session |
|
77 @return Error code |
|
78 @capability LocalServices |
|
79 */ |
|
80 EXPORT_C TInt RHCIDirectAccess::Open(RSocketServ& /*aSocketServ*/) |
|
81 { |
|
82 return Open(); |
|
83 } |
|
84 |
|
85 /** |
|
86 Applies an asynchronous control operation on the HCI. |
|
87 |
|
88 Data may be passed and received if a descriptor address is provided as an argument. |
|
89 Only one Ioctl() operation may be outstanding for each RHCIDirectAccess. |
|
90 |
|
91 @see RSocket::Ioctl(TUint aCommand,TRequestStatus &aStatus,TDes8* aDesc,TUint aLevel) |
|
92 @param aCommand Ioctl command. |
|
93 @param aStatus Status parameter for asynchronous request |
|
94 @param aDesc Pointer to a descriptor in which data may be sent and received on completion. |
|
95 @param aLevel Control operation level. Should be KSolBtHCI for this API |
|
96 */ |
|
97 EXPORT_C void RHCIDirectAccess::Ioctl(TUint aCommand, TRequestStatus& aStatus, TDes8* aDesc,TUint aLevel) |
|
98 { |
|
99 if(!iHCIServerSession) |
|
100 { |
|
101 TRequestStatus* status = &aStatus; |
|
102 User::RequestComplete(status, KErrNotSupported); |
|
103 return; |
|
104 } |
|
105 |
|
106 iHCIServerSession->SendAsync(aCommand, aDesc, NULL, aLevel, aStatus); |
|
107 } |
|
108 |
|
109 /** |
|
110 Cancels the Ioctl() asynchronous control operation. |
|
111 @see RSocket::CancelIoctl() |
|
112 */ |
|
113 EXPORT_C void RHCIDirectAccess::CancelIoctl() |
|
114 { |
|
115 if(!iHCIServerSession) |
|
116 { |
|
117 return; |
|
118 } |
|
119 |
|
120 iHCIServerSession->SendSync(KHCIDirectAccessCancel, NULL, NULL, 0); |
|
121 } |
|
122 |
|
123 /** |
|
124 Applies an asynchronous control operation on the HCI. |
|
125 |
|
126 Data may be passed and received if a descriptor address is provided as an argument. |
|
127 Only one AsyncMessage operation may be outstanding for each RHCIDirectAccess. |
|
128 |
|
129 @param aCommand Message identifier. |
|
130 @param aStatus Status parameter for asynchronous request |
|
131 @param aDesc Pointer to a descriptor in which data may be sent and received on completion. |
|
132 */ |
|
133 EXPORT_C void RHCIDirectAccess::AsyncMessage(TUint aCommand, TRequestStatus& aStatus, TDes8* aDesc) |
|
134 { |
|
135 if(!iHCIServerSession) |
|
136 { |
|
137 TRequestStatus* status = &aStatus; |
|
138 User::RequestComplete(status, KErrNotSupported); |
|
139 return; |
|
140 } |
|
141 |
|
142 iHCIServerSession->SendAsync(aCommand, aDesc, NULL, 0, aStatus); |
|
143 } |
|
144 |
|
145 /** |
|
146 Cancels the Ioctl() asynchronous control operation. |
|
147 @see RSocket::CancelIoctl() |
|
148 */ |
|
149 EXPORT_C void RHCIDirectAccess::CancelAsyncMessage() |
|
150 { |
|
151 if(iHCIServerSession) |
|
152 { |
|
153 return; |
|
154 } |
|
155 |
|
156 iHCIServerSession->SendSync(KHCIDirectAccessCancel, NULL, NULL, 0); |
|
157 } |
|
158 |
|
159 /** |
|
160 Originally a getter for the sub-session handle. |
|
161 This facility has now been removed. |
|
162 @deprecated |
|
163 @return Always return zero |
|
164 */ |
|
165 EXPORT_C TInt RHCIDirectAccess::SubSessionHandle() |
|
166 { |
|
167 return 0; |
|
168 } |