author | mikaruus <mika.a.ruuskanen@nokia.com> |
Thu, 14 Jan 2010 10:44:58 +0200 | |
changeset 5 | 8ccc39f9d787 |
parent 0 | 63b37f68c1ce |
child 7 | fa67e03b87df |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* Copyright (c) 2009 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 the License "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 |
* |
|
16 |
*/ |
|
17 |
||
18 |
// INCLUDE FILES |
|
19 |
#include "cusbpnisareceiver.h" |
|
20 |
#include "cusbpnusbsender.h" |
|
21 |
#include "cusbpnpacket.h" |
|
22 |
#include "usbpndefinitions.h" // For constants |
|
23 |
#include "usbpntrace.h" |
|
24 |
||
5
8ccc39f9d787
New release based on our 2010wk02 release
mikaruus <mika.a.ruuskanen@nokia.com>
parents:
0
diff
changeset
|
25 |
#include "OstTraceDefinitions.h" |
0 | 26 |
#ifdef OST_TRACE_COMPILER_IN_USE |
27 |
#include "cusbpnisareceiverTraces.h" |
|
28 |
#endif |
|
29 |
||
30 |
#include <iscapi.h> // For RIscApi |
|
31 |
#include <d32usbc.h> // For RDevUsbcClient |
|
32 |
#include <phonetisi.h> // For Phonet definitions |
|
33 |
#ifndef NCP_COMMON_BRIDGE_FAMILY |
|
34 |
#include <pn_const.h> // For Resource ID |
|
35 |
#include <mediaisi.h> // For Media specific message ID |
|
36 |
#endif /* NCP_COMMON_BRIDGE_FAMILY */ |
|
37 |
||
38 |
// EXTERNAL DATA STRUCTURES |
|
39 |
// EXTERNAL FUNCTION PROTOTYPES |
|
40 |
// CONSTANTS |
|
41 |
// MACROS |
|
42 |
// LOCAL CONSTANTS AND MACROS |
|
43 |
// MODULE DATA STRUCTURES |
|
44 |
// LOCAL FUNCTION PROTOTYPES |
|
45 |
// FORWARD DECLARATIONS |
|
46 |
||
47 |
// ============================= LOCAL FUNCTIONS =============================== |
|
48 |
// ============================ MEMBER FUNCTIONS =============================== |
|
49 |
||
50 |
// ----------------------------------------------------------------------------- |
|
51 |
// CUsbPnIsaReceiver::CUsbPnIsaReceiver |
|
52 |
// C++ default constructor can NOT contain any code, that |
|
53 |
// might leave. |
|
54 |
// ----------------------------------------------------------------------------- |
|
55 |
// |
|
56 |
CUsbPnIsaReceiver::CUsbPnIsaReceiver( RIscApi& aIscApi ) |
|
57 |
#ifdef NCP_COMMON_ENOSW_IN_USE |
|
58 |
// CUsbPnUsbSender uses ECommTransmitPriority=100. |
|
59 |
// Set priority lower than 100, so that CUsbPnUsbSender can send packages. |
|
60 |
:CActive( 99 ) |
|
61 |
#else |
|
62 |
:CActive( CActive::EPriorityStandard - 1 ) |
|
63 |
#endif |
|
64 |
,iIscApi(aIscApi) |
|
65 |
,iRecvPtr(0,0) |
|
66 |
,iForwardFlag(EFalse) |
|
67 |
{ |
|
68 |
OstTrace1( TRACE_NORMAL, CUSBPNISARECEIVER_CUSBPNISARECEIVER_ENTRY, "CUsbPnIsaReceiver::CUsbPnIsaReceiver;aIscApi=%x", ( TUint )&( aIscApi ) ); |
|
69 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::CUsbPnIsaReceiver( aIscApi:0x%x )" ), &aIscApi ) ); |
|
70 |
||
71 |
CActiveScheduler::Add(this); |
|
72 |
||
73 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CUSBPNISARECEIVER_EXIT, "CUsbPnIsaReceiver::CUsbPnIsaReceiver - return" ); |
|
74 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::CUsbPnIsaReceiver() - return" ) ) ); |
|
75 |
} |
|
76 |
||
77 |
// ----------------------------------------------------------------------------- |
|
78 |
// CUsbPnIsaReceiver::ConstructL |
|
79 |
// Symbian 2nd phase constructor can leave. |
|
80 |
// ----------------------------------------------------------------------------- |
|
81 |
// |
|
82 |
void CUsbPnIsaReceiver::ConstructL( RDevUsbcClient& aLdd ) |
|
83 |
{ |
|
84 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CONSTRUCTL_ENTRY, "CUsbPnIsaReceiver::ConstructL" ); |
|
85 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::ConstructL()" ) ) ); |
|
86 |
||
87 |
iUsbSender = CUsbPnUsbSender::NewL( *this, aLdd ); |
|
88 |
||
89 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CONSTRUCTL_EXIT, "CUsbPnIsaReceiver::ConstructL - return void" ); |
|
90 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::ConstructL() - return void" ) ) ); |
|
91 |
} |
|
92 |
||
93 |
// ----------------------------------------------------------------------------- |
|
94 |
// CUsbPnIsaReceiver::NewL |
|
95 |
// Two-phased constructor. |
|
96 |
// ----------------------------------------------------------------------------- |
|
97 |
// |
|
98 |
CUsbPnIsaReceiver* CUsbPnIsaReceiver::NewL( RIscApi& aIscApi, RDevUsbcClient& aLdd ) |
|
99 |
{ |
|
100 |
OstTraceExt2( TRACE_NORMAL, CUSBPNISARECEIVER_NEWL_ENTRY, "CUsbPnIsaReceiver::NewL;aIscApi=%x;aLdd=%x", ( TUint )&( aIscApi ), ( TUint )&( aLdd ) ); |
|
101 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::NewL( aIscApi:0x%x, aLdd:0x%x )" ), &aIscApi, &aLdd ) ); |
|
102 |
||
103 |
CUsbPnIsaReceiver* self = new( ELeave ) CUsbPnIsaReceiver( aIscApi ); |
|
104 |
||
105 |
CleanupStack::PushL( self ); |
|
106 |
self->ConstructL( aLdd ); |
|
107 |
CleanupStack::Pop( self ); |
|
108 |
||
109 |
OstTrace1( TRACE_NORMAL, CUSBPNISARECEIVER_NEWL_EXIT, "CUsbPnIsaReceiver::NewL - return;self=%x", self ); |
|
110 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::NewL() - return 0x%x" ), self ) ); |
|
111 |
return self; |
|
112 |
} |
|
113 |
||
114 |
// Destructor |
|
115 |
CUsbPnIsaReceiver::~CUsbPnIsaReceiver() |
|
116 |
{ |
|
117 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CUSBPNISARECEIVER_DESTRUCTOR_ENTRY, "CUsbPnIsaReceiver::~CUsbPnIsaReceiver" ); |
|
118 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::~CUsbPnIsaReceiver()" ) ) ); |
|
119 |
||
120 |
Cancel(); |
|
121 |
if( iUsbSender ) |
|
122 |
{ |
|
123 |
delete iUsbSender; |
|
124 |
} |
|
125 |
||
126 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CUSBPNISARECEIVER_DESTRUCTOR_EXIT, "CUsbPnIsaReceiver::~CUsbPnIsaReceiver - return" ); |
|
127 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::~CUsbPnIsaReceiver() - return" ) ) ); |
|
128 |
} |
|
129 |
||
130 |
// ----------------------------------------------------------------------------- |
|
131 |
// CUsbPnIsaReceiver::DoCancel |
|
132 |
// ?implementation_description |
|
133 |
// (other items were commented in a header). |
|
134 |
// ----------------------------------------------------------------------------- |
|
135 |
// |
|
136 |
void CUsbPnIsaReceiver::DoCancel( ) |
|
137 |
{ |
|
138 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_DOCANCEL_ENTRY, "CUsbPnIsaReceiver::DoCancel" ); |
|
139 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::DoCancel()" ) ) ); |
|
140 |
||
141 |
iIscApi.ReceiveCancel(); |
|
142 |
||
143 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_DOCANCEL_EXIT, "CUsbPnIsaReceiver::DoCancel - return void" ); |
|
144 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::DoCancel() - return void" ) ) ); |
|
145 |
} |
|
146 |
||
147 |
// ----------------------------------------------------------------------------- |
|
148 |
// CUsbPnIsaReceiver::RunL |
|
149 |
// ?implementation_description |
|
150 |
// (other items were commented in a header). |
|
151 |
// ----------------------------------------------------------------------------- |
|
152 |
// |
|
153 |
void CUsbPnIsaReceiver::RunL( ) |
|
154 |
{ |
|
155 |
OstTrace1( TRACE_API, CUSBPNISARECEIVER_RUNL_ENTRY, "CUsbPnIsaReceiver::RunL;iStatus=%d", iStatus.Int() ); |
|
156 |
A_TRACE( ( _T( "CUsbPnIsaReceiver::RunL() iStatus:%d" ), iStatus.Int() ) ); |
|
157 |
||
158 |
User::LeaveIfError(iStatus.Int()); |
|
159 |
||
160 |
iRecvPtr.Set( iPacket->Buffer().Des() ); |
|
161 |
||
162 |
#ifndef NCP_COMMON_BRIDGE_FAMILY |
|
163 |
//Media specific resp from SOS USB MM |
|
164 |
if( (iRecvPtr[ISI_HEADER_OFFSET_RESOURCEID] == PN_MEDIA_CONTROL) && |
|
165 |
(iRecvPtr[ISI_HEADER_OFFSET_MESSAGEID] == PNS_MEDIA_SPECIFIC_RESP) ) |
|
166 |
{ |
|
167 |
OstTrace0( TRACE_API, CUSBPNISARECEIVER_RUNL, "CUsbPnIsaReceiver::RunL - Media specific resp" ); |
|
168 |
A_TRACE( ( _T( "CUsbPnIsaReceiver::RunL - Media specific resp" ))); |
|
169 |
// Empty packet buffer and receive next packet to it. |
|
170 |
iPacket->ReleaseL(); |
|
171 |
iRecvPtr.Set( iPacket->Buffer().Des() ); |
|
172 |
iIscApi.Receive( iStatus, iRecvPtr, iNeededLength ); |
|
173 |
OstTrace0( TRACE_DETAILED, CUSBPNISARECEIVER_RUNL_DUP1, "CUsbPnIsaReceiver::RunL - receiving new" ); |
|
174 |
E_TRACE((_T("CUsbPnUsbReceiver::RunL - Receiving new"))); |
|
175 |
SetActive(); |
|
176 |
} |
|
177 |
else |
|
178 |
#endif /* NCP_COMMON_BRIDGE_FAMILY */ |
|
179 |
{ |
|
180 |
||
181 |
//Normal case |
|
182 |
if( iForwardFlag ) |
|
183 |
{ |
|
184 |
ConstructMessage(); |
|
185 |
iUsbSender->Send( *iPacket ); |
|
186 |
Receive( iForwardFlag ); |
|
187 |
} |
|
188 |
||
189 |
// PC phonet connection not open |
|
190 |
else |
|
191 |
{ |
|
192 |
OstTrace0( TRACE_API, CUSBPNISARECEIVER_RUNL_DUP2, "CUsbPnIsaReceiver::RunL - Discarding" ); |
|
193 |
A_TRACE( ( _T( "CUsbPnIsaReceiver::RunL - Discarding" ))); |
|
194 |
// Empty packet buffer and receive next packet to it. |
|
195 |
iPacket->ReleaseL(); |
|
196 |
iRecvPtr.Set( iPacket->Buffer().Des() ); |
|
197 |
iIscApi.Receive( iStatus, iRecvPtr, iNeededLength ); |
|
198 |
OstTrace0( TRACE_DETAILED, CUSBPNISARECEIVER_RUNL_DUP3, "CUsbPnIsaReceiver::RunL - receiving new" ); |
|
199 |
E_TRACE((_T("CUsbPnUsbReceiver::RunL - Receiving new"))); |
|
200 |
SetActive(); |
|
201 |
} |
|
202 |
} |
|
203 |
||
204 |
OstTrace0( TRACE_API, CUSBPNISARECEIVER_RUNL_EXIT, "CUsbPnIsaReceiver::RunL - return void" ); |
|
205 |
A_TRACE( ( _T( "CUsbPnIsaReceiver::RunL() - return void" ) ) ); |
|
206 |
} |
|
207 |
||
208 |
// ----------------------------------------------------------------------------- |
|
209 |
// CUsbPnIsaReceiver::RunError |
|
210 |
// ?implementation_description |
|
211 |
// (other items were commented in a header). |
|
212 |
// ----------------------------------------------------------------------------- |
|
213 |
// |
|
214 |
TInt CUsbPnIsaReceiver::RunError( TInt aError ) |
|
215 |
{ |
|
216 |
OstTrace1( TRACE_API, CUSBPNISARECEIVER_RUNERROR_ENTRY, "CUsbPnIsaReceiver::RunError;aError=%d", aError ); |
|
217 |
A_TRACE( ( _T( "CUsbPnIsaReceiver::RunError( aError:%d )" ), aError ) ); |
|
218 |
||
219 |
switch( aError ) |
|
220 |
{ |
|
221 |
case KErrNoMemory: |
|
222 |
{ |
|
223 |
OstTrace0( TRACE_DETAILED, CUSBPNISARECEIVER_RUNERROR, "CUsbPnIsaReceiver::RunError - Release packet buffer and alloc bigger for temporary use" ); |
|
224 |
E_TRACE( ( _T( "CUsbPnIsaReceiver::RunError - Release packet buffer and alloc bigger for temporary use" ))); |
|
225 |
aError = KErrNone; |
|
226 |
TRAP( aError, iPacket->ReallocBufferL( iNeededLength ) ); |
|
227 |
if( aError == KErrNone ) |
|
228 |
{ |
|
229 |
iRecvPtr.Set( iPacket->Buffer().Des() ); |
|
230 |
iIscApi.Receive( iStatus, iRecvPtr, iNeededLength ); |
|
231 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_RUNERROR_DUP1, "CUsbPnIsaReceiver::RunError - Receiving into bigger" ); |
|
232 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::RunError - Receiving into bigger" )) ); |
|
233 |
SetActive(); |
|
234 |
} |
|
235 |
break; |
|
236 |
} |
|
237 |
case KErrOverflow: |
|
238 |
{ |
|
239 |
OstTrace0( TRACE_DETAILED, CUSBPNISARECEIVER_RUNERROR_DUP2, "CUsbPnIsaReceiver::RunError - Release ISC buffer." ); |
|
240 |
E_TRACE( ( _T( "CUsbPnIsaReceiver::RunError - Release ISC buffer." ))); |
|
241 |
aError = KErrNone; |
|
242 |
iIscApi.ResetBuffers(); // Clear ISC buffer. (connection was probably down, so the old messages are not needed) |
|
243 |
break; |
|
244 |
} |
|
245 |
default: |
|
246 |
{ |
|
247 |
TRACE_ASSERT_ALWAYS; |
|
248 |
User::Panic( KUsbPnPanicCat, aError ); |
|
249 |
break; |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
OstTrace1( TRACE_NORMAL, CUSBPNISARECEIVER_RUNERROR_EXIT, "CUsbPnIsaReceiver::RunError - return;aError=%d", aError ); |
|
254 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::RunError() return - aError:%d )" ), aError ) ); |
|
255 |
return aError; |
|
256 |
} |
|
257 |
||
258 |
// ----------------------------------------------------------------------------- |
|
259 |
// CUsbPnIsaReceiver::Receive |
|
260 |
// aForward should be ETrue only when Phonet connection is open to PC |
|
261 |
// (other items were commented in a header). |
|
262 |
// ----------------------------------------------------------------------------- |
|
263 |
// |
|
264 |
void CUsbPnIsaReceiver::Receive( TBool aForward ) |
|
265 |
{ |
|
266 |
OstTrace1( TRACE_NORMAL, CUSBPNISARECEIVER_RECEIVE_ENTRY, "CUsbPnIsaReceiver::Receive;aForward=%d", aForward ); |
|
267 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::Receive( aForward:%d)" ), aForward )); |
|
268 |
||
269 |
iForwardFlag = aForward; |
|
270 |
||
271 |
if(!IsActive()) |
|
272 |
{ |
|
273 |
TRAPD( err, iPacket = &iUsbSender->PacketL() ); |
|
274 |
if(!err) |
|
275 |
{ |
|
276 |
iRecvPtr.Set( iPacket->Buffer().Des() ); |
|
277 |
iIscApi.Receive( iStatus, iRecvPtr, iNeededLength ); |
|
278 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_RECEIVE, "CUsbPnIsaReceiver::Receive - Receiving" ); |
|
279 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::Receive - Receiving" )) ); |
|
280 |
SetActive(); |
|
281 |
} |
|
282 |
else |
|
283 |
{ |
|
284 |
// No free packets so receiving not activated until sender |
|
285 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_RECEIVE_DUP1, "CUsbPnIsaReceiver::Receive - Sender tells when to continue" ); |
|
286 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::Receive - Sender tells when to continue" )) ); |
|
287 |
} |
|
288 |
} |
|
289 |
||
290 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_RECEIVE_EXIT, "CUsbPnIsaReceiver::Receive - return void" ); |
|
291 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::Receive() - return void" ) ) ); |
|
292 |
} |
|
293 |
||
294 |
// ----------------------------------------------------------------------------- |
|
295 |
// CUsbPnIsaReceiver::SetForwardFlag |
|
296 |
// aForward should be ETrue only when Phonet connection is open to PC |
|
297 |
// (other items were commented in a header). |
|
298 |
// ----------------------------------------------------------------------------- |
|
299 |
// |
|
300 |
void CUsbPnIsaReceiver::SetForwardFlag( TBool aForward ) |
|
301 |
{ |
|
302 |
OstTrace1( TRACE_NORMAL, CUSBPNISARECEIVER_SETFORWARDFLAG_ENTRY, "CUsbPnIsaReceiver::SetForwardFlag=%d", aForward ); |
|
303 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::SetForwardFlag( aForward:%d)" ), aForward )); |
|
304 |
||
305 |
iForwardFlag = aForward; |
|
306 |
||
307 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_SETFORWARDFLAG_EXIT, "CUsbPnIsaReceiver::SetForwardFlag - return void" ); |
|
308 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::SetForwardFlag() - return void" ) ) ); |
|
309 |
} |
|
310 |
||
311 |
// ----------------------------------------------------------------------------- |
|
312 |
// CUsbPnIsaReceiver::ConstructMessage |
|
313 |
// ?implementation_description |
|
314 |
// (other items were commented in a header). |
|
315 |
// ----------------------------------------------------------------------------- |
|
316 |
// |
|
317 |
void CUsbPnIsaReceiver::ConstructMessage() |
|
318 |
{ |
|
319 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CONSTRUCTMESSAGE_ENTRY, "CUsbPnIsaReceiver::ConstructMessage" ); |
|
320 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::ConstructMessage()" ) ) ); |
|
321 |
||
322 |
// Converts the endianess of message length |
|
323 |
OstTrace1( TRACE_DETAILED, CUSBPNISARECEIVER_CONSTRUCTMESSAGE, "CUsbPnIsaReceiver::ConstructMessage - Convert endianness;iRecvPtr.Length()=%d", iRecvPtr.Length() ); |
|
324 |
E_TRACE( ( _T( "CUsbPnIsaReceiver::ConstructMessage() - Convert endianness - iRecvPtr.Length():%d" ), iRecvPtr.Length() ) ); |
|
325 |
TUint8 tmp4(iRecvPtr[ISI_HEADER_OFFSET_LENGTH]); |
|
326 |
TUint8 tmp5(iRecvPtr[ISI_HEADER_OFFSET_LENGTH +1]); |
|
327 |
iRecvPtr[ISI_HEADER_OFFSET_LENGTH] = tmp5; |
|
328 |
iRecvPtr[ISI_HEADER_OFFSET_LENGTH +1] = tmp4; |
|
329 |
||
330 |
OstTrace0( TRACE_NORMAL, CUSBPNISARECEIVER_CONSTRUCTMESSAGE_EXIT, "CUsbPnIsaReceiver::ConstructMessage - return void" ); |
|
331 |
C_TRACE( ( _T( "CUsbPnIsaReceiver::ConstructMessage() - return void" ) ) ); |
|
332 |
} |
|
333 |
||
334 |
// ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
335 |
||
336 |
// End of File |