|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This class holds the HCI Extension Conduit singleton |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32cmn.h> |
|
22 #include "BTSapHciExtensionMan.h" |
|
23 #include "debug.h" |
|
24 |
|
25 // CONSTANT |
|
26 |
|
27 /** |
|
28 * A prefix patch in all commands for compatible reason with stack |
|
29 */ |
|
30 const TUint8 KHciExtensionCmdPatch[] = {0xFC, 0x00, 0x00}; |
|
31 |
|
32 /** |
|
33 * Common prerfix of additional functionality command |
|
34 */ |
|
35 const TUint8 KHciExtensionCmdCommomPrefix[] = {0x00, 0xFC}; |
|
36 |
|
37 /** |
|
38 * Command Channel ID (Type of command) |
|
39 */ |
|
40 // Channel Id of additional functionality command |
|
41 const TUint KHciExtensionFunctionalityChannelID = 0xF0; |
|
42 |
|
43 /** |
|
44 * Command opcode and parameter total length |
|
45 */ |
|
46 // ENCRYPTION_KEY_LENGTH_READ_CMD |
|
47 const TUint8 KEncryptionKeyLengthReadOpcode = 0x07; |
|
48 |
|
49 const TInt KEncryptionKeyLengthReadCmdParamLen = 8; |
|
50 |
|
51 /** |
|
52 * Event constants |
|
53 */ |
|
54 const TInt KHciExtensionEventIndexOfOpcode = 2; |
|
55 |
|
56 const TInt KEncryptionKeyLengthReadEventLen = 6; |
|
57 |
|
58 // DATA TYPES |
|
59 |
|
60 // ================= MEMBER FUNCTIONS ======================= |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CBTHciExtensionMan::NewL() |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CBTHciExtensionMan* CBTHciExtensionMan::NewL() |
|
67 { |
|
68 CBTHciExtensionMan* self = new (ELeave) CBTHciExtensionMan(); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(); |
|
72 return self; |
|
73 } |
|
74 |
|
75 // Destructor. |
|
76 CBTHciExtensionMan::~CBTHciExtensionMan() |
|
77 { |
|
78 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::~CBTHciExtensionMan >>"))); |
|
79 if (iConduit) |
|
80 { |
|
81 iConduit->StopWaitingForEvent(); |
|
82 delete iConduit; |
|
83 } |
|
84 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::~CBTHciExtensionMan <<"))); |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------- |
|
88 // CBTHciExtensionMan::HandleReqeustL |
|
89 // --------------------------------------------------------- |
|
90 // |
|
91 void CBTHciExtensionMan::GetEncryptionKeyLengthL(const TBTDevAddr& aBTDevAddr, TRequestStatus& aStatus) |
|
92 { |
|
93 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::HandleRequestL >>"))); |
|
94 |
|
95 TInt err = KErrNone; |
|
96 aStatus = KRequestPending; |
|
97 iStatus = &aStatus; |
|
98 |
|
99 CBTHciExtensionCmd* cmd = NULL; |
|
100 TBTDevAddrPckgBuf pckg; |
|
101 pckg = aBTDevAddr; |
|
102 |
|
103 cmd = CBTHciExtensionCmd::NewLC(KEncryptionKeyLengthReadOpcode); |
|
104 |
|
105 cmd->SetParamL(pckg().Des()); |
|
106 |
|
107 if (err == KErrNone) |
|
108 { |
|
109 iRequestOpcode = cmd->Opcode(); |
|
110 TPtrC8 ptr = cmd->DesC(); |
|
111 TUint16 requestOpcode = ptr[0] << 8 | ptr[1]; |
|
112 err = iConduit->IssueCommandL(requestOpcode, ptr.Mid(sizeof(KHciExtensionCmdPatch))); |
|
113 if (err) |
|
114 { |
|
115 BTSAP_TRACE_OPT(KBTSAP_TRACE_ERROR, BTSapPrintTrace(_L("[BTSap] iConduit->IssueCommandL err %d"), err)); |
|
116 } |
|
117 } |
|
118 else |
|
119 { |
|
120 User::RequestComplete(iStatus, err); |
|
121 } |
|
122 if (cmd) |
|
123 { |
|
124 CleanupStack::PopAndDestroy(cmd); |
|
125 } |
|
126 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::HandleRequestL <<"))); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------- |
|
130 // CBTHciExtensionMan::GetResultL |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 TInt CBTHciExtensionMan::GetResultL(TUint8& aKeyLength) |
|
134 { |
|
135 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::GetResultL: enc key length: %d"),iKeyLength )); |
|
136 if ( iStatus && iStatus->Int() == KRequestPending ) |
|
137 { |
|
138 return KErrNotReady; |
|
139 } |
|
140 |
|
141 aKeyLength = iKeyLength; |
|
142 return KErrNone; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------- |
|
146 // CBTHciExtensionMan::CancelRequest |
|
147 // --------------------------------------------------------- |
|
148 // |
|
149 void CBTHciExtensionMan::CancelRequest() |
|
150 { |
|
151 iConduit->StopWaitingForEvent(); |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CBTHciExtensionMan::CommandCompleted |
|
156 // --------------------------------------------------------- |
|
157 // |
|
158 void CBTHciExtensionMan::CommandCompleted(TInt aError) |
|
159 { |
|
160 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::CommandCompleted(%d)"), aError)); |
|
161 if(aError == KErrNone) |
|
162 { |
|
163 aError = iConduit->WaitForEvent(); |
|
164 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::CommandCompleted, iConduit->WaitForEvent %d"), aError)); |
|
165 } |
|
166 if (aError != KErrNone) |
|
167 { |
|
168 User::RequestComplete(iStatus, aError); |
|
169 } |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------- |
|
173 // CBTHciExtensionMan::ReceiveEvent |
|
174 // --------------------------------------------------------- |
|
175 // |
|
176 TBool CBTHciExtensionMan::ReceiveEvent(TDesC8& aEvent, TInt aError) |
|
177 { |
|
178 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::ReceiveEvent(aError %d) >>"), aError)); |
|
179 if (aError != KErrNone) |
|
180 { |
|
181 User::RequestComplete(iStatus, aError); |
|
182 return EFalse; |
|
183 } |
|
184 |
|
185 CBTHciExtensionCmdEvent* event = NULL; |
|
186 TInt err; |
|
187 TRAP(err, event = CBTHciExtensionCmdEvent::NewL(aEvent)); |
|
188 if (!event) |
|
189 { |
|
190 User::RequestComplete(iStatus, err); |
|
191 return EFalse; |
|
192 } |
|
193 if (event->Opcode() != iRequestOpcode) |
|
194 { |
|
195 User::RequestComplete(iStatus, KErrArgument); |
|
196 delete event; |
|
197 return EFalse; |
|
198 } |
|
199 switch (iRequestOpcode) |
|
200 { |
|
201 case KEncryptionKeyLengthReadOpcode: |
|
202 { |
|
203 TPtrC8 desptr = event->DesC(); |
|
204 iKeyLength = desptr[desptr.Length() - 1]; |
|
205 err = KErrNone; |
|
206 break; |
|
207 } |
|
208 default: |
|
209 { |
|
210 err = KErrNotSupported; |
|
211 break; |
|
212 } |
|
213 } |
|
214 delete event; |
|
215 User::RequestComplete(iStatus, err); |
|
216 |
|
217 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::ReceiveEvent %d <<"), err)); |
|
218 return EFalse; |
|
219 } |
|
220 |
|
221 // --------------------------------------------------------- |
|
222 // CBTHciExtensionMan::ConstructL |
|
223 // --------------------------------------------------------- |
|
224 // |
|
225 void CBTHciExtensionMan::ConstructL() |
|
226 { |
|
227 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::ConstructL >>"))); |
|
228 iConduit = CHciExtensionConduit::NewL(*this); |
|
229 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionMan::ConstructL, iConduit %d <<"), iConduit)); |
|
230 } |
|
231 |
|
232 // --------------------------------------------------------- |
|
233 // CBTHciExtensionMan::CBTHciExtensionMan |
|
234 // --------------------------------------------------------- |
|
235 // |
|
236 CBTHciExtensionMan::CBTHciExtensionMan(): iKeyLength(0) |
|
237 { |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------- |
|
241 // CBTHciExtensionCmd::NewL |
|
242 // --------------------------------------------------------- |
|
243 // |
|
244 CBTHciExtensionCmd* CBTHciExtensionCmd::NewL(TUint8 aOpcode) |
|
245 { |
|
246 CBTHciExtensionCmd* self = CBTHciExtensionCmd::NewLC(aOpcode); |
|
247 CleanupStack::Pop(); |
|
248 return self; |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CBTHciExtensionCmd::NewLC |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 CBTHciExtensionCmd* CBTHciExtensionCmd::NewLC(TUint8 aOpcode) |
|
256 { |
|
257 CBTHciExtensionCmd* self = new (ELeave) CBTHciExtensionCmd(aOpcode); |
|
258 CleanupStack::PushL(self); |
|
259 self->ConstructL(); |
|
260 return self; |
|
261 } |
|
262 |
|
263 // Destructor. |
|
264 CBTHciExtensionCmd::~CBTHciExtensionCmd() |
|
265 { |
|
266 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::~CBTHciExtensionCmd >>"))); |
|
267 delete iCmdDes; |
|
268 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::~CBTHciExtensionCmd <<"))); |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------- |
|
272 // CBTHciExtensionCmd::Opcode |
|
273 // --------------------------------------------------------- |
|
274 // |
|
275 TUint8 CBTHciExtensionCmd::Opcode() const |
|
276 { |
|
277 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::Opcode %d >>"), iOpcode)); |
|
278 return iOpcode; |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------- |
|
282 // CBTHciExtensionCmd::CmdDesC |
|
283 // --------------------------------------------------------- |
|
284 // |
|
285 TPtrC8 CBTHciExtensionCmd::DesC() const |
|
286 { |
|
287 return iCmdDes->Des(); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------- |
|
291 // CBTHciExtensionCmd::SetParamL |
|
292 // --------------------------------------------------------- |
|
293 // |
|
294 void CBTHciExtensionCmd::SetParamL(const TDesC8& aParam) |
|
295 { |
|
296 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::SetParamL param len %d >>"), aParam.Length())); |
|
297 TInt length = aParam.Length(); |
|
298 if (length != iParamTotalLength - 2) |
|
299 { |
|
300 User::Leave(KErrArgument); |
|
301 } |
|
302 iCmdDes->Des().Replace(iCmdLength - length, length, aParam); |
|
303 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::SetParamL <<"))); |
|
304 } |
|
305 |
|
306 // --------------------------------------------------------- |
|
307 // CBTHciExtensionCmd::CBTHciExtensionCmd |
|
308 // --------------------------------------------------------- |
|
309 // |
|
310 CBTHciExtensionCmd::CBTHciExtensionCmd(TUint8 aOpcode) |
|
311 : iOpcode(aOpcode) |
|
312 { |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------- |
|
316 // CBTHciExtensionCmd::ConstructL |
|
317 // --------------------------------------------------------- |
|
318 // |
|
319 void CBTHciExtensionCmd::ConstructL() |
|
320 { |
|
321 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::ConstructL >>"))); |
|
322 switch (iOpcode) |
|
323 { |
|
324 case KEncryptionKeyLengthReadOpcode: |
|
325 { |
|
326 iChannelID = KHciExtensionFunctionalityChannelID; |
|
327 iParamTotalLength = KEncryptionKeyLengthReadCmdParamLen; |
|
328 iCmdLength = sizeof(KHciExtensionCmdPatch) + |
|
329 sizeof(KHciExtensionCmdCommomPrefix) + iParamTotalLength + 1; |
|
330 break; |
|
331 } |
|
332 default: |
|
333 User::Leave(KErrArgument); |
|
334 } |
|
335 InitializeCmdDesL(); |
|
336 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::ConstructL <<"))); |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------- |
|
340 // CBTHciExtensionCmd::InitializeCmdDesL |
|
341 // --------------------------------------------------------- |
|
342 // |
|
343 void CBTHciExtensionCmd::InitializeCmdDesL() |
|
344 { |
|
345 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::InitializeCmdDesL >>"))); |
|
346 iCmdDes = HBufC8::NewL(iCmdLength); |
|
347 TPtr8 cmdPtr = iCmdDes->Des(); |
|
348 cmdPtr.Append(KHciExtensionCmdPatch, sizeof(KHciExtensionCmdPatch)); |
|
349 cmdPtr.Append(KHciExtensionCmdCommomPrefix, sizeof(KHciExtensionCmdCommomPrefix)); |
|
350 cmdPtr.Append(iParamTotalLength); |
|
351 cmdPtr.Append(iChannelID); |
|
352 cmdPtr.Append(iOpcode); |
|
353 cmdPtr.AppendFill(0, iParamTotalLength - 2); |
|
354 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmd::InitializeCmdDesL, len %d <<"), cmdPtr.Length())); |
|
355 } |
|
356 |
|
357 CBTHciExtensionCmdEvent* CBTHciExtensionCmdEvent::NewL(const TDesC8& aEvent) |
|
358 { |
|
359 CBTHciExtensionCmdEvent* self = CBTHciExtensionCmdEvent::NewLC(aEvent); |
|
360 CleanupStack::Pop(); |
|
361 return self; |
|
362 } |
|
363 |
|
364 CBTHciExtensionCmdEvent* CBTHciExtensionCmdEvent::NewLC(const TDesC8& aEvent) |
|
365 { |
|
366 CBTHciExtensionCmdEvent* self = new (ELeave) CBTHciExtensionCmdEvent(); |
|
367 CleanupStack::PushL(self); |
|
368 self->ConstructL(aEvent); |
|
369 return self; |
|
370 } |
|
371 |
|
372 CBTHciExtensionCmdEvent::~CBTHciExtensionCmdEvent() |
|
373 { |
|
374 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmdEvent::~CBTHciExtensionCmdEvent >>"))); |
|
375 delete iEventDes; |
|
376 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmdEvent::~CBTHciExtensionCmdEvent <<"))); |
|
377 } |
|
378 |
|
379 TUint8 CBTHciExtensionCmdEvent::Opcode() const |
|
380 { |
|
381 return (*iEventDes)[KHciExtensionEventIndexOfOpcode]; |
|
382 } |
|
383 |
|
384 TPtrC8 CBTHciExtensionCmdEvent::DesC() const |
|
385 { |
|
386 return iEventDes->Des(); |
|
387 } |
|
388 |
|
389 CBTHciExtensionCmdEvent::CBTHciExtensionCmdEvent() |
|
390 { |
|
391 } |
|
392 |
|
393 void CBTHciExtensionCmdEvent::ConstructL(const TDesC8& aEvent) |
|
394 { |
|
395 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmdEvent::ConstructL len %d >>"), aEvent.Length())); |
|
396 if (aEvent.Length() > KHciExtensionEventIndexOfOpcode) |
|
397 { |
|
398 TInt desLength = 0; |
|
399 // Get the opcode of this event |
|
400 TUint8 opcode = aEvent[KHciExtensionEventIndexOfOpcode]; |
|
401 BTSAP_TRACE_OPT(KBTSAP_TRACE_INFO, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmdEvent::ConstructL opcode %d >>"), opcode)); |
|
402 switch (opcode) |
|
403 { |
|
404 case KEncryptionKeyLengthReadOpcode: |
|
405 { |
|
406 if (aEvent.Length() != KEncryptionKeyLengthReadEventLen) |
|
407 { |
|
408 User::Leave(KErrArgument); |
|
409 } |
|
410 desLength = KEncryptionKeyLengthReadEventLen; |
|
411 break; |
|
412 } |
|
413 default: |
|
414 User::Leave(KErrNotSupported); |
|
415 } |
|
416 iEventDes = HBufC8::NewL(desLength); |
|
417 TPtr8 ptr = iEventDes->Des(); |
|
418 ptr.Append(aEvent); |
|
419 } |
|
420 else |
|
421 { |
|
422 User::Leave(KErrArgument); |
|
423 } |
|
424 BTSAP_TRACE_OPT(KBTSAP_TRACE_FUNCTIONS, BTSapPrintTrace(_L("[BTSap] CBTHciExtensionCmdEvent::ConstructL <<"))); |
|
425 } |
|
426 |
|
427 // End of File |