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
00327
00328 #if TRACE_DEFINE_STRINGS
00329 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NULL);
00330 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_STARTINPUT);
00331 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_STARTOUTPUT);
00332 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_HDRINVALID);
00333 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TOOSHORT);
00334 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_WRONGADDR);
00335 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_SRCMULTI);
00336 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_RXMULTI);
00337 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_RXUNI);
00338 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_HDRUNKNOWN);
00339 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_CHECKSUM);
00340 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_MEMORY);
00341 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TIMEOUT);
00342 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_OUTOFORDER);
00343 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_DAD_NS);
00344 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_DAD_DONE);
00345 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NA_SENT);
00346 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NA_UNKNOWN);
00347 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NA_NOLLAO);
00348 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_INVALIDPARAM);
00349 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ULSET);
00350 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ULNOTSET);
00351 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_IIDMATCH);
00352 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ADDRDUPLICATE);
00353 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ROUTINGHEADER);
00354 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_ROUTEFAILED);
00355 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NARECEIVED);
00356 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_NOTAUTOCONF);
00357 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_TR_TOOBIG);
00358
00359
00360 PGM_P trace_trigger_array[] PROGMEM = {
00361 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NULL),
00362 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_STARTINPUT),
00363 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_STARTOUTPUT),
00364 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_HDRINVALID),
00365 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TOOSHORT),
00366 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_WRONGADDR),
00367 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_SRCMULTI),
00368 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_RXMULTI),
00369 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_RXUNI),
00370 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_HDRUNKNOWN),
00371 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_CHECKSUM),
00372 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_MEMORY),
00373 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TIMEOUT),
00374 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_OUTOFORDER),
00375 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_DAD_NS),
00376 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_DAD_DONE),
00377 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NA_SENT),
00378 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NA_UNKNOWN),
00379 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NA_NOLLAO),
00380 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_INVALIDPARAM),
00381 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ULSET),
00382 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ULNOTSET),
00383 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_IIDMATCH),
00384 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ADDRDUPLICATE),
00385 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ROUTINGHEADER),
00386 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_ROUTEFAILED),
00387 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NARECEIVED),
00388 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_NOTAUTOCONF),
00389 TRACE_INIT_STRINGARRAY(FIP_TRACE_TR_TOOBIG),
00390
00391 };
00392
00393 #else
00394 extern PGM_P trace_trigger_array[] PROGMEM;
00395 #endif
00396
00397
00398
00399 #define FIP_TRACE_ACT_NONE 0
00400 #define FIP_TRACE_ACT_NONE_S ""
00401
00402 #define FIP_TRACE_ACT_DROPPED 1
00403 #define FIP_TRACE_ACT_DROPPED_S "Dropped"
00404
00405 #define FIP_TRACE_ACT_EXCEPTION 2
00406 #define FIP_TRACE_ACT_EXCEPTION_S "Exception raised"
00407
00408 #define FIP_TRACE_ACT_SKIPDAD 3
00409 #define FIP_TRACE_ACT_SKIPDAD_S "Moving address to preferred"
00410
00411 #define FIP_TRACE_ACT_DISABLED 4
00412 #define FIP_TRACE_ACT_DISABLED_S "Disabled"
00413
00414 #define FIP_TRACE_ACT_FAILED 5
00415 #define FIP_TRACE_ACT_FAILED_S "Failed"
00416
00417
00418
00419 #if TRACE_DEFINE_STRINGS
00420 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_NONE);
00421 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_DROPPED);
00422 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_EXCEPTION);
00423 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_SKIPDAD);
00424 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_DISABLED);
00425 TRACE_DEFINE_CONSTSTRING(FIP_TRACE_ACT_FAILED);
00426
00427
00428 PGM_P trace_action_array[] PROGMEM = {
00429 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_NONE),
00430 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_DROPPED),
00431 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_EXCEPTION),
00432 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_SKIPDAD),
00433 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_DISABLED),
00434 TRACE_INIT_STRINGARRAY(FIP_TRACE_ACT_FAILED),
00435
00436 };
00437 #else
00438 extern PGM_P trace_action_array[] PROGMEM;
00439 #endif
00440
00441 typedef unsigned char fip_trace_lvl_t;
00442 typedef unsigned char fip_trace_tr_t;
00443 typedef unsigned char fip_trace_act_t;
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454 #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)
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468 #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);
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478 #define TRACE_ADDVARH(level, format, name) TRACE_ADDVAR(level, format, HOST, #name, &name, sizeof(name))
00479
00480
00481
00482
00483
00484
00485
00486
00487 #define TRACE_ADDRET(level) TRACE_ADDVAR(level, POINTER, HOST, "Retaddr", builtin_getRPtr(), sizeof(void *));
00488
00489
00490
00491
00492
00493
00494
00495
00496 #define TRACE_ADDIP6ADDR(level, name, addr) TRACE_ADDVAR(level, IPV6ADDR, MSBFIRST, name, addr, 16)
00497
00498
00499 #define TRACE_FORMAT_NULL 0
00500
00501
00502 #define TRACE_FORMAT_UNSIGNED 1
00503
00504
00505 #define TRACE_FORMAT_SIGNED 2
00506
00507
00508 #define TRACE_FORMAT_HEX 3
00509
00510
00511 #define TRACE_FORMAT_IPV6ADDR 4
00512
00513
00514 #define TRACE_FORMAT_BYTEADDR 5
00515
00516 #define TRACE_FORMAT_POINTER 6
00517
00518
00519
00520 #define TRACE_ORDER_MSBFIRST 0x80
00521
00522
00523 #define TRACE_ORDER_LSBFIRST 0x00
00524
00525
00526 #define TRACE_ORDER_MASK 0x80
00527
00528
00529 #define TRACE_FORMAT_MASK 0x7F
00530
00531 #define TRACE_ORDER_HOST TRACE_ORDER_LSBFIRST
00532 #define TRACE_ORDER_NETWORK TRACE_ORDER_MSBFIRST
00533
00534
00535
00536 void fip_trace_print(fip_trace_lvl_t level,
00537 const char * funcName,
00538 fip_trace_tr_t trigger,
00539 fip_trace_act_t action);
00540
00541
00542
00543
00544 void fip_trace_addvar(unsigned char format_code,
00545 char * name,
00546 unsigned char *ptr,
00547 unsigned char size);
00548
00549
00550
00551 void fip_trace_test(void);
00552
00553
00554
00555 #endif