|
1 // Copyright (c) 2003-2009 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 #include <bluetooth/logger.h> |
|
17 #include "L2CapDebugControlInterface.h" |
|
18 |
|
19 #include <bt_subscribe.h> |
|
20 #include "l2util.h" |
|
21 #include "BTSec.h" |
|
22 |
|
23 #ifdef __FLOG_ACTIVE |
|
24 _LIT8(KLogComponent, LOG_COMPONENT_L2CAP); |
|
25 #endif |
|
26 |
|
27 CDebugControlInterface::CDebugControlInterface() |
|
28 : iSDUFlushQueuedSDUFlushed(0), |
|
29 iSDUFlushPartialSentSDUFlushed(0), |
|
30 iSDUFlushSentSDUFlushed(0), |
|
31 iFlushedPDUMuxerResend(0), |
|
32 iFlushedPDUDataFlowResend(0), |
|
33 iFlushedPDUIFrame(0) |
|
34 { |
|
35 LOG_FUNC |
|
36 for(TInt i=0;i<EMaxType;i++) |
|
37 { |
|
38 for(TInt j=0;j<EMaxAllocationType;j++) |
|
39 { |
|
40 iAllocations[i][j] = NULL; |
|
41 } |
|
42 } |
|
43 DefinePublications(); |
|
44 } |
|
45 |
|
46 CDebugControlInterface::~CDebugControlInterface() |
|
47 { |
|
48 LOG_FUNC |
|
49 DeletePublications(); |
|
50 |
|
51 iPDUTimerRecords.ResetAndDestroy(); |
|
52 iPDUTimerRecords.Close(); |
|
53 iPDUGroupTimerRecords.ResetAndDestroy(); |
|
54 iPDUGroupTimerRecords.Close(); |
|
55 } |
|
56 |
|
57 |
|
58 /*static*/ CDebugControlInterface* CDebugControlInterface::NewL() |
|
59 { |
|
60 LOG_STATIC_FUNC |
|
61 // This is done this way to allow future enhancement of this class. |
|
62 CDebugControlInterface* self = new(ELeave) CDebugControlInterface(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 void CDebugControlInterface::DefinePublications() |
|
67 { |
|
68 LOG_FUNC |
|
69 |
|
70 //Capabilities don't really matter here because these |
|
71 //keys are only used in debug builds |
|
72 _LIT_SECURITY_POLICY_PASS(KPassPolicy); |
|
73 |
|
74 for(TInt i=0;i<EMaxType;i++) |
|
75 { |
|
76 for(TInt j=0;j<EMaxAllocationType;j++) |
|
77 { |
|
78 (void)(iProperty.Define(KPropertyKeyBluetoothL2CapDebugBase + (i * 0x10) + j, |
|
79 RProperty::EInt, |
|
80 KPassPolicy, |
|
81 KPassPolicy)); |
|
82 } |
|
83 } |
|
84 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGGetTimerGrpCID, |
|
85 RProperty::EInt, |
|
86 KPassPolicy, |
|
87 KPassPolicy)); |
|
88 |
|
89 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGMinPDUGetTime, |
|
90 RProperty::EInt, |
|
91 KPassPolicy, |
|
92 KPassPolicy)); |
|
93 |
|
94 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGMaxPDUGetTime, |
|
95 RProperty::EInt, |
|
96 KPassPolicy, |
|
97 KPassPolicy)); |
|
98 |
|
99 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGMinPDUSentTime, |
|
100 RProperty::EInt, |
|
101 KPassPolicy, |
|
102 KPassPolicy)); |
|
103 |
|
104 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGMaxPDUSentTime, |
|
105 RProperty::EInt, |
|
106 KPassPolicy, |
|
107 KPassPolicy)); |
|
108 |
|
109 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGAvePDUGetTime, |
|
110 RProperty::EInt, |
|
111 KPassPolicy, |
|
112 KPassPolicy)); |
|
113 |
|
114 (void)(iProperty.Define(KPropertyKeyBluetoothL2DBGAvePDUSentTime, |
|
115 RProperty::EInt, |
|
116 KPassPolicy, |
|
117 KPassPolicy)); |
|
118 |
|
119 (void)(iProperty.Define(KPropertyKeyBluetoothQueuedSDUFlushedCounter, |
|
120 RProperty::EInt, |
|
121 KPassPolicy, |
|
122 KPassPolicy)); |
|
123 |
|
124 (void)(iProperty.Define(KPropertyKeyBluetoothPartialSentSDUFlushedCounter, |
|
125 RProperty::EInt, |
|
126 KPassPolicy, |
|
127 KPassPolicy)); |
|
128 |
|
129 (void)(iProperty.Define(KPropertyKeyBluetoothSentSDUFlushedCounter, |
|
130 RProperty::EInt, |
|
131 KPassPolicy, |
|
132 KPassPolicy)); |
|
133 |
|
134 (void)(iProperty.Define(KPropertyKeyBluetoothFlushedPDUMuxerResend, |
|
135 RProperty::EInt, |
|
136 KPassPolicy, |
|
137 KPassPolicy)); |
|
138 |
|
139 (void)(iProperty.Define(KPropertyKeyBluetoothFlushedPDUDataFlowResend, |
|
140 RProperty::EInt, |
|
141 KPassPolicy, |
|
142 KPassPolicy)); |
|
143 |
|
144 (void)(iProperty.Define(KPropertyKeyBluetoothFlushedPDUIFrame, |
|
145 RProperty::EInt, |
|
146 KPassPolicy, |
|
147 KPassPolicy)); |
|
148 |
|
149 (void)(iProperty.Define(KPropertyKeyBluetoothIncompleteErroredSDUReceived, |
|
150 RProperty::EInt, |
|
151 KPassPolicy, |
|
152 KPassPolicy)); |
|
153 } |
|
154 |
|
155 void CDebugControlInterface::DeletePublications() |
|
156 { |
|
157 LOG_FUNC |
|
158 TSecureId thisSID = RProcess().SecureId(); |
|
159 |
|
160 for(TInt i=0;i<EMaxType;i++) |
|
161 { |
|
162 for(TInt j=0;j<EMaxAllocationType;j++) |
|
163 { |
|
164 iProperty.Delete(thisSID, |
|
165 KPropertyKeyBluetoothL2CapDebugBase + (i * 0x10) + j); |
|
166 } |
|
167 } |
|
168 |
|
169 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGGetTimerGrpCID); |
|
170 |
|
171 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGMinPDUGetTime); |
|
172 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGMaxPDUGetTime); |
|
173 |
|
174 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGMinPDUSentTime); |
|
175 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGMaxPDUSentTime); |
|
176 |
|
177 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGAvePDUGetTime); |
|
178 iProperty.Delete(thisSID, KPropertyKeyBluetoothL2DBGAvePDUSentTime); |
|
179 |
|
180 |
|
181 iProperty.Delete(thisSID, KPropertyKeyBluetoothQueuedSDUFlushedCounter); |
|
182 iProperty.Delete(thisSID, KPropertyKeyBluetoothPartialSentSDUFlushedCounter); |
|
183 iProperty.Delete(thisSID, KPropertyKeyBluetoothSentSDUFlushedCounter); |
|
184 iProperty.Delete(thisSID, KPropertyKeyBluetoothFlushedPDUMuxerResend); |
|
185 iProperty.Delete(thisSID, KPropertyKeyBluetoothFlushedPDUDataFlowResend); |
|
186 iProperty.Delete(thisSID, KPropertyKeyBluetoothFlushedPDUIFrame); |
|
187 iProperty.Delete(thisSID, KPropertyKeyBluetoothIncompleteErroredSDUReceived); |
|
188 } |
|
189 |
|
190 |
|
191 // Debug Interface. |
|
192 void CDebugControlInterface::ObjectAllocation(TObjectType aObjectType, TAllocationType aAllocType) |
|
193 { |
|
194 LOG_FUNC |
|
195 TSecureId thisSID = RProcess().SecureId(); |
|
196 |
|
197 iAllocations[aObjectType][aAllocType]++; |
|
198 (void)iProperty.Set(thisSID, |
|
199 KPropertyKeyBluetoothL2CapDebugBase + (aObjectType * 0x10) + aAllocType, |
|
200 iAllocations[aObjectType][aAllocType]); |
|
201 |
|
202 |
|
203 if(aAllocType == EAllocated && |
|
204 (iAllocations[aObjectType][EAllocated] - iAllocations[aObjectType][EDeleted]) > iAllocations[aObjectType][EPeak]) |
|
205 { |
|
206 iAllocations[aObjectType][EPeak] = static_cast<TUint16>(iAllocations[aObjectType][EAllocated] - iAllocations[aObjectType][EDeleted]); |
|
207 (void)iProperty.Set(thisSID, |
|
208 KPropertyKeyBluetoothL2CapDebugBase + (aObjectType * 0x10) + EPeak, |
|
209 iAllocations[aObjectType][EPeak]); |
|
210 } |
|
211 } |
|
212 |
|
213 void CDebugControlInterface::PDUTimer(TPDUTimerEvent aEvent, TAny* aUID, TUint16 aGrpID) |
|
214 { |
|
215 LOG_FUNC |
|
216 TPDUTimerRecord* rec = NULL; |
|
217 TInt rerr = KErrNone; |
|
218 |
|
219 switch(aEvent) |
|
220 { |
|
221 case EBFrameCreated: |
|
222 rec = new TPDUTimerRecord(aUID, aGrpID, TPDUTimerRecord::EPDUBFrameTimer); |
|
223 if(rec) |
|
224 { |
|
225 rerr = iPDUTimerRecords.Append(rec); |
|
226 } |
|
227 else |
|
228 { |
|
229 rerr = KErrNoMemory; |
|
230 } |
|
231 break; |
|
232 |
|
233 case EIFrameCreated: |
|
234 rec = new TPDUTimerRecord(aUID, aGrpID, TPDUTimerRecord::EPDUIFrameTimer); |
|
235 if(rec) |
|
236 { |
|
237 rerr = iPDUTimerRecords.Append(rec); |
|
238 } |
|
239 else |
|
240 { |
|
241 rerr = KErrNoMemory; |
|
242 } |
|
243 break; |
|
244 |
|
245 case EUnsegmentedFrameCreated: |
|
246 rec = new TPDUTimerRecord(aUID, aGrpID, TPDUTimerRecord::EPDUUnsegmentedFrameTimer); |
|
247 if(rec) |
|
248 { |
|
249 rerr = iPDUTimerRecords.Append(rec); |
|
250 } |
|
251 else |
|
252 { |
|
253 rerr = KErrNoMemory; |
|
254 } |
|
255 break; |
|
256 |
|
257 case EGetPDUCalled: |
|
258 { |
|
259 TIdentityRelation<TPDUTimerRecord> relation(UIDLinkMatch); |
|
260 TPDUTimerRecord temp(aUID, 0, TPDUTimerRecord::TPDUTimerType(0)); |
|
261 TInt ix = iPDUTimerRecords.Find(&temp, relation); |
|
262 if(ix != KErrNotFound) |
|
263 { |
|
264 iPDUTimerRecords[ix]->MarkGetPDUCalled(); |
|
265 } |
|
266 else |
|
267 { |
|
268 rerr = KErrNotFound; |
|
269 } |
|
270 } |
|
271 break; |
|
272 |
|
273 case EPDUSent: |
|
274 { |
|
275 TPDUTimerRecord* uidRec = NULL; |
|
276 TIdentityRelation<TPDUTimerRecord> relation(UIDLinkMatch); |
|
277 TPDUTimerRecord temp(aUID, 0, TPDUTimerRecord::TPDUTimerType(0)); |
|
278 TInt ix = iPDUTimerRecords.Find(&temp, relation); |
|
279 if(ix != KErrNotFound) |
|
280 { |
|
281 uidRec = iPDUTimerRecords[ix]; |
|
282 uidRec->MarkPDUSent(); |
|
283 |
|
284 TIdentityRelation<TPDUGroupTimerRecord> relGroup(GroupLinkMatch); |
|
285 TPDUGroupTimerRecord tempGrp(aGrpID, iProperty); |
|
286 TInt grpIx = iPDUGroupTimerRecords.Find(&tempGrp, relGroup); |
|
287 if(grpIx == KErrNotFound) |
|
288 { |
|
289 TPDUGroupTimerRecord* grpRecord = new TPDUGroupTimerRecord(aGrpID, iProperty); |
|
290 if(grpRecord) |
|
291 { |
|
292 rerr = iPDUGroupTimerRecords.Append(grpRecord); |
|
293 grpIx = iPDUGroupTimerRecords.Count() - 1; |
|
294 } |
|
295 else |
|
296 { |
|
297 rerr = KErrNoMemory; |
|
298 } |
|
299 } |
|
300 if(rerr == KErrNone) |
|
301 { |
|
302 iPDUGroupTimerRecords[grpIx]->UpdateGroup(uidRec->GetPDUTI(), |
|
303 uidRec->SentPDUTI()); |
|
304 } |
|
305 |
|
306 iPDUTimerRecords.Remove(ix); |
|
307 delete uidRec; |
|
308 } |
|
309 else |
|
310 { |
|
311 rerr = KErrNotFound; |
|
312 } |
|
313 } |
|
314 break; |
|
315 |
|
316 default: |
|
317 Panic(EL2CAPUpdatePDUTimerDebugFailed); |
|
318 break; |
|
319 }; |
|
320 } |
|
321 |
|
322 void CDebugControlInterface::UpdateFlushCounters(TFlushCountersEvent aEvent) |
|
323 { |
|
324 LOG_FUNC |
|
325 TSecureId thisSID = RProcess().SecureId(); |
|
326 |
|
327 switch(aEvent) |
|
328 { |
|
329 case ESDUFlushQueuedSDUFlushed: |
|
330 iSDUFlushQueuedSDUFlushed++; |
|
331 (void)(iProperty.Set(thisSID, |
|
332 KPropertyKeyBluetoothQueuedSDUFlushedCounter, |
|
333 iSDUFlushQueuedSDUFlushed)); |
|
334 break; |
|
335 |
|
336 case ESDUFlushPartialSentSDUFlushed: |
|
337 iSDUFlushPartialSentSDUFlushed++; |
|
338 (void)(iProperty.Set(thisSID, |
|
339 KPropertyKeyBluetoothPartialSentSDUFlushedCounter, |
|
340 iSDUFlushPartialSentSDUFlushed)); |
|
341 break; |
|
342 |
|
343 case ESDUFlushSentSDUFlushed: |
|
344 iSDUFlushSentSDUFlushed++; |
|
345 (void)(iProperty.Set(thisSID, |
|
346 KPropertyKeyBluetoothSentSDUFlushedCounter, |
|
347 iSDUFlushSentSDUFlushed)); |
|
348 break; |
|
349 |
|
350 case EFlushedPDUMuxerResend: |
|
351 iFlushedPDUMuxerResend++; |
|
352 (void)(iProperty.Set(thisSID, |
|
353 KPropertyKeyBluetoothFlushedPDUMuxerResend, |
|
354 iFlushedPDUMuxerResend)); |
|
355 break; |
|
356 |
|
357 case EFlushedPDUDataFlowResend: |
|
358 iFlushedPDUDataFlowResend++; |
|
359 (void)(iProperty.Set(thisSID, |
|
360 KPropertyKeyBluetoothFlushedPDUDataFlowResend, |
|
361 iFlushedPDUDataFlowResend)); |
|
362 break; |
|
363 |
|
364 case EFlushedPDUIFrame: |
|
365 iFlushedPDUIFrame++; |
|
366 (void)(iProperty.Set(thisSID, |
|
367 KPropertyKeyBluetoothFlushedPDUIFrame, |
|
368 iFlushedPDUIFrame)); |
|
369 break; |
|
370 |
|
371 case EIncompleteErroredSDUReceived: |
|
372 iIncompleteErroredSDUReceived++; |
|
373 (void)(iProperty.Set(thisSID, |
|
374 KPropertyKeyBluetoothIncompleteErroredSDUReceived, |
|
375 iIncompleteErroredSDUReceived)); |
|
376 break; |
|
377 |
|
378 default: |
|
379 Panic(EL2CAPInvalidDebugFlushCounterEvent); |
|
380 break; |
|
381 }; |
|
382 } |
|
383 |
|
384 |
|
385 /*static*/ TBool CDebugControlInterface::UIDLinkMatch(const TPDUTimerRecord& aA, |
|
386 const TPDUTimerRecord& aB) |
|
387 { |
|
388 LOG_STATIC_FUNC |
|
389 return aA.GetUID() == aB.GetUID(); |
|
390 } |
|
391 |
|
392 /*static*/ TBool CDebugControlInterface::GroupLinkMatch(const TPDUGroupTimerRecord& aA, |
|
393 const TPDUGroupTimerRecord& aB) |
|
394 { |
|
395 LOG_STATIC_FUNC |
|
396 return aA.GetGroupID() == aB.GetGroupID(); |
|
397 } |
|
398 |
|
399 |
|
400 TPDUTimerRecord::TPDUTimerRecord(TAny* aUID, TUint16 aGroupID, TPDUTimerType aTimerType) |
|
401 : iUID(aUID), |
|
402 iGroupID(aGroupID), |
|
403 iTimerType(aTimerType) |
|
404 { |
|
405 LOG_FUNC |
|
406 iTime.HomeTime(); |
|
407 } |
|
408 |
|
409 void TPDUTimerRecord::MarkGetPDUCalled() |
|
410 { |
|
411 LOG_FUNC |
|
412 TTime temp; |
|
413 temp.HomeTime(); |
|
414 iGetPDUTI = temp.MicroSecondsFrom(iTime); |
|
415 } |
|
416 |
|
417 void TPDUTimerRecord::MarkPDUSent() |
|
418 { |
|
419 LOG_FUNC |
|
420 TTime temp; |
|
421 temp.HomeTime(); |
|
422 iSentPDUTI = temp.MicroSecondsFrom(iTime); |
|
423 } |
|
424 |
|
425 |
|
426 |
|
427 TPDUGroupTimerRecord::TPDUGroupTimerRecord(TUint16 aGroupID, RProperty& aProperty) |
|
428 : iMinGetPDU(0), |
|
429 iMinSentPDU(0), |
|
430 iMaxGetPDU(0), |
|
431 iMaxSentPDU(0), |
|
432 iAveGetPDU(0), |
|
433 iAveSentPDU(0), |
|
434 iSampleSize(0), |
|
435 iGroupID(aGroupID), |
|
436 iProperty(aProperty) |
|
437 { |
|
438 LOG_FUNC |
|
439 } |
|
440 |
|
441 void TPDUGroupTimerRecord::UpdateGroup(const TTimeIntervalMicroSeconds& aGetPDUTime, |
|
442 const TTimeIntervalMicroSeconds& aSentPDUTime) |
|
443 { |
|
444 LOG_FUNC |
|
445 // Covert the arguments to ms intervals. |
|
446 TInt newGetPDUTime = I64INT(aGetPDUTime.Int64()) / 1000; |
|
447 TInt newSentPDUTime = I64INT(aSentPDUTime.Int64()) / 1000; |
|
448 |
|
449 if(newGetPDUTime < iMinGetPDU || iSampleSize == 0) |
|
450 { |
|
451 iMinGetPDU = newGetPDUTime; |
|
452 } |
|
453 if(newGetPDUTime > iMaxGetPDU || iSampleSize == 0) |
|
454 { |
|
455 iMaxGetPDU = newGetPDUTime; |
|
456 } |
|
457 |
|
458 if(newSentPDUTime < iMinSentPDU || iSampleSize == 0) |
|
459 { |
|
460 iMinSentPDU = newSentPDUTime; |
|
461 } |
|
462 if(newSentPDUTime > iMaxSentPDU || iSampleSize == 0) |
|
463 { |
|
464 iMaxSentPDU = newSentPDUTime; |
|
465 } |
|
466 |
|
467 iAveGetPDU = ((iAveGetPDU * iSampleSize) + newGetPDUTime) / (iSampleSize + 1); |
|
468 iAveSentPDU = ((iAveSentPDU * iSampleSize) + newSentPDUTime) / (iSampleSize + 1); |
|
469 ++iSampleSize; |
|
470 |
|
471 TInt cid = 0; |
|
472 TSecureId thisSID = RProcess().SecureId(); |
|
473 |
|
474 if(iProperty.Get(thisSID, |
|
475 KPropertyKeyBluetoothL2DBGSetTimerGrpCID, |
|
476 cid) == KErrNone) |
|
477 { |
|
478 if(cid == iGroupID) |
|
479 { |
|
480 (void)iProperty.Set(thisSID, |
|
481 KPropertyKeyBluetoothL2DBGGetTimerGrpCID, |
|
482 iGroupID); |
|
483 |
|
484 (void)iProperty.Set(thisSID, |
|
485 KPropertyKeyBluetoothL2DBGMinPDUGetTime, |
|
486 iMinGetPDU); |
|
487 (void)iProperty.Set(thisSID, |
|
488 KPropertyKeyBluetoothL2DBGMaxPDUGetTime, |
|
489 iMaxGetPDU); |
|
490 |
|
491 (void)iProperty.Set(thisSID, |
|
492 KPropertyKeyBluetoothL2DBGMinPDUSentTime, |
|
493 iMinSentPDU); |
|
494 (void)iProperty.Set(thisSID, |
|
495 KPropertyKeyBluetoothL2DBGMaxPDUSentTime, |
|
496 iMaxSentPDU); |
|
497 |
|
498 (void)iProperty.Set(thisSID, |
|
499 KPropertyKeyBluetoothL2DBGAvePDUGetTime, |
|
500 iAveGetPDU); |
|
501 (void)iProperty.Set(thisSID, |
|
502 KPropertyKeyBluetoothL2DBGAvePDUSentTime, |
|
503 iAveSentPDU); |
|
504 |
|
505 } |
|
506 } |
|
507 } |