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 |
|
|
19 |
|
|
20 |
#include <nk_priv.h> // For __ASSERT_NO_FAST_MUTEX published partner
|
|
21 |
#include <kern_priv.h> // For __ASSERT_CRITICAL published partner
|
|
22 |
#include <dfcs.h> // For TDfc
|
|
23 |
#include "memapi.h" // For MemApi
|
|
24 |
|
|
25 |
#include "p2pkernelchannel.h" // For DP2PKernelChannel
|
|
26 |
#include "p2proutertrace.h" // For TRACEs
|
|
27 |
#include "p2pdefs.h" // For EP2PAmountOfProtocols
|
|
28 |
#include "msgqueue.h" // For DMsgQueue
|
|
29 |
#include "p2pinternaldefs.h" // For EP2P...
|
|
30 |
|
|
31 |
// CONST
|
|
32 |
const TInt KFirstParam( 0 );
|
|
33 |
const TInt KSecondParam( 1 );
|
|
34 |
const TInt KThirdParam( 2 );
|
|
35 |
const TInt KDestroyChannelMsg( 0xff );
|
|
36 |
const TInt KP2PKernelChannelMsgQueDfcPrio( 2 ); // LDD FW has one
|
|
37 |
const TInt KP2PKernelEmptyRxQueuePrio( 1 );
|
|
38 |
|
|
39 |
enum TP2PKernelChannelFaults
|
|
40 |
{
|
|
41 |
EP2PKernelChannelMemAllocFailure = 0x00,
|
|
42 |
EP2PKernelChannelMemAllocFailure2,
|
|
43 |
EP2PKernelChannelNotThreadContext,
|
|
44 |
EP2PKernelChannelNotThreadContext2,
|
|
45 |
EP2PKernelChannelNotThreadContext3,
|
|
46 |
EP2PKernelChannelNullParam,
|
|
47 |
EP2PKernelChannelNullParam2,
|
|
48 |
EP2PKernelChannelNullParam3,
|
|
49 |
EP2PKernelChannelNullParam4,
|
|
50 |
EP2PKernelChannelNullParam5,
|
|
51 |
EP2PKernelChannelNullParam6,
|
|
52 |
EP2PKernelChannelWrongParam,
|
|
53 |
EP2PKernelChannelWrongParam2,
|
|
54 |
EP2PKernelChannelWrongParam3,
|
|
55 |
EP2PKernelChannelWrongResponse,
|
|
56 |
EP2PKernelChannelNullPtr,
|
|
57 |
EP2PKernelChannelWrongRequest,
|
|
58 |
EP2PKernelChannelWrongRequest2,
|
|
59 |
EP2PKernelChannelWrongRequest3,
|
|
60 |
EP2PKernelChannelWrongRequest4,
|
|
61 |
EP2PKernelChannelOverTheLimits,
|
|
62 |
EP2PKernelChannelOverTheLimits2,
|
|
63 |
EP2PKernelChannelOverTheLimits3,
|
|
64 |
EP2PKernelChannelOverTheLimits4,
|
|
65 |
EP2PKernelChannelSameRequestTwice,
|
|
66 |
EP2PKernelChannelDfcAlreadyQueued,
|
|
67 |
EP2PKernelChannelRxBufferNotReleased,
|
|
68 |
};
|
|
69 |
|
9
|
70 |
// Create a common Kernel channel FW (P2P, ISI, etc..) after APIs are locked
|
0
|
71 |
|
|
72 |
DP2PKernelChannel::DP2PKernelChannel(
|
|
73 |
// None
|
|
74 |
) :
|
|
75 |
iP2PProtocolId( EP2PAmountOfProtocols ),
|
|
76 |
iKernelChMsgQue( MsgQDfc, this, NULL, KP2PKernelChannelMsgQueDfcPrio )
|
|
77 |
{
|
|
78 |
|
|
79 |
C_TRACE( ( _T( "DP2PKernelChannel::DP2PKernelChannel 0x%x 0x%x>" ), this, iP2PProtocolId ) );
|
|
80 |
iRouterIf = MP2PChRouterIf::GetIf();
|
|
81 |
ASSERT_RESET_ALWAYS( iRouterIf, ( EP2PKernelChannelMemAllocFailure | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
82 |
iRequests = new DP2PKernelAsyncRequests( EP2PLastAsyncRequest );
|
|
83 |
iRx = new DMsgQueue( KP2PLddRxQueuSize );
|
|
84 |
iEmptyRxDfc = new TDfc( EmptyRxDfc, this, iRouterIf->GetDfcThread( MP2PChRouterIf::EP2PDfcThread ), KP2PKernelEmptyRxQueuePrio );
|
|
85 |
ASSERT_RESET_ALWAYS( ( iEmptyRxDfc && iRequests && iRx ), ( EP2PKernelChannelMemAllocFailure2 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
86 |
iKernelChMsgQue.SetDfcQ( iRouterIf->GetDfcThread( MP2PChRouterIf::EP2PDfcThread ) );
|
|
87 |
iKernelChMsgQue.Receive();
|
|
88 |
C_TRACE( ( _T( "DP2PKernelChannel::DP2PKernelChannel 0x%x 0x%x<" ), this, iP2PProtocolId ) );
|
|
89 |
|
|
90 |
}
|
|
91 |
|
|
92 |
DP2PKernelChannel::~DP2PKernelChannel(
|
|
93 |
// None
|
|
94 |
)
|
|
95 |
{
|
|
96 |
|
|
97 |
C_TRACE( ( _T( "DP2PKernelChannel::~DP2PKernelChannel 0x%x 0x%x>" ), this, iP2PProtocolId ) );
|
|
98 |
// Send channel destroyed message to complete with EFalse.
|
|
99 |
TThreadMessage& m=Kern::Message();
|
|
100 |
m.iValue = KDestroyChannelMsg;
|
|
101 |
m.SendReceive( &iKernelChMsgQue );
|
|
102 |
iP2PProtocolId = EP2PAmountOfProtocols;
|
|
103 |
C_TRACE( ( _T( "DP2PKernelChannel::~DP2PKernelChannel iRx 0x%x" ), iRx ) );
|
|
104 |
// Only modified in constructor, if not created already reseted.
|
|
105 |
delete iRx;
|
|
106 |
iRx = NULL;
|
|
107 |
C_TRACE( ( _T( "DP2PKernelChannel::~DP2PKernelChannel iEmptyRxDfc 0x%x" ), iEmptyRxDfc ) );
|
|
108 |
// Only modified in constructor, if not created already reseted.
|
9
|
109 |
if (iEmptyRxDfc)
|
|
110 |
{
|
|
111 |
iEmptyRxDfc->Cancel();
|
|
112 |
}
|
0
|
113 |
delete iEmptyRxDfc;
|
|
114 |
iEmptyRxDfc = NULL;
|
|
115 |
iPtrPtrToRxBuf = NULL;
|
|
116 |
iRouterIf = NULL;
|
|
117 |
C_TRACE( ( _T( "DP2PKernelChannel::~DP2PKernelChannel iRequests 0x%x" ), iEmptyRxDfc ) );
|
|
118 |
// Only modified in constructor, if not created already reseted.
|
|
119 |
delete iRequests;
|
|
120 |
iRequests = NULL;
|
|
121 |
C_TRACE( ( _T( "DP2PKernelChannel::~DP2PKernelChannel 0x%x 0x%x<" ), this, iP2PProtocolId ) );
|
|
122 |
|
|
123 |
}
|
|
124 |
|
|
125 |
// Handling of the request from kernel api
|
|
126 |
// Puts calling thread waiting until TThreadMessage::SendReceive is completed
|
|
127 |
TInt DP2PKernelChannel::HandleRequest(
|
|
128 |
TThreadMessage& aMsg
|
|
129 |
)
|
|
130 |
{
|
|
131 |
|
|
132 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleRequest 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, aMsg.iValue ) );
|
9
|
133 |
|
0
|
134 |
__ASSERT_CRITICAL; // From kern_priv.h published partner
|
|
135 |
__ASSERT_NO_FAST_MUTEX; // From nk_priv.h published partner.
|
|
136 |
ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PKernelChannelNotThreadContext | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
137 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleRequest 0x%x == 0x%x " ), iP2PProtocolId, EP2PAmountOfProtocols ) );
|
|
138 |
TInt valueToReturn( KErrAlreadyExists );
|
|
139 |
// Channel is not open, either still closed or open is pending.
|
|
140 |
if( EP2PAmountOfProtocols <= iP2PProtocolId )
|
|
141 |
{
|
|
142 |
// Accept only open and close calls
|
|
143 |
switch( aMsg.iValue )
|
|
144 |
{
|
|
145 |
// Open and close calls are legal
|
|
146 |
case EP2PAsyncOpen:
|
|
147 |
case EP2PClose:
|
|
148 |
{
|
|
149 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleRequest open or close 0x%x" ), this ) );
|
|
150 |
valueToReturn = aMsg.SendReceive( &iKernelChMsgQue );
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
case KMaxTInt:
|
|
154 |
{
|
|
155 |
// Accept only open cancellation when channel is not open.
|
|
156 |
ASSERT_RESET_ALWAYS( ( KMaxTInt & aMsg.Int0() == EP2PAsyncOpen ), ( EP2PKernelChannelWrongParam3 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
157 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleRequest open cancel 0x%x" ), this ) );
|
|
158 |
valueToReturn = aMsg.SendReceive( &iKernelChMsgQue );
|
|
159 |
break;
|
|
160 |
}
|
|
161 |
default:
|
|
162 |
{
|
|
163 |
ASSERT_RESET_ALWAYS( ( 0 ), ( EP2PKernelChannelWrongParam | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
164 |
break;
|
|
165 |
}
|
|
166 |
}
|
|
167 |
}
|
|
168 |
// Channel is open.
|
|
169 |
else
|
|
170 |
{
|
|
171 |
// Accept all calls except open.
|
|
172 |
if( EP2PAsyncOpen != aMsg.iValue )
|
|
173 |
{
|
|
174 |
valueToReturn = aMsg.SendReceive( &iKernelChMsgQue );
|
|
175 |
}
|
|
176 |
}
|
|
177 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleRequest 0x%x 0x%x %d<" ), this, iP2PProtocolId, valueToReturn ) );
|
|
178 |
return valueToReturn;
|
|
179 |
|
|
180 |
}
|
|
181 |
|
|
182 |
// From MP2PRouterChIf start
|
|
183 |
// Called only in router extension thread context.
|
|
184 |
void DP2PKernelChannel::ConnectionLost()
|
|
185 |
{
|
|
186 |
|
|
187 |
C_TRACE( ( _T( "DP2PKernelChannel::ConnectionLost 0x%x 0x%x %d %d 0x%x>" ), this, iP2PProtocolId ) );
|
|
188 |
EnqueChannelRequestCompleteDfc( EP2PAsyncConnectionLost, KErrNotReady );
|
|
189 |
ResetQueues();
|
|
190 |
//Closing( iP2PProtocolId );
|
|
191 |
C_TRACE( ( _T( "DP2PKernelChannel::ConnectionLost 0x%x 0x%x %d %d 0x%x<" ), this, iP2PProtocolId ) );
|
|
192 |
|
|
193 |
}
|
|
194 |
|
|
195 |
// Called only in router extension thread context.
|
|
196 |
void DP2PKernelChannel::EnqueChannelRequestCompleteDfc(
|
|
197 |
TInt aRequest,
|
|
198 |
TInt aStatusToComplete
|
|
199 |
)
|
|
200 |
{
|
|
201 |
|
|
202 |
C_TRACE( ( _T( "DP2PKernelChannel::EnqueChannelRequestCompleteDfc 0x%x 0x%x %d %d 0x%x>" ), this, iP2PProtocolId, aRequest, aStatusToComplete ) );
|
|
203 |
ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PKernelChannelNotThreadContext2 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
9
|
204 |
// assert router ext thread context
|
0
|
205 |
if( aRequest == EP2PAsyncOpen )
|
|
206 |
{
|
|
207 |
iP2PProtocolId = ( KErrNone == aStatusToComplete || KErrInUse == aStatusToComplete ) ? ~iP2PProtocolId : EP2PAmountOfProtocols;
|
|
208 |
}
|
|
209 |
iRequests->Complete( aRequest, aStatusToComplete );
|
|
210 |
C_TRACE( ( _T( "DP2PKernelChannel::EnqueChannelRequestCompleteDfc 0x%x 0x%x %d %d 0x%x<" ), this, iP2PProtocolId, aRequest, aStatusToComplete ) );
|
|
211 |
|
|
212 |
}
|
|
213 |
|
|
214 |
// Called in 1...N transceivers thread context
|
|
215 |
void DP2PKernelChannel::ReceiveMsg(
|
|
216 |
const TDesC8& aMessage
|
|
217 |
)
|
|
218 |
{
|
|
219 |
|
|
220 |
C_TRACE( ( _T( "DP2PKernelChannel::ReceiveMsg 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, &aMessage ) );
|
|
221 |
ASSERT_THREAD_CONTEXT_ALWAYS( ( EP2PKernelChannelNotThreadContext3 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
222 |
iRx->Add( aMessage );
|
|
223 |
iEmptyRxDfc->Enque();
|
|
224 |
C_TRACE( ( _T( "DP2PKernelChannel::ReceiveMsg 0x%x 0x%x 0x%x<" ), this, iP2PProtocolId, &aMessage ) );
|
|
225 |
|
|
226 |
}
|
|
227 |
|
|
228 |
// From MP2PRouterChIf end
|
|
229 |
|
|
230 |
// Internal functions
|
|
231 |
void DP2PKernelChannel::EmptyRxDfc(
|
|
232 |
TAny* aPtr // self
|
|
233 |
)
|
|
234 |
{
|
|
235 |
|
|
236 |
DP2PKernelChannel& chTmp = *reinterpret_cast<DP2PKernelChannel*>( aPtr );
|
|
237 |
C_TRACE( ( _T( "DP2PKernelChannel::EmptyRxDfc 0x%x 0x%x>" ), &chTmp, chTmp.iP2PProtocolId ) );
|
|
238 |
if( chTmp.iRequests->IsPending( EP2PAsyncReceive ) && chTmp.iRx->Count() > 0 )
|
|
239 |
{
|
|
240 |
C_TRACE( ( _T( "DP2PKernelChannel::EmptyRxDfc 0x%x 0x%x writing to kernel client" ), &chTmp, chTmp.iP2PProtocolId ) );
|
|
241 |
TDes8*& tmpWrite = *chTmp.iPtrPtrToRxBuf;
|
|
242 |
tmpWrite = &chTmp.iRx->Get();
|
|
243 |
C_TRACE( ( _T( "DP2PKernelChannel::EmptyRxDfc 0x%x 0x%x 0x%x 0x%x clientRx 0x%x " ), &chTmp, chTmp.iP2PProtocolId, chTmp.iPtrPtrToRxBuf, &chTmp.iPtrPtrToRxBuf, *chTmp.iPtrPtrToRxBuf ) );
|
|
244 |
chTmp.EnqueChannelRequestCompleteDfc( EP2PAsyncReceive, KErrNone );
|
|
245 |
}
|
|
246 |
else
|
|
247 |
{
|
|
248 |
C_TRACE( ( _T( "DP2PKernelChannel::EmptyRxDfc 0x%x 0x%x no receive active or no message" ), &chTmp, chTmp.iP2PProtocolId ) );
|
|
249 |
}
|
|
250 |
C_TRACE( ( _T( "DP2PKernelChannel::EmptyRxDfc 0x%x 0x%x <" ), &chTmp, chTmp.iP2PProtocolId ) );
|
|
251 |
|
|
252 |
}
|
|
253 |
|
|
254 |
void DP2PKernelChannel::MsgQDfc(
|
|
255 |
TAny* aPtr
|
|
256 |
)
|
|
257 |
{
|
|
258 |
|
|
259 |
C_TRACE( ( _T( "DP2PKernelChannel::MsgQDfc>" ) ) );
|
|
260 |
DP2PKernelChannel* tmp = reinterpret_cast<DP2PKernelChannel*>( aPtr );
|
|
261 |
tmp->HandleThreadMsg( static_cast<TThreadMessage&>(*tmp->iKernelChMsgQue.iMessage ) );
|
|
262 |
C_TRACE( ( _T( "DP2PKernelChannel::MsgQDfc<" ) ) );
|
|
263 |
|
|
264 |
}
|
|
265 |
|
|
266 |
void DP2PKernelChannel::HandleThreadMsg(
|
|
267 |
TThreadMessage& aMsg
|
|
268 |
)
|
|
269 |
{
|
|
270 |
|
|
271 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleThreadMsg 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, &aMsg ) );
|
|
272 |
TThreadMessage& m = ( aMsg );
|
|
273 |
TInt completeValue( KErrNone );
|
|
274 |
TBool complete( ETrue );
|
|
275 |
switch( m.iValue )
|
|
276 |
{
|
|
277 |
// All asynchronous requests. Return result after DFC function is run.
|
|
278 |
case EP2PAsyncReceive:
|
|
279 |
case EP2PAsyncOpen:
|
|
280 |
case EP2PAsyncConnectionLost:
|
|
281 |
{
|
|
282 |
// No need to check return value in async functions, completed to client from DFC.
|
|
283 |
HandleDfcRequest( m );
|
|
284 |
break;
|
|
285 |
}
|
|
286 |
// From synchronized request return the result immediately
|
|
287 |
case EP2PClose:
|
|
288 |
case EP2PAllocateBlock:
|
|
289 |
case EP2PDeallocateBlock:
|
|
290 |
case EP2PSend:
|
|
291 |
{
|
|
292 |
completeValue = HandleSyncRequest( m );
|
|
293 |
break;
|
|
294 |
}
|
|
295 |
case KDestroyChannelMsg:
|
|
296 |
{
|
|
297 |
completeValue = KErrNone;
|
|
298 |
// Don't receive anymore messages.
|
|
299 |
complete = EFalse;
|
|
300 |
break;
|
|
301 |
}
|
|
302 |
case KMaxTInt:
|
|
303 |
{
|
|
304 |
completeValue = KErrNone;
|
|
305 |
DoCancel( KMaxTInt, m.Int0() );
|
|
306 |
break;
|
|
307 |
}
|
|
308 |
default:
|
|
309 |
{
|
|
310 |
ASSERT_RESET_ALWAYS( 0, ( EP2PKernelChannelWrongRequest | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
311 |
break;
|
|
312 |
}
|
|
313 |
}
|
|
314 |
m.Complete( completeValue, complete );
|
|
315 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleThreadMsg 0x%x 0x%x<" ), this, iP2PProtocolId ) );
|
|
316 |
|
|
317 |
}
|
|
318 |
|
|
319 |
void DP2PKernelChannel::HandleDfcRequest(
|
|
320 |
TThreadMessage& aMsg
|
|
321 |
)
|
|
322 |
{
|
|
323 |
|
|
324 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, &aMsg ) );
|
|
325 |
TThreadMessage& m = ( aMsg );
|
|
326 |
TInt request( m.iValue );
|
|
327 |
ASSERT_RESET_ALWAYS( m.iArg, ( EP2PKernelChannelNullParam | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
328 |
// If request already active.
|
|
329 |
ASSERT_RESET_ALWAYS( EP2PLastAsyncRequest > ( request ), ( EP2PKernelChannelWrongRequest4 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
330 |
if( iRequests->IsPending( request) )
|
|
331 |
{
|
|
332 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest existing 0x%x 0x%x request 0x%x" ), this, iP2PProtocolId, request ) );
|
|
333 |
TRACE_ASSERT_INFO( 0, ( (TUint8)iP2PProtocolId << KProtocolIdShift | (TUint8)request << KExtraInfoShift ) );
|
|
334 |
// Should not give same request object twice before completing the first one.
|
|
335 |
ASSERT_RESET_ALWAYS( 0, ( EP2PKernelChannelSameRequestTwice | static_cast<TUint8>( iP2PProtocolId ) << KProtocolIdShift | static_cast<TUint8>( request ) << KExtraInfoShift ) );
|
|
336 |
}
|
|
337 |
else
|
|
338 |
{
|
|
339 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest 0x%x 0x%x handling %d" ), this, iP2PProtocolId, request ) );
|
|
340 |
//NOTE! These are tight to parameter passing!!
|
|
341 |
TUint32* tablePtr = reinterpret_cast<TUint32*>( m.Ptr0() );
|
|
342 |
TInt* dfcStatus = reinterpret_cast<TInt*>( tablePtr[ 0 ] );
|
|
343 |
TDfc* dfc = reinterpret_cast<TDfc*>( tablePtr[ 1 ] );
|
|
344 |
ASSERT_RESET_ALWAYS( dfcStatus, ( EP2PKernelChannelNullParam2 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
345 |
ASSERT_RESET_ALWAYS( dfc, ( EP2PKernelChannelNullParam3 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
346 |
iRequests->SetPending( request, dfc, dfcStatus );
|
|
347 |
switch( request )
|
|
348 |
{
|
|
349 |
case EP2PAsyncOpen:
|
|
350 |
{
|
|
351 |
iP2PProtocolId = tablePtr[ KThirdParam ];
|
|
352 |
iP2PProtocolId = ~iP2PProtocolId;
|
|
353 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest EP2PNokiaKernelOpen 0x%x 0x%x 0x%x" ), this, iP2PProtocolId, ~iP2PProtocolId ) );
|
9
|
354 |
iRouterIf->Connect( ~iP2PProtocolId, this );
|
0
|
355 |
break;
|
|
356 |
}
|
|
357 |
case EP2PAsyncReceive:
|
|
358 |
{
|
|
359 |
ASSERT_RESET_ALWAYS( !iPtrPtrToRxBuf, ( EP2PKernelChannelRxBufferNotReleased | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
360 |
iPtrPtrToRxBuf = reinterpret_cast<TDes8**>( tablePtr[ KThirdParam ] );
|
|
361 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest EIADAsyncReceive 0x%x 0x%x 0x%x 0x%x" ), this, iP2PProtocolId, iPtrPtrToRxBuf, &iPtrPtrToRxBuf ) );
|
|
362 |
iEmptyRxDfc->Enque();
|
|
363 |
break;
|
|
364 |
}
|
|
365 |
case EP2PAsyncConnectionLost:
|
|
366 |
{
|
|
367 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest EP2PAsyncConnectionLost 0x%x 0x%x" ), this, iP2PProtocolId ) );
|
|
368 |
// If the connection is already lost when function is called return immediately.
|
|
369 |
// This might happend in between calls to ::Open and ::NotifyClose
|
|
370 |
if( !iRouterIf->ConnectionExist( iP2PProtocolId ) )
|
|
371 |
{
|
|
372 |
EnqueChannelRequestCompleteDfc( EP2PAsyncConnectionLost, KErrNotReady );
|
|
373 |
ResetQueues();
|
|
374 |
//Closing( iP2PProtocolId );
|
|
375 |
}
|
|
376 |
break;
|
|
377 |
}
|
|
378 |
default:
|
|
379 |
{
|
|
380 |
ASSERT_RESET_ALWAYS( 0, ( EP2PKernelChannelWrongRequest2 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
381 |
break;
|
|
382 |
}
|
|
383 |
}
|
|
384 |
}
|
|
385 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleDfcRequest 0x%x 0x%x 0x%x<" ), this, iP2PProtocolId, &aMsg ) );
|
|
386 |
|
|
387 |
}
|
|
388 |
|
|
389 |
TInt DP2PKernelChannel::HandleSyncRequest(
|
|
390 |
TThreadMessage& aMsg
|
|
391 |
)
|
|
392 |
{
|
|
393 |
|
|
394 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, &aMsg ) );
|
|
395 |
TThreadMessage& m = ( aMsg );
|
|
396 |
TInt request( m.iValue );
|
|
397 |
ASSERT_RESET_ALWAYS( m.iArg, ( EP2PKernelChannelNullParam4 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
398 |
TInt returnValue( KErrNone );
|
|
399 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest 0x%x 0x%x handling %d" ), this, iP2PProtocolId, request ) );
|
|
400 |
TUint32* tablePtr = reinterpret_cast<TUint32*>( m.Ptr0() );
|
|
401 |
// NOTE! values depend on the P2P Kernel API parameters
|
|
402 |
switch( request )
|
|
403 |
{
|
|
404 |
case EP2PClose:
|
|
405 |
{
|
|
406 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest EP2PClose 0x%x 0x%x" ), this, iP2PProtocolId ) );
|
|
407 |
Closing( iP2PProtocolId );
|
|
408 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest EP2PClose 0x%x 0x%x" ), this, iP2PProtocolId ) );
|
|
409 |
returnValue = KErrNone;
|
|
410 |
break;
|
|
411 |
}
|
|
412 |
case EP2PAllocateBlock:
|
|
413 |
{
|
|
414 |
const TInt size = *reinterpret_cast<TInt*>( tablePtr[ KFirstParam ] );
|
|
415 |
TDes8*& block = *(reinterpret_cast<TDes8**>( tablePtr[ KSecondParam ] ));
|
|
416 |
C_TRACE( ( _T( "DP2PKernelChannel:: EP2PAllocateBlock 0x%x 0x%x block 0x%x %d" ), this, iP2PProtocolId, block, size ) );
|
|
417 |
block = ( &MemApi::AllocBlock( size ) );
|
|
418 |
break;
|
|
419 |
}
|
|
420 |
case EP2PDeallocateBlock:
|
|
421 |
{
|
|
422 |
TDes8& block = *reinterpret_cast<TDes8*>( tablePtr[ KFirstParam ] );
|
|
423 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest EP2PAllocateBlock 0x%x 0x%x block 0x%x" ), this, iP2PProtocolId, &block ) );
|
|
424 |
// Needed to ensure that right channel is deleting the right block. (Could it be done otherways too?)
|
|
425 |
if( iPtrPtrToRxBuf )
|
|
426 |
{
|
|
427 |
if ( &block == *iPtrPtrToRxBuf )
|
|
428 |
{
|
|
429 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest release 0x%x 0x%x clientRx 0x%x"), iPtrPtrToRxBuf, &iPtrPtrToRxBuf, *iPtrPtrToRxBuf ) );
|
|
430 |
iPtrPtrToRxBuf = NULL;
|
|
431 |
}
|
|
432 |
}
|
|
433 |
MemApi::DeallocBlock( block );
|
|
434 |
break;
|
|
435 |
}
|
|
436 |
case EP2PSend:
|
|
437 |
{
|
|
438 |
TDes8& block = *reinterpret_cast<TDes8*>( tablePtr[ KFirstParam ] );
|
|
439 |
C_TRACE( ( _T( "DISAKernelChannel::HandleSyncRequest EP2PSend 0x%x 0x%x block 0x%x" ), this, iP2PProtocolId, &block ) );
|
|
440 |
returnValue = iRouterIf->Send( block, iP2PProtocolId );
|
|
441 |
break;
|
|
442 |
}
|
|
443 |
default:
|
|
444 |
{
|
|
445 |
ASSERT_RESET_ALWAYS( 0, ( EP2PKernelChannelWrongRequest3 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
446 |
break;
|
|
447 |
}
|
|
448 |
}
|
|
449 |
C_TRACE( ( _T( "DP2PKernelChannel::HandleSyncRequest 0x%x 0x%x 0x%x %d<" ), this, iP2PProtocolId, &aMsg, returnValue ) );
|
|
450 |
return returnValue;
|
|
451 |
|
|
452 |
}
|
|
453 |
|
|
454 |
void DP2PKernelChannel::DoCancel(
|
|
455 |
TInt aRequest,
|
|
456 |
TInt aMask )
|
|
457 |
{
|
|
458 |
|
|
459 |
C_TRACE( ( _T( "DP2PKernelChannel::DoCancel 0x%x 0x%x>" ), this, iP2PProtocolId ) );
|
|
460 |
ASSERT_RESET_ALWAYS( EP2PLastAsyncRequest > ( aMask&aRequest ), EP2PKernelChannelOverTheLimits | EDP2PKernelChannelId << KClassIdentifierShift );
|
|
461 |
if( iRequests->IsPending( aMask&aRequest ) )
|
|
462 |
{
|
|
463 |
switch( aMask&aRequest )
|
|
464 |
{
|
|
465 |
case EP2PAsyncOpen:
|
|
466 |
{
|
|
467 |
C_TRACE( ( _T( "DP2PKernelChannel::DoCancel EP2PAsyncOpen 0x%x 0x%x" ), this, iP2PProtocolId ) );
|
|
468 |
ResetQueues();
|
|
469 |
Close( ~iP2PProtocolId );
|
|
470 |
break;
|
|
471 |
}
|
|
472 |
case EP2PAsyncReceive:
|
|
473 |
{
|
|
474 |
C_TRACE( ( _T( "DP2PKernelChannel::DoCancel EIADAsyncReceive 0x%x 0x%x ptrs 0x%x 0x%x" ), this, iP2PProtocolId, iPtrPtrToRxBuf, &iPtrPtrToRxBuf ) );
|
|
475 |
iPtrPtrToRxBuf = NULL;
|
|
476 |
break;
|
|
477 |
}
|
|
478 |
case EP2PAsyncConnectionLost:
|
|
479 |
{
|
|
480 |
C_TRACE( ( _T( "DP2PKernelChannel::DoCancel EP2PAsyncConnectionLost 0x%x 0x%x" ), this, iP2PProtocolId ) );
|
|
481 |
break;
|
|
482 |
}
|
|
483 |
default:
|
|
484 |
{
|
|
485 |
ASSERT_RESET_ALWAYS( 0, EP2PKernelChannelWrongRequest | EDP2PKernelChannelId << KClassIdentifierShift );
|
|
486 |
break;
|
|
487 |
}
|
|
488 |
}
|
|
489 |
EnqueChannelRequestCompleteDfc( aMask&aRequest, KErrCancel );
|
|
490 |
}
|
|
491 |
else
|
|
492 |
{
|
|
493 |
C_TRACE( ( _T( "DP2PKernelChannel::DoCancel nothing to cancel 0x%x 0x%x" ), this, iP2PProtocolId ) );
|
|
494 |
}
|
|
495 |
C_TRACE( ( _T( "DP2PKernelChannel::DoCancel 0x%x 0x%x<" ), this, iP2PProtocolId ) );
|
|
496 |
|
|
497 |
}
|
|
498 |
|
|
499 |
void DP2PKernelChannel::Close(
|
|
500 |
const TUint8 aP2PProtocolId
|
|
501 |
)
|
|
502 |
{
|
|
503 |
|
|
504 |
C_TRACE( ( _T( "DP2PKernelChannel::Close 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, aP2PProtocolId ) );
|
|
505 |
if( EP2PAmountOfProtocols != iP2PProtocolId )
|
|
506 |
{
|
|
507 |
C_TRACE( ( _T( "DP2PKernelChannel::Close closing 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, aP2PProtocolId ) );
|
|
508 |
iRouterIf->Close( aP2PProtocolId );
|
|
509 |
}
|
|
510 |
iP2PProtocolId = EP2PAmountOfProtocols;
|
|
511 |
C_TRACE( ( _T( "DP2PKernelChannel::Close 0x%x 0x%x 0x%x<" ), this, iP2PProtocolId, aP2PProtocolId ) );
|
|
512 |
|
|
513 |
}
|
|
514 |
|
|
515 |
void DP2PKernelChannel::Closing(
|
|
516 |
const TUint8 aP2PProtocolId
|
|
517 |
)
|
|
518 |
{
|
|
519 |
|
|
520 |
C_TRACE( ( _T( "DP2PKernelChannel::Closing 0x%x 0x%x 0x%x>" ), this, iP2PProtocolId, aP2PProtocolId ) );
|
|
521 |
ResetQueues();
|
|
522 |
for( TInt i( EP2PLastSyncRequest ); i < EP2PLastAsyncRequest; ++i )
|
|
523 |
{
|
|
524 |
C_TRACE( ( _T( "DP2PKernelChannel::CancelRequests req to cancel %d" ), i ) );
|
|
525 |
DoCancel( KMaxTInt, i );
|
|
526 |
}
|
|
527 |
Close( iP2PProtocolId );
|
|
528 |
C_TRACE( ( _T( "DP2PKernelChannel::Closing 0x%x 0x%x 0x%x<" ), this, iP2PProtocolId, aP2PProtocolId ) );
|
|
529 |
|
|
530 |
}
|
|
531 |
|
|
532 |
void DP2PKernelChannel::ResetQueues(
|
|
533 |
// None
|
|
534 |
)
|
|
535 |
{
|
|
536 |
|
|
537 |
C_TRACE( ( _T( "DP2PKernelChannel::ResetQueues 0x%x 0x%x>" ), this, iP2PProtocolId ) );
|
9
|
538 |
// assert router ext thread context
|
0
|
539 |
if( iRx )
|
|
540 |
{
|
|
541 |
C_TRACE( ( _T( "DP2PKernelChannel::ResetQueues 0x%x 0x%x iRx 0x%x" ), this, iP2PProtocolId, iRx ) );
|
|
542 |
while( iRx->Count() )
|
|
543 |
{
|
|
544 |
MemApi::DeallocBlock( iRx->Get() );
|
|
545 |
}
|
|
546 |
}
|
|
547 |
C_TRACE( ( _T( "DP2PKernelChannel::ResetQueues 0x%x 0x%x<" ), this, iP2PProtocolId ) );
|
|
548 |
|
|
549 |
}
|
|
550 |
// Internal functions
|
|
551 |
|
|
552 |
// Internal class
|
|
553 |
|
|
554 |
DP2PKernelChannel::DP2PKernelAsyncRequests::DP2PKernelAsyncRequests(
|
|
555 |
const TInt aSize
|
|
556 |
)
|
|
557 |
{
|
|
558 |
|
|
559 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::DP2PKernelAsyncRequests size %d>" ), aSize ) );
|
|
560 |
iRequestLock = new NFastMutex();
|
|
561 |
iShDfcFunctionList = new TDfc*[ aSize ];
|
|
562 |
iShRequestStatusList = new TInt*[ aSize ];
|
|
563 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::DP2PKernelAsyncRequests<" ) ) );
|
|
564 |
|
|
565 |
}
|
|
566 |
|
|
567 |
|
|
568 |
DP2PKernelChannel::DP2PKernelAsyncRequests::~DP2PKernelAsyncRequests()
|
|
569 |
{
|
|
570 |
|
|
571 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::~DP2PKernelAsyncRequests>" ) ) );
|
|
572 |
// Delete space reserved for the array not the contents of the array, so mem behind pointers that are not owned are not deleted.
|
|
573 |
delete iShDfcFunctionList;
|
|
574 |
delete iShRequestStatusList;
|
|
575 |
// Deletes lock
|
|
576 |
delete iRequestLock;
|
|
577 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::~DP2PKernelAsyncRequests<" ) ) );
|
|
578 |
|
|
579 |
}
|
|
580 |
|
|
581 |
void DP2PKernelChannel::DP2PKernelAsyncRequests::SetPending(
|
|
582 |
const TUint aRequest,
|
|
583 |
TDfc* aDfc,
|
|
584 |
TInt* aStatus
|
|
585 |
)
|
|
586 |
{
|
|
587 |
|
|
588 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::SetPending %d 0x%x 0x%x>" ), aRequest, aDfc, aStatus ) );
|
|
589 |
ASSERT_RESET_ALWAYS( aDfc, ( EP2PKernelChannelNullParam5 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
590 |
ASSERT_RESET_ALWAYS( aStatus, ( EP2PKernelChannelNullParam5 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
591 |
ASSERT_RESET_ALWAYS( ( EP2PLastAsyncRequest > aRequest && EP2PAsyncReceive <= aRequest ), ( EP2PKernelChannelOverTheLimits2 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
592 |
// Note asserts must be done before holding the lock.
|
|
593 |
NKern::FMWait( iRequestLock );
|
|
594 |
iShDfcFunctionList[ aRequest ] = aDfc;
|
|
595 |
iShRequestStatusList[ aRequest ] = aStatus;
|
|
596 |
*iShRequestStatusList[ aRequest ] = KRequestPending;
|
|
597 |
NKern::FMSignal( iRequestLock );
|
|
598 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::SetPending %d 0x%x 0x%x<" ), aRequest, aDfc, aStatus ) );
|
|
599 |
|
|
600 |
}
|
|
601 |
|
|
602 |
TBool DP2PKernelChannel::DP2PKernelAsyncRequests::IsPending(
|
|
603 |
const TUint aRequest
|
|
604 |
)
|
|
605 |
{
|
|
606 |
|
|
607 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::IsPending %d>" ), aRequest ) );
|
|
608 |
ASSERT_RESET_ALWAYS( ( EP2PLastAsyncRequest > aRequest && EP2PAsyncReceive <= aRequest ), ( EP2PKernelChannelOverTheLimits3 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
609 |
TBool ret( EFalse );
|
|
610 |
NKern::FMWait( iRequestLock );
|
|
611 |
ret = ( iShDfcFunctionList[ aRequest ] && iShRequestStatusList[ aRequest ] ) ? ETrue : EFalse;
|
|
612 |
NKern::FMSignal( iRequestLock );
|
|
613 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::IsPending %d %d<" ), aRequest, ret ) );
|
|
614 |
return ret;
|
|
615 |
|
|
616 |
}
|
|
617 |
|
|
618 |
void DP2PKernelChannel::DP2PKernelAsyncRequests::Complete(
|
|
619 |
const TUint aRequest,
|
|
620 |
const TInt aStatusToComplete
|
|
621 |
)
|
|
622 |
{
|
|
623 |
|
|
624 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::Complete %d>" ), aRequest ) );
|
|
625 |
// Check that request is legal.
|
|
626 |
ASSERT_RESET_ALWAYS( ( EP2PLastAsyncRequest > aRequest && EP2PAsyncReceive <= aRequest ), ( EP2PKernelChannelOverTheLimits4 | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
627 |
NKern::FMWait( iRequestLock );
|
|
628 |
TDfc* completeDfc = iShDfcFunctionList[ aRequest ];
|
|
629 |
if( ( completeDfc && iShRequestStatusList[ aRequest ] ) )
|
|
630 |
{
|
|
631 |
// Writing straight to clients pointer. There is a risk that malfunctioning client can mess up it's own pointer, if used out side of rx dfc, but what can you do..
|
|
632 |
*iShRequestStatusList[ aRequest ] = aStatusToComplete;
|
|
633 |
ASSERT_RESET_ALWAYS( !completeDfc->Queued(), ( EP2PKernelChannelDfcAlreadyQueued | EDP2PKernelChannelId << KClassIdentifierShift ) );
|
|
634 |
completeDfc->Enque();
|
|
635 |
iShDfcFunctionList[ aRequest ] = NULL;
|
|
636 |
}
|
|
637 |
NKern::FMSignal( iRequestLock );
|
|
638 |
C_TRACE( ( _T( "DP2PKernelAsyncRequests::Complete %d<" ), aRequest ) );
|
|
639 |
|
|
640 |
}
|
|
641 |
|
|
642 |
// Internal class
|
|
643 |
|
|
644 |
// End of file.
|
|
645 |
|