-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtipackconv.js
More file actions
1161 lines (968 loc) · 47.4 KB
/
tipackconv.js
File metadata and controls
1161 lines (968 loc) · 47.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// (c) npeter 2020-11-20
//
// Convert TI Packet Sniffer data file (*.psd) into a format which can be imported into Excel for analysis
//
// Rev 1.0.0 - first release
//const { timeStamp } = require('console')
//var remote = require('remote')
//var dialog = remote.require('dialog')
const version = '1.0.0'
let SPDU = { // Sniffer protocol data unit
hdr: {
SPDUInformation: null,
SPDUInformationRaw: null,
SPDUNumber: null,
timeStampUs: null,
timeStampS: null,
timeDeltaS: null,
SPDULength: null
},
fdr: {
payload: [null]
},
status: {
rssi: null, // Byte1
devInfo: null, // Byte2 0-7
crcOk: null, // Byte2 7
msg: null
}
}
let MPDU = { // MAC layer protocol data unit
hdr: {
type: null,
length: null,
frameControl: null,
frameControlRaw: null,
security: null,
sequenceNumber: null,
destPANid: null,
destAddr: null,
srcPANid: null,
srcAddr: null,
},
fdr:{
payload: [null],
checkSum: null
}
}
let NPDU = { // network layer protocol data unit
hdr: { // octets
fctrl: { // 2
raw: null,
frameType: null,
protocolVersion: null,
discoverRoute: null,
multicastFlag: null,
security: null,
srcRoute: null,
destIEEEaddr: null,
srcIEEEaddr: null,
endDeviceIndicator: null
},
destAddr: null, // 2
srcAddr: null, // 2
brodcastRadius: null, // 1
broadcastSeqNum: null, // 1
destIEEEaddr: null, // 0/8
srcIEEEaddr: null, // 0/8
multicastControl: null, // 0/1
sourceRouteSubframe: null // var
},
fdr: {
payload: [null] // var
},
cmd: {
cmdIdentifier: null, // 1
cmdPayload: null, // var
type: null
}
}
let APDU = { // application layer data unit
hdr: { // octets
frameControl: { // 2
raw: null,
frameType: null,
deliveryMode: null,
ackFormat: null,
security: null,
ackReq: null,
extendedHdr: null
},
frameControlRaw: null, // -
destEndpoint: null, // 0/1
groupAddr: null, // 0/2
clusterIdentifier: null, // 0/2
profilIdentifier: null, // 0/2
srcEndpoint: null, // 0/1
apsCounter: null, // 1
extendedHdr: null // 0/var
},
fdr: {
apsCmdIdentifier: null,
payload: [null] // var
},
cmd: {
type: null
}
}
const BIT_00 = 0b0000000000000001
const BIT_01 = 0b0000000000000010
const BIT_02 = 0b0000000000000100
const BIT_03 = 0b0000000000001000
const BIT_04 = 0b0000000000010000
const BIT_05 = 0b0000000000100000
const BIT_06 = 0b0000000001000000
const BIT_07 = 0b0000000010000000
const BIT_08 = 0b0000000100000000
const BIT_09 = 0b0000001000000000
const BIT_10 = 0b0000010000000000
const BIT_11 = 0b0000100000000000
const BIT_12 = 0b0001000000000000
const BIT_13 = 0b0010000000000000
const BIT_14 = 0b0100000000000000
const BIT_15 = 0b1000000000000000
// SPDU information coding
const SPDU_INFORMATION_LENGTH_INCLUDING_FRAME_STATUS_BYTE_MSK = 0b00001
const SPDU_INFORMATION_CORRELATION_USED_MSK = 0b00010
const SPDU_INFORMATION_INCOMPLETE_SPDU_MSK = 0b00100
const SPDU_INFORMATION_GENERIC_SNIFFER_IS_USED_MSK = 0b10000
// SPDU status byte 2 CRC OK
const SPDU_STATUS_BYTE2_CRC_MSK = BIT_07
// MPDU coding
const MPDU_CONTROL_FIELD_MPDU_TYPE_BEACON = 0
const MPDU_CONTROL_FIELD_MPDU_TYPE_DATA = 1
const MPDU_CONTROL_FIELD_MPDU_TYPE_ACKNOWLEDGEMENT = 2
const MPDU_CONTROL_FIELD_MPDU_TYPE_MPDU = 3
const MPDU_CONTROL_FIELD_MPDU_TYPE_MSK = BIT_00 | BIT_01 | BIT_02
const MPDU_CONTROL_FIELD_SECURITY_ENABLED_MSK = BIT_03
const MPDU_CONTROL_FIELD_MPDU_PENDING_MSK = BIT_04
const MPDU_CONTROL_FIELD_ACK_REQUEST_MSK = BIT_05
const MPDU_CONTROL_FIELD_PAN_COMPR_MSK = BIT_06
const MPDU_CONTROL_FIELD_DEST_ADDR_MODE_MSK = BIT_10 | BIT_11
const MPDU_CONTROL_FIELD_SRC_ADDR_MODE_MSK = BIT_14 | BIT_15
const MPDU_CONTROL_FIELD_DEST_ADDR_MODE_NOT_PRESENT = (0<<10)
const MPDU_CONTROL_FIELD_DEST_ADDR_MODE_RESERVED = (1<<10)
const MPDU_CONTROL_FIELD_DEST_ADDR_MODE_SHORT_ADDR = (2<<10)
const MPDU_CONTROL_FIELD_DEST_ADDR_MODE_EXTENTED_ADDR = (3<<10)
const MPDU_CONTROL_FIELD_SRC_ADDR_MODE_NOT_PRESENT = (0<<14)
const MPDU_CONTROL_FIELD_SRC_ADDR_MODE_RESERVED = (1<<14)
const MPDU_CONTROL_FIELD_SRC_ADDR_MODE_SHORT_ADDR = (2<<14)
const MPDU_CONTROL_FIELD_SRC_ADDR_MODE_EXTENTED_ADDR = (3<<14)
// NWK coding
const NPDU_CONTROL_NPDU_TYPE_MSK = BIT_00 | BIT_01
const NPDU_CONTROL_PROTOCOL_VERSION_MSK = BIT_02 | BIT_03 | BIT_04 | BIT_05
const NPDU_CONTROL_DISCOVER_ROUTE_MSK = BIT_06 | BIT_07
const NPDU_CONTROL_MULTICAST_FLAG_MSK = BIT_08
const NPDU_CONTROL_SECURITY_MSK = BIT_09
const NPDU_CONTROL_SRC_ROUTE_MSK = BIT_10
const NPDU_CONTROL_DEST_IEEEADDR_MSK = BIT_11
const NPDU_CONTROL_SRC_IEEEADDR_MSK = BIT_12
const NPDU_CONTROL_END_DEVICE_INITIATOR_MSK = BIT_13
const NPDU_CONTROL_RESERVED_MSK = BIT_14 | BIT_15
const NPDU_CONTROL_NPDU_TYPE_DATA = (0<<0)
const NPDU_CONTROL_NPDU_TYPE_NPDU_COMMAND = (1<<0)
const NPDU_CONTROL_NPDU_TYPE_INTER_PAN = (3<<0)
const NPDU_CONTROL_NPDU_PROTOCOL_VERSION_RSHIFT = 2
const NPDU_CONTROL_DISCOVER_ROUTE_SUPPRESS = (0<<6)
const NPDU_CONTROL_DISCOVER_ROUTE_ENABLE = (1<<6)
const NPDU_COMMAND_ROUTE_REQUEST = 0x01
const NPDU_COMMAND_ROUTE_REPLAY = 0x02
const NPDU_COMMAND_NW_STATUS = 0x03
const NPDU_COMMAND_LEAVE = 0x04
const NPDU_COMMAND_ROUTE_SPDU = 0x05
const NPDU_COMMAND_REJOIN_REQUEST = 0x06
const NPDU_COMMAND_REJOIN_RESPONSE = 0x07
const NPDU_COMMAND_LINK_STATUS = 0x08
const NPDU_COMMAND_NW_REPORT = 0x09
const NPDU_COMMAND_NW_UPDATE = 0x0a
const NPDU_COMMAND_END_DEVICE_TIMEOUT_REQUEST = 0x0b
const NPDU_COMMAND_END_DEVICE_TIMEOUT_RESPONSE = 0x0c
// APDU coding
const APDU_FRAME_TYPE_MSK = BIT_00 | BIT_01
const APDU_DELIVERY_MODE_MSK = BIT_02 | BIT_03
const APDU_ACK_FORMAT_MSK = BIT_04
const APDU_SEQURITY_MSK = BIT_05
const APDU_ACK_REQUEST_MSK = BIT_06
const APDU_EXTENDET_HDR_PRESENT_MSK = BIT_07
const APDU_FRAME_TYPE_DATA = (0<<0)
const APDU_FRAME_TYPE_CMD = (1<<0)
const APDU_FRAME_TYPE_ACK = (2<<0)
const APDU_FRAME_TYPE_INTER_PAN = (3<<0)
// Delivery mode subfield 2.2.5.1.1.2
const APDU_DELIVERY_MODE_NORMAL_UNICAST = (0<<2)
const APDU_DELIVERY_MODE_BROADCAST = (2<<2)
const APDU_DELIVERY_MODE_GROUP_ADDRESSING = (3<<2)
const APDU_CMD_IDENT_ROUTE_REQ = 0x01
const APDU_CMD_IDENT_ROUTE_RPL = 0x02
const APDU_CMD_IDENT_NW_STATUS = 0x03
const APDU_CMD_IDENT_LEAVE = 0x04
const APDU_CMD_IDENT_ROUTE_RECORD = 0x05
const APDU_CMD_IDENT_REJOIN_REQ = 0x06
const APDU_CMD_IDENT_REJOIN_RSP = 0x07
const APDU_CMD_IDENT_LINK_STATUS = 0x08
const APDU_CMD_IDENT_NW_REPORT = 0x09
const APDU_CMD_IDENT_NW_UPDATE = 0x0a
const APDU_CMD_IDENT_END_DEVICE_TOUT_REQ = 0x0b
const APDU_CMD_IDENT_END_DEVICE_TOUT_RSP = 0x0c
/*
*/
function tiPackConv() {
const path = require('path')
const commander = require('commander')
const program = new commander.Command()
program
.requiredOption('-i, --infile <infile>, ', 'sniff input file')
.option('-o, --outfile <outfile, ', 'sniff output file')
.option('-v, --verbose, ', 'verbose')
.version(version)
program.parse(process.argv)
//console.log('program.infile :' + program.infile)
//console.log('program.outfile:' + program.outfile)
//console.log('program.verbose:' + program.verbose)
let fnameIn = null
let fnameOut = null
let verbose = false
if (program.infile != undefined) {
fnameIn = program.infile
pathObj = path.parse(program.infile)
if (pathObj.ext == '.psd') {
if (program.outfile != undefined) {
fnameOut = program.outfile
}
else {
if (pathObj.dir.length > 0) {
fnameOut = pathObj.dir + '/' + pathObj.name + '.txt'
}
else {
fnameOut = pathObj.name + '.txt'
}
}
}
else {
console.log('+++ err: wrong infile extension:' + pathObj.ext)
}
}
else {
console.log('+++ err: infile name missed' )
}
verbose = (program.verbose != undefined) ? true : false
//console.log('fnameIn : ' + fnameIn )
//console.log('fnameOut: ' + fnameOut)
//console.log('verbose : ' + verbose )
if ((fnameIn != null) & (fnameOut != 0)) {
doTiPackConv(fnameIn, fnameOut, verbose)
}
}
// test only
function tiPackConvTest() {
const fnameLst =
[
'QS1_2020_12_08_a', /*
'QS1_2020_12_03_b', /*
'QS1_2020_12_03_a',
'QS1_2020_12_2_a_low_power'
'tst_2020_12_2_0111',
'test_01112020_12_01',
'MPPT_0001',
'MPPT_0010',
'MPPT_0100',
'MPPT_1000',
'MPPT_1011',
'pair_QS1_TI_ZBPro_2020-11-03',
'pair_YC600_TI_ZBPro' */
]
const fnameExtIn = 'psd'
const fnameExtOut = 'txt'
const pathIn = 'E:\\Projekte\\ghJS\\TiPackConv\\Sniff\\'
const pathOut = 'E:\\Projekte\\ghJS\\TiPackConv\\Sniff\\'
fnameLst.forEach(fname => {
let fnameIn = pathIn + fname + '.' + fnameExtIn
let fnameOut = pathOut + fname + '.' + fnameExtOut
doTiPackConv(fnameIn, fnameOut, true)
})
}
/*
doTiPackConv
Todo
@sniffIn
input file TI Packet Sniffer format
@sniffOut
output file to be imported into excel (with space as separator)
@verbose - console output
*/
function doTiPackConv(sniffIn, sniffOut, verbose) {
verbose = (verbose == undefined | verbose == null) ? false : verbose
let frameCnt = 0
const basename = require('path').win32.basename(sniffIn, '.psd')
//let fsr = require('fs')
let buffer = require('fs').readFileSync(sniffIn, (err, file) => {
throw err
})
let fsw = require('fs')
// output header line 1
fsw.writeFileSync(sniffOut, sniffIn + '\n', function (err, file) {
if (err) throw err
console.log('writeFileSync()')
})
// output header line 2
fsw.appendFileSync(sniffOut, ' ' + outSpduHdr(1) + outMpduHdr(1) + outNpduHdr(1) + outApduHdr(1) + '\n', function (err, file) {
if (err) throw err
console.log('writeFileSync()')
})
// output header line 3
fsw.appendFileSync(sniffOut, basename + ' ' + outSpduHdr(2) + outMpduHdr(2) + outNpduHdr(2) + outApduHdr(2) + '\n', (err) => {
if (err) throw err
})
let spdu = SPDU
let mpdu = MPDU
let npdu = NPDU
let apdu = APDU
let bufferIdx = 0
let spduTimeStampS = 0
//
do {
clearXpdu(spdu)
clearXpdu(mpdu)
clearXpdu(npdu)
clearXpdu(apdu)
let errorMsg = null
spdu.fdr.payload = []
mpdu.fdr.payload = []
npdu.fdr.payload = []
apdu.fdr.payload = []
let sidx = bufferIdx
bufferIdx += 151 // prepare for next spdu
spdu.hdr.SPDUInformationRaw = raw2Int(buffer.slice(sidx, sidx+1));
spdu.hdr.SPDUInformation = raw2Int(buffer.slice(sidx, sidx+1)); sidx += 1
spdu.hdr.SPDUNumber = raw2Int(buffer.slice(sidx, sidx+4)); sidx += 4
spdu.hdr.timeStampUs = raw2Int(buffer.slice(sidx, sidx+8)) / 32; sidx += 8
spdu.hdr.timeStampS = Math.floor(spdu.hdr.timeStampUs / 1000000)
spdu.hdr.timeDeltaS = spdu.hdr.timeStampS - spduTimeStampS
spduTimeStampS = spdu.hdr.timeStampS
spdu.hdr.SPDULength = raw2Int(buffer.slice(sidx, sidx+2)); sidx += 2
if ( spdu.hdr.SPDUInformationRaw & SPDU_INFORMATION_LENGTH_INCLUDING_FRAME_STATUS_BYTE_MSK ) {
spdu.hdr.SPDULength--
}
spdu.fdr.payload = buffer.slice(sidx, sidx+spdu.hdr.SPDULength-1); sidx += spdu.hdr.SPDULength-1
spdu.status.rssi = raw2Int(buffer.slice(sidx, sidx+1)); sidx += 1
spdu.status.devInfo = raw2Int(buffer.slice(sidx, sidx+1)); sidx += 1
spdu.status.crcOk = (spdu.status.devInfo & SPDU_STATUS_BYTE2_CRC_MSK) ? true : false
//console.log(buffer.slice(bufferIdx, bufferIdx+151))
if (spdu.status.crcOk) {
// MPDU
let midx = 0
mpdu.hdr.length = raw2Int(spdu.fdr.payload.slice(midx, midx+1)).toString(); midx += 1
mpdu.hdr.frameControlRaw = raw2Int(spdu.fdr.payload.slice(midx, midx+2)).toString();
mpdu.hdr.frameControl = 'bx' + raw2Int(spdu.fdr.payload.slice(midx, midx+2)).toString(2); midx += 2
mpdu.hdr.sequenceNumber = raw2Int(spdu.fdr.payload.slice(midx, midx+1)).toString(); midx += 1
// mpdu frame type, dest addressing mode, src addressing mode
const mpduFrameControlFieldType = mpdu.hdr.frameControlRaw & MPDU_CONTROL_FIELD_MPDU_TYPE_MSK
const mpduFrameControlFieldDestAddr = mpdu.hdr.frameControlRaw & MPDU_CONTROL_FIELD_DEST_ADDR_MODE_MSK
const mpduFrameControlFieldSrcAddr = mpdu.hdr.frameControlRaw & MPDU_CONTROL_FIELD_SRC_ADDR_MODE_MSK
// dest pan 0/2
if (mpduFrameControlFieldDestAddr) {
mpdu.hdr.destPANid = raw2hex(spdu.fdr.payload.slice(midx, midx+2), 4); midx += 2
}
// destAddr 0/2/8
if (mpduFrameControlFieldDestAddr) {
if (mpduFrameControlFieldDestAddr == MPDU_CONTROL_FIELD_DEST_ADDR_MODE_SHORT_ADDR) {
mpdu.hdr.destAddr = raw2hex(spdu.fdr.payload.slice(midx, midx+2), 4); midx += 2
}
else if (mpduFrameControlFieldDestAddr == MPDU_CONTROL_FIELD_DEST_ADDR_MODE_EXTENTED_ADDR) {
mpdu.hdr.destAddr = raw2hex(spdu.fdr.payload.slice(midx, midx+8), 16); midx += 8
}
else {
mpdu.hdr.destAddr = 'mpduFrameControlFieldDestAddr_RESERVED'
}
}
// srcPan 0/2
if (mpduFrameControlFieldSrcAddr & !(mpdu.hdr.frameControlRaw & MPDU_CONTROL_FIELD_PAN_COMPR_MSK)) {
mpdu.hdr.srcPANid = raw2hex(spdu.fdr.payload.slice(midx, midx+2), 4); midx += 2
}
// srcAddr 0/2/8
if (mpduFrameControlFieldSrcAddr) {
if (mpduFrameControlFieldSrcAddr == MPDU_CONTROL_FIELD_SRC_ADDR_MODE_SHORT_ADDR) {
mpdu.hdr.srcAddr = raw2hex(spdu.fdr.payload.slice(midx, midx+2), 4); midx += 2
}
else if (mpduFrameControlFieldSrcAddr == MPDU_CONTROL_FIELD_SRC_ADDR_MODE_EXTENTED_ADDR) {
mpdu.hdr.srcAddr = raw2hex(spdu.fdr.payload.slice(midx, midx+8), 16); midx += 8
}
else {
mpdu.hdr.destAddr = 'mpduFrameControlFieldDestAddr_RESERVED'
}
}
// auxiliary security header field 7.2.1.7
if (mpdu.hdr.frameControlRaw & MPDU_CONTROL_FIELD_SECURITY_ENABLED_MSK) {
mpdu.hdr.security = 'SECURITY_NOT_SUPPORTED'
}
else {
mpdu.hdr.security = '0'
}
// Beacon Frame format
if ( mpduFrameControlFieldType == MPDU_CONTROL_FIELD_MPDU_TYPE_BEACON) {
mpdu.hdr.type = 'BEACON'
}
// Data Frame format
else if ( mpduFrameControlFieldType == MPDU_CONTROL_FIELD_MPDU_TYPE_DATA) {
// todo short addressing mode
mpdu.hdr.type = 'DATA'
mpdu.fdr.payload = spdu.fdr.payload.slice(midx)
// todo checksum
// ==========================================================================================
// NPDU decoding ============================================================================
// ==========================================================================================
var nidx = 0
npdu.hdr.fctrl.raw = raw2Int(mpdu.fdr.payload.slice(nidx, nidx+2)), nidx += 2
// FrameControl Frame Type
const npduFrameType = npdu.hdr.fctrl.raw & NPDU_CONTROL_NPDU_TYPE_MSK
if (npduFrameType == NPDU_CONTROL_NPDU_TYPE_DATA) {
npdu.hdr.fctrl.frameType = 'DATA'
}
else if (npduFrameType == NPDU_CONTROL_NPDU_TYPE_NPDU_COMMAND) {
npdu.hdr.fctrl.frameType = 'CMD'
}
else if (npduFrameType == NPDU_CONTROL_NPDU_TYPE_INTER_PAN) {
npdu.hdr.fctrl.frameType = 'INTER_PAN'
}
else {
npdu.hdr.fctrl.frameType = 'npdu.hdr.fctrl.frameType_INVALID_' + npduFrameType
}
// FrameControl Protocol Version
npdu.hdr.fctrl.protocolVersion = (npdu.hdr.fctrl.raw & NPDU_CONTROL_PROTOCOL_VERSION_MSK) >> NPDU_CONTROL_NPDU_PROTOCOL_VERSION_RSHIFT
// FrameControl Discover Route
if ( (npdu.hdr.fctrl.raw & NPDU_CONTROL_DISCOVER_ROUTE_MSK) == NPDU_CONTROL_DISCOVER_ROUTE_SUPPRESS) {
npdu.hdr.fctrl.discoverRoute = 'SUPR'
}
else if ( (npdu.hdr.fctrl.raw & NPDU_CONTROL_DISCOVER_ROUTE_MSK) == NPDU_CONTROL_DISCOVER_ROUTE_ENABLE) {
npdu.hdr.fctrl.discoverRoute = 'ROUTE_EN'
}
else {
npdu.hdr.fctrl.discoverRoute = 'RESERVED_'+((npdu.hdr.fctrl.raw & NPDU_CONTROL_DISCOVER_ROUTE_MSK)>>6)
}
// FrameControl etc
npdu.hdr.fctrl.multicastFlag = (npdu.hdr.fctrl.raw & NPDU_CONTROL_MULTICAST_FLAG_MSK ) ? '1' : '0'
npdu.hdr.fctrl.security = (npdu.hdr.fctrl.raw & NPDU_CONTROL_SECURITY_MSK ) ? '1' : '0'
npdu.hdr.fctrl.srcRoute = (npdu.hdr.fctrl.raw & NPDU_CONTROL_SRC_ROUTE_MSK ) ? '1' : '0'
npdu.hdr.fctrl.destIEEEaddr = (npdu.hdr.fctrl.raw & NPDU_CONTROL_DEST_IEEEADDR_MSK ) ? '1' : '0'
npdu.hdr.fctrl.srcIEEEaddr = (npdu.hdr.fctrl.raw & NPDU_CONTROL_SRC_IEEEADDR_MSK ) ? '1' : '0'
npdu.hdr.fctrl.endDeviceIndicator = (npdu.hdr.fctrl.raw & NPDU_CONTROL_END_DEVICE_INITIATOR_MSK ) ? '1' : '0'
npdu.hdr.destAddr = raw2hex(mpdu.fdr.payload.slice(nidx, nidx+2), 4); nidx += 2
npdu.hdr.srcAddr = raw2hex(mpdu.fdr.payload.slice(nidx, nidx+2), 4); nidx += 2
npdu.hdr.brodcastRadius = raw2Int(mpdu.fdr.payload.slice(nidx, nidx+1)).toString(); nidx += 1
npdu.hdr.broadcastSeqNum = raw2Int(mpdu.fdr.payload.slice(nidx, nidx+1)).toString(); nidx += 1
if ( npdu.hdr.fctrl.raw & NPDU_CONTROL_DEST_IEEEADDR_MSK ) {
npdu.hdr.destIEEEaddr = raw2hex(mpdu.fdr.payload.slice(nidx, nidx+8), 16); nidx += 8
}
if ( npdu.hdr.fctrl.raw & NPDU_CONTROL_SRC_IEEEADDR_MSK ) {
npdu.hdr.srcIEEEaddr = raw2hex(mpdu.fdr.payload.slice(nidx, nidx+8), 16); nidx += 8
}
if ( npdu.hdr.fctrl.raw & NPDU_CONTROL_SRC_ROUTE_MSK ) {
var sourceRoutelength = 1
npdu.hdr.sourceRouteSubframe = 'npdu.hdr.sourceRouteSubframe_NOT_SUPPORTED'
}
if ( npdu.hdr.fctrl.raw & NPDU_CONTROL_MULTICAST_FLAG_MSK ) {
npdu.hdr.multicastControl = raw2hex(mpdu.fdr.payload.slice(nidx, nidx+1), 2); nidx += 1
}
npdu.fdr.payload = mpdu.fdr.payload.slice(nidx)
if (npduFrameType == NPDU_CONTROL_NPDU_TYPE_DATA) {
npdu.hdr.type = 'NPDU DATA'
// =====================================================================================================
// APDU decoding =======================================================================================
// =====================================================================================================
var aidx = 0
apdu.hdr.frameControl.raw = raw2Int(npdu.fdr.payload.slice(aidx, aidx+1)); aidx += 1
const apduFrameType = apdu.hdr.frameControl.raw & APDU_FRAME_TYPE_MSK
if (apduFrameType == APDU_FRAME_TYPE_DATA) {
apdu.hdr.frameControl.frameType = 'DATA'
}
else if (apduFrameType == APDU_FRAME_TYPE_CMD) {
apdu.hdr.frameControl.frameType = 'CMD'
}
else if (apduFrameType == APDU_FRAME_TYPE_ACK) {
apdu.hdr.frameControl.frameType = 'ACK'
}
else if (apduFrameType == APDU_FRAME_TYPE_INTER_PAN) {
apdu.hdr.frameControl.frameType = 'INTER_PAN'
}
else {
throw 'invalid apdu.hdr.frameControl.frameType'
}
const apduDeliveryMode = apdu.hdr.frameControl.raw & APDU_DELIVERY_MODE_MSK
if (apduDeliveryMode == APDU_DELIVERY_MODE_NORMAL_UNICAST) {
apdu.hdr.frameControl.deliveryMode = 'UNICAST'
}
else if (apduDeliveryMode == APDU_DELIVERY_MODE_BROADCAST) {
apdu.hdr.frameControl.deliveryMode = 'BROADCAST'
}
else if (apduDeliveryMode == APDU_DELIVERY_MODE_GROUP_ADDRESSING) {
apdu.hdr.frameControl.deliveryMode = 'GROUP'
}
else {
apdu.hdr.frameControl.deliveryMode = 'INVALID_apduDeliveryMode_' + apduDeliveryMode
}
apdu.hdr.frameControl.ackFormat = (apdu.hdr.frameControl.raw & APDU_ACK_FORMAT_MSK ) ? '1' : '0'
apdu.hdr.frameControl.security = (apdu.hdr.frameControl.raw & APDU_SEQURITY_MSK ) ? '1' : '0'
apdu.hdr.frameControl.ackReq = (apdu.hdr.frameControl.raw & APDU_ACK_REQUEST_MSK ) ? '1' : '0'
apdu.hdr.frameControl.extendedHdr = (apdu.hdr.frameControl.raw & APDU_EXTENDET_HDR_PRESENT_MSK) ? '1' : '0'
// Destination Endpoint 2.2.5.1.2
if ( (apduDeliveryMode == APDU_DELIVERY_MODE_NORMAL_UNICAST) | (apduDeliveryMode == APDU_DELIVERY_MODE_BROADCAST) ) {
apdu.hdr.destEndpoint = raw2hex(npdu.fdr.payload.slice(aidx, aidx+1), 2); aidx += 1
}
// Group address field 2.2.5.1.
if ( apduDeliveryMode == APDU_DELIVERY_MODE_GROUP_ADDRESSING ) {
apdu.hdr.groupAddr = raw2hex(npdu.fdr.payload.slice(aidx, aidx+2), 4); aidx += 2
}
// Cluster identifier and profil identifier 2.2.5.1.4-5
if ( (apduFrameType == APDU_FRAME_TYPE_DATA) | (apduFrameType == APDU_FRAME_TYPE_ACK) ) {
apdu.hdr.clusterIdentifier = raw2hex(npdu.fdr.payload.slice(aidx, aidx+2), 4); aidx += 2
apdu.hdr.profilIdentifier = raw2hex(npdu.fdr.payload.slice(aidx, aidx+2), 4); aidx += 2
}
// Source Endpoint Field 2.2.5.1.6 & 2.2.5.2.1
if (apduFrameType == APDU_FRAME_TYPE_DATA) {
apdu.hdr.srcEndpoint = raw2hex(npdu.fdr.payload.slice(aidx, aidx+1), 2); aidx += 1
}
// APS Counter 2.2.5.1.7
apdu.hdr.apsCounter = raw2Int(npdu.fdr.payload.slice(aidx, aidx+1)).toString(); aidx += 1
// Extended Hdr 2.2.5.1.8
if (apdu.hdr.frameControlRaw & APDU_EXTENDET_HDR_PRESENT_MSK) {
// todo extended hdr
// extended framecontrol
// block number
// ACK bitfield
}
// APDU Data Frame Format 2.2.5.2.1
if (apduFrameType == APDU_FRAME_TYPE_DATA) {
apdu.fdr.payload = npdu.fdr.payload.slice(aidx)
apdu.fdr.apsCmdIdentifier = null
}
// APDU Command Frames 3.4.
else if (apduFrameType == APDU_FRAME_TYPE_CMD) {
apdu.fdr.apsCmdIdentifier = raw2Int(npdu.fdr.payload.slice(aidx, aidx+1)).toString(); aidx += 1
apdu.fdr.payload = npdu.fdr.payload.slice(aidx)
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_ROUTE_REQ) {
apdu.cmd.type = 'AL CMD Route Request'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_ROUTE_RPL) {
apdu.cmd.type = 'AL CMD Route Replay'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_NW_STATUS) {
apdu.cmd.type = 'AL CMD Network Status'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_LEAVE) {
apdu.cmd.type = 'AL CMD Leave'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_ROUTE_RECORD) {
apdu.cmd.type = 'AL CMD Route Record'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_REJOIN_REQ) {
apdu.cmd.type = 'AL CMD Rejoin Request'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_REJOIN_RSP) {
apdu.cmd.type = 'AL CMD Rejoin Response'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_LINK_STATUS) {
apdu.cmd.type = 'AL CMD Link Status'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_NW_REPORT) {
apdu.cmd.type = 'AL CMD Route Request'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_NW_REPORT) {
apdu.cmd.type = 'AL CMD Network Report'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_END_DEVICE_TOUT_REQ) {
apdu.cmd.type = 'AL CMD End Device Timeout Request'
}
if (apdu.fdr.apsCmdIdentifier == APDU_CMD_IDENT_END_DEVICE_TOUT_RSP) {
apdu.cmd.type = 'AL CMD End Device Timeout Response'
}
else {
apdu.cmd.type = 'RESERVED_' + apdu.fdr.apsCmdIdentifier
}
}
else if (apduFrameType == APDU_FRAME_TYPE_ACK) {
apdu.hdr.type = 'APDU Acknowledgement'
}
else if (apduFrameType == APDU_FRAME_TYPE_INTER_PAN) {
apdu.hdr.type = 'APDU Inter-PAN APS'
}
else {
apdu.hdr.type = 'INVALID_APDU_TYPE_' + apduFrameType
}
}
else if (npduFrameType == NPDU_CONTROL_NPDU_TYPE_NPDU_COMMAND) {
npdu.hdr.type = 'CMD'
npdu.cmd.cmdIdentifier = raw2Int(npdu.fdr.payload.slice(0,1))
npdu.cmd.cmdPayload = npdu.fdr.payload.slice(1)
if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_ROUTE_REQUEST) {
npdu.cmd.type = 'ROUTE_REQ'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_ROUTE_REPLAY) {
npdu.cmd.type = 'ROUTE_REPL'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_NW_STATUS) {
npdu.cmd.type = 'NW_STATUS'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_LEAVE) {
npdu.cmd.type = 'LEAVE'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_ROUTE_SPDU) {
npdu.cmd.type = 'ROUTE_SPDU'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_REJOIN_REQUEST) {
npdu.cmd.type = 'REJOIN_REQ'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_REJOIN_RESPONSE) {
npdu.cmd.type = 'REJOIN_RESP'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_LINK_STATUS) {
npdu.cmd.type = 'LINK_STATUS'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_NW_REPORT) {
npdu.cmd.type = 'NW_REPORT'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_NW_UPDATE) {
npdu.cmd.type = 'NW_UPDATE'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_END_DEVICE_TIMEOUT_REQUEST) {
npdu.cmd.type = 'ED_TOUT_REQ'
}
else if (npdu.cmd.cmdIdentifier & NPDU_COMMAND_END_DEVICE_TIMEOUT_RESPONSE) {
npdu.cmd.type = 'ED_TOUT_RESP'
}
else {
npdu.cmd.type = 'UNKNOWN: ' + npdu.cmd.cmdIdentifier
}
}
else if (npduFrameType == NPDU_CONTROL_NPDU_TYPE_INTER_PAN) {
npdu.hdr.type = 'INTER_PAN'
}
else {
npdu.hdr.type = 'npdu.hdr.type_RESERVED_' + npdu.hdr.type
}
}
// Acknowledgement Frame format
else if ( mpduFrameControlFieldType == MPDU_CONTROL_FIELD_MPDU_TYPE_ACKNOWLEDGEMENT) {
mpdu.hdr.type = 'ACK'
}
// mpdu command Frame format
else if ( mpduFrameControlFieldType == MPDU_CONTROL_FIELD_MPDU_TYPE_MPDU) {
mpdu.hdr.type = 'CMD'
}
// reserved
else {
mpdu.hdr.type = 'RESERVED'
}
}
else { // if (!spdu.status.crcOk)
spdu.status.msg = 'CRC_error'
errorMsg = 'CRC error at SPDU ' + spdu.hdr.SPDUNumber
}
//printSpdu(spdu)
//printMpdu(mpdu)
//printNpdu(npdu)
//printApdu(apdu)
var sSpdu = outSpdu(spdu)
var sMpdu = outMpdu(mpdu)
var sNpdu = outNpdu(npdu)
var sApdu = outApdu(apdu)
if ( (!verbose) & (errorMsg != null)) {
console.log(errorMsg)
}
else if (verbose) {
console.log(sSpdu + sMpdu + sNpdu + sApdu)
}
fsw.appendFileSync(sniffOut, basename + ' ' + sSpdu + sMpdu + sNpdu + sApdu + '\n', (err) => {
if (err) throw err
})
frameCnt++
} while( bufferIdx < buffer.length)
console.log(sniffIn + ' -> ' + sniffOut + ' ' + frameCnt + ' frames processed')
}
/*
Output functions
*/
function printSpdu(spdu) {
console.log('')
console.log('+++ SPDU ++++++++++++++++++++++++++++++++++++++++++++++++++')
console.log('spdu.hdr.SPDUInformation:' + spdu.hdr.SPDUInformation)
console.log('spdu.hdr.SPDUNumber :' + spdu.hdr.SPDUNumber)
console.log('spdu.hdr.timeStampUs :' + spdu.hdr.timeStampUs)
console.log('spdu.hdr.timeStampS :' + spdu.hdr.timeStampS)
console.log('spdu.hdr.SPDULength :' + spdu.hdr.SPDULength)
console.log('spdu.fdr.payload.length :' + spdu.fdr.payload.length)
console.log('spdu.fdr.payload :' + payload2HexString(spdu.fdr.payload))
}
function outSpduHdr(line)
{
let s = ''
if (line == 1) {
s += 'SPDU . . . . '
}
else {
s += 'info no time delta length '
}
return s
}
function outSpdu(spdu) {
let s = ''
s += spdu.hdr.SPDUInformation + ' '
s += spdu.hdr.SPDUNumber + ' '
s += spdu.hdr.timeStampS + ' '
s += spdu.hdr.timeDeltaS + ' '
s += spdu.hdr.SPDULength + ' '
if (spdu.status.msg != null) s += spdu.status.msg + ' '
//s += 'info=' + spdu.fdr.payload.length + ' '
//s += 'info=' + payload2HexString(spdu.fdr.payload) + ' '
return s
}
function printMpdu(mpdu) {
if (mpdu.hdr.length != null) console.log('+++ %s ++++++++++++++++++++++++++++++++++++++++++++', mpdu.hdr.type)
if (mpdu.hdr.length != null) console.log('mpdu.hdr.length :' + mpdu.hdr.length)
if (mpdu.hdr.frameControl != null) console.log('mpdu.hdr.frameControl :' + mpdu.hdr.frameControl)
if (mpdu.hdr.sequenceNumber != null) console.log('mpdu.hdr.sequenceNumber:' + mpdu.hdr.sequenceNumber)
if (mpdu.hdr.destPANid != null) console.log('mpdu.hdr.destPANid :' + mpdu.hdr.destPANid)
if (mpdu.hdr.destAddr != null) console.log('mpdu.hdr.destAddr :' + mpdu.hdr.destAddr)
if (mpdu.hdr.srcAddr != null) console.log('mpdu.hdr.srcAddr :' + mpdu.hdr.srcAddr)
if (mpdu.fdr.payload != null) console.log('mpdu.fdr.payload.length:' + mpdu.fdr.payload.length)
if (mpdu.fdr.payload != null) console.log('mpdu.fdr.payload :' + payload2HexString(mpdu.fdr.payload))
if (mpdu.fdr.checkSum != null) console.log('mpdu.fdr.checkSum :' + mpdu.fdr.checkSum)
}
function outMpduHdr(line)
{
let s = ''
if (line == 1) {
s += 'MPDU . . . . . . . . '
}
else {
s += 'type length frameCtrl seqNo destPANid destAddr srcAddr length cs '
}
return s
}
function outMpdu(mpdu) {
let s = '';
if (mpdu.hdr.length != null) {
if (mpdu.hdr.length != null) s += mpdu.hdr.type + ' '
else s += '. '
if (mpdu.hdr.length != null) s += mpdu.hdr.length + ' '
else s += '. '
if (mpdu.hdr.frameControl != null) s += mpdu.hdr.frameControl + ' '
else s += '. '
if (mpdu.hdr.sequenceNumber != null) s += mpdu.hdr.sequenceNumber + ' '
else s += '. '
if (mpdu.hdr.destPANid != null) s += mpdu.hdr.destPANid + ' '
else s += '. '
if (mpdu.hdr.destAddr != null) s += mpdu.hdr.destAddr + ' '
else s += '. '
if (mpdu.hdr.srcAddr != null) s += mpdu.hdr.srcAddr + ' '
else s += '. '
if (mpdu.fdr.payload != null) s += mpdu.fdr.payload.length + ' '
else s += '. '
//if (mpdu.fdr.payload != null) s += payload2HexString(mpdu.fdr.payload) + ' '
//else s += '. '
if (mpdu.fdr.checkSum != null) s += mpdu.fdr.checkSum + ' '
else s += '. '
}
else {
s += '. . . . . . . '
}
return s
}
function printNpdu(npdu) {
if (npdu.hdr.fctrl.frameType != null) console.log('+++ %s ++++++++++++++++++++++++++++++++++++++++++++++++++', npdu.hdr.fctrl.frameType)
if (npdu.hdr.fctrl.protocolVersion != null) console.log('npdu.hdr.fctrl.protocolVersion :' + npdu.hdr.fctrl.protocolVersion)
if (npdu.hdr.fctrl.discoverRoute != null) console.log('npdu.hdr.fctrl.discoverRoute :' + npdu.hdr.fctrl.discoverRoute)
if (npdu.hdr.fctrl.multicastFlag != null) console.log('npdu.hdr.fctrl.multicastFlag :' + npdu.hdr.fctrl.multicastFlag)
if (npdu.hdr.fctrl.security != null) console.log('npdu.hdr.fctrl.security :' + npdu.hdr.fctrl.security)
if (npdu.hdr.fctrl.srcRoute != null) console.log('npdu.hdr.fctrl.srcRoute :' + npdu.hdr.fctrl.srcRoute)
if (npdu.hdr.fctrl.destIEEEaddr != null) console.log('npdu.hdr.fctrl.destIEEEaddr :' + npdu.hdr.fctrl.destIEEEaddr)
if (npdu.hdr.fctrl.srcIEEEaddr != null) console.log('npdu.hdr.fctrl.srcIEEEaddr :' + npdu.hdr.fctrl.srcIEEEaddr)
if (npdu.hdr.fctrl.endDeviceIndicator != null) console.log('npdu.hdr.fctrl.endDeviceIndicator :' + npdu.hdr.fctrl.endDeviceIndicator)
if (npdu.hdr.destAddr != null) console.log('npdu.hdr.destAddr :' + npdu.hdr.destAddr)
if (npdu.hdr.srcAddr != null) console.log('npdu.hdr.srcAddr :' + npdu.hdr.srcAddr)
if (npdu.hdr.brodcastRadius != null) console.log('npdu.hdr.brodcastRadius :' + npdu.hdr.brodcastRadius)
if (npdu.hdr.broadcastSeqNum != null) console.log('npdu.hdr.broadcastSeqNum :' + npdu.hdr.broadcastSeqNum)
if (npdu.hdr.destIEEEaddr != null) console.log('npdu.hdr.destIEEEaddr :' + npdu.hdr.destIEEEaddr)
if (npdu.hdr.srcIEEEaddr != null) console.log('npdu.hdr.srcIEEEaddr :' + npdu.hdr.srcIEEEaddr)
if (npdu.hdr.multicastControl != null) console.log('npdu.hdr.multicastControl :' + npdu.hdr.multicastControl)
if (npdu.fdr.payload.length != null) console.log('npdu.fdr.payload.length :' + npdu.fdr.payload.length)
if (npdu.fdr.payload.length != null) console.log('npdu.fdr.payload :' + payload2HexString(npdu.fdr.payload))
}
function outNpduHdr(line)
{
let s = ''
if (line == 1) {
s += 'NPDU . . . . . . . . '
s += '. . . . . . . . . . '
}
else {
s += 'type cmd protVers discR mcFlag sec srcR destIEEEaddr srcIEEEaddr eDevInd '
s += 'destAddr srcAddr bcRadius bcSeqNo destIEEEaddr srcIEEEadr mcCtrl length payload '
}
return s
}
function outNpdu(npdu) {
let s = '';
if (npdu.hdr.fctrl.frameType != null) {
if (npdu.hdr.fctrl.frameType != null) s += npdu.hdr.fctrl.frameType + ' '
else s += '. '
if (npdu.cmd.type != null) s += npdu.cmd.type + ' '
else s += '. '
if (npdu.hdr.fctrl.protocolVersion != null) s += npdu.hdr.fctrl.protocolVersion + ' '
else s += '. '
if (npdu.hdr.fctrl.discoverRoute != null) s += npdu.hdr.fctrl.discoverRoute + ' '
else s += '. '
if (npdu.hdr.fctrl.multicastFlag != null) s += npdu.hdr.fctrl.multicastFlag + ' '
else s += '. '
if (npdu.hdr.fctrl.security != null) s += npdu.hdr.fctrl.security + ' '
else s += '. '
if (npdu.hdr.fctrl.srcRoute != null) s += npdu.hdr.fctrl.srcRoute + ' '
else s += '. '
if (npdu.hdr.fctrl.destIEEEaddr != null) s += npdu.hdr.fctrl.destIEEEaddr + ' '
else s += '. '
if (npdu.hdr.fctrl.srcIEEEaddr != null) s += npdu.hdr.fctrl.srcIEEEaddr + ' '
else s += '. '
if (npdu.hdr.fctrl.endDeviceIndicator != null) s += npdu.hdr.fctrl.endDeviceIndicator + ' '
else s += '. '
if (npdu.hdr.destAddr != null) s += npdu.hdr.destAddr + ' '
else s += '. '
if (npdu.hdr.srcAddr != null) s += npdu.hdr.srcAddr + ' '
else s += '. '
if (npdu.hdr.brodcastRadius != null) s += npdu.hdr.brodcastRadius + ' '
else s += '. '
if (npdu.hdr.broadcastSeqNum != null) s += npdu.hdr.broadcastSeqNum + ' '
else s += '. '