27
|
1 |
// Copyright (c) 2006-2010 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 |
//
|
|
15 |
|
|
16 |
/**
|
|
17 |
@file
|
|
18 |
@internalComponent
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include "hciserverrequestmgr.h"
|
|
22 |
#include "HciCorePluginImpl.h"
|
|
23 |
#include "corehciutil.h"
|
|
24 |
|
|
25 |
#include <bluetooth/hci/hciipc.h>
|
|
26 |
#include <bluetooth/hci/vendordebugcommand.h>
|
|
27 |
#include <bluetooth/hci/vendordebugcompleteevent.h>
|
|
28 |
#include <bluetooth/hci/vendordebugevent.h>
|
|
29 |
|
|
30 |
#include <bluetooth/hcicommandqueueclient.h>
|
|
31 |
#include <bluetooth/hcicommandqueue.h>
|
|
32 |
#include <bluetooth/btpowercontrol.h>
|
|
33 |
#include <bluetooth/dutmode.h>
|
|
34 |
#include <bluetooth/a2dpoptimisation.h>
|
|
35 |
#include <bluetooth/a2dpoptimisationparams.h>
|
|
36 |
|
|
37 |
#include <bluetooth/logger.h>
|
|
38 |
#include <bluetooth/btpowercontrolmessages.h>
|
|
39 |
|
|
40 |
#include <es_sock.h>
|
|
41 |
#include <bt_sock.h>
|
|
42 |
|
|
43 |
#ifdef __FLOG_ACTIVE
|
|
44 |
_LIT8(KLogComponent, LOG_COMPONENT_HCISERVER);
|
|
45 |
#endif
|
|
46 |
|
|
47 |
const TInt KHCIServerIpcDesOutParam = 2;
|
|
48 |
|
|
49 |
void CHCIServerRequestManager::BlockAsync(CHCISession& aSession, const RMessage2& aMessage)
|
|
50 |
{
|
|
51 |
LOG_FUNC
|
|
52 |
|
|
53 |
iAsyncTaskMessage = aMessage;
|
|
54 |
iAsyncTaskSession = &aSession;
|
|
55 |
iBlockMask |= MaskBit();
|
|
56 |
}
|
|
57 |
|
|
58 |
void CHCIServerRequestManager::CompleteAsyncTask(TInt aError)
|
|
59 |
{
|
|
60 |
LOG_FUNC
|
|
61 |
|
|
62 |
//check message is not already complete
|
|
63 |
if(iAsyncTaskMessage.Handle())
|
|
64 |
{
|
|
65 |
iAsyncTaskMessage.Complete(aError);
|
|
66 |
}
|
|
67 |
else
|
|
68 |
{
|
|
69 |
__ASSERT_DEBUG(EFalse, PANIC(KHciServerPanicCat, EMessageAlreadyCompleted));
|
|
70 |
}
|
|
71 |
|
|
72 |
// Remove Async block
|
|
73 |
iAsyncTaskSession = 0;
|
|
74 |
iBlockMask &= ~MaskBit();
|
|
75 |
}
|
|
76 |
|
|
77 |
TBool CHCIServerRequestManager::IsAsyncBlocked()
|
|
78 |
{
|
|
79 |
LOG_FUNC
|
|
80 |
|
|
81 |
return (iBlockMask & MaskBit());
|
|
82 |
}
|
|
83 |
|
|
84 |
CHCIServerRequestManager::CHCIServerRequestManager(CCoreHCIPluginImpl& aHCI)
|
|
85 |
: iHCI(aHCI)
|
|
86 |
{
|
|
87 |
LOG_FUNC
|
|
88 |
}
|
|
89 |
|
|
90 |
void CHCIServerRequestManager::ConstructL()
|
|
91 |
{
|
|
92 |
LOG_FUNC
|
|
93 |
}
|
|
94 |
|
|
95 |
void CHCIServerRequestManager::ServiceL(CHCISession& aSession, const RMessage2& aMessage)
|
|
96 |
{
|
|
97 |
if(aMessage.Function() == EServiceSpecificRequest)
|
|
98 |
{
|
|
99 |
if(HasCapabilities(aMessage))
|
|
100 |
{
|
|
101 |
DoServiceL(aSession, aMessage);
|
|
102 |
}
|
|
103 |
// else HasCapabilities failed (and has dealt with aMessage).
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
// The client has issued a bad HCI Server request, we only expect a server specific
|
|
108 |
// request to be made (the specific request being encoded in the TIpcArgs).
|
|
109 |
PanicClient(aMessage, EUnknownHciServerFunction);
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
//
|
|
114 |
// HCI Direct Access Service
|
|
115 |
//
|
|
116 |
CHCIDirectAccessManager* CHCIDirectAccessManager::NewL(CCoreHCIPluginImpl& aHCI)
|
|
117 |
{
|
|
118 |
LOG_STATIC_FUNC
|
|
119 |
|
|
120 |
CHCIDirectAccessManager* self = new (ELeave) CHCIDirectAccessManager(aHCI);
|
|
121 |
CleanupStack::PushL(self);
|
|
122 |
self->ConstructL();
|
|
123 |
CleanupStack::Pop(self);
|
|
124 |
return self;
|
|
125 |
}
|
|
126 |
|
|
127 |
void CHCIDirectAccessManager::SetHCICommandQueue(MHCICommandQueue& aHCICommandQueue)
|
|
128 |
{
|
|
129 |
LOG_FUNC
|
|
130 |
|
|
131 |
__ASSERT_ALWAYS(!iHCICommandQueue, PANIC(KCoreHciPanicCat, EInterfaceAlreadyInitialised));
|
|
132 |
iHCICommandQueue = &aHCICommandQueue;
|
|
133 |
}
|
|
134 |
|
|
135 |
/*virtual*/ TBool CHCIDirectAccessManager::HasCapabilities(const RMessage2& aMessage)
|
|
136 |
{
|
|
137 |
LOG_FUNC
|
|
138 |
|
|
139 |
TBool allowed = EFalse;
|
|
140 |
|
|
141 |
switch (aMessage.Int0())
|
|
142 |
{
|
|
143 |
case KHCIDirectAccessVendorCommand:
|
|
144 |
// Drop through
|
|
145 |
case KHCIDirectAccessCancel: // requires Network Control + Local Services
|
|
146 |
allowed = aMessage.HasCapability(ECapabilityNetworkControl) && aMessage.HasCapability(ECapabilityLocalServices);
|
|
147 |
break;
|
|
148 |
|
|
149 |
default:
|
|
150 |
PanicClient(aMessage, EUnknownDirectAccessFunction);
|
|
151 |
return EFalse;
|
|
152 |
}
|
|
153 |
|
|
154 |
if(!allowed)
|
|
155 |
{
|
|
156 |
aMessage.Complete(KErrPermissionDenied);
|
|
157 |
}
|
|
158 |
|
|
159 |
return allowed;
|
|
160 |
}
|
|
161 |
|
|
162 |
/*virtual*/ void CHCIDirectAccessManager::DoServiceL(CHCISession& aSession, const RMessage2& aMessage)
|
|
163 |
{
|
|
164 |
LOG_FUNC
|
|
165 |
|
|
166 |
TInt request = aMessage.Int0();
|
|
167 |
|
|
168 |
switch (request)
|
|
169 |
{
|
|
170 |
case KHCIDirectAccessCancel:
|
|
171 |
if (iAsyncTaskSession != &aSession)
|
|
172 |
{
|
|
173 |
return; //drop - not for current async task
|
|
174 |
}
|
|
175 |
|
|
176 |
// clear cache
|
|
177 |
iMessage = NULL;
|
|
178 |
|
|
179 |
// perform cancellation procedure
|
|
180 |
CompleteAsyncTask(KErrCancel);
|
|
181 |
break;
|
|
182 |
|
|
183 |
case KHCIDirectAccessVendorCommand:
|
|
184 |
{
|
|
185 |
if (IsAsyncBlocked())
|
|
186 |
{
|
|
187 |
aMessage.Complete(KErrInUse);
|
|
188 |
return;
|
|
189 |
}
|
|
190 |
|
|
191 |
const TInt len = User::LeaveIfError(aMessage.GetDesLength(1));
|
|
192 |
|
|
193 |
// Check the Vendor Command is at least 3 bytes long for the opcode
|
|
194 |
// and the length
|
|
195 |
if (len < 3)
|
|
196 |
{
|
|
197 |
PanicClient(aMessage, EInvalidVendorCommand);
|
|
198 |
break;
|
|
199 |
}
|
|
200 |
|
|
201 |
HBufC8* buf = HBufC8::NewLC(len);
|
|
202 |
TPtr8 params(buf->Des());
|
|
203 |
aMessage.ReadL(1, params);
|
|
204 |
|
|
205 |
// Extract the opcode and create the new command
|
|
206 |
TUint16 opcode = LittleEndian::Get16(params.Ptr());
|
|
207 |
|
|
208 |
if (iHCICommandQueue)
|
|
209 |
{
|
|
210 |
CVendorDebugCommand* cmd = CVendorDebugCommand::NewL(opcode);
|
|
211 |
|
|
212 |
// Remove the opcode and length from the Vendor Command parameters,
|
|
213 |
// these will be added again to the command frame once it has been
|
|
214 |
// formatted
|
|
215 |
cmd->Command() = params.RightTPtr(params.Length() - 3);
|
|
216 |
|
|
217 |
// cmd will be deleted in MhcqAddCommandL if Leaves.
|
|
218 |
TUint qid = iHCICommandQueue->MhcqAddCommandL(cmd, *this);
|
|
219 |
|
|
220 |
// Block only after we succeed in adding a command.
|
|
221 |
BlockAsync(aSession, aMessage);
|
|
222 |
|
|
223 |
// Cache to return completion data to client
|
|
224 |
iMessage = &aMessage;
|
|
225 |
}
|
|
226 |
else
|
|
227 |
{
|
|
228 |
// Slight possible race that a request is made before we have been
|
|
229 |
// given the command queue to work with - so don't panic just error.
|
|
230 |
aMessage.Complete(KErrNotReady);
|
|
231 |
}
|
|
232 |
CleanupStack::PopAndDestroy(buf);
|
|
233 |
}
|
|
234 |
break;
|
|
235 |
|
|
236 |
default:
|
|
237 |
// Unknown message, panic client
|
|
238 |
PanicClient(aMessage, EUnknownDirectAccessFunction);
|
|
239 |
break;
|
|
240 |
}
|
|
241 |
}
|
|
242 |
|
|
243 |
/*virtual*/ void CHCIDirectAccessManager::MhcqcCommandErrored(TInt aErrorCode, const CHCICommandBase* /*aCommand*/)
|
|
244 |
{
|
|
245 |
LOG_FUNC
|
|
246 |
|
|
247 |
// clear cache
|
|
248 |
iMessage = NULL;
|
|
249 |
|
|
250 |
CompleteAsyncTask(aErrorCode);
|
|
251 |
}
|
|
252 |
|
|
253 |
/*virtual*/ void CHCIDirectAccessManager::MhcqcCommandEventReceived(const THCIEventBase& aEvent, const CHCICommandBase* aCommand)
|
|
254 |
{
|
|
255 |
LOG_FUNC
|
|
256 |
|
|
257 |
// We are not the unmatched event observer therefore we must always get a
|
|
258 |
// command
|
|
259 |
__ASSERT_DEBUG(aCommand, PANIC(KCoreHciPanicCat, EReceivedUnmatchedEvent));
|
|
260 |
|
|
261 |
// It is possible to receive an event but not have a message to complete. This
|
|
262 |
// could happen if a request was cancelled after a Vendor Specific command was
|
|
263 |
// sent, in this case we do nothing.
|
|
264 |
if (iMessage)
|
|
265 |
{
|
|
266 |
TInt err = KErrNone;
|
|
267 |
|
|
268 |
const THCIEventCode eventcode(aEvent.EventCode());
|
|
269 |
switch(eventcode)
|
|
270 |
{
|
|
271 |
case ECommandCompleteEvent:
|
|
272 |
{
|
|
273 |
if ((aCommand->Opcode() & KVendorDebugOGF) == KVendorDebugOGF)
|
|
274 |
{
|
|
275 |
const TVendorDebugCompleteEvent& event = TVendorDebugCompleteEvent::Cast(aEvent);
|
|
276 |
|
|
277 |
// Return the event
|
|
278 |
err = iMessage->Write(KHCIServerIpcDesOutParam, event.VendorDebugData());
|
|
279 |
}
|
|
280 |
else
|
|
281 |
{
|
|
282 |
__ASSERT_DEBUG(EFalse, PANIC(KHciServerPanicCat, ENonVendorOpcodeCompleted));
|
|
283 |
}
|
|
284 |
}
|
|
285 |
break;
|
|
286 |
|
|
287 |
case EVendorDebugEvent:
|
|
288 |
{
|
|
289 |
const TVendorDebugEvent& event = TVendorDebugEvent::Cast(aEvent);
|
|
290 |
|
|
291 |
// Return the event
|
|
292 |
err = iMessage->Write(KHCIServerIpcDesOutParam, event.VendorDebugData());
|
|
293 |
}
|
|
294 |
break;
|
|
295 |
|
|
296 |
default:
|
|
297 |
__ASSERT_DEBUG(EFalse, PANIC(KCoreHciPanicCat, EReceivedUnknownEvent));
|
|
298 |
break;
|
|
299 |
}
|
|
300 |
|
|
301 |
CompleteAsyncTask(err);
|
|
302 |
}
|
|
303 |
}
|
|
304 |
|
|
305 |
/*virtual*/ void CHCIDirectAccessManager::CompleteAsyncTask(TInt aError)
|
|
306 |
{
|
|
307 |
LOG_FUNC
|
|
308 |
|
|
309 |
if (!IsAsyncBlocked())
|
|
310 |
{
|
|
311 |
return; //drop
|
|
312 |
}
|
|
313 |
|
|
314 |
CHCIServerRequestManager::CompleteAsyncTask(aError);
|
|
315 |
}
|
|
316 |
|
|
317 |
CHCIDirectAccessManager::CHCIDirectAccessManager(CCoreHCIPluginImpl& aHCI)
|
|
318 |
: CHCIServerRequestManager(aHCI)
|
|
319 |
{
|
|
320 |
LOG_FUNC
|
|
321 |
}
|
|
322 |
|
|
323 |
|
|
324 |
TUint CHCIDirectAccessManager::MaskBit() const
|
|
325 |
{
|
|
326 |
LOG_FUNC
|
|
327 |
|
|
328 |
return EHCIDirectAccessMaskBit;
|
|
329 |
}
|
|
330 |
|
|
331 |
//
|
|
332 |
// Power Control Service
|
|
333 |
//
|
|
334 |
CBTPowerControlManager* CBTPowerControlManager::NewL(CCoreHCIPluginImpl& aHCI)
|
|
335 |
{
|
|
336 |
LOG_STATIC_FUNC
|
|
337 |
|
|
338 |
CBTPowerControlManager* self = new (ELeave) CBTPowerControlManager(aHCI);
|
|
339 |
CleanupStack::PushL(self);
|
|
340 |
self->ConstructL();
|
|
341 |
CleanupStack::Pop(self);
|
|
342 |
return self;
|
|
343 |
}
|
|
344 |
|
|
345 |
TBool CBTPowerControlManager::HasCapabilities(const RMessage2& aMessage)
|
|
346 |
{
|
|
347 |
LOG_FUNC
|
|
348 |
|
|
349 |
TBool allowed(EFalse);
|
|
350 |
|
|
351 |
switch (aMessage.Int0())
|
|
352 |
{
|
|
353 |
case KHCICancelPower:
|
|
354 |
// fall through
|
|
355 |
case EHCISetPower: // requires Network Control + Local Services
|
|
356 |
allowed = aMessage.HasCapability(ECapabilityNetworkControl) && aMessage.HasCapability(ECapabilityLocalServices);
|
|
357 |
break;
|
|
358 |
|
|
359 |
case EHCIGetPower: // requires Local Services
|
|
360 |
allowed = aMessage.HasCapability(ECapabilityLocalServices);
|
|
361 |
break;
|
|
362 |
|
|
363 |
default:
|
|
364 |
PanicClient(aMessage, EUnknownPowerControlFunction);
|
|
365 |
return EFalse;
|
|
366 |
}
|
|
367 |
|
|
368 |
if(!allowed)
|
|
369 |
{
|
|
370 |
aMessage.Complete(KErrPermissionDenied);
|
|
371 |
}
|
|
372 |
|
|
373 |
return allowed;
|
|
374 |
}
|
|
375 |
|
|
376 |
/*virtual*/ void CBTPowerControlManager::DoServiceL(CHCISession& aSession, const RMessage2& aMessage)
|
|
377 |
{
|
|
378 |
LOG_FUNC
|
|
379 |
|
|
380 |
TInt request = aMessage.Int0();
|
|
381 |
TInt err;
|
|
382 |
TBTPowerState state;
|
|
383 |
|
|
384 |
switch (request)
|
|
385 |
{
|
|
386 |
case KHCICancelPower:
|
|
387 |
if(iAsyncTaskSession!=&aSession)
|
|
388 |
{
|
|
389 |
return; //drop - not for current async task
|
|
390 |
}
|
|
391 |
|
|
392 |
//perform cancellation procedure
|
|
393 |
CompleteAsyncTask(KErrCancel);
|
|
394 |
break;
|
|
395 |
|
|
396 |
case EHCISetPower:
|
|
397 |
if(IsAsyncBlocked())
|
|
398 |
{
|
|
399 |
aMessage.Complete(KErrInUse);
|
|
400 |
return;
|
|
401 |
}
|
|
402 |
|
|
403 |
//Should be called before set power because it could complete synchronously
|
|
404 |
BlockAsync(aSession, aMessage);
|
|
405 |
state = static_cast<TBTPowerState>(aMessage.Int3());
|
|
406 |
err = iHCI.SetPower(state, NULL);
|
|
407 |
if(err != KErrNone)
|
|
408 |
{
|
|
409 |
CompleteAsyncTask(err);
|
|
410 |
return;
|
|
411 |
}
|
|
412 |
break;
|
|
413 |
|
|
414 |
case EHCIGetPower:
|
|
415 |
{
|
|
416 |
err = iHCI.GetPower(state, NULL);
|
|
417 |
if(err != KErrNone)
|
|
418 |
{
|
|
419 |
aMessage.Complete(err);
|
|
420 |
return;
|
|
421 |
}
|
|
422 |
|
|
423 |
TPckg<TBTPowerState> pckg(state);
|
|
424 |
TRAP(err, aMessage.WriteL(EPSStateReturnSlot, pckg));
|
|
425 |
aMessage.Complete(err);
|
|
426 |
}
|
|
427 |
break; //synchronous so do not block
|
|
428 |
|
|
429 |
default:
|
|
430 |
// Unknown message
|
|
431 |
PanicClient(aMessage, EUnknownPowerControlFunction);
|
|
432 |
break;
|
|
433 |
}
|
|
434 |
}
|
|
435 |
|
|
436 |
/*virtual*/ void CBTPowerControlManager::CompleteAsyncTask(TInt aError)
|
|
437 |
{
|
|
438 |
LOG_FUNC
|
|
439 |
|
|
440 |
if(!IsAsyncBlocked())
|
|
441 |
{
|
|
442 |
return; //drop
|
|
443 |
}
|
|
444 |
|
|
445 |
CHCIServerRequestManager::CompleteAsyncTask(aError);
|
|
446 |
}
|
|
447 |
|
|
448 |
void CBTPowerControlManager::CompleteRequest(TInt aError)
|
|
449 |
{
|
|
450 |
CompleteAsyncTask(aError);
|
|
451 |
}
|
|
452 |
|
|
453 |
CBTPowerControlManager::CBTPowerControlManager(CCoreHCIPluginImpl& aHCI)
|
|
454 |
: CHCIServerRequestManager(aHCI)
|
|
455 |
{
|
|
456 |
LOG_FUNC
|
|
457 |
}
|
|
458 |
|
|
459 |
|
|
460 |
TUint CBTPowerControlManager::MaskBit() const
|
|
461 |
{
|
|
462 |
LOG_FUNC
|
|
463 |
|
|
464 |
return EBTPowerControlMaskBit;
|
|
465 |
}
|
|
466 |
|
|
467 |
//
|
|
468 |
// Bluetooth HCI Utils Service
|
|
469 |
//
|
|
470 |
CBluetoothDutModeManager* CBluetoothDutModeManager::NewL(CCoreHCIPluginImpl& aHCI)
|
|
471 |
{
|
|
472 |
LOG_STATIC_FUNC
|
|
473 |
|
|
474 |
CBluetoothDutModeManager* self = new (ELeave) CBluetoothDutModeManager(aHCI);
|
|
475 |
CleanupStack::PushL(self);
|
|
476 |
self->ConstructL();
|
|
477 |
CleanupStack::Pop(self);
|
|
478 |
return self;
|
|
479 |
}
|
|
480 |
|
|
481 |
TBool CBluetoothDutModeManager::HasCapabilities(const RMessage2& aMessage)
|
|
482 |
{
|
|
483 |
LOG_FUNC
|
|
484 |
|
|
485 |
TBool allowed(EFalse);
|
|
486 |
|
|
487 |
switch (aMessage.Int0())
|
|
488 |
{
|
|
489 |
case RBluetoothDutMode::EHCIActivateDutMode:
|
|
490 |
// fall through
|
|
491 |
case RBluetoothDutMode::EHCIDeactivateDutMode: // requires Network Control + Local Services
|
|
492 |
allowed = aMessage.HasCapability(ECapabilityNetworkControl) && aMessage.HasCapability(ECapabilityLocalServices);
|
|
493 |
break;
|
|
494 |
|
|
495 |
default:
|
|
496 |
PanicClient(aMessage, EUnknownBluetoothDutModeFunction);
|
|
497 |
return EFalse;
|
|
498 |
}
|
|
499 |
|
|
500 |
if(!allowed)
|
|
501 |
{
|
|
502 |
aMessage.Complete(KErrPermissionDenied);
|
|
503 |
}
|
|
504 |
|
|
505 |
return allowed;
|
|
506 |
}
|
|
507 |
|
|
508 |
/*virtual*/ void CBluetoothDutModeManager::DoServiceL(CHCISession& /*aSession*/, const RMessage2& aMessage)
|
|
509 |
{
|
|
510 |
LOG_FUNC
|
|
511 |
|
|
512 |
TInt request = aMessage.Int0();
|
|
513 |
TInt err = KErrNotSupported;
|
|
514 |
|
|
515 |
switch (request)
|
|
516 |
{
|
|
517 |
case RBluetoothDutMode::EHCIActivateDutMode:
|
|
518 |
// Implementation is adaptation specific and therefore not supported in our reference HCI Server
|
|
519 |
LOG(_L("EHCIActivateDutMode"));
|
|
520 |
aMessage.Complete(err);
|
|
521 |
break;
|
|
522 |
|
|
523 |
case RBluetoothDutMode::EHCIDeactivateDutMode:
|
|
524 |
// Implementation is adaptation specific and therefore not supported in our reference HCI Server
|
|
525 |
LOG(_L("EHCIDeactivateDutMode"));
|
|
526 |
aMessage.Complete(err);
|
|
527 |
break;
|
|
528 |
|
|
529 |
default:
|
|
530 |
// Unknown message
|
|
531 |
PanicClient(aMessage, EUnknownBluetoothDutModeFunction);
|
|
532 |
break;
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
CBluetoothDutModeManager::CBluetoothDutModeManager(CCoreHCIPluginImpl& aHCI)
|
|
537 |
: CHCIServerRequestManager(aHCI)
|
|
538 |
{
|
|
539 |
LOG_FUNC
|
|
540 |
}
|
|
541 |
|
|
542 |
|
|
543 |
TUint CBluetoothDutModeManager::MaskBit() const
|
|
544 |
{
|
|
545 |
LOG_FUNC
|
|
546 |
|
|
547 |
return EBluetoothDutModeMaskBit;
|
|
548 |
}
|
|
549 |
|
|
550 |
//
|
|
551 |
// A2DP Optimiser Service
|
|
552 |
//
|
|
553 |
CA2dpOptimiserManager* CA2dpOptimiserManager::NewL(CCoreHCIPluginImpl& aHCI)
|
|
554 |
{
|
|
555 |
LOG_STATIC_FUNC
|
|
556 |
|
|
557 |
CA2dpOptimiserManager* self = new (ELeave) CA2dpOptimiserManager(aHCI);
|
|
558 |
CleanupStack::PushL(self);
|
|
559 |
self->ConstructL();
|
|
560 |
CleanupStack::Pop(self);
|
|
561 |
return self;
|
|
562 |
}
|
|
563 |
|
|
564 |
TBool CA2dpOptimiserManager::HasCapabilities(const RMessage2& aMessage)
|
|
565 |
{
|
|
566 |
LOG_FUNC
|
|
567 |
|
|
568 |
TBool allowed(EFalse);
|
|
569 |
|
|
570 |
switch (aMessage.Int0())
|
|
571 |
{
|
|
572 |
case RA2dpOptimiser::EHCIA2dpOptimiseAcl:
|
|
573 |
// fall through
|
|
574 |
case RA2dpOptimiser::EHCIA2dpRemoveAclOptimisation: // requires Network Control + Local Services
|
|
575 |
allowed = aMessage.HasCapability(ECapabilityNetworkControl) && aMessage.HasCapability(ECapabilityLocalServices);
|
|
576 |
break;
|
|
577 |
|
|
578 |
default:
|
|
579 |
PanicClient(aMessage, EUnknownA2dpOptimiserFunction);
|
|
580 |
return EFalse;
|
|
581 |
}
|
|
582 |
|
|
583 |
if(!allowed)
|
|
584 |
{
|
|
585 |
aMessage.Complete(KErrPermissionDenied);
|
|
586 |
}
|
|
587 |
|
|
588 |
return allowed;
|
|
589 |
}
|
|
590 |
|
|
591 |
/*virtual*/ void CA2dpOptimiserManager::DoServiceL(CHCISession& /*aSession*/, const RMessage2& aMessage)
|
|
592 |
{
|
|
593 |
LOG_FUNC
|
|
594 |
|
|
595 |
TInt request = aMessage.Int0();
|
|
596 |
TInt err = KErrNotSupported;
|
|
597 |
TBuf<20> targetAddrBuf;
|
|
598 |
|
|
599 |
switch (request)
|
|
600 |
{
|
|
601 |
case RA2dpOptimiser::EHCIA2dpOptimiseAcl:
|
|
602 |
// Implementation is adaptation specific and therefore not supported in our reference HCI Server
|
|
603 |
if (aMessage.GetDesLength(1) == sizeof(TA2dpOptimisationParams))
|
|
604 |
{
|
|
605 |
TPckgBuf<TA2dpOptimisationParams> args;
|
|
606 |
|
|
607 |
aMessage.ReadL(1, args);
|
|
608 |
args().RemoteDeviceAddress().GetReadable(targetAddrBuf);
|
|
609 |
LOG3(_L("EHCIA2dpOptimiseAcl BT Addr: %S, Peak Bandwidth: %d, Access Latency: %d\n"),
|
|
610 |
&targetAddrBuf, args().PeakBandwidth(), args().AccessLatency());
|
|
611 |
|
|
612 |
aMessage.Complete(err);
|
|
613 |
}
|
|
614 |
else
|
|
615 |
{
|
|
616 |
PanicClient(aMessage, EInvalidArgument);
|
|
617 |
}
|
|
618 |
break;
|
|
619 |
|
|
620 |
case RA2dpOptimiser::EHCIA2dpRemoveAclOptimisation:
|
|
621 |
// Implementation is adaptation specific and therefore not supported in our reference HCI Server
|
|
622 |
if (aMessage.GetDesLength(1) == sizeof(TBTDevAddr))
|
|
623 |
{
|
|
624 |
TPckgBuf<TBTDevAddr> addrBuf;
|
|
625 |
|
|
626 |
aMessage.ReadL(1, addrBuf);
|
|
627 |
addrBuf().GetReadable(targetAddrBuf);
|
|
628 |
LOG1(_L("EHCIA2dpRemoveAclOptimisation BT Addr: %S\n"), &targetAddrBuf);
|
|
629 |
|
|
630 |
aMessage.Complete(err);
|
|
631 |
}
|
|
632 |
else
|
|
633 |
{
|
|
634 |
PanicClient(aMessage, EInvalidArgument);
|
|
635 |
}
|
|
636 |
break;
|
|
637 |
|
|
638 |
default:
|
|
639 |
// Unknown message
|
|
640 |
PanicClient(aMessage, EUnknownA2dpOptimiserFunction);
|
|
641 |
break;
|
|
642 |
}
|
|
643 |
}
|
|
644 |
|
|
645 |
CA2dpOptimiserManager::CA2dpOptimiserManager(CCoreHCIPluginImpl& aHCI)
|
|
646 |
: CHCIServerRequestManager(aHCI)
|
|
647 |
{
|
|
648 |
LOG_FUNC
|
|
649 |
}
|
|
650 |
|
|
651 |
|
|
652 |
TUint CA2dpOptimiserManager::MaskBit() const
|
|
653 |
{
|
|
654 |
LOG_FUNC
|
|
655 |
|
|
656 |
return EA2dpOptimiserMaskBit;
|
|
657 |
}
|
|
658 |
|