|
1 // Copyright (c) 2007-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 "hctlusboriginalaclin.h" |
|
22 |
|
23 #include "hctlusboriginal.h" |
|
24 #include "hctlusboriginalutils.h" |
|
25 |
|
26 // These files are included to get HCI specification defined constants. |
|
27 #include <bluetooth/hci/hciframe.h> |
|
28 #include <bluetooth/hci/event.h> |
|
29 |
|
30 #include <bluetooth/logger.h> |
|
31 |
|
32 #ifdef __FLOG_ACTIVE |
|
33 _LIT8(KLogComponent, LOG_COMPONENT_HCTL_USB_ORIGINAL); |
|
34 #endif |
|
35 |
|
36 |
|
37 CHCTLUsbOriginalAclIn::CHCTLUsbOriginalAclIn(CHCTLUsbOriginal& aHCTLUsbOriginal, RUsbInterface& aInterface) |
|
38 : CActive(EPriorityStandard) |
|
39 , iHCTLUsbOriginal(aHCTLUsbOriginal) |
|
40 , iInterface(aInterface) |
|
41 , iTransfer(CHctlAclDataFrame::KHCTLMaxACLDataSize) |
|
42 { |
|
43 LOG_FUNC |
|
44 CActiveScheduler::Add(this); |
|
45 } |
|
46 |
|
47 CHCTLUsbOriginalAclIn::~CHCTLUsbOriginalAclIn() |
|
48 { |
|
49 LOG_FUNC |
|
50 Cancel(); |
|
51 iPipe.Close(); |
|
52 iTransfer.Close(); |
|
53 } |
|
54 |
|
55 CHCTLUsbOriginalAclIn* CHCTLUsbOriginalAclIn::NewL(CHCTLUsbOriginal& aHCTLUsbOriginal, RUsbInterface& aInterface) |
|
56 { |
|
57 LOG_STATIC_FUNC |
|
58 CHCTLUsbOriginalAclIn* self = new(ELeave) CHCTLUsbOriginalAclIn(aHCTLUsbOriginal, aInterface); |
|
59 CleanupStack::PushL(self); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop(); |
|
62 return self; |
|
63 } |
|
64 |
|
65 void CHCTLUsbOriginalAclIn::ConstructL() |
|
66 { |
|
67 LOG_FUNC |
|
68 LEAVEIFERRORL(iInterface.RegisterTransferDescriptor(iTransfer)); |
|
69 LEAVEIFERRORL(iInterface.OpenPipeForEndpoint(iPipe, KEndpointNumber, EFalse)); |
|
70 } |
|
71 |
|
72 void CHCTLUsbOriginalAclIn::QueueRead() |
|
73 { |
|
74 LOG_FUNC |
|
75 |
|
76 __ASSERT_DEBUG(!IsActive(), PANIC(KUsbOriginalPanic, EReadAttemptWhenReadOutstanding)); |
|
77 |
|
78 // I think the spec states that a single ACL packet is contained in a single USB |
|
79 // transaction. As such we don't need to mess around working out how much to read |
|
80 // we just need to issue a transfer big enough to get all the data possible. |
|
81 // Of course it is unlikely that a controller would batch up that much data - it might be |
|
82 // better to just expect a 3 DH-5 payload size instead... |
|
83 |
|
84 iTransfer.SaveData(iTransfer.WritableBuffer().MaxLength()); |
|
85 |
|
86 SetActive(); |
|
87 iPipe.Transfer(iTransfer, iStatus); |
|
88 } |
|
89 |
|
90 void CHCTLUsbOriginalAclIn::RunL() |
|
91 { |
|
92 LOG_FUNC |
|
93 // Only process the read if it has completed successfully. |
|
94 LEAVEIFERRORL(iStatus.Int()); |
|
95 iHCTLUsbOriginal.ProcessACLData(iTransfer.Buffer()); |
|
96 QueueRead(); |
|
97 } |
|
98 |
|
99 void CHCTLUsbOriginalAclIn::DoCancel() |
|
100 { |
|
101 LOG_FUNC |
|
102 iPipe.CancelAllTransfers(); |
|
103 } |
|
104 |
|
105 TInt CHCTLUsbOriginalAclIn::RunError(TInt aError) |
|
106 { |
|
107 LOG_FUNC |
|
108 LOG1(_L8("\taError = %d"), aError); |
|
109 // The HCTL can not recover from this. Reset the controller and restart the host. |
|
110 // TODO we should try to handle the case where the device is unpluged. |
|
111 iHCTLUsbOriginal.MhriStartHardReset(); |
|
112 return KErrNone; |
|
113 } |
|
114 |
|
115 void CHCTLUsbOriginalAclIn::Start() |
|
116 { |
|
117 LOG_FUNC |
|
118 __ASSERT_DEBUG(!IsActive(), PANIC(KUsbOriginalPanic, EStartCalledWhenReadOutstanding)); |
|
119 QueueRead(); |
|
120 } |