00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef FIP_TRACE_H_
00032 #define FIP_TRACE_H_
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 #define TRACE_LEVEL_NONE 4
00143
00144 #define TRACE_LEVEL_ERROR 3
00145
00146 #define TRACE_LEVEL_WARN 2
00147
00148 #define TRACE_LEVEL_INFO 1
00149
00150 #define TRACE_LEVEL_DEBUG 0
00151
00152
00153 #define TRACE_LEVEL_DEFAULT TRACE_LEVEL_INFO
00154
00155 #ifdef TRACE_USE_DYNAMIC
00156 #if TRACE_USE_DYNAMIC
00157 #undef TRACE_LEVEL
00158 extern unsigned char fip_global_trace_level;
00159 #define TRACE_LEVEL fip_global_trace_level
00160 #endif
00161 #endif
00162
00163 #ifdef MINIMIZE_STRING_WASTE
00164 #define TRACE_LEVEL TRACE_LEVEL_NONE
00165 #endif
00166
00167 #ifndef TRACE_LEVEL
00168 #define TRACE_LEVEL TRACE_LEVEL_DEFAULT
00169 #endif
00170
00171
00172
00173
00174 #ifndef TRACE_DEFINE_STRINGS
00175 #define TRACE_DEFINE_STRINGS 0
00176 #endif
00177
00178
00179 #ifndef __builtin_extract_return_address
00180 #define __builtin_extract_return_address
00181 #endif
00182
00183
00184
00185
00186 #define builtin_getRPtr() __builtin_extract_return_address(__builtin_return_address(0))
00187
00188
00189 #if __AVR__
00190 #define TRACE_DEFINE_CONSTSTRING(a) const char a##_P[] __attribute__((__progmem__)) = a##_S
00191 #else
00192
00193 #define memcpy_P memcpy
00194
00195 #define printf_P printf
00196
00197 #define PROGMEM
00198
00199 #define PGM_P const char *
00200
00201 #define TRACE_DEFINE_CONSTSTRING(a) const char a##_P[] = a##_S
00202 #endif
00203
00204
00205
00206
00207
00208
00209
00210 #define TRACE_INIT_STRINGARRAY(a) [a] = a##_P
00211
00212
00213 #define TRACE_LEVEL_DEBUG_S "DEBUG"
00214 #define TRACE_LEVEL_INFO_S "INFO"
00215 #define TRACE_LEVEL_WARN_S "WARN"
00216 #define TRACE_LEVEL_ERROR_S "ERROR"
00217 #define TRACE_LEVEL_NONE_S ""
00218
00219 #if TRACE_DEFINE_STRINGS
00220 TRACE_DEFINE_CONSTSTRING(TRACE_LEVEL_DEBUG);
00221 TRACE_DEFINE_CONSTSTRING(TRACE_LEVEL_INFO);
00222 TRACE_DEFINE_CONSTSTRING(TRACE_LEVEL_WARN);
00223 TRACE_DEFINE_CONSTSTRING(TRACE_LEVEL_ERROR);
00224 TRACE_DEFINE_CONSTSTRING(TRACE_LEVEL_NONE);
00225
00226 PGM_P trace_level_array[] PROGMEM = {
00227 TRACE_INIT_STRINGARRAY(TRACE_LEVEL_DEBUG),
00228 TRACE_INIT_STRINGARRAY(TRACE_LEVEL_INFO),
00229 TRACE_INIT_STRINGARRAY(TRACE_LEVEL_WARN),
00230 TRACE_INIT_STRINGARRAY(TRACE_LEVEL_ERROR),
00231 TRACE_INIT_STRINGARRAY(TRACE_LEVEL_NONE),
00232 };
00233 #else
00234 extern PGM_P trace_level_array[] PROGMEM;
00235 #endif
00236
00237
00238
00239 #define FIP_TRACE_TR_NULL 0
00240 #define FIP_TRACE_TR_NULL_S ""
00241
00242 #define FIP_TRACE_TR_STARTINPUT 1
00243 #define FIP_TRACE_TR_STARTINPUT_S "Input processing begins"
00244
00245 #define FIP_TRACE_TR_STARTOUTPUT 2
00246 #define FIP_TRACE_TR_STARTOUTPUT_S "Output processing begins"
00247
00248 #define FIP_TRACE_TR_HDRINVALID 3
00249 #define FIP_TRACE_TR_HDRINVALID_S "Header Invalid"
00250
00251 #define FIP_TRACE_TR_TOOSHORT 4
00252 #define FIP_TRACE_TR_TOOSHORT_S "Packet too short"
00253
00254 #define FIP_TRACE_TR_WRONGADDR 5
00255 #define FIP_TRACE_TR_WRONGADDR_S "Packet not addressed to us"
00256
00257 #define FIP_TRACE_TR_SRCMULTI 6
00258 #define FIP_TRACE_TR_SRCMULTI_S "Source Address Multicast"
00259
00260 #define FIP_TRACE_TR_RXMULTI 7
00261 #define FIP_TRACE_TR_RXMULTI_S "Packet destined to us, multicast"
00262
00263 #define FIP_TRACE_TR_RXUNI 8
00264 #define FIP_TRACE_TR_RXUNI_S "Packet destined to us, unicast"
00265
00266 #define FIP_TRACE_TR_HDRUNKNOWN 9
00267 #define FIP_TRACE_TR_HDRUNKNOWN_S "Header type unknown"
00268
00269 #define FIP_TRACE_TR_CHECKSUM 10
00270 #define FIP_TRACE_TR_CHECKSUM_S "Checksum invalid"
00271
00272 #define FIP_TRACE_TR_MEMORY 11
00273 #define FIP_TRACE_TR_MEMORY_S "Out of memory"
00274
00275 #define FIP_TRACE_TR_TIMEOUT 12
00276 #define FIP_TRACE_TR_TIMEOUT_S "Timeout exceeded"
00277
00278 #define FIP_TRACE_TR_OUTOFORDER 13
00279 #define FIP_TRACE_TR_OUTOFORDER_S "Out of order packet delivery"
00280
00281 #define FIP_TRACE_TR_DAD_NS 14
00282 #define FIP_TRACE_TR_DAD_NS_S "DAD: NS Sent"
00283
00284 #define FIP_TRACE_TR_DAD_DONE 15
00285 #define FIP_TRACE_TR_DAD_DONE_S "DAD: Finished OK"
00286
00287 #define FIP_TRACE_TR_NA_SENT 16
00288 #define FIP_TRACE_TR_NA_SENT_S "Unsolicited NA Sent"
00289
00290 #define FIP_TRACE_TR_NA_UNKNOWN 17
00291 #define FIP_TRACE_TR_NA_UNKNOWN_S "NA Received but dropped as no reference in neighbour cache"
00292
00293 #define FIP_TRACE_TR_NA_NOLLAO 18
00294 #define FIP_TRACE_TR_NA_NOLLAO_S "NA Received but dropped as no LLAO present"
00295
00296 #define FIP_TRACE_TR_INVALIDPARAM 19
00297 #define FIP_TRACE_TR_INVALIDPARAM_S "Invalid Parameters"
00298
00299 #define FIP_TRACE_TR_ULSET 20
00300 #define FIP_TRACE_TR_ULSET_S "U/L Bit Set"
00301
00302 #define FIP_TRACE_TR_ULNOTSET 21
00303 #define FIP_TRACE_TR_ULNOTSET_S "U/L Bit Not Set"
00304
00305 #define FIP_TRACE_TR_IIDMATCH 22
00306 #define FIP_TRACE_TR_IIDMATCH_S "IID Matches"
00307
00308 #define FIP_TRACE_TR_ADDRDUPLICATE 24
00309 #define FIP_TRACE_TR_ADDRDUPLICATE_S "Duplicate Address"
00310
00311 #define FIP_TRACE_TR_ROUTINGHEADER 25
00312 #define FIP_TRACE_TR_ROUTINGHEADER_S "Routing Header"
00313
00314 #define FIP_TRACE_TR_ROUTEFAILED 26
00315 #define FIP_TRACE_TR_ROUTEFAILED_S "Route Failed"
00316
00317 #define FIP_TRACE_TR_NARECEIVED 27
00318 #define FIP_TRACE_TR_NARECEIVED_S "NA Received"
00319
00320 #define FIP_TRACE_TR_NOTAUTOCONF 28
00321 #define FIP_TRACE_TR_NOTAUTOCONF_S "Address not autoconf based"
00322
00323 #define FIP_TRACE_TR_TOOBIG 29
00324 #define FIP_TRACE_TR_TOOBIG_S "Packet too big"
00325
00326 #define FIP_TRACE_TR_TTLZERO 30
00327 #define FIP_TRACE_TR_TTLZERO_S "TTL of Zero"
00328
00329 #define FIP_TRACE_TR_UNKNOWNOPT 31
00330 #define FIP_TRACE_TR_UNKNOWNOPT_S "Unknown option type"
00331
00332 #define FIP_TRACE_TR_ECHOREQ 32
00333 #define FIP_TRACE_TR_ECHOREQ_S "ICMP Echo Request"
00334
00335 #define FIP_TRACE_TR_QUEUE 33
00336 #define FIP_TRACE_TR_QUEUE_S "Packet removed from Queue"
00337
00338 #define FIP_TRACE_TR_FRAG 34
00339 #define FIP_TRACE_TR_FRAG_S "Fragmentation"
00340
00341
00342
00343 #if TRACE_DEFINE_STRINGS
00344 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NULL);
00345 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_STARTINPUT);
00346 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_STARTOUTPUT);
00347 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_HDRINVALID);
00348 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TOOSHORT);
00349 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_WRONGADDR);
00350 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_SRCMULTI);
00351 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_RXMULTI);
00352 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_RXUNI);
00353 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_HDRUNKNOWN);
00354 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_CHECKSUM);
00355 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_MEMORY);
00356 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TIMEOUT);
00357 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_OUTOFORDER);
00358 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_DAD_NS);
00359 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_DAD_DONE);
00360 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NA_SENT);
00361 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NA_UNKNOWN);
00362 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NA_NOLLAO);
00363 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_INVALIDPARAM);
00364 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ULSET);
00365 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ULNOTSET);
00366 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_IIDMATCH);
00367 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ADDRDUPLICATE);
00368 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ROUTINGHEADER);
00369 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ROUTEFAILED);
00370 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NARECEIVED);
00371 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NOTAUTOCONF);
00372 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TOOBIG);
00373 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TTLZERO);
00374 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_UNKNOWNOPT);
00375 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ECHOREQ);
00376 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_QUEUE);
00377 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_FRAG);
00378
00379
00380 PGM_P trace_trigger_array[] PROGMEM = {
00381 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NULL),
00382 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_STARTINPUT),
00383 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_STARTOUTPUT),
00384 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_HDRINVALID),
00385 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TOOSHORT),
00386 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_WRONGADDR),
00387 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_SRCMULTI),
00388 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_RXMULTI),
00389 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_RXUNI),
00390 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_HDRUNKNOWN),
00391 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_CHECKSUM),
00392 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_MEMORY),
00393 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TIMEOUT),
00394 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_OUTOFORDER),
00395 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_DAD_NS),
00396 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_DAD_DONE),
00397 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NA_SENT),
00398 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NA_UNKNOWN),
00399 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NA_NOLLAO),
00400 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_INVALIDPARAM),
00401 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ULSET),
00402 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ULNOTSET),
00403 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_IIDMATCH),
00404 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ADDRDUPLICATE),
00405 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ROUTINGHEADER),
00406 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ROUTEFAILED),
00407 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NARECEIVED),
00408 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NOTAUTOCONF),
00409 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TOOBIG),
00410 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TTLZERO),
00411 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_UNKNOWNOPT),
00412 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ECHOREQ),
00413 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_QUEUE),
00414 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_FRAG),
00415
00416 };
00417
00418 #else
00419 extern PGM_P trace_trigger_array[] PROGMEM;
00420 #endif
00421
00422
00423
00424 #define FIP_TRACE_ACT_NONE 0
00425 #define FIP_TRACE_ACT_NONE_S ""
00426
00427 #define FIP_TRACE_ACT_DROPPED 1
00428 #define FIP_TRACE_ACT_DROPPED_S "Dropped"
00429
00430 #define FIP_TRACE_ACT_EXCEPTION 2
00431 #define FIP_TRACE_ACT_EXCEPTION_S "Exception raised"
00432
00433 #define FIP_TRACE_ACT_SKIPDAD 3
00434 #define FIP_TRACE_ACT_SKIPDAD_S "Moving address to preferred"
00435
00436 #define FIP_TRACE_ACT_DISABLED 4
00437 #define FIP_TRACE_ACT_DISABLED_S "Disabled"
00438
00439 #define FIP_TRACE_ACT_FAILED 5
00440 #define FIP_TRACE_ACT_FAILED_S "Failed"
00441
00442 #define FIP_TRACE_ACT_SENDING 6
00443 #define FIP_TRACE_ACT_SENDING_S "Sending"
00444
00445 #define FIP_TRACE_ACT_DONE 7
00446 #define FIP_TRACE_ACT_DONE_S "Done"
00447
00448
00449
00450 #if TRACE_DEFINE_STRINGS
00451 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_NONE);
00452 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_DROPPED);
00453 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_EXCEPTION);
00454 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_SKIPDAD);
00455 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_DISABLED);
00456 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_FAILED);
00457 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_SENDING);
00458 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_DONE);
00459
00460
00461 PGM_P trace_action_array[] PROGMEM = {
00462 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_NONE),
00463 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_DROPPED),
00464 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_EXCEPTION),
00465 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_SKIPDAD),
00466 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_DISABLED),
00467 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_FAILED),
00468 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_SENDING),
00469 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_DONE),
00470
00471 };
00472 #else
00473 extern PGM_P trace_action_array[] PROGMEM;
00474 #endif
00475
00476 typedef unsigned char fip_trace_lvl_t;
00477 typedef unsigned char fip_trace_tr_t;
00478 typedef unsigned char fip_trace_act_t;
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489 #define TRACE(level, trigger, action) if(TRACE_LEVEL_##level >= TRACE_LEVEL) fip_trace_print(TRACE_LEVEL_##level, __func__, FIP_TRACE_TR_##trigger, FIP_TRACE_ACT_##action)
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503 #define TRACE_ADDVAR(level, format, order, name, ptr, size) if(TRACE_LEVEL_##level >= TRACE_LEVEL) fip_trace_addvar(TRACE_ORDER_##order | TRACE_FORMAT_##format, name, (unsigned char *)ptr, size);
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513 #define TRACE_ADDVARH(level, format, name) TRACE_ADDVAR(level, format, HOST, #name, &name, sizeof(name))
00514
00515
00516
00517
00518
00519
00520
00521
00522 #define TRACE_ADDRET(level) TRACE_ADDVAR(level, POINTER, HOST, "Retaddr", builtin_getRPtr(), sizeof(void *));
00523
00524
00525
00526
00527
00528
00529
00530
00531 #define TRACE_ADDIP6ADDR(level, name, addr) TRACE_ADDVAR(level, IPV6ADDR, MSBFIRST, name, addr, 16)
00532
00533
00534 #define TRACE_FORMAT_NULL 0
00535
00536
00537 #define TRACE_FORMAT_UNSIGNED 1
00538
00539
00540 #define TRACE_FORMAT_SIGNED 2
00541
00542
00543 #define TRACE_FORMAT_HEX 3
00544
00545
00546 #define TRACE_FORMAT_IPV6ADDR 4
00547
00548
00549 #define TRACE_FORMAT_BYTEADDR 5
00550
00551 #define TRACE_FORMAT_POINTER 6
00552
00553
00554
00555 #define TRACE_ORDER_MSBFIRST 0x80
00556
00557
00558 #define TRACE_ORDER_LSBFIRST 0x00
00559
00560
00561 #define TRACE_ORDER_MASK 0x80
00562
00563
00564 #define TRACE_FORMAT_MASK 0x7F
00565
00566 #define TRACE_ORDER_HOST TRACE_ORDER_LSBFIRST
00567 #define TRACE_ORDER_NETWORK TRACE_ORDER_MSBFIRST
00568
00569
00570
00571 void fip_trace_print(fip_trace_lvl_t level,
00572 const char * funcName,
00573 fip_trace_tr_t trigger,
00574 fip_trace_act_t action);
00575
00576
00577
00578
00579 void fip_trace_addvar(unsigned char format_code,
00580 char * name,
00581 unsigned char *ptr,
00582 unsigned char size);
00583
00584
00585
00586 void fip_trace_test(void);
00587
00588
00589
00590 #endif