AT-NFC 2.1 (win) AT-NFC kernel set

hal_trace.h
Go to the documentation of this file.
1 #ifndef HAL_TRACE_H
2 #define HAL_TRACE_H
3
4 /* ****************************** HAL TRACE API declaration ******************************** */
8 /* ***************************************************************************************** */
9
10 /* ***************************************************************************************** */
17 /* ***************************************************************************************** */
18
19 /* ********************************* hal_set_trace_mode ************************************ */
28 /* ***************************************************************************************** */
29 extern KER_BOOL hal_set_trace_mode(KER_CTX_PARAM KER_BYTE btTraceMode);
30
31 /* ********************************* hal_get_trace_mode ************************************ */
37 /* ***************************************************************************************** */
38 extern KER_BYTE hal_get_trace_mode(KER_CTX_SINGLE_PARAM);
39
40 /* ********************************** hal_trace_string ************************************* */
49 /* ***************************************************************************************** */
50 extern KER_BOOL hal_trace_string(KER_CTX_PARAM const KER_CHAR* pchString);
51
52 /* ********************************** hal_trace_buffer ************************************* */
62 /* ***************************************************************************************** */
63 extern KER_BOOL hal_trace_buffer(KER_CTX_PARAM const KER_BYTE* pbtDataBuffer, KER_INT16U usDataBufferSize);
64
65 /* *********************************** hal_trace_time ************************************** */
72 /* ***************************************************************************************** */
73 extern KER_BOOL hal_trace_time(KER_CTX_SINGLE_PARAM);
74
75 /* ********************************* hal_keep_trace_time *********************************** */
85 /* ***************************************************************************************** */
86 extern KER_BOOL hal_keep_trace_time(KER_CTX_PARAM KER_BYTE* pbtTimeBuffer, KER_INT16U* pusTimeBufferSize);
87
88 /* *********************************** hal_trace_flush ************************************* */
95 /* ***************************************************************************************** */
96 extern KER_BOOL hal_trace_flush(KER_CTX_SINGLE_PARAM);
97
98 /* ************************************** hal_error **************************************** */
109 /* ***************************************************************************************** */
110 extern KER_BOOL hal_error(KER_CTX_PARAM KER_INT16U usTraceLevel, KER_RES resErrCode, const KER_CHAR* pchErrorText);
111
112 /* *********************************** trace marcos **************************************** */
117 /* ***************************************************************************************** */
118 #define KER_TRACE_MODE_STD 0x00
119 #define KER_TRACE_MODE_SENS 0x01
121 #define KER_TRACE_APDU_REQ_TAB " "
122 #define KER_TRACE_APDU_INT_REQ_TAB " Int"
123 #define KER_TRACE_APDU_INT_RESP_TAB " Int"
124 #define KER_TRACE_APDU_RESP_TAB " "
126 #define KER_TRACE_COMB_TAB " "
127 /* ***************************************************************************************** */
128
129 /* ***************************************************************************************** */
130 /* Use this macro to include trace */
131 /* ***************************************************************************************** */
132 #define KER_DBG_EX(IgnoreLevel,ErrLevel) ((KER_DEBUG == KER_TRUE) && ((KER_DEBUG_LEVEL >= ErrLevel) || (KER_DEBUG_ALL == KER_TRUE) || (IgnoreLevel == KER_TRUE)))
133 #define KER_DBG(ErrLevel) KER_DBG_EX(KER_FALSE,ErrLevel)
134 #define KER_INFO KER_DBG_EX(KER_TRUE,0)
136 /* ***************************************************************************************** */
137 /* Use this macro to trace eol */
138 /* ***************************************************************************************** */
139 #ifndef KER_TRACE_EOL /* If Custom trace not defined, then use default */
140 #define KER_TRACE_EOL "\r\n"
141 #endif /* KER_TRACE_EOL */
142
143 /* ***************************************************************************************** */
144 /* Use this macro to trace comment headers */
145 /* ***************************************************************************************** */
146 #ifndef KER_COMMENT_HDR_NO_TIME /* If Custom trace not defined, then use default */
147 /* check trace level */
148 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
153 /* default trace comment w/o time macro */
154 #define KER_COMMENT_HDR_NO_TIME(comment) \
155 do \
156 { \
157 KER_CHAR ar_chHeader[] = "****************************************************************"; \
158 hal_trace_string(KER_CTX KER_TRACE_EOL); \
159 if ((sizeof(comment) + 12) >= sizeof(ar_chHeader)) \
160 { \
161 hal_trace_string(KER_CTX "***** "); \
162 hal_trace_string(KER_CTX comment); \
163 hal_trace_string(KER_CTX " *****"); \
164 } \
165 else \
166 { \
167 KER_BYTE btOffset = (sizeof(ar_chHeader) - (sizeof(comment) + 2)) / 2; \
168 ar_chHeader[btOffset] = ' '; \
169 KER_MEM_ADD(ar_chHeader, sizeof(ar_chHeader), btOffset + 1, comment, sizeof(comment) - 1); \
170 ar_chHeader[btOffset + sizeof(comment)] = ' '; \
171 hal_trace_string(KER_CTX ar_chHeader); \
172 } \
173 hal_trace_string(KER_CTX KER_TRACE_EOL); \
174 } \
175 while(0)
176 #else
177 /* empty trace comment w/o time macro */
178 #define KER_COMMENT_HDR_NO_TIME(commnet)
179 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
180 #endif /* KER_COMMENT_HDR_NO_TIME */
181
182 /* ***************************************************************************************** */
183 /* Use this macro to trace comment headers */
184 /* ***************************************************************************************** */
185 #ifndef KER_COMMENT_HDR_EX /* If Custom trace not defined, then use default */
186 /* check trace level */
187 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
192 /* default trace comment macro */
193 #define KER_COMMENT_HDR_EX(comment) \
194 do \
195 { \
196 KER_COMMENT_HDR_NO_TIME(comment); \
197 hal_trace_time(KER_CTX_SINGLE); \
198 hal_trace_string(KER_CTX KER_TRACE_EOL KER_TRACE_EOL); \
199 } \
200 while(0)
201 #else
202 /* empty trace comment macro */
203 #define KER_COMMENT_HDR_EX(commnet)
204 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
205 #endif /* KER_COMMENT_HDR_EX */
206
207 /* ***************************************************************************************** */
208 /* Use this macro to trace comment footers */
209 /* ***************************************************************************************** */
210 #ifndef KER_COMMENT_FTR_EX /* If Custom trace not defined, then use default */
211 /* check trace level */
212 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
217 /* default trace comment macro */
218 #define KER_COMMENT_FTR_EX(comment) \
219 do \
220 { \
221 KER_CHAR ar_chHeader[] = "****************************************************************"; \
222 if ((sizeof(comment) + 12) >= sizeof(ar_chHeader)) \
223 { \
224 hal_trace_string(KER_CTX "*end* "); \
225 hal_trace_string(KER_CTX comment); \
226 hal_trace_string(KER_CTX " *end*"); \
227 } \
228 else \
229 { \
230 KER_BYTE btOffset = (sizeof(ar_chHeader) - (sizeof(comment) + 12)) / 2; \
231 KER_MEM_ADD(ar_chHeader, sizeof(ar_chHeader), btOffset, "*end* ", 6); \
232 KER_MEM_ADD(ar_chHeader, sizeof(ar_chHeader), btOffset + 6, comment, sizeof(comment) - 1); \
233 KER_MEM_ADD(ar_chHeader, sizeof(ar_chHeader), btOffset + 6 + sizeof(comment) - 1, " *end*", 6); \
234 hal_trace_string(KER_CTX ar_chHeader); \
235 } \
236 hal_trace_string(KER_CTX KER_TRACE_EOL KER_TRACE_EOL); \
237 hal_trace_flush(KER_CTX_SINGLE); \
238 } \
239 while(0)
240 #else
241 /* empty trace comment macro */
242 #define KER_COMMENT_FTR_EX()
243 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
244 #endif /* KER_COMMENT_FTR_EX */
245
246 /* ***************************************************************************************** */
247 /* Use this macro to define default trace header text */
248 /* ***************************************************************************************** */
249 #ifndef KER_COMMENT_HDR_TEXT /* If Custom trace not defined, then use default */
250 /* check trace level */
251 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
252 #define KER_COMMENT_HDR_TEXT(text) const KER_CHAR const_ch___CommentHeader[] = text
253 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
254 #endif /* KER_COMMENT_HDR_TEXT */
255
256 /* ***************************************************************************************** */
257 /* Use this macro to define default trace header */
258 /* ***************************************************************************************** */
259 #ifndef KER_COMMENT_HDR /* If Custom trace not defined, then use default */
260 /* check trace level */
261 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
262 #define KER_COMMENT_HDR(text) KER_COMMENT_HDR_TEXT(text); KER_COMMENT_HDR_EX(const_ch___CommentHeader)
263 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
264 #endif /* KER_COMMENT_HDR */
265
266 /* ***************************************************************************************** */
267 /* Use this macro to define default trace footer text */
268 /* ***************************************************************************************** */
269 #ifndef KER_COMMENT_FTR /* If Custom trace not defined, then use default */
270 /* check trace level */
271 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
272 #define KER_COMMENT_FTR() KER_COMMENT_FTR_EX(const_ch___CommentHeader)
273 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
274 #endif /* KER_COMMENT_FTR */
275
276 /* ***************************************************************************************** */
277 /* Use this macro to trace text w/o eol */
278 /* ***************************************************************************************** */
279 #ifndef KER_COMMENT_TEXT /* If Custom trace not defined, then use default */
280 /* check trace level */
281 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
286 /* default trace text macro */
287 #define KER_COMMENT_TEXT(text) hal_trace_string(KER_CTX text)
288 #else
289 /* empty trace text macro */
290 #define KER_COMMENT_TEXT(text)
291 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
292 #endif /* KER_COMMENT_TEXT */
293
294 /* ***************************************************************************************** */
295 /* Use this macro to trace comments */
296 /* ***************************************************************************************** */
297 #ifndef KER_COMMENT /* If Custom trace not defined, then use default */
298 /* check trace level */
299 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
304 /* default trace comment macro */
305 #define KER_COMMENT(comment) \
306 do \
307 { \
308 hal_trace_string(KER_CTX comment); \
309 hal_trace_string(KER_CTX KER_TRACE_EOL); \
310 } \
311 while(0)
312 #else
313 /* empty trace comment macro */
314 #define KER_COMMENT(commnet)
315 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
316 #endif /* KER_COMMENT */
317
318 /* ***************************************************************************************** */
319 /* Use this macro to define default trace test mode text */
320 /* ***************************************************************************************** */
321 #ifndef KER_COMMENT_TEST_MODE /* If Custom trace not defined, then use default */
322 /* check trace level */
323 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
324 #define KER_COMMENT_TEST_MODE() KER_COMMENT("########################## TEST MODE! ##########################")
325 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
326 #endif /* KER_COMMENT_TEST_MODE */
327
328 /* ***************************************************************************************** */
329 /* Use this macro to define default trace test mode disabled text */
330 /* ***************************************************************************************** */
331 #ifndef KER_COMMENT_TEST_MODE_DISABLED /* If Custom trace not defined, then use default */
332 /* check trace level */
333 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
334 #define KER_COMMENT_TEST_MODE_DISABLED() KER_COMMENT("###################### TEST MODE DISABLED ######################")
335 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
336 #endif /* KER_COMMENT_TEST_MODE_DISABLED */
337
338 /* ***************************************************************************************** */
339 /* Use this macro to trace time */
340 /* ***************************************************************************************** */
341 #ifndef KER_TRACE_TIME /* If Custom trace not defined, then use default */
342 /* check trace level */
343 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
348 /* default trace comment macro */
349 #define KER_TRACE_TIME() hal_trace_time(KER_CTX_SINGLE)
350 #else
351 /* empty trace comment macro */
352 #define KER_TRACE_TIME()
353 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
354 #endif /* KER_TRACE_TIME */
355
356 /* ***************************************************************************************** */
357 /* Use this macro to trace comments with hex data */
358 /* ***************************************************************************************** */
359 #ifndef KER_COMMENT_HEX /* If Custom trace not defined, then use default */
360 /* check trace level */
361 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
366 /* default trace comment with hex data macro */
367 #define KER_COMMENT_HEX(comment_start, buff, buff_len, comment_end) \
368 do \
369 { \
370 hal_trace_string(KER_CTX comment_start); \
371 hal_trace_buffer(KER_CTX buff, buff_len); \
372 hal_trace_string(KER_CTX comment_end); \
373 } \
374 while(0)
375 #else
376 /* empty trace comment macro */
377 #define KER_COMMENT_HEX(comment_start, buff, buff_len, comment_end)
378 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
379 #endif /* KER_COMMENT_HEX */
380
381 /* ***************************************************************************************** */
382 /* Use this macro to fill text string with hex data */
383 /* ***************************************************************************************** */
384 #ifndef KER_TEXT_HEX /* If Custom trace not defined, then use default */
387 #define KER_TEXT_HEX(dest, dest_len, buff, buff_len) \
388 do \
389 { \
390 KER_INT16U usI; \
391 KER_CHAR ar_chBuff[8]; \
392 KER_MEM_SET(dest, dest_len, 0, dest_len); \
393 for (usI = 0; usI < (KER_BYTE)(buff_len); usI++) \
394 { \
395 hal_sprintf(KER_CTX ar_chBuff, sizeof(ar_chBuff), "%02X", (KER_NATIVE_UINT)buff[usI]); \
396 KER_MEM_ADD(dest, dest_len, usI * 2, ar_chBuff, 2); \
397 } \
398 } \
399 while(0)
400 #endif /* KER_TEXT_HEX */
401
402 /* ***************************************************************************************** */
403 /* Use this macro to trace comments with ansi string data */
404 /* ***************************************************************************************** */
405 #ifndef KER_COMMENT_STR /* If Custom trace not defined, then use default */
406 /* check trace level */
407 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
412 /* default trace comment with ansi string data buffer macro */
413 #define KER_COMMENT_STR(comment_start, buff, buff_len, comment_end) \
414 do \
415 { \
416 KER_CHAR ar_ch___Buffer[8]; \
417 KER_INT16U us___Pos; \
418 hal_trace_string(KER_CTX comment_start); \
419 for (us___Pos = 0; us___Pos < (buff_len); us___Pos++) \
420 { \
421 if ((buff)[us___Pos] >= 0x20) \
422 hal_sprintf(KER_CTX ar_ch___Buffer, sizeof(ar_ch___Buffer), "%c", (KER_CHAR)((buff)[us___Pos])); \
423 else \
424 hal_sprintf(KER_CTX ar_ch___Buffer, sizeof(ar_ch___Buffer), "[%02X]", (KER_NATIVE_UINT)((buff)[us___Pos])); \
425 hal_trace_string(KER_CTX ar_ch___Buffer); \
426 } \
427 hal_trace_string(KER_CTX comment_end); \
428 } \
429 while(0)
430 #else
431 /* empty trace comment macro */
432 #define KER_COMMENT_STR(comment_start, buff, buff_len, comment_end)
433 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
434 #endif /* KER_COMMENT_STR */
435
436 /* ***************************************************************************************** */
437 /* Use this macro to declare one buffer for all trace error calls per function */
438 /* ***************************************************************************************** */
439 #ifndef KER_TRACE_ERR_BUF /* If Custom trace not defined, then use default */
442 #define KER_TRACE_ERR_BUF KER_CHAR ar_ch___ErrBuffer[32];
443 #endif
444
445 /* ***************************************************************************************** */
446 /* Use this macro to declare one buffer for all trace error calls per function (debug only) */
447 /* ***************************************************************************************** */
448 #ifndef KER_TRACE_SYS_ERR_BUF /* If Custom trace not defined, then use default */
451 #ifdef _DEBUG
452 #define KER_TRACE_SYS_ERR_BUF KER_CHAR ar_ch___ErrBuffer[32];
453 #else
454 #define KER_TRACE_SYS_ERR_BUF
455 #endif // _DEBUG
456 #endif
457
458 /* ***************************************************************************************** */
459 /* Use this macro to declare one buffer for all trace info calls per function */
460 /* ***************************************************************************************** */
461 #ifndef KER_TRACE_BUF /* If Custom trace not defined, then use default */
464 #define KER_TRACE_BUF(Size) KER_CHAR ar_ch___InfBuffer[Size];
465 #endif
466
467 /* ***************************************************************************************** */
468 /* Use this macro to reset common trace buffer for PCI SSS. */
469 /* ***************************************************************************************** */
470 #ifndef KER_RESET_TRACE_BUF /* If Custom trace not defined, then use default */
473 #define KER_RESET_TRACE_BUF KER_MEM_SET(ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), 0, sizeof(ar_ch___InfBuffer));
474 #endif
475
476 /* ***************************************************************************************** */
477 /* Use this macro to trace errors */
478 /* ***************************************************************************************** */
479 #ifndef KER_ERROR /* If Custom trace not defined, then use default */
480 #ifdef _DEBUG
485 #define KER_ERROR(err_code,trace_level,comment) \
486 do \
487 { \
488 if ((KER_DEBUG == KER_TRUE) && (trace_level <= KER_DEBUG_LEVEL)) \
489 { \
490 /* trace comment firstly*/ \
491 if (comment != KER_NULL) \
492 { \
493 /* trace to erl */ \
494 hal_error(KER_CTX trace_level, err_code, comment); \
495 /* trace to emv */ \
496 hal_trace_string(KER_CTX comment); \
497 } \
498 /* trace error */ \
499 hal_sprintf(KER_CTX ar_ch___ErrBuffer, sizeof(ar_ch___ErrBuffer), " Error: %08lX ", (KER_NATIVE_ULONG)(err_code)); \
500 hal_trace_string(KER_CTX ar_ch___ErrBuffer); \
501 hal_trace_string(KER_CTX __FILE__); \
502 hal_sprintf(KER_CTX ar_ch___ErrBuffer, sizeof(ar_ch___ErrBuffer), " line:%lu" KER_TRACE_EOL, (KER_NATIVE_ULONG)__LINE__); \
503 hal_trace_string(KER_CTX ar_ch___ErrBuffer); \
504 } \
505 } \
506 while(0)
507 #else /* _DEBUG */
512 #define KER_ERROR(err_code,trace_level,comment) \
513 do \
514 { \
515 if ((KER_DEBUG == KER_TRUE) && (trace_level <= KER_DEBUG_LEVEL)) \
516 { \
517 /* trace comment firstly*/ \
518 if (comment != KER_NULL) \
519 { \
520 /* trace to erl */ \
521 hal_error(KER_CTX trace_level, err_code, comment); \
522 /* trace to emv */ \
523 hal_trace_string(KER_CTX comment); \
524 } \
525 /* trace error */ \
526 hal_sprintf(KER_CTX ar_ch___ErrBuffer, sizeof(ar_ch___ErrBuffer), " Error: %08lX" KER_TRACE_EOL, (KER_NATIVE_ULONG)(err_code)); \
527 /* trace to emv */ \
528 hal_trace_string(KER_CTX ar_ch___ErrBuffer); \
529 } \
530 } \
531 while(0)
532 #endif /* _DEBUG */
533 #endif /* KER_ERROR */
534
535 /* ***************************************************************************************** */
536 /* Use this macro to trace system errors (to erl only) */
537 /* ***************************************************************************************** */
538 #ifndef KER_SYS_ERROR /* If Custom trace not defined, then use default */
539 #ifdef _DEBUG
545 #define KER_SYS_ERROR(err_code,trace_level,comment) \
546 do \
547 { \
548 /* trace */ \
549 if (comment != KER_NULL) \
550 { \
551 /* trace error */ \
552 hal_error(KER_CTX trace_level, err_code, comment); \
553 } \
554 hal_sprintf(KER_CTX ar_ch___ErrBuffer, sizeof(ar_ch___ErrBuffer), "line:%lu file: ", (KER_NATIVE_ULONG)__LINE__); \
555 hal_error(KER_CTX trace_level, err_code, ar_ch___ErrBuffer); \
556 hal_error(KER_CTX trace_level, err_code, __FILE__); \
557 } \
558 while(0)
559 #else /* _DEBUG */
565 #define KER_SYS_ERROR(err_code,trace_level,comment) hal_error(KER_CTX trace_level, err_code, comment)
566 #endif /* _DEBUG */
567 #endif /* KER_SYS_ERROR */
568
569 /* ***************************************************************************************** */
570 /* Use this macro to trace system info (to erl only) */
571 /* ***************************************************************************************** */
572 #ifndef KER_SYS_INFO /* If Custom trace not defined, then use default */
578 #define KER_SYS_INFO(err_code,trace_level,comment) hal_error(KER_CTX trace_level, err_code, comment)
579 #endif /* KER_SYS_INFO */
580
581 /* ***************************************************************************************** */
582 /* Use this macro to trace tag not found */
583 /* ***************************************************************************************** */
584 #ifndef KER_TRACE_TAG_NOT_FOUND /* If Custom trace not defined, then use default */
585 /* check trace level */
586 #if (KER_DBG(KER_DBG_LEVEL_TAG_INFO))
591 #define KER_TRACE_TAG_NOT_FOUND(tag, tag_length) \
592 do \
593 { \
594 hal_trace_string(KER_CTX "Tag ["); \
595 hal_trace_buffer(KER_CTX tag, tag_length); \
596 hal_trace_string(KER_CTX "] not found!" KER_TRACE_EOL); \
597 } \
598 while (0)
599 #else
600 /* empty trace tag not found macro */
601 #define KER_TRACE_TAG_NOT_FOUND(tag,tag_length)
602 #endif /* KER_DBG(KER_DBG_LEVEL_TAG_INFO) */
603 #endif /* KER_TRACE_TAG_NOT_FOUND */
604
605 /* ***************************************************************************************** */
606 /* Use this macro to trace tag duplication */
607 /* ***************************************************************************************** */
608 #ifndef KER_TRACE_TAG_DUPLICATION /* If Custom trace not defined, then use default */
609 /* check trace level */
610 #if (KER_DBG(KER_DBG_LEVEL_TAG_INFO))
617 /*#define KER_TRACE_TAG_DUPLICATION(tag,tag_length,tlv1,tlv1_length,tlv2,tlv2_length) \
618 do \
619 { \
620 hal_trace_string(KER_CTX "Tag ["); \
621 hal_trace_buffer(KER_CTX tag, tag_length); \
622 hal_trace_string(KER_CTX "] duplication: "); \
623 hal_trace_buffer(KER_CTX tlv1, tlv1_length); \
624 hal_trace_string(KER_CTX " "); \
625 hal_trace_buffer(KER_CTX tlv2, tlv2_length); \
626 hal_trace_string(KER_CTX KER_TRACE_EOL); \
627 } \
628 while (0)
629 */
630 #define KER_TRACE_TAG_DUPLICATION(tag,tag_length,tlv1,tlv1_length,tlv2,tlv2_length) \
631 do \
632 { \
633 hal_trace_string(KER_CTX "Tag ["); \
634 hal_trace_buffer(KER_CTX tag, tag_length); \
635 hal_trace_string(KER_CTX "] duplication!" KER_TRACE_EOL); \
636 } \
637 while (0)
638 #else
639 /* empty trace tag not found macro */
640 #define KER_TRACE_TAG_DUPLICATION(tag,tag_length,tlv1,tlv1_length,tlv2,tlv2_length)
641 #endif /* KER_DBG(KER_DBG_LEVEL_TAG_INFO) */
642 #endif /* KER_TRACE_TAG_DUPLICATION */
643
644
645 /* ***************************************************************************************** */
646 /* Use this macro to trace APDU */
647 /* ***************************************************************************************** */
648 #ifndef KER_TRACE_APDU_REQ /* If Custom trace not defined, then use default */
649 /* check trace level */
650 #if (KER_DBG(KER_DBG_LEVEL_APDU))
657 #define KER_TRACE_APDU_REQ(bInternal,btCase,btCLA,btINS,btP1,btP2,usLc,pbtData,usLe) \
658 do \
659 { \
660 hal_sprintf(KER_CTX ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), "%sRequest: <%02X><%02X><%02X><%02X><%02X> ", \
661 (bInternal)?KER_TRACE_APDU_INT_REQ_TAB:KER_TRACE_APDU_REQ_TAB,(KER_NATIVE_UINT)(btCLA),(KER_NATIVE_UINT)(btINS),(KER_NATIVE_UINT)(btP1),(KER_NATIVE_UINT)(btP2),(KER_NATIVE_UINT)(usLc)); \
662 hal_trace_string(KER_CTX ar_ch___InfBuffer); \
663 if ((hal_get_trace_mode(KER_CTX_SINGLE) == KER_TRACE_MODE_SENS) || (((btCLA) == EMV_APDU_CLA_UNI) && ((btINS) == EMV_APDU_INS_SELECT)))\
664 hal_trace_buffer(KER_CTX pbtData, usLc); \
665 else \
666 hal_trace_string(KER_CTX "..."); \
667 if (usLe != KER_EMVL1_LE_NULL) \
668 hal_sprintf(KER_CTX ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), " <%02X> [Case%u]" KER_TRACE_EOL, (KER_NATIVE_UINT)(usLe), (KER_NATIVE_UINT)(btCase)); \
669 else \
670 hal_sprintf(KER_CTX ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), " [Case%u]" KER_TRACE_EOL, (KER_NATIVE_UINT)(btCase)); \
671 hal_trace_string(KER_CTX ar_ch___InfBuffer); \
672 } \
673 while (0)
674 #else
675 /* empty trace apdu macro */
676 #define KER_TRACE_APDU_REQ(bInternal,btCase,btCLA,btINS,btP1,btP2,btLc,pbtData,btLe)
677 #endif /* KER_DBG(KER_DBG_LEVEL_APDU) */
678 #endif /* KER_TRACE_APDU_REQ */
679
680
681 #ifndef KER_TRACE_APDU_RESP /* If Custom trace not defined, then use default */
682 /* check trace level */
683 #if (KER_DBG(KER_DBG_LEVEL_APDU))
690 #define KER_TRACE_APDU_RESP(INTERNAL,SW1SW2,DATA,DATA_LEN) \
691 do \
692 { \
693 hal_sprintf(KER_CTX ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), "%sResponse: Len = %u Sw1Sw2 = <%04X> ", (INTERNAL)?KER_TRACE_APDU_INT_RESP_TAB:KER_TRACE_APDU_RESP_TAB,(KER_NATIVE_UINT)(DATA_LEN),(KER_NATIVE_UINT)(SW1SW2)); \
694 hal_trace_string(KER_CTX ar_ch___InfBuffer); \
695 if (hal_get_trace_mode(KER_CTX_SINGLE) == KER_TRACE_MODE_SENS) \
696 hal_trace_buffer(KER_CTX (DATA), (DATA_LEN)); \
697 hal_trace_string(KER_CTX KER_TRACE_EOL); \
698 } \
699 while (0)
700 #else
701 /* empty trace apdu macro */
702 #define KER_TRACE_APDU_RESP(INTERNAL,SW1SW2,DATA,DATA_LEN)
703 #endif /* KER_DBG(KER_DBG_LEVEL_APDU) */
704 #endif /* KER_TRACE_APDU_RESP */
705
706
707 #ifndef KER_TRACE_NFC_APDU_RESP /* If Custom trace not defined, then use default */
708 /* check trace level */
709 #if (KER_DBG(KER_DBG_LEVEL_APDU))
716 #define KER_TRACE_NFC_APDU_RESP(INTERNAL,SW1SW2,EXEC_TIME,DATA,DATA_LEN) \
717 do \
718 { \
719 hal_sprintf(KER_CTX ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), "%sResponse: Time = %lu Len = %u Sw1Sw2 = <%04X> ", \
720 (INTERNAL)?KER_TRACE_APDU_INT_RESP_TAB:KER_TRACE_APDU_RESP_TAB, (KER_NATIVE_ULONG)(EXEC_TIME), (KER_NATIVE_UINT)(DATA_LEN), (KER_NATIVE_UINT)(SW1SW2)); \
721 hal_trace_string(KER_CTX ar_ch___InfBuffer); \
722 if (hal_get_trace_mode(KER_CTX_SINGLE) == KER_TRACE_MODE_SENS) \
723 hal_trace_buffer(KER_CTX (DATA), (DATA_LEN)); \
724 hal_trace_string(KER_CTX KER_TRACE_EOL); \
725 } \
726 while (0)
727 #else
728 /* empty trace apdu macro */
729 #define KER_TRACE_NFC_APDU_RESP(INTERNAL,SW1SW2,EXEC_TIME,DATA,DATA_LEN)
730 #endif /* KER_DBG(KER_DBG_LEVEL_APDU) */
731 #endif /* KER_TRACE_NFC_APDU_RESP */
732
733
734 #ifndef KER_TRACE_SUPP_AIDS /* If Custom trace not defined, then use default */
735 /* check trace level */
736 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
741 #define KER_TRACE_SUPP_APP_LIST_DEFAULT /* force to include default implementation - see hal_trace_def.c */
743 KER_VOID def_hal_trace_supp_app(KER_CTX_PARAM const KER_TLV* pSuppAppList);
745 #define KER_TRACE_SUPP_AIDS(AidList) def_hal_trace_supp_app(KER_CTX AidList);
746 #else
747 /* empty trace supp aids macro */
748 #define KER_TRACE_SUPP_AIDS(AidList)
749 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
750 #endif /* KER_TRACE_SUPP_AIDS */
751
752
753 #ifndef KER_TRACE_CL /* If Custom trace not defined, then use default */
754 /* check trace level */
755 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
760 #define KER_TRACE_CL_DEFAULT /* force to include default implementation - see hal_trace_def.c */
762 KER_VOID def_hal_trace_cl(KER_CTX_PARAM const KER_TLV* pCL);
764 #define KER_TRACE_CL(CL) def_hal_trace_cl(KER_CTX CL);
765 #else
766 /* empty trace supp aids macro */
767 #define KER_TRACE_SUPP_AIDS(pAidList)
768 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
769 #endif /* KER_TRACE_CL */
770
771
772 #ifndef KER_TRACE_TAG /* If Custom trace not defined, then use default */
773 /* check trace level */
774 #if (KER_DBG(KER_DBG_LEVEL_TAG_LIST))
779 #define KER_TRACE_TAG_DEFAULT /* force to include default implementation - see hal_trace_def.c */
781 KER_VOID def_hal_trace_tag(KER_CTX_PARAM const KER_BYTE* pbtTlv, KER_INT16U usTlvLen, KER_INT16U usOrigin);
783 #define KER_TRACE_TAG(Tlv,TlvLen,Origin) def_hal_trace_tag(KER_CTX Tlv,TlvLen,Origin)
784 #else
785 /* empty trace tag macro */
786 #define KER_TRACE_TAG(TagList,Origin)
787 #endif /* KER_DBG(KER_DBG_LEVEL_TAG_LIST) */
788 #endif /* KER_TRACE_TAG */
789
790
791 #ifndef KER_TRACE_CVM_LIST /* If Custom trace not defined, then use default */
792 /* check trace level */
793 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
798 #define KER_TRACE_CVM_LIST(TranPtr, TrType, TrCurr, IccCurr, AmountX, AmountY) \
799 do \
800 { \
801 hal_sprintf(KER_CTX ar_ch___InfBuffer, sizeof(ar_ch___InfBuffer), "CVM List processing: TrType:%02lX Curr:%03lu/%03lu TrAmount:%lu%s CashbackAmount:%lu%s Amount X:%lu Amount Y:%lu StartPos:%lu" KER_TRACE_EOL, \
802 (KER_NATIVE_ULONG)(TrType), (KER_NATIVE_ULONG)(TrCurr), (KER_NATIVE_ULONG)(IccCurr), \
803 (KER_NATIVE_ULONG)(TranPtr->ulAmountAuthLO), (TranPtr->ulAmountAuthHI > 0)?"(!)":"", \
804 (KER_NATIVE_ULONG)(TranPtr->ulAmountOtherLO), (TranPtr->ulAmountOtherHI > 0)?"(!)":"", \
805 (KER_NATIVE_ULONG)(AmountX), (KER_NATIVE_ULONG)(AmountY), (KER_NATIVE_ULONG)((TranPtr->usCvmOffset - 8)/2)); \
806 hal_trace_string(KER_CTX ar_ch___InfBuffer); \
807 } \
808 while (0)
809 #else
810 /* empty trace supp aids macro */
811 #define KER_TRACE_CVM_LIST(TranPtr, TrType, TrCurr, IccCurr, AmountX, AmountY)
812 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
813 #endif /* KER_TRACE_CVM_LIST */
814
815
816 #ifndef KER_TRACE_TVR /* If Custom trace not defined, then use default */
817 /* check trace level */
818 #if (KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT))
823 #define KER_TRACE_TVR_DEFAULT /* force to include default implementation - see hal_trace_def.c */
825 KER_VOID def_hal_trace_tvr(KER_CTX_PARAM const KER_CHAR* pchComment, const KER_BYTE* pbtTvr, KER_BYTE btTvrLen);
827 #define KER_TRACE_TVR(Comment,Tvr,TvrLen) def_hal_trace_tvr(KER_CTX Comment, Tvr, TvrLen)
828 #else
829 /* empty trace tvr macro */
830 #define KER_TRACE_TVR(Comment,Tvr,TvrLen)
831 #endif /* KER_DBG(KER_DBG_LEVEL_TRACE_COMMENT) */
832 #endif /* KER_TRACE_TVR */
833
834
835 /* If Custom trace not defined, then use default */
836 #ifndef KER_TRC_CUSTOM
837
839 #define KER_TRC_STD hal_set_trace_mode(KER_CTX KER_TRACE_MODE_STD);
841 #define KER_TRC_SENS hal_set_trace_mode(KER_CTX KER_TRACE_MODE_SENS);
842
844 #define KER_TRC_S hal_sprintf(KER_CTX ar_ch___InfBuffer,sizeof(ar_ch___InfBuffer),
846 #define KER_TRC_E ); hal_trace_string(KER_CTX ar_ch___InfBuffer);
848 #define KER_TRC_NL hal_trace_string(KER_CTX KER_TRACE_EOL);
850 #define KER_TRC_TIME hal_trace_time(KER_CTX_SINGLE);
851
852 #endif /* KER_TRC_CUSTOM */
853
856 #endif /* HAL_TRACE_H */
KER_VOID
void KER_VOID
Definition: emv_platform.h:66
KER_BOOL
KER_INT8U KER_BOOL
Definition: emv_platform.h:67
KER_BYTE
uint8_t KER_BYTE
Definition: emv_platform.h:70
KER_RES
KER_INT16U KER_RES
Definition: emv_platform.h:68
KER_INT16U
unsigned short KER_INT16U
Definition: emv_platform.h:61
KER_CHAR
char KER_CHAR
Definition: emv_platform.h:65
KER_CTX_PARAM
#define KER_CTX_PARAM
Definition: emv_context.h:53
KER_CTX_SINGLE_PARAM
#define KER_CTX_SINGLE_PARAM
Definition: emv_context.h:58
def_hal_trace_supp_app
KER_VOID def_hal_trace_supp_app(KER_CTX_PARAM const KER_TLV *pSuppAppList)
Default "trace supported applications" implementation.
hal_trace_time
KER_BOOL hal_trace_time(KER_CTX_SINGLE_PARAM)
Trace timestamp.
hal_trace_buffer
KER_BOOL hal_trace_buffer(KER_CTX_PARAM const KER_BYTE *pbtDataBuffer, KER_INT16U usDataBufferSize)
Trace povided data buffer.
hal_keep_trace_time
KER_BOOL hal_keep_trace_time(KER_CTX_PARAM KER_BYTE *pbtTimeBuffer, KER_INT16U *pusTimeBufferSize)
Keep trace timestamp.
def_hal_trace_tag
KER_VOID def_hal_trace_tag(KER_CTX_PARAM const KER_BYTE *pbtTlv, KER_INT16U usTlvLen, KER_INT16U usOrigin)
Default "trace obtained tag" implementation.
def_hal_trace_cl
KER_VOID def_hal_trace_cl(KER_CTX_PARAM const KER_TLV *pCL)
Default "trace candidate list" implementation.
hal_trace_string
KER_BOOL hal_trace_string(KER_CTX_PARAM const KER_CHAR *pchString)
Trace povided nul-term string.
hal_get_trace_mode
KER_BYTE hal_get_trace_mode(KER_CTX_SINGLE_PARAM)
Get trace mode.
hal_error
KER_BOOL hal_error(KER_CTX_PARAM KER_INT16U usTraceLevel, KER_RES resErrCode, const KER_CHAR *pchErrorText)
Trace error to system error journal.
hal_trace_flush
KER_BOOL hal_trace_flush(KER_CTX_SINGLE_PARAM)
Flush trace to trace file (optional)
hal_set_trace_mode
KER_BOOL hal_set_trace_mode(KER_CTX_PARAM KER_BYTE btTraceMode)
Set trace mode.
def_hal_trace_tvr
KER_VOID def_hal_trace_tvr(KER_CTX_PARAM const KER_CHAR *pchComment, const KER_BYTE *pbtTvr, KER_BYTE btTvrLen)
Default "trace TVR" implementation.
tag_KER_TLV
TLV container structure.
Definition: emv_data.h:63