-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpacket-ant.c
1826 lines (1743 loc) · 57.6 KB
/
packet-ant.c
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
/*
* Copyright 2009 `date +paul@ant%m%y.sbrk.co.uk`
* Released under GPLv3
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <glib.h>
#include <epan/conversation.h>
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/reassemble.h>
#include "packet-ant.h"
#define ANTITEM(TREE, SYNC, LEN) {if (tree) proto_tree_add_item(TREE, SYNC, tvb, offset, LEN, TRUE); offset += LEN;}
#define NANTITEM(TREE, SYNC, LEN) {if (tree) proto_tree_add_item(TREE, SYNC, tvb, offset, LEN, TRUE);}
void proto_reg_handoff_ant(void);
/* per conversation details */
struct ant_info {
guint8 first[MAXCHAN]; /* whether the lastXX fields are valid */
guint16 devtype[MAXCHAN]; /* device type */
struct {
struct {
guint16 rr[MAXCHAN]; /* last r-r for HR records */
guint8 seq[MAXCHAN]; /* last sequence# for HR records */
} hr;
struct {
guint8 r1[MAXCHAN]; /* last R1 for power */
guint8 r2[MAXCHAN]; /* last R2 for power */
guint8 n[MAXCHAN]; /* last N for power */
guint16 p[MAXCHAN]; /* last P for power */
guint16 t[MAXCHAN]; /* last T for power */
} power;
struct {
guint16 cranktime[MAXCHAN];
guint16 crankrev[MAXCHAN];
guint16 wheeltime[MAXCHAN];
guint16 wheelrev[MAXCHAN];
} bike;
struct {
guint16 time[MAXCHAN];
guint16 dist[MAXCHAN];
guint16 speed[MAXCHAN];
guint8 stridecnt[MAXCHAN];
guint8 updlatency[MAXCHAN];
guint8 cad[MAXCHAN];
guint16 spdp1[MAXCHAN];
} foot;
struct {
guint16 seq[MAXCHAN];
guint8 burst_seq[MAXCHAN];
guint8 seq_id[MAXCHAN];
guint8 islast[MAXCHAN];
} burst;
} last;
};
/* per packet data. */
struct pkt_data {
guint8 first;
guint8 devtype;
struct {
struct {
guint16 rr;
guint8 seq;
} hr;
struct {
guint8 r1;
guint8 r2;
guint8 n;
guint16 p;
guint16 t;
} power;
struct {
guint16 cranktime;
guint16 crankrev;
guint16 wheeltime;
guint16 wheelrev;
} bike;
struct {
guint16 time;
guint16 dist;
guint16 speed;
guint8 stridecnt;
guint8 updlatency;
guint8 cad;
guint16 spdp1;
} foot;
} last;
struct {
struct {
guint16 seq;
guint8 burst_seq;
guint8 seq_id;
guint8 islast;
} burst;
} this;
};
static GHashTable *msg_fragment_table = NULL;
static GHashTable *msg_reassembled_table = NULL;
static int hf_msg_fragments = -1;
static int hf_msg_fragment = -1;
static int hf_msg_fragment_overlap = -1;
static int hf_msg_fragment_overlap_conflicts = -1;
static int hf_msg_fragment_multiple_tails = -1;
static int hf_msg_fragment_too_long_fragment = -1;
static int hf_msg_fragment_error = -1;
static int hf_msg_reassembled_in = -1;
static gint ett_msg_fragment = -1;
static gint ett_msg_fragments = -1;
static const fragment_items msg_frag_items = {
/* Fragment subtrees */
&ett_msg_fragment,
&ett_msg_fragments,
/* Fragment fields */
&hf_msg_fragments,
&hf_msg_fragment,
&hf_msg_fragment_overlap,
&hf_msg_fragment_overlap_conflicts,
&hf_msg_fragment_multiple_tails,
&hf_msg_fragment_too_long_fragment,
&hf_msg_fragment_error,
/* Reassembled in field */
&hf_msg_reassembled_in,
/* Tag */
"Message fragments"
};
static int proto_ant = -1;
static int hf_ant_sync = -1;
static int hf_ant_msg_length = -1;
static int hf_ant_msg_id = -1;
static int hf_ant_data = -1;
static int hf_ant_checksum = -1;
static int hf_ant_data_chan = -1;
static int hf_ant_data_chanstat = -1;
static int hf_ant_data_period = -1;
static int hf_ant_data_devno = -1;
static int hf_ant_data_devtype = -1;
static int hf_ant_data_transtype = -1;
static int hf_ant_data_waveform = -1;
static int hf_ant_data_data = -1;
static int hf_ant_data_mbz = -1;
static int hf_ant_data_nk = -1;
static int hf_ant_data_msgid = -1;
static int hf_ant_data_msgcode = -1;
static int hf_ant_data_chtype = -1;
static int hf_ant_data_net = -1;
static int hf_ant_pd_page = -1;
static int hf_ant_pd_rr = -1;
static int hf_ant_pd_oldrr = -1;
static int hf_ant_pd_newrr = -1;
static int hf_ant_pd_prevrr = -1;
static int hf_ant_pd_seq = -1;
static int hf_ant_pd_hr = -1;
static int hf_ant_data_maxchan = -1;
static int hf_ant_data_maxnet = -1;
static int hf_ant_data_srchto = -1;
static int hf_ant_data_freq = -1;
static int hf_ant_bm_no_rx_chans = -1;
static int hf_ant_bm_no_tx_chans = -1;
static int hf_ant_bm_no_rx_msgs = -1;
static int hf_ant_bm_no_tx_msgs = -1;
static int hf_ant_bm_no_ackd_msgs = -1;
static int hf_ant_bm_no_burst_msgs = -1;
static int hf_ant_bm_net = -1;
static int hf_ant_bm_serial = -1;
static int hf_ant_bm_per_chan_tx_power = -1;
static int hf_ant_bm_low_prio_srch = -1;
static int hf_ant_bm_script = -1;
static int hf_ant_bm_search_list = -1;
static int hf_ant_bm_led = -1;
static int hf_ant_bm_ext_msg = -1;
static int hf_ant_bm_scan_mode = -1;
static int hf_ant_bm_prox_srch = -1;
static int hf_ant_bm_ext_assign = -1;
static int hf_ant_bm_burst_seq_end = -1;
static int hf_ant_bm_burst_seq = -1;
static int hf_ant_bm_burst_chan = -1;
static int hf_ant_unk = -1;
static int hf_ant_ub = -1;
static int hf_ant_u0 = -1;
static int hf_ant_u1 = -1;
static int hf_ant_u2 = -1;
static int hf_ant_hwver = -1;
static int hf_ant_manu = -1;
static int hf_ant_model = -1;
static int hf_ant_swver = -1;
static int hf_ant_serial = -1;
static int hf_ant_torque_cfg = -1;
static int hf_ant_torque_raw = -1;
static int hf_ant_torque_offset = -1;
static int hf_ant_batt = -1;
static int hf_ant_r1 = -1;
static int hf_ant_r2 = -1;
static int hf_ant_n = -1;
static int hf_ant_p = -1;
static int hf_ant_t = -1;
static int hf_ant_cranktime = -1;
static int hf_ant_crankrev = -1;
static int hf_ant_wheeltime = -1;
static int hf_ant_wheelrev = -1;
static int hf_ant_cadx = -1;
static int hf_ant_time_frac = -1;
static int hf_ant_time_int = -1;
static int hf_ant_dist_int = -1;
static int hf_ant_dist_frac = -1;
static int hf_ant_spd_int = -1;
static int hf_ant_spd_frac = -1;
static int hf_ant_stride_count = -1;
static int hf_ant_update_latency = -1;
static int hf_ant_pref1f0 = -1;
static int hf_ant_pref1f1 = -1;
static int hf_ant_pref1f2 = -1;
static int hf_ant_pref1f3 = -1;
static int hf_ant_pref1f4 = -1;
static int hf_ant_pref1f5 = -1;
static int hf_ant_pref1f6 = -1;
static int hf_ant_pref1f7 = -1;
static int hf_ant_pref2f0 = -1;
static int hf_ant_pref2f1 = -1;
static int hf_ant_pref2f2 = -1;
static int hf_ant_pref2f3 = -1;
static int hf_ant_pref2f4 = -1;
static int hf_ant_pref2f5 = -1;
static int hf_ant_pref2f6 = -1;
static int hf_ant_pref2f7 = -1;
static int hf_ant_43_b1f0 = -1;
static int hf_ant_43_b1f1 = -1;
static int hf_ant_43_b1f2 = -1;
static int hf_ant_43_b1f3 = -1;
static int hf_ant_43_b1f4 = -1;
static int hf_ant_43_b1f5 = -1;
static int hf_ant_43_b1f6 = -1;
static int hf_ant_43_b1f7 = -1;
static int hf_ant_phase = -1;
static int hf_ant_b2 = -1;
static int hf_ant_b3 = -1;
static int hf_ant_product_id = -1;
static int hf_ant_b4 = -1;
static int hf_ant_b5 = -1;
static int hf_ant_b6 = -1;
static int hf_ant_b7 = -1;
static int hf_ant_cmd = -1;
static int hf_ant_pcid = -1;
static int hf_ant_fpodid = -1;
static int hf_ant_bpodid = -1;
static int hf_ant_hrmid = -1;
static int hf_ant_unitid = -1;
static int hf_ant_unitname = -1;
static int hf_ant_firmware = -1;
static int hf_ant_auth = -1;
static int hf_ant_autolap = -1;
static int hf_ant_run_lo = -1;
static int hf_ant_run_hi = -1;
static int hf_ant_hrm_lo = -1;
static int hf_ant_hrm_hi = -1;
static int hf_ant_weight = -1;
static int hf_ant_pref_cksum = -1;
static int hf_ant_xid = -1;
static int hf_ant_x0 = -1;
static int hf_ant_x1 = -1;
static int hf_ant_x2 = -1;
static int hf_ant_x3 = -1;
static int hf_ant_run_id = -1;
static int hf_ant_run_prev = -1;
static int hf_ant_run_time = -1;
static int hf_ant_run_date = -1;
static int hf_ant_lap_next = -1;
static int hf_ant_lap_type = -1;
static int hf_ant_lap_speed = -1;
static int hf_ant_lap_dist = -1;
static int hf_ant_lap_time = -1;
static int hf_ant_lap_cals = -1;
static int hf_ant_lap_avghr = -1;
static int hf_ant_lap_maxhr = -1;
static int hf_ant_lap_avgcad = -1;
static int hf_ant_lap_maxcad = -1;
static int hf_ant_lap_steps = -1;
static int hf_ant_speed_dist = -1;
static int hf_ant_cad = -1;
static int hf_ant_hr = -1;
static int hf_ant_auth_len = -1;
/* TODO tfs_enabled_disabled in tfs.h */
static const true_false_string tfs_enabled = {
"Enabled",
"Disabled"
};
static const value_string product_ids[] = {
{1, "HRM1"},
{2, "AXH01"},
{3, "AXB01"},
{4, "AXB02"},
{5, "HRM2SS"},
{717, "FR405"},
{782, "FR50"},
{988, "FR60"},
{1018, "FR310XT"},
{1036, "EDGE500"},
{10007, "SDM4"},
{20119, "TRAINING_CENTER"},
{65534, "CONNECT"},
{0, NULL}
};
static const value_string chtypes[] = {
{0x00, "Bidirectional Slave"},
{0x10, "Bidirectional Master" },
{0x20, "Shared Bidrectional Slave" },
{0x30, "Shared Bidirectional Master" },
{0x40, "RX Only" },
{0x50, "TX Only" },
{0, NULL}
};
static const value_string devtypes[] = {
{DEVTYPE_ANTFS, "ANTFS"},
{DEVTYPE_SUUHRM, "Suunto HRM"},
{DEVTYPE_HRM, "HRM"},
{DEVTYPE_BIKE_POWER, "Bike power" },
{DEVTYPE_SDM, "SDM" },
{DEVTYPE_BIKE_SPEED_CADENCE, "Bike speed cadence"},
{DEVTYPE_ENVIRONMENT_SENSOR, "Environment sensor"},
{DEVTYPE_FITNESS_EQUIPMENT, "Fitness equipment"},
{DEVTYPE_WEIGHT_SCALE, "Weight scale"},
{DEVTYPE_BIKE_CADENCE, "Bike cadence"},
{DEVTYPE_BIKE_SPEED, "Bike speed"},
{0, NULL}
};
static const value_string cmds44[] = {
{2, "Switch frequency"},
{3, "Authenticate"},
{4, "Request ID"},
{0, NULL}
};
static const value_string chanstats[] = {
{0, "Unassigned"},
{1, "Assigned" },
{2, "Searching" },
{3, "Tracking" },
{0, NULL}
};
static const value_string codes[] = {
{0x0, "No error"},
{0x1, "Search Timeout" },
{0x2, "RX Fail" },
{0x3, "TX" },
{0x4, "Transfer RX Failed" },
{0x5, "Transfer TX Completed" },
{0x6, "Transfer TX Failed" },
{0x7, "Channel Closed" },
{0x8, "RX Fail Go To Search" },
{0x9, "Channel Collision" },
{0xa, "Transfer TX Start" },
{0x28, "Invalid message"},
{0, NULL}
};
#if 0
static const value_string periods[] = {
{4096, "Garmin head unit"},
{6554, "Suunto"},
{8070, "ANT+ HRM"},
{0, NULL}
};
#endif
static const value_string msgs[] = {
{0x1, "Channel event"},
{0x3d, "Suunto config"},
{MESG_RESPONSE_EVENT_ID, "Response event"},
{MESG_UNASSIGN_CHANNEL_ID, "Unassign channel" },
{MESG_ASSIGN_CHANNEL_ID, "Assign channel" },
{MESG_CHANNEL_MESG_PERIOD_ID, "Message period" },
{MESG_CHANNEL_SEARCH_TIMEOUT_ID, "Search timeout" },
{MESG_CHANNEL_RADIO_FREQ_ID, "Radio frequency" },
{MESG_NETWORK_KEY_ID, "Network key" },
{MESG_SEARCH_WAVEFORM_ID, "Search waveform" },
{MESG_SYSTEM_RESET_ID, "System reset" },
{MESG_OPEN_CHANNEL_ID, "Open channel" },
{MESG_CLOSE_CHANNEL_ID, "Close channel" },
{MESG_REQUEST_ID, "Request" },
{MESG_BROADCAST_DATA_ID, "Broadcast data" },
{MESG_ACKNOWLEDGED_DATA_ID, "Acknowledged data" },
{MESG_BURST_DATA_ID, "Burst data" },
{MESG_CHANNEL_ID_ID, "Channel ID" },
{MESG_CHANNEL_STATUS_ID, "Channel status" },
{MESG_CAPABILITIES_ID, "Capabilities" },
{MESG_EXT_BROADCAST_DATA_ID, "Extended Broadcast data" },
{MESG_EXT_ACKNOWLEDGED_DATA_ID, "Extended Acknowledged data" },
{MESG_EXT_BURST_DATA_ID, "Extended Burst data" },
{0, NULL}
};
#if 0
static const value_string netkeys[] = {
{0xb9ad3228757ec74dULL, "Suunto"},
{0xa8a423b9f55e63c1ULL, "Garmin head unit"},
{0xb9a521fbbd72c345ULL, "ANT+"},
{0, NULL}
};
#endif
static gint ett_ant = -1;
static gint ett_ant_data = -1;
static void
msg_init_protocol(void)
{
fprintf(stderr, "msginit\n");
fragment_table_init(&msg_fragment_table);
reassembled_table_init(&msg_reassembled_table);
}
/* get per conversation channel data */
static struct ant_info *
get_ant_infop(packet_info *pinfo)
{
conversation_t *conversation;
struct ant_info *ant_infop;
int i;
if (!(conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype,
pinfo->srcport, pinfo->destport, 0))) {
conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst,
pinfo->ptype, pinfo->srcport,pinfo->destport, 0);
}
ant_infop = conversation_get_proto_data(conversation, proto_ant);
if (!ant_infop) {
ant_infop = se_alloc(sizeof(struct ant_info));
for (i = 0; i < MAXCHAN; i++) {
ant_infop->first[i] = 1;
}
conversation_add_proto_data(conversation, proto_ant, ant_infop);
}
return ant_infop;
}
/* initialise per packet data from per conv data */
static struct pkt_data *
new_pdata(struct ant_info *ant_infop, guint8 chan)
{
struct pkt_data *p_data;
p_data = se_alloc(sizeof(struct pkt_data));
p_data->first = ant_infop->first[chan];
p_data->devtype = ant_infop->devtype[chan];
/* copy should depend on devtype, but should get away with it */
p_data->last.hr.rr = ant_infop->last.hr.rr[chan];
p_data->last.hr.seq = ant_infop->last.hr.seq[chan];
p_data->last.power.r1 = ant_infop->last.power.r1[chan];
p_data->last.power.r2 = ant_infop->last.power.r2[chan];
p_data->last.power.n = ant_infop->last.power.n[chan];
p_data->last.power.p = ant_infop->last.power.p[chan];
p_data->last.power.t = ant_infop->last.power.t[chan];
p_data->last.power.t = ant_infop->last.power.t[chan];
p_data->last.bike.cranktime = ant_infop->last.bike.cranktime[chan];
p_data->last.bike.crankrev = ant_infop->last.bike.crankrev[chan];
p_data->last.bike.wheeltime = ant_infop->last.bike.wheeltime[chan];
p_data->last.bike.wheelrev = ant_infop->last.bike.wheelrev[chan];
return p_data;
}
static int
dissect_burst(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
struct pkt_data *p_data;
int offset;
guint8 phase;
guint8 page;
guint8 flag;
int i, j;
int val;
if (tree) {
p_data = p_get_proto_data(pinfo->fd, proto_ant);
//fprintf(stderr, "pdata %p\n", p_data);
page = tvb_get_guint8(tvb, offset);
ANTITEM(tree, hf_ant_pd_page, 1);
NANTITEM(tree, hf_ant_43_b1f0, 1);
NANTITEM(tree, hf_ant_43_b1f1, 1);
NANTITEM(tree, hf_ant_43_b1f2, 1);
NANTITEM(tree, hf_ant_43_b1f3, 1);
NANTITEM(tree, hf_ant_43_b1f4, 1);
NANTITEM(tree, hf_ant_43_b1f5, 1);
NANTITEM(tree, hf_ant_43_b1f6, 1);
ANTITEM(tree, hf_ant_43_b1f7, 1);
phase = tvb_get_guint8(tvb, offset);
switch (page) {
case 0x43:
ANTITEM(tree, hf_ant_phase, 1);
ANTITEM(tree, hf_ant_b3, 1);
switch (phase) {
case 1:
ANTITEM(tree, hf_ant_pcid, 4);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_ub, 1);
ANTITEM(tree, hf_ant_ub, 1);
ANTITEM(tree, hf_ant_unitid, 4);
if (tvb_length_remaining(tvb, offset)) {
ANTITEM(tree, hf_ant_unitname, 16);
}
break;
case 3:
flag = tvb_get_guint8(tvb, offset+2);
switch (flag) {
case 0:
ANTITEM(tree, hf_ant_pcid, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u1, 4);
ANTITEM(tree, hf_ant_unitid, 4);
break;
case 1:
/* Forerunner 50 decoder from: http://darkskiez.co.uk/index.php?page=Garmin_ForeRunner_Decoder */
ANTITEM(tree, hf_ant_product_id, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_product_id, 2);
ANTITEM(tree, hf_ant_unitname, 16);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_unitid, 4);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_auth, 8);
ANTITEM(tree, hf_ant_fpodid, 2);
ANTITEM(tree, hf_ant_hrmid, 2);
ANTITEM(tree, hf_ant_bpodid, 2); /* TODO: confirm */
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_firmware, 16);
NANTITEM(tree, hf_ant_pref1f0, 1);
NANTITEM(tree, hf_ant_pref1f1, 1);
NANTITEM(tree, hf_ant_pref1f2, 1);
NANTITEM(tree, hf_ant_pref1f3, 1);
NANTITEM(tree, hf_ant_pref1f4, 1);
NANTITEM(tree, hf_ant_pref1f5, 1);
NANTITEM(tree, hf_ant_pref1f6, 1);
ANTITEM(tree, hf_ant_pref1f7, 1);
NANTITEM(tree, hf_ant_pref2f0, 1);
NANTITEM(tree, hf_ant_pref2f1, 1);
NANTITEM(tree, hf_ant_pref2f2, 1);
NANTITEM(tree, hf_ant_pref2f3, 1);
NANTITEM(tree, hf_ant_pref2f4, 1);
NANTITEM(tree, hf_ant_pref2f5, 1);
NANTITEM(tree, hf_ant_pref2f6, 1);
ANTITEM(tree, hf_ant_pref2f7, 1);
ANTITEM(tree, hf_ant_autolap, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_run_lo, 2);
ANTITEM(tree, hf_ant_run_hi, 2);
ANTITEM(tree, hf_ant_hrm_lo, 1);
ANTITEM(tree, hf_ant_hrm_hi, 1);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_weight, 1);
ANTITEM(tree, hf_ant_ub, 1);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_pref_cksum, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_xid, 1);
ANTITEM(tree, hf_ant_ub, 1);
ANTITEM(tree, hf_ant_x0, 6);
ANTITEM(tree, hf_ant_x1, 6);
ANTITEM(tree, hf_ant_x2, 6);
ANTITEM(tree, hf_ant_x3, 6);
for (i = 1; i <= 100; i++) {
val = tvb_get_guint8(tvb, offset);
proto_tree_add_uint_format_value(tree, hf_ant_run_id, tvb, offset, 1, i, "%d %d", val, i); offset++;
//ANTITEM(tree, hf_ant_run_id, 1);
ANTITEM(tree, hf_ant_run_prev, 1);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_run_time, 2);
ANTITEM(tree, hf_ant_run_date, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
}
for (i = 1; i <= 100; i++) {
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_lap_next, 1);
ANTITEM(tree, hf_ant_lap_type, 1);
ANTITEM(tree, hf_ant_lap_speed, 2);
ANTITEM(tree, hf_ant_lap_dist, 4);
ANTITEM(tree, hf_ant_lap_time, 4);
ANTITEM(tree, hf_ant_lap_cals, 2);
ANTITEM(tree, hf_ant_lap_avghr, 1);
ANTITEM(tree, hf_ant_lap_maxhr, 1);
ANTITEM(tree, hf_ant_lap_avgcad, 1);
ANTITEM(tree, hf_ant_lap_maxcad, 1);
ANTITEM(tree, hf_ant_lap_steps, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
}
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_u0, 2);
for (i = 1; i <= 100; i++) {
ANTITEM(tree, hf_ant_u0, 2);
for (j = 1; j <= 50; j++) {
ANTITEM(tree, hf_ant_speed_dist, 3);
ANTITEM(tree, hf_ant_cad, 1);
ANTITEM(tree, hf_ant_hr, 1);
}
}
break;
}
break;
}
break;
case 0x44:
ANTITEM(tree, hf_ant_cmd, 1);
ANTITEM(tree, hf_ant_auth_len, 1);
switch (phase) {
case 3:
ANTITEM(tree, hf_ant_pcid, 4);
//ANTITEM(tree, hf_ant_u0, 2);
ANTITEM(tree, hf_ant_auth, 8);
ANTITEM(tree, hf_ant_data_mbz, 8);
break;
}
break;
}
}
return offset;
}
static int
dissect_ant(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
int offset;
int len;
int msgid;
int rmsg;
guint16 newrr;
guint8 newseq;
guint8 newr1;
guint8 newr2;
guint8 newn;
guint16 newp;
guint16 newt;
int chan;
guint64 netkey;
char *netstr;
guint16 val;
guint8 page;
float batt;
struct ant_info *ant_infop;
struct pkt_data *p_data;
guint8 rdiff;
guint8 ndiff;
guint16 pdiff;
guint16 tdiff;
float nm;
float rpm;
float watts;
guint8 ext;
guint16 newwheeltime, diffwheeltime;
guint16 newcranktime, diffcranktime;
guint16 newwheelrev, diffwheelrev;
guint16 newcrankrev, diffcrankrev;
guint8 cadx1, cadx2;
guint8 cmd;
guint8 phase;
guint8 burst_last, burst_seq, burst_chan;
fragment_data *frag_msg;
tvbuff_t *new_tvb, *next_tvb;
proto_tree *msg_tree;
gboolean save_fragmented = FALSE;
proto_item *antdata_item = NULL;
proto_item *ti;
proto_tree *ant_tree;
proto_tree *dtree = NULL; /* data tree. TODO: dissect ANT data in subdissector */
int i;
packet_info cpinfo;
guint8 cksum;
/*
* requirements for ANT packet: len >= ANT_MIN_LEN, must start with SYNC
* could also use:
* valid checksum
* tvb len = len + header + trailer, though would miss packets with trailing nulls
*/
if (tvb_length(tvb) < ANT_MIN_LEN) {
return 0;
}
if (MESG_TX_SYNC != tvb_get_guint8(tvb, 0)) {
fprintf(stderr, "not sync len %d isfrag %d\n", tvb_length(tvb), pinfo->fragmented);
return 0;
}
len = tvb_get_guint8(tvb, LEN_OFFSET);
msgid = tvb_get_guint8(tvb, MSGID_OFFSET);
if (check_col(pinfo->cinfo, COL_PROTOCOL))
col_set_str(pinfo->cinfo, COL_PROTOCOL, "ANT");
if (check_col(pinfo->cinfo, COL_INFO))
col_set_str(pinfo->cinfo, COL_INFO, "ANT Message");
offset = 0;
if (tree) {
ti = proto_tree_add_item(tree, proto_ant, tvb, 0, -1, TRUE);
ant_tree = proto_item_add_subtree(ti, ett_ant);
msg_tree = proto_item_add_subtree(dtree, ett_msg_fragments);
}
ANTITEM(ant_tree, hf_ant_sync, 1);
ANTITEM(ant_tree, hf_ant_msg_length, 1);
ANTITEM(ant_tree, hf_ant_msg_id, 1);
if (len > 0) {
if (tree) {
/*antdata_item = NANTITEM(ant_tree, hf_ant_data, len);*/ /* TODO no data for this */
antdata_item = proto_tree_add_item(ant_tree, hf_ant_data, tvb, offset, len, TRUE);
dtree = proto_item_add_subtree(antdata_item, ett_ant_data);
}
switch (msgid) {
case MESG_CAPABILITIES_ID:
ANTITEM(dtree, hf_ant_data_maxchan, 1);
ANTITEM(dtree, hf_ant_data_maxnet, 1);
/* TODO - show reserved bits */
NANTITEM(dtree, hf_ant_bm_no_rx_chans, 1);
NANTITEM(dtree, hf_ant_bm_no_tx_chans, 1);
NANTITEM(dtree, hf_ant_bm_no_rx_msgs, 1);
NANTITEM(dtree, hf_ant_bm_no_tx_msgs, 1);
NANTITEM(dtree, hf_ant_bm_no_ackd_msgs, 1);
ANTITEM(dtree, hf_ant_bm_no_burst_msgs, 1);
NANTITEM(dtree, hf_ant_bm_net, 1);
NANTITEM(dtree, hf_ant_bm_serial, 1);
NANTITEM(dtree, hf_ant_bm_per_chan_tx_power, 1);
NANTITEM(dtree, hf_ant_bm_low_prio_srch, 1);
NANTITEM(dtree, hf_ant_bm_script, 1);
ANTITEM(dtree, hf_ant_bm_search_list, 1);
if (len > 4) {
NANTITEM(dtree, hf_ant_bm_led, 1);
NANTITEM(dtree, hf_ant_bm_ext_msg, 1);
NANTITEM(dtree, hf_ant_bm_scan_mode, 1);
NANTITEM(dtree, hf_ant_bm_prox_srch, 1);
ANTITEM(dtree, hf_ant_bm_ext_assign, 1);
}
break;
case MESG_ASSIGN_CHANNEL_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
ANTITEM(dtree, hf_ant_data_chtype, 1);
ANTITEM(dtree, hf_ant_data_net, 1);
break;
case MESG_CHANNEL_SEARCH_TIMEOUT_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
val = tvb_get_guint8(tvb, offset);
proto_tree_add_uint_format_value(dtree, hf_ant_data_srchto, tvb, offset, 1, val, "%d (%.1f secs)", val, val*2.5); offset++;
break;
case MESG_CHANNEL_RADIO_FREQ_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
val = tvb_get_guint8(tvb, offset);
proto_tree_add_uint_format_value(dtree, hf_ant_data_freq, tvb, offset, 1, val, "%d (%dMHz)", val, 2400+val); offset++;
break;
case MESG_BURST_DATA_ID:
burst_last = tvb_get_guint8(tvb, offset) & (1 << 7);
burst_seq = (tvb_get_guint8(tvb, offset) & (3 << 5)) >> 5;
burst_chan = tvb_get_guint8(tvb, offset) & 31;
p_data = p_get_proto_data(pinfo->fd, proto_ant);
ant_infop = 0;
if (!p_data) {
ant_infop = get_ant_infop(pinfo);
p_data = new_pdata(ant_infop, burst_chan);
p_data->this.burst.seq = ant_infop->last.burst.seq[burst_chan]++;
p_data->this.burst.seq_id = ant_infop->last.burst.seq_id[burst_chan];
p_data->this.burst.islast = burst_last;
p_data->this.burst.burst_seq = ant_infop->last.burst.burst_seq[burst_chan] = burst_seq;
p_add_proto_data(pinfo->fd, proto_ant, p_data);
if (burst_last) {
//fprintf(stderr, "burst %d %d %d\n", burst_seq, burst_chan, burst_last);
ant_infop->last.burst.seq[burst_chan] = 0;
ant_infop->last.burst.seq_id[burst_chan]++;
}
}
NANTITEM(dtree, hf_ant_bm_burst_seq_end, 1);
NANTITEM(dtree, hf_ant_bm_burst_seq, 1);
ANTITEM(dtree, hf_ant_bm_burst_chan, 1);
save_fragmented = pinfo->fragmented;
pinfo->fragmented = 1;
frag_msg = fragment_add_seq_check(tvb, offset, pinfo, p_data->this.burst.seq_id,
msg_fragment_table, msg_reassembled_table, p_data->this.burst.seq,
MIN(8, tvb_length_remaining(tvb, offset)-1), burst_last?0:1);
//fprintf(stderr, "frag %p seq %d last %d seq %d\n", frag_msg, p_data->this.burst.seq, burst_last?1:0, p_data->this.burst.seq_id);
//fprintf(stderr, "burst rem %d %d\n", tvb_length_remaining(tvb, offset)-1, MIN(8,tvb_length_remaining(tvb, offset)-1));
new_tvb = process_reassembled_data(tvb, offset, pinfo, "reassembled burst", frag_msg,
&msg_frag_items, NULL, dtree);
ANTITEM(dtree, hf_ant_data_data, len-1);
if (tree) {
if (frag_msg) {
col_append_str(pinfo->cinfo, COL_INFO, " burst reassembled");
} else {
col_append_fstr(pinfo->cinfo, COL_INFO, " burst %u", p_data->this.burst.seq);
}
}
if (new_tvb) {
//fprintf(stderr, "new size %d\n", tvb_reported_length_remaining(new_tvb, 0));
next_tvb = new_tvb;
dissect_burst(new_tvb, pinfo, dtree);
} else {
next_tvb = tvb_new_subset(tvb, offset, -1, -1);
}
pinfo->fragmented = save_fragmented;
/*
if (burst_last && next_tvb) {
dissect_ant(new_tvb, pinfo, msg_tree);
}
*/
break;
case MESG_CHANNEL_ID_ID:
chan = tvb_get_guint8(tvb, CHAN_OFFSET);
ANTITEM(dtree, hf_ant_data_chan, 1);
ANTITEM(dtree, hf_ant_data_devno, 2);
ant_infop = get_ant_infop(pinfo);
ant_infop->devtype[chan] = tvb_get_guint8(tvb, DEVTYPE_OFFSET);
ANTITEM(dtree, hf_ant_data_devtype, 1);
ANTITEM(dtree, hf_ant_data_transtype, 1);
break;
case MESG_SEARCH_WAVEFORM_ID:
ANTITEM(dtree, hf_ant_data_chan, 1)
ANTITEM(dtree, hf_ant_data_waveform, 2);
break;
case MESG_CHANNEL_MESG_PERIOD_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
val = tvb_get_letohs(tvb, PERIOD_OFFSET);
proto_tree_add_uint_format_value(dtree, hf_ant_data_period, tvb, offset, 2,
val, "%d (%.2fHz)", val, 32768.0/val); offset += 2;
break;
case MESG_REQUEST_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
ANTITEM(dtree, hf_ant_data_msgid, 1);
break;
case MESG_CHANNEL_STATUS_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
ANTITEM(dtree, hf_ant_data_chanstat, 1);
break;
case MESG_NETWORK_KEY_ID:
ANTITEM(dtree, hf_ant_data_net, 1);
netkey = tvb_get_ntoh64(tvb, offset);
if ((netkey & ANTP_MASK) == ANTP_MASK)
netstr = "(unknown)";
else
netstr = "(invalid key)";
switch (netkey) {
case SUUNTO_KEY:
netstr = "(Suunto)";
break;
case GMNHU_KEY:
netstr = "(Garmin head unit)";
break;
case ANTP_KEY:
netstr = "(ANT+)";
break;
}
proto_tree_add_text(dtree, tvb, offset, 8, "Network key: %" G_GINT64_MODIFIER "x %s",
netkey, netstr);
offset+= 8;
break;
case MESG_RESPONSE_EVENT_ID:
ANTITEM(dtree, hf_ant_data_chan, 1);
rmsg = tvb_get_guint8(tvb, RMSG_OFFSET); /* special case == 1 */
ANTITEM(dtree, hf_ant_data_msgid, 1);
ANTITEM(dtree, hf_ant_data_msgcode, 1);
break;
case MESG_SYSTEM_RESET_ID:
ANTITEM(dtree, hf_ant_data_mbz, 1);
break;
case MESG_BROADCAST_DATA_ID:
case MESG_EXT_BROADCAST_DATA_ID:
chan = tvb_get_guint8(tvb, CHAN_OFFSET);
ANTITEM(dtree, hf_ant_data_chan, 1);
if (MESG_EXT_BROADCAST_DATA_ID == msgid) {
ANTITEM(dtree, hf_ant_data_devno, 2);
ANTITEM(dtree, hf_ant_data_devtype, 1);
ANTITEM(dtree, hf_ant_data_transtype, 1);
ext = EXT_ADD;
} else
ext = 0;
p_data = p_get_proto_data(pinfo->fd, proto_ant);
ant_infop = 0;
if (!p_data) {
ant_infop = get_ant_infop(pinfo);
p_data = new_pdata(ant_infop, chan);
if (MESG_EXT_BROADCAST_DATA_ID == msgid)
p_data->devtype = tvb_get_guint8(tvb, DEVTYPE_OFFSET);
p_add_proto_data(pinfo->fd, proto_ant, p_data);
}
page = tvb_get_guint8(tvb, offset);
if (p_data->devtype == DEVTYPE_HRM) {
ANTITEM(dtree, hf_ant_pd_page, 1);
ANTITEM(dtree, hf_ant_data_data, 3);
newrr = tvb_get_letohs(tvb, RR_OFFSET+ext);
newseq = tvb_get_guint8(tvb, SEQ_OFFSET+ext);
if (ant_infop) {
ant_infop->last.hr.rr[chan] = newrr;
ant_infop->last.hr.seq[chan] = newseq;
ant_infop->first[chan] = 0;
}
if (p_data->last.hr.seq != newseq && !p_data->first) {
proto_tree_add_text(dtree, tvb, offset, 2, "R-R time: %d was %d, diff %d, R-R HR %.1f",
newrr, p_data->last.hr.rr, newrr-p_data->last.hr.rr, 60.0*1024.0/(newrr-p_data->last.hr.rr));
} else {
NANTITEM(dtree, hf_ant_pd_rr, 2);
}
offset += 2;