summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-gsm_cbsp.c
blob: 235942761f90429e661a68b4d4eabe799b28b3f0 (plain)
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
/* packet-gsm_cbsp.c
 * Dissector for GSM / 3GPP TS 48.049 Cell Broadcast Service Protocol (CBSP)
 *
 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/conversation.h>
#include <epan/asn1.h>

#include "packet-e164.h"
#include "packet-e212.h"
#include "packet-gsm_map.h"
#include "packet-cell_broadcast.h"

/***********************************************************************
 * TLV related definitions
 ***********************************************************************/

/*! Entry in a TLV parser array */
struct tlv_p_entry {
	uint16_t len;		/*!< length */
	const uint8_t *val;	/*!< pointer to value */
};

/*! TLV type */
enum tlv_type {
	TLV_TYPE_NONE,		/*!< no type */
	TLV_TYPE_FIXED,		/*!< fixed-length value-only */
	TLV_TYPE_TV,		/*!< tag-value (8bit) */
	TLV_TYPE_TLV,		/*!< tag-length-value */
	TLV_TYPE_TL16V,		/*!< tag, 16 bit length, value */
};

/*! Definition of a single IE (Information Element) */
struct tlv_def {
	enum tlv_type type;	/*!< TLV type */
	uint8_t fixed_len;	/*!< length in case of TLV_TYPE_FIXED */
};

/*! Definition of All 256 IE / TLV */
struct tlv_definition {
	struct tlv_def def[256];
};


/***********************************************************************
 * CBSP Protocol Definitions, see libosmocore/include/gsm/protocol/gsm_48_049.h
 ***********************************************************************/

#define CBSP_TCP_PORT 48049

/* 8.2.1 Information Element Identifiers */
enum cbsp_iei {
	CBSP_IEI_MSG_CONTENT		= 0x01,
	CBSP_IEI_OLD_SERIAL_NR		= 0x02,
	CBSP_IEI_NEW_SERIAL_NR		= 0x03,
	CBSP_IEI_CELL_LIST		= 0x04,
	CBSP_IEI_CATEGORY		= 0x05,
	CBSP_IEI_REP_PERIOD		= 0x06,
	CBSP_IEI_NUM_BCAST_REQ		= 0x07,
	CBSP_IEI_NUM_BCAST_COMPL_LIST	= 0x08,
	CBSP_IEI_FAILURE_LIST		= 0x09,
	CBSP_IEI_RR_LOADING_LIST	= 0x0a,
	CBSP_IEI_CAUSE			= 0x0b,
	CBSP_IEI_DCS			= 0x0c,
	CBSP_IEI_RECOVERY_IND		= 0x0d,
	CBSP_IEI_MSG_ID			= 0x0e,
	CBSP_IEI_EMERG_IND		= 0x0f,
	CBSP_IEI_WARN_TYPE		= 0x10,
	CBSP_IEI_WARN_SEC_INFO		= 0x11,
	CBSP_IEI_CHANNEL_IND		= 0x12,
	CBSP_IEI_NUM_OF_PAGES		= 0x13,
	CBSP_IEI_SCHEDULE_PERIOD	= 0x14,
	CBSP_IEI_NUM_OF_RES_SLOTS	= 0x15,
	CBSP_IEI_BCAST_MSG_TYPE		= 0x16,
	CBSP_IEI_WARNING_PERIOD		= 0x17,
	CBSP_IEI_KEEP_ALIVE_REP_PERIOD	= 0x18,
};

/* 8.2.2 Message Type */
enum cbsp_msg_type {
	CBSP_MSGT_WRITE_REPLACE		= 0x01,
	CBSP_MSGT_WRITE_REPLACE_COMPL	= 0x02,
	CBSP_MSGT_WRITE_REPLACE_FAIL	= 0x03,
	CBSP_MSGT_KILL			= 0x04,
	CBSP_MSGT_KILL_COMPL		= 0x05,
	CBSP_MSGT_KILL_FAIL		= 0x06,
	CBSP_MSGT_LOAD_QUERY		= 0x07,
	CBSP_MSGT_LOAD_QUERY_COMPL	= 0x08,
	CBSP_MSGT_LOAD_QUERY_FAIL	= 0x09,
	CBSP_MSGT_MSG_STATUS_QUERY	= 0x0a,
	CBSP_MSGT_MSG_STATUS_QUERY_COMPL= 0x0b,
	CBSP_MSGT_MSG_STATUS_QUERY_FAIL	= 0x0c,
	CBSP_MSGT_SET_DRX		= 0x0d,
	CBSP_MSGT_SET_DRX_COMPL		= 0x0e,
	CBSP_MSGT_SET_DRX_FAIL		= 0x0f,
	CBSP_MSGT_RESET			= 0x10,
	CBSP_MSGT_RESET_COMPL		= 0x11,
	CBSP_MSGT_RESET_FAIL		= 0x12,
	CBSP_MSGT_RESTART		= 0x13,
	CBSP_MSGT_FAILURE		= 0x14,
	CBSP_MSGT_ERROR_IND		= 0x15,
	CBSP_MSGT_KEEP_ALIVE		= 0x16,
	CBSP_MSGT_KEEP_ALIVE_COMPL	= 0x17,
};

/* 8.2.7 Category */
enum cbsp_category {
	CBSP_CATEG_HIGH_PRIO		= 0x00,
	CBSP_CATEG_BACKGROUND		= 0x01,
	CBSP_CATEG_NORMAL		= 0x02,
};

/* 8.2.9 Number of Broadcast Info */
enum cbsp_num_bcast_info {
	CBSP_NUM_BCAST_INFO_VALID	= 0x0,
	CBSP_NUM_BCAST_INFO_OVERFLOW	= 0x1,
	CBSP_NUM_BCAST_INFO_UNKNOWN	= 0x2,
};

static const value_string cbsp_num_bcast_info_vals[] = {
	{ CBSP_NUM_BCAST_INFO_VALID,	"Number of Broadcasts Complete is Valid" },
	{ CBSP_NUM_BCAST_INFO_OVERFLOW,	"Number of Broadcasts Complete has Overflown" },
	{ CBSP_NUM_BCAST_INFO_UNKNOWN,	"Number of Broadcasts Complete is undefined" },
	{ 0, NULL }
};

static const value_string cbsp_num_bcast_shortinfo_vals[] = {
	{ CBSP_NUM_BCAST_INFO_VALID,	"Valid" },
	{ CBSP_NUM_BCAST_INFO_OVERFLOW,	"Overflow" },
	{ CBSP_NUM_BCAST_INFO_UNKNOWN,	"Unknown" },
	{ 0, NULL }
};

/* Cell ID Discriminator (8.2.11, ...) */
enum cbsp_cell_id_disc {
	CBSP_CIDD_WHOLE_CGI		= 0x0,
	CBSP_CIDD_LAC_CI		= 0x1,
	CBSP_CIDD_CI			= 0x2,
	CBSP_CIDD_LAI			= 0x4,
	CBSP_CIDD_LAC			= 0x5,
	CBSP_CIDD_ALL_IN_BSC		= 0x6,
};

/* 8.2.13 Cause */
enum cbsp_cause {
	CBSP_CAUSE_PARAM_NOT_RECOGNISED			= 0x00,
	CBSP_CAUSE_PARAM_VAL_INVALID			= 0x01,
	CBSP_CAUSE_MSG_REF_NOT_IDENTIFIED		= 0x02,
	CBSP_CAUSE_CELL_ID_NOT_VALID			= 0x03,
	CBSP_CAUSE_UNRECOGNISED_MSG			= 0x04,
	CBSP_CAUSE_MISSING_MAND_IE			= 0x05,
	CBSP_CAUSE_BSC_CAPACITY_EXCEEDED		= 0x06,
	CBSP_CAUSE_CELL_MEMORY_EXCEEDED			= 0x07,
	CBSP_CAUSE_BSC_MEMORY_EXCEEDED			= 0x08,
	CBSP_CAUSE_CB_NOT_SUPPORTED			= 0x09,
	CBSP_CAUSE_CB_NOT_OPERATIONAL			= 0x0a,
	CBSP_CAUSE_INCOMPATIBLE_DRX_PARAM		= 0x0b,
	CBSP_CAUSE_EXT_CHAN_NOT_SUPPORTED		= 0x0c,
	CBSP_CAUSE_MSG_REF_ALREADY_USED			= 0x0d,
	CBSP_CAUSE_UNSPECIFIED_ERROR			= 0x0e,
	CBSP_CAUSE_LAI_OR_LAC_NPT_VALID			= 0x0f,
};

/* 8.2.15 */
static const value_string cbsp_recov_ind_vals[] = {
	{ 0x0,	"CBS/emergency message data available" },
	{ 0x1,	"CBS/emergency message data lost" },
	{ 0, NULL }
};

/* 8.2.17 */
static const value_string cbsp_emerg_ind_vals[] = {
	{ 0x0,	"reserved" },
	{ 0x1,	"ETWS information available" },
	{ 0, NULL }
};

/* 8.2.20 */
static const value_string cbsp_chan_ind_vals[] = {
	{ 0x0,	"basic channel" },
	{ 0x1,	"extended channel" },
	{ 0, NULL }
};

/* 8.2.24 */
static const value_string cbsp_bcast_msg_type_vals[] = {
	{ 0x0,	"CBS message broadcasting" },
	{ 0x1,	"emergency message broadcasting" },
	{ 0, NULL }
};

/* conversion function from 8.2.25 warning period to seconds */
static int cbsp_warn_period_to_secs(uint8_t warn_per)
{
	if (warn_per <= 0x0a)
		return warn_per;
	else if (warn_per <= 0x14)
		return 10 + (warn_per-0x0a)*2;
	else if (warn_per <= 0x26)
		return 30 + (warn_per-0x14)*5;
	else if (warn_per <= 0x56)
		return 120 + (warn_per-0x26)*10;
	else if (warn_per <= 0xba)
		return 600 + (warn_per-0x56)*60;
	else
		return -1;
}

static const value_string cbsp_cell_id_disc_vals[] = {
	{ CBSP_CIDD_WHOLE_CGI,		"CGI" },
	{ CBSP_CIDD_LAC_CI,		"LAC+CI" },
	{ CBSP_CIDD_CI,			"CI" },
	{ CBSP_CIDD_LAI,		"LAI" },
	{ CBSP_CIDD_LAC,		"LAC" },
	{ CBSP_CIDD_ALL_IN_BSC,		"BSS" },
	{ 0, NULL }
};

static const value_string cbsp_iei_names[] = {
	{ CBSP_IEI_MSG_CONTENT,		"Message Content" },
	{ CBSP_IEI_OLD_SERIAL_NR,	"Old Serial Number" },
	{ CBSP_IEI_NEW_SERIAL_NR,	"New Serial Number" },
	{ CBSP_IEI_CELL_LIST,		"Cell List" },
	{ CBSP_IEI_CATEGORY,		"Category" },
	{ CBSP_IEI_REP_PERIOD,		"Repetition Period" },
	{ CBSP_IEI_NUM_BCAST_REQ,	"Number of Broadcasts Requested" },
	{ CBSP_IEI_NUM_BCAST_COMPL_LIST,"Number of Broadcasts Completed List" },
	{ CBSP_IEI_FAILURE_LIST,	"Failure List" },
	{ CBSP_IEI_RR_LOADING_LIST,	"Radio Resource Loading List" },
	{ CBSP_IEI_CAUSE,		"Cause" },
	{ CBSP_IEI_DCS,			"Data Coding Scheme" },
	{ CBSP_IEI_RECOVERY_IND,	"Recovery Indication" },
	{ CBSP_IEI_MSG_ID,		"Message Identifier" },
	{ CBSP_IEI_EMERG_IND,		"Emergency Indicator" },
	{ CBSP_IEI_WARN_TYPE,		"Warning Type" },
	{ CBSP_IEI_WARN_SEC_INFO,	"Warning Security Information" },
	{ CBSP_IEI_CHANNEL_IND,		"Channel Indicator" },
	{ CBSP_IEI_NUM_OF_PAGES,	"Number of Pages" },
	{ CBSP_IEI_SCHEDULE_PERIOD,	"Schedule Period" },
	{ CBSP_IEI_NUM_OF_RES_SLOTS,	"Number of Reserved Slots" },
	{ CBSP_IEI_BCAST_MSG_TYPE,	"Broadcast Message Type" },
	{ CBSP_IEI_WARNING_PERIOD,	"Waring Period" },
	{ CBSP_IEI_KEEP_ALIVE_REP_PERIOD, "Keep Alive Repetition Period" },
	{ 0, NULL }
};

static const value_string cbsp_msg_type_names[] = {
	{ CBSP_MSGT_WRITE_REPLACE,		"WRITE-REPLACE" },
	{ CBSP_MSGT_WRITE_REPLACE_COMPL,	"WRITE-REPLACE COMPLETE" },
	{ CBSP_MSGT_WRITE_REPLACE_FAIL,		"WRITE-REPLACE FAILURE" },
	{ CBSP_MSGT_KILL,			"KILL" },
	{ CBSP_MSGT_KILL_COMPL,			"KILL COMPLETE" },
	{ CBSP_MSGT_KILL_FAIL,			"KILL FAILURE" },
	{ CBSP_MSGT_LOAD_QUERY,			"LOAD QUERY" },
	{ CBSP_MSGT_LOAD_QUERY_COMPL,		"LOAD QUERY COMPLETE" },
	{ CBSP_MSGT_LOAD_QUERY_FAIL,		"LOAD QUERY FAILURE" },
	{ CBSP_MSGT_MSG_STATUS_QUERY,		"MESSAGE STATUS QUERY" },
	{ CBSP_MSGT_MSG_STATUS_QUERY_COMPL,	"MESSAGE STATUS QUERY COMPLETE" },
	{ CBSP_MSGT_MSG_STATUS_QUERY_FAIL,	"MESSAGE STATUS QUERY FAILURE" },
	{ CBSP_MSGT_SET_DRX,			"SET-DRX" },
	{ CBSP_MSGT_SET_DRX_COMPL,		"SET-DRX COMPLETE" },
	{ CBSP_MSGT_SET_DRX_FAIL,		"SET-DRX FAILURE" },
	{ CBSP_MSGT_RESET,			"RESET" },
	{ CBSP_MSGT_RESET_COMPL,		"RESET COMPLETE" },
	{ CBSP_MSGT_RESET_FAIL,			"RESET FAILURE" },
	{ CBSP_MSGT_RESTART,			"RESTART" },
	{ CBSP_MSGT_FAILURE,			"FAILURE" },
	{ CBSP_MSGT_ERROR_IND,			"ERROR INDICATION" },
	{ CBSP_MSGT_KEEP_ALIVE,			"KEEP-ALIVE" },
	{ CBSP_MSGT_KEEP_ALIVE_COMPL,		"KEEP-ALIVE COMPLETE" },
	{ 0, NULL }
};

static const value_string cbsp_category_names[] = {
	{ CBSP_CATEG_HIGH_PRIO,		"High Priority" },
	{ CBSP_CATEG_BACKGROUND,	"Background" },
	{ CBSP_CATEG_NORMAL,		"Normal" },
	{ 0, NULL }
};

/* 8.2.13 */
static const value_string cbsp_cause_vals[] = {
	{ CBSP_CAUSE_PARAM_NOT_RECOGNISED,	"Parameter-not-recognized" },
	{ CBSP_CAUSE_PARAM_VAL_INVALID,		"Parameter-value-invalid" },
	{ CBSP_CAUSE_MSG_REF_NOT_IDENTIFIED,	"Message-reference-not-identified" },
	{ CBSP_CAUSE_CELL_ID_NOT_VALID,		"Cell-identity-not-valid" },
	{ CBSP_CAUSE_UNRECOGNISED_MSG,		"Unrecognised-message" },
	{ CBSP_CAUSE_MISSING_MAND_IE,		"Missing-mandatory-element" },
	{ CBSP_CAUSE_BSC_CAPACITY_EXCEEDED,	"BSC-capacity-exceeded" },
	{ CBSP_CAUSE_CELL_MEMORY_EXCEEDED,	"Cell-memory-exceeded" },
	{ CBSP_CAUSE_BSC_MEMORY_EXCEEDED,	"BSC-memory-exceeded" },
	{ CBSP_CAUSE_CB_NOT_SUPPORTED,		"Cell-broadcast-not-supported" },
	{ CBSP_CAUSE_CB_NOT_OPERATIONAL,	"Cell-broadcast-not-operational" },
	{ CBSP_CAUSE_INCOMPATIBLE_DRX_PARAM,	"Incompatible-DRX-parameter" },
	{ CBSP_CAUSE_EXT_CHAN_NOT_SUPPORTED,	"Extended-channel-not-supported" },
	{ CBSP_CAUSE_MSG_REF_ALREADY_USED,	"Message-reference-already-used" },
	{ CBSP_CAUSE_UNSPECIFIED_ERROR,		"Unspecified-error" },
	{ CBSP_CAUSE_LAI_OR_LAC_NPT_VALID,	"LAI-or-LAC-not-valid" },
	{ 0, NULL }
};

static const struct tlv_definition cbsp_att_tlvdef = {
	.def = {
		[CBSP_IEI_MSG_CONTENT] =		{ TLV_TYPE_FIXED, 83 },
		[CBSP_IEI_OLD_SERIAL_NR] =		{ TLV_TYPE_FIXED, 2 },
		[CBSP_IEI_NEW_SERIAL_NR] =		{ TLV_TYPE_FIXED, 2 },
		[CBSP_IEI_CELL_LIST] =			{ TLV_TYPE_TL16V, 0 },
		[CBSP_IEI_CATEGORY] =			{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_REP_PERIOD] =			{ TLV_TYPE_FIXED, 2 },
		[CBSP_IEI_NUM_BCAST_REQ] =		{ TLV_TYPE_FIXED, 2 },
		[CBSP_IEI_NUM_BCAST_COMPL_LIST] =	{ TLV_TYPE_TL16V, 0 },
		[CBSP_IEI_FAILURE_LIST] =		{ TLV_TYPE_TL16V, 0 },
		[CBSP_IEI_RR_LOADING_LIST] =		{ TLV_TYPE_TL16V, 0 },
		[CBSP_IEI_CAUSE] =			{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_DCS] =			{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_RECOVERY_IND] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_MSG_ID] =			{ TLV_TYPE_FIXED, 2 },
		[CBSP_IEI_EMERG_IND] =			{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_WARN_TYPE] =			{ TLV_TYPE_FIXED, 2 },
		[CBSP_IEI_WARN_SEC_INFO] =		{ TLV_TYPE_FIXED, 50 },
		[CBSP_IEI_CHANNEL_IND] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_NUM_OF_PAGES] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_SCHEDULE_PERIOD] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_NUM_OF_RES_SLOTS] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_BCAST_MSG_TYPE] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_WARNING_PERIOD] =		{ TLV_TYPE_TV, 0 },
		[CBSP_IEI_KEEP_ALIVE_REP_PERIOD] =	{ TLV_TYPE_TV, 0 },
	},
};

/***********************************************************************
 * Wireshark Dissector Implementation
 ***********************************************************************/

void proto_register_cbsp(void);
void proto_reg_handoff_cbsp(void);

static dissector_handle_t cbsp_handle;

static int proto_cbsp;

static int hf_cbsp_msg_type;
static int hf_cbsp_msg_len;
static int hf_cbsp_iei;
static int hf_cbsp_ie_len;
static int hf_cbsp_ie_payload;

static int hf_cbsp_old_serial_nr;
static int hf_cbsp_new_serial_nr;
static int hf_cbsp_category;
static int hf_cbsp_rep_period;
static int hf_cbsp_num_bcast_req;
static int hf_cbsp_cause;
static int hf_cbsp_dcs;
static int hf_cbsp_recovery_ind;
static int hf_cbsp_msg_id;
static int hf_cbsp_emerg_ind;
static int hf_cbsp_warn_type;
static int hf_cbsp_channel_ind;
static int hf_cbsp_num_of_pages;
static int hf_cbsp_cb_msg_page;
static int hf_cbsp_cbs_page_content;
static int hf_cbsp_sched_period;
static int hf_cbsp_num_of_res_slots;
static int hf_cbsp_bcast_msg_type;
static int hf_cbsp_warning_period;
static int hf_cbsp_keepalive_period;
static int hf_cbsp_user_info_length;
static int hf_cbsp_cell_id_disc;
static int hf_cbsp_cell_load1;
static int hf_cbsp_cell_load2;
static int hf_cbsp_num_bcast_compl;
static int hf_cbsp_num_bcast_info;
static int hf_cbsp_lac;
static int hf_cbsp_ci;

static int ett_cbsp;
static int ett_cbsp_ie;
static int ett_cbsp_cbs_data_coding;
static int ett_cbsp_cbs_page_content;
static int ett_cbsp_cell_list;
static int ett_cbsp_fail_list;
static int ett_cbsp_load_list;
static int ett_cbsp_num_bcast_compl_list;

static void
dissect_cbsp_content_ie(tvbuff_t *tvb, packet_info *pinfo, unsigned offset, int len, proto_tree *tree,
			uint8_t sms_encoding, proto_item *ti)
{
	proto_item *cbs_page_item;
	tvbuff_t *next_tvb, *unpacked_tvb;
	const uint8_t *pstr;

	proto_tree_add_item(tree, hf_cbsp_user_info_length, tvb, offset, 1, ENC_NA);
	cbs_page_item = proto_tree_add_item(tree, hf_cbsp_cb_msg_page, tvb, offset+1, len-1, ENC_NA);
	next_tvb = tvb_new_subset_length(tvb, offset+1, len-1);

	unpacked_tvb = dissect_cbs_data(sms_encoding, next_tvb, tree, pinfo, 0);
	if (tree) {
		unsigned captured_len = tvb_captured_length(unpacked_tvb);
		proto_tree *cbs_page_subtree = proto_item_add_subtree(cbs_page_item, ett_cbsp_cbs_page_content);
		proto_tree_add_item_ret_string(cbs_page_subtree, hf_cbsp_cbs_page_content, unpacked_tvb,
						0, captured_len, ENC_UTF_8|ENC_NA, pinfo->pool,
						&pstr);
		proto_item_append_text(ti, ": '%s'", pstr);
	}
}

/* Section 8.2.6 Cell List */
static int
dissect_cell_id_elem(uint8_t discr, tvbuff_t *tvb, packet_info *pinfo, unsigned offset, int len _U_,
		     proto_tree *tree, proto_item *ti)
{
	unsigned base_offs = offset;
	char *mcc_mnc;
	uint32_t lac, ci;

	switch (discr) {
	case CBSP_CIDD_WHOLE_CGI:
		mcc_mnc = dissect_e212_mcc_mnc_wmem_packet_str(tvb, pinfo, tree, offset, E212_NONE, true);
		offset += 3;
		proto_tree_add_item_ret_uint(tree, hf_cbsp_lac, tvb, offset, 2, ENC_NA, &lac);
		offset += 2;
		proto_tree_add_item_ret_uint(tree, hf_cbsp_ci, tvb, offset, 2, ENC_NA, &ci);
		offset += 2;
		proto_item_append_text(ti, ": %s, LAC 0x%04x, CI 0x%04x", mcc_mnc, lac, ci);
		break;
	case CBSP_CIDD_LAC_CI:
		proto_tree_add_item_ret_uint(tree, hf_cbsp_lac, tvb, offset, 2, ENC_NA, &lac);
		offset += 2;
		proto_tree_add_item_ret_uint(tree, hf_cbsp_ci, tvb, offset, 2, ENC_NA, &ci);
		offset += 2;
		proto_item_append_text(ti, ": LAC 0%04x, CI 0x%04x", lac, ci);
		break;
	case CBSP_CIDD_CI:
		proto_tree_add_item_ret_uint(tree, hf_cbsp_ci, tvb, offset, 2, ENC_NA, &ci);
		offset += 2;
		proto_item_append_text(ti, ": CI 0x%04x", ci);
		break;
	case CBSP_CIDD_LAI:
		mcc_mnc = dissect_e212_mcc_mnc_wmem_packet_str(tvb, pinfo, tree, offset, E212_NONE, true);
		offset += 3;
		proto_tree_add_item_ret_uint(tree, hf_cbsp_lac, tvb, offset, 2, ENC_NA, &lac);
		offset += 2;
		proto_item_append_text(ti, ": %s, LAC 0x%04x", mcc_mnc, lac);
		break;
	case CBSP_CIDD_LAC:
		proto_tree_add_item_ret_uint(tree, hf_cbsp_lac, tvb, offset, 2, ENC_NA, &lac);
		offset += 2;
		proto_item_append_text(ti, ": LAC 0x%04x", lac);
		break;
	case CBSP_CIDD_ALL_IN_BSC:
		break;
	default:
		return -1;
	}

	return offset - base_offs;
}

/* return the length of a single list element of the given discriminator/type */
static int cell_id_len(uint8_t discr)
{
	switch (discr) {
	case CBSP_CIDD_WHOLE_CGI:
		return 7;
	case CBSP_CIDD_LAC_CI:
		return 4;
	case CBSP_CIDD_CI:
		return 2;
	case CBSP_CIDD_LAI:
		return 5;
	case CBSP_CIDD_LAC:
		return 2;
	case CBSP_CIDD_ALL_IN_BSC:
		return 0;
	default:
		return -1;
	}
}

static void
dissect_cell_id_list_ie(tvbuff_t *tvb, packet_info *pinfo, unsigned offset, unsigned len, proto_tree *tree,
			proto_item *parent_ti)
{
	unsigned base_offs = offset;
	uint32_t discr;
	unsigned count = 0;

	/* list-global discriminator */
	proto_tree_add_item_ret_uint(tree, hf_cbsp_cell_id_disc, tvb, offset, 1, ENC_NA, &discr);
	discr &= 0x0f;
	offset++;

	/* iterate over list items */
	while (offset - base_offs < len) {
		proto_tree *elem_tree;
		proto_item *ti;
		int rc;

		unsigned remain_len = len - (offset - base_offs);
		elem_tree = proto_tree_add_subtree(tree, tvb, offset, cell_id_len(discr),
						   ett_cbsp_cell_list, &ti,
						   "Cell List Item");
		rc = dissect_cell_id_elem(discr, tvb, pinfo, offset, remain_len, elem_tree, ti);
		if (rc <= 0)
			break;
		offset += rc;
		count++;
	}
	proto_item_append_text(parent_ti, " (%s): %u items",
				val_to_str_const(discr, cbsp_cell_id_disc_vals, ""), count);
}

static void
dissect_rr_load_list_ie(tvbuff_t *tvb, packet_info *pinfo, unsigned offset, unsigned len, proto_tree *tree,
			proto_item *parent_ti)
{
	unsigned base_offs = offset;
	uint32_t discr;
	unsigned count = 0;

	/* list-global discriminator */
	proto_tree_add_item_ret_uint(tree, hf_cbsp_cell_id_disc, tvb, offset, 1, ENC_NA, &discr);
	discr &= 0x0f;
	offset++;

	/* iterate over list items */
	while (offset - base_offs < len) {
		proto_tree *elem_tree;
		uint32_t load1, load2;
		proto_item *ti;
		int rc;

		unsigned remain_len = len - (offset - base_offs);
		elem_tree = proto_tree_add_subtree(tree, tvb, offset, cell_id_len(discr)+2,
						   ett_cbsp_load_list, &ti,
						   "RR Load List Item");
		rc = dissect_cell_id_elem(discr, tvb, pinfo, offset, remain_len, elem_tree, ti);
		if (rc <= 0)
			break;
		offset += rc;

		proto_tree_add_item_ret_uint(elem_tree, hf_cbsp_cell_load1, tvb, offset++, 1,
					     ENC_NA, &load1);
		proto_tree_add_item_ret_uint(elem_tree, hf_cbsp_cell_load2, tvb, offset++, 1,
					     ENC_NA, &load2);
		proto_item_append_text(ti, ": L1=%u%%, L2=%u%%", load1, load2);
		count++;
	}
	proto_item_append_text(parent_ti, " (%s): %u items",
				val_to_str_const(discr, cbsp_cell_id_disc_vals, ""), count);
}

static void
dissect_failure_list_ie(tvbuff_t *tvb, packet_info *pinfo, unsigned offset, unsigned len, proto_tree *tree,
			proto_item *parent_ti)
{
	unsigned base_offs = offset;
	unsigned count = 0;

	/* iterate over list items, each with its own discriminator */
	while (offset - base_offs < len) {
		proto_tree *elem_tree;
		proto_item *ti;
		unsigned remain_len, cause;
		int rc;

		uint8_t discr = tvb_get_uint8(tvb, offset) & 0x0f;
		elem_tree = proto_tree_add_subtree(tree, tvb, offset, cell_id_len(discr)+2,
						   ett_cbsp_fail_list, &ti,
						   "Failure List Item");
		proto_tree_add_item(elem_tree, hf_cbsp_cell_id_disc, tvb, offset++, 1, ENC_NA);
		remain_len = len - (offset - base_offs);
		rc = dissect_cell_id_elem(discr, tvb, pinfo, offset, remain_len, elem_tree, ti);
		if (rc <= 0)
			break;
		offset += rc;

		proto_tree_add_item_ret_uint(elem_tree, hf_cbsp_cause, tvb, offset++, 1, ENC_NA, &cause);
		proto_item_append_text(ti, ": Cause %s",
					val_to_str_const(cause, cbsp_cause_vals, "Undefined"));
		count++;
	}
	proto_item_append_text(parent_ti, ": %u items", count);

}

static void
dissect_bc_compl_list_ie(tvbuff_t *tvb, packet_info *pinfo, unsigned offset, unsigned len, proto_tree *tree,
			 proto_item *parent_ti)
{
	unsigned base_offs = offset;
	uint32_t discr;
	unsigned count = 0;

	/* list-global discriminator */
	proto_tree_add_item_ret_uint(tree, hf_cbsp_cell_id_disc, tvb, offset, 1, ENC_NA, &discr);
	discr &= 0x0f;
	offset++;

	/* iterate over list items */
	while (offset - base_offs < len) {
		proto_tree *elem_tree;
		proto_item *ti;
		uint32_t num_bc, num_bi;
		int rc;

		unsigned remain_len = len - (offset - base_offs);
		elem_tree = proto_tree_add_subtree(tree, tvb, offset, cell_id_len(discr)+3,
						   ett_cbsp_num_bcast_compl_list, &ti,
						   "Number of Broadcasts completed");
		rc = dissect_cell_id_elem(discr, tvb, pinfo, offset, remain_len, elem_tree, ti);
		if (rc <= 0)
			break;
		offset += rc;

		proto_tree_add_item_ret_uint(elem_tree, hf_cbsp_num_bcast_compl, tvb, offset, 2, ENC_NA,
					     &num_bc);
		offset += 2;
		proto_tree_add_item_ret_uint(elem_tree, hf_cbsp_num_bcast_info, tvb, offset++, 1, ENC_NA,
					     &num_bi);
		proto_item_append_text(ti, ": NumBC=%u (%s)", num_bc,
					val_to_str_const(num_bi, cbsp_num_bcast_shortinfo_vals, ""));
		count++;
	}
	proto_item_append_text(parent_ti, " (%s): %u items",
				val_to_str_const(discr, cbsp_cell_id_disc_vals, ""), count);
}

static int
dissect_cbsp_tlvs(tvbuff_t *tvb, int base_offs, int length, packet_info *pinfo, proto_tree *tree)
{
	uint8_t sms_encoding = SMS_ENCODING_7BIT;
	int offset = base_offs;

	while (offset - base_offs < length) {
		uint8_t tag;		 /* Information Element Identifier */
		unsigned int len;	 /* Length of payload */
		unsigned int len_len = 0;/* Length of "length" field (may be 0) */
		proto_item *ti;
		proto_tree *att_tree, *subtree;
		uint32_t tmp_u;
		int secs;

		tag = tvb_get_uint8(tvb, offset);
		offset++;

		switch (cbsp_att_tlvdef.def[tag].type) {
		case TLV_TYPE_TV:
			len = 1;
			len_len = 0;
			break;
		case TLV_TYPE_FIXED:
			len = cbsp_att_tlvdef.def[tag].fixed_len;
			len_len = 0;
			break;
		case TLV_TYPE_TLV:
			len = tvb_get_uint8(tvb, offset);
			break;
		case TLV_TYPE_TL16V:
			len = tvb_get_uint16(tvb, offset, ENC_BIG_ENDIAN);
			len_len = 2;
			break;
		default:
			return length;
		}

		att_tree = proto_tree_add_subtree_format(tree, tvb, offset-1, 1+len_len+len,
						ett_cbsp_ie, &ti, "IE: %s",
						val_to_str(tag, cbsp_iei_names, "Unknown 0x%02x"));
		proto_tree_add_item(att_tree, hf_cbsp_iei, tvb, offset-1, 1, ENC_NA);
		if (len_len)
			proto_tree_add_uint(att_tree, hf_cbsp_ie_len, tvb, offset, len_len, len);

		offset += len_len;

		switch (tag) {
		case CBSP_IEI_MSG_CONTENT:
			dissect_cbsp_content_ie(tvb, pinfo, offset, len, att_tree, sms_encoding, ti);
			break;
		case CBSP_IEI_OLD_SERIAL_NR:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_old_serial_nr, tvb, offset, len, ENC_BIG_ENDIAN, &tmp_u);
			proto_item_append_text(ti, ": 0x%04x", tmp_u);
			break;
		case CBSP_IEI_NEW_SERIAL_NR:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_new_serial_nr, tvb, offset, len, ENC_BIG_ENDIAN, &tmp_u);
			proto_item_append_text(ti, ": 0x%04x", tmp_u);
			break;
		case CBSP_IEI_CATEGORY:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_category, tvb, offset, len, ENC_NA,&tmp_u);
			proto_item_append_text(ti, ": %s", val_to_str_const(tmp_u, cbsp_category_names, ""));
			break;
		case CBSP_IEI_REP_PERIOD:
			{
				uint64_t tmp_u64;
				crumb_spec_t cbsp_rep_period_crumbs[] = {
					{  0, 8 },
					{ 12, 4 },
					{  0, 0 }
				};

				proto_tree_add_split_bits_item_ret_val(att_tree, hf_cbsp_rep_period, tvb, offset<<3, cbsp_rep_period_crumbs, &tmp_u64);
				proto_item_append_text(ti, ": %u", (uint16_t)tmp_u64);
			}
			break;
		case CBSP_IEI_NUM_BCAST_REQ:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_num_bcast_req, tvb, offset, len, ENC_BIG_ENDIAN, &tmp_u);
			proto_item_append_text(ti, ": %u", tmp_u);
			break;
		case CBSP_IEI_CAUSE:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_cause, tvb, offset, len, ENC_NA, &tmp_u);
			proto_item_append_text(ti, ": %s", val_to_str_const(tmp_u, cbsp_cause_vals, ""));
			break;
		case CBSP_IEI_DCS:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_dcs, tvb, offset, len, ENC_NA, &tmp_u);
			subtree = proto_item_add_subtree(att_tree, ett_cbsp_cbs_data_coding);
			sms_encoding = dissect_cbs_data_coding_scheme(tvb, pinfo, subtree, offset);
			proto_item_append_text(ti, ": 0x%02x", tmp_u);
			break;
		case CBSP_IEI_RECOVERY_IND:
			proto_tree_add_item(att_tree, hf_cbsp_recovery_ind, tvb, offset, len, ENC_NA);
			break;
		case CBSP_IEI_MSG_ID:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_msg_id, tvb, offset, len, ENC_BIG_ENDIAN, &tmp_u);
			proto_item_append_text(ti, ": 0x%04x", tmp_u);
			break;
		case CBSP_IEI_EMERG_IND:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_emerg_ind, tvb, offset, len, ENC_NA, &tmp_u);
			proto_item_append_text(ti, ": %s", val_to_str_const(tmp_u, cbsp_emerg_ind_vals, ""));
			break;
		case CBSP_IEI_WARN_TYPE:
			proto_tree_add_item(att_tree, hf_cbsp_warn_type, tvb, offset, len, ENC_NA);
			break;
		case CBSP_IEI_CHANNEL_IND:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_channel_ind, tvb, offset, len, ENC_NA, &tmp_u);
			proto_item_append_text(ti, ": %s", val_to_str_const(tmp_u, cbsp_chan_ind_vals, ""));
			break;
		case CBSP_IEI_NUM_OF_PAGES:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_num_of_pages, tvb, offset, len, ENC_NA, &tmp_u);
			proto_item_append_text(ti, ": %u", tmp_u);
			break;
		case CBSP_IEI_SCHEDULE_PERIOD:
			proto_tree_add_item(att_tree, hf_cbsp_sched_period, tvb, offset, len, ENC_NA);
			break;
		case CBSP_IEI_NUM_OF_RES_SLOTS:
			proto_tree_add_item(att_tree, hf_cbsp_num_of_res_slots, tvb, offset, len, ENC_NA);
			break;
		case CBSP_IEI_BCAST_MSG_TYPE:
			proto_tree_add_item_ret_uint(att_tree, hf_cbsp_bcast_msg_type, tvb, offset, len, ENC_NA, &tmp_u);
			proto_item_append_text(ti, ": %s", val_to_str_const(tmp_u, cbsp_bcast_msg_type_vals, ""));
			break;
		case CBSP_IEI_WARNING_PERIOD:
			secs = cbsp_warn_period_to_secs(tvb_get_uint8(tvb, offset));
			proto_tree_add_uint(att_tree, hf_cbsp_warning_period, tvb, offset, len, secs);
			proto_item_append_text(ti, ": %u (s)", secs);
			break;
		case CBSP_IEI_KEEP_ALIVE_REP_PERIOD:
			secs = cbsp_warn_period_to_secs(tvb_get_uint8(tvb, offset));
			proto_tree_add_uint(att_tree, hf_cbsp_keepalive_period, tvb, offset, len, secs);
			proto_item_append_text(ti, ": %u (s)", secs);
			break;
		case CBSP_IEI_CELL_LIST:
			dissect_cell_id_list_ie(tvb, pinfo, offset, len, att_tree, ti);
			break;
		case CBSP_IEI_NUM_BCAST_COMPL_LIST:
			dissect_bc_compl_list_ie(tvb, pinfo, offset, len, att_tree, ti);
			break;
		case CBSP_IEI_FAILURE_LIST:
			dissect_failure_list_ie(tvb, pinfo, offset, len, att_tree, ti);
			break;
		case CBSP_IEI_RR_LOADING_LIST:
			dissect_rr_load_list_ie(tvb, pinfo, offset, len, att_tree, ti);
			break;
		case CBSP_IEI_WARN_SEC_INFO:
			/* this element is bogus / not used anyway, no need for a dissector */
		default:
			/* Unknown/unsupported IE: Print raw payload in addition to IEI + Length printed above */
			proto_tree_add_item(att_tree, hf_cbsp_ie_payload, tvb, offset, len, ENC_NA);
			break;
		}

		offset += len;
	}

	return offset;
}

static int
dissect_cbsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
	int len_ind, offset = 0;
	proto_item *ti;
	proto_tree *cbsp_tree = NULL;
	uint8_t msg_type;
	const char *str;


	//len = tvb_reported_length(tvb);
	msg_type = tvb_get_uint8(tvb, offset + 0);
	len_ind = tvb_get_uint24(tvb, offset + 1, ENC_BIG_ENDIAN);

	col_set_str(pinfo->cinfo, COL_PROTOCOL, "CBSP");

	col_clear(pinfo->cinfo, COL_INFO);
	str = val_to_str(msg_type, cbsp_msg_type_names, "Unknown CBSP Message Type 0x%02x");
	col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", str);

	if (tree) {
		ti = proto_tree_add_protocol_format(tree, proto_cbsp, tvb, 0, len_ind+4, "CBSP %s", str);
		cbsp_tree = proto_item_add_subtree(ti, ett_cbsp);

		proto_tree_add_item(cbsp_tree, hf_cbsp_msg_type,
				    tvb, offset, 1, ENC_BIG_ENDIAN);
		offset++;

		proto_tree_add_item(cbsp_tree, hf_cbsp_msg_len, tvb, offset, 3, ENC_BIG_ENDIAN);
		offset += 3;

		dissect_cbsp_tlvs(tvb, offset, tvb_reported_length_remaining(tvb, offset), pinfo,
				  cbsp_tree);
	}

	return tvb_captured_length(tvb);
}

void
proto_register_cbsp(void)
{
	static hf_register_info hf[] = {
		{ &hf_cbsp_msg_type, { "Message Type", "cbsp.msg_type",
		  FT_UINT8, BASE_DEC, VALS(cbsp_msg_type_names), 0, NULL, HFILL } },
		{ &hf_cbsp_msg_len, { "Message Length", "cbsp.msg_len",
		  FT_UINT24, BASE_DEC, NULL, 0, NULL, HFILL } },

		{ &hf_cbsp_iei, { "Information Element Identifier", "cbsp.ie.iei",
		  FT_UINT8, BASE_DEC, VALS(cbsp_iei_names), 0, NULL, HFILL } },
		{ &hf_cbsp_ie_len, { "Information Element Length", "cbsp.ie.len",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_ie_payload, { "Information Element Payload", "cbsp.ie.payload",
		  FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL } },

		{ &hf_cbsp_old_serial_nr, { "Old Serial Number", "cbsp.old_serial_nr",
		  FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_new_serial_nr, { "New Serial Number", "cbsp.new_serial_nr",
		  FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_category, { "Category", "cbsp.category",
		  FT_UINT8, BASE_HEX, VALS(cbsp_category_names), 0, NULL, HFILL } },
		{ &hf_cbsp_rep_period, { "Repetition Period (units of 1.883s)", "cbsp.rep_period",
		  FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_num_bcast_req, { "Number of Broadcasts Requested", "cbsp.num_bcast_req",
		  FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_cause, { "Cause", "cbsp.cause",
		  FT_UINT8, BASE_HEX, VALS(cbsp_cause_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_dcs, { "Data Coding Scheme", "cbsp.dcs",
		  FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_recovery_ind, { "Recovery Indication", "cbsp.recovery_ind",
		  FT_UINT8, BASE_HEX, VALS(cbsp_recov_ind_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_msg_id, { "Message Identifier", "cbsp.message_id",
		  FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_emerg_ind, { "Emergency Indicator", "cbsp.emergency_ind",
		  FT_UINT8, BASE_HEX, VALS(cbsp_emerg_ind_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_warn_type, { "Warning Type", "cbsp.warn_type",
		  FT_UINT8, BASE_HEX, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_channel_ind, { "Channel Indicator", "cbsp.channel_ind",
		  FT_UINT8, BASE_HEX, VALS(cbsp_chan_ind_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_num_of_pages, { "Number of Pages", "cbsp.num_of_pages",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_cb_msg_page, { "CBS Message Information Page", "cbsp.cb_msg_page",
		  FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_cbs_page_content, { "CBS Page Content", "cbsp.cb_page_content",
		  FT_STRING, BASE_NONE, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_sched_period, { "Schedule Period", "cbsp.sched_period",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_num_of_res_slots, { "Number of Reserved Slots", "cbsp.num_of_res_slots",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_bcast_msg_type, { "Broadcast Message Type", "cbsp.bcast_msg_type",
		  FT_UINT8, BASE_DEC, VALS(cbsp_bcast_msg_type_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_warning_period, { "Warning Period", "cbsp.warning_period",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_keepalive_period, { "Keepalive Repetition Period", "cbsp.keepalive_rep_period",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_user_info_length, { "User Information Length", "cbsp.user_info_len",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_cell_id_disc, { "Cell ID Discriminator", "cbsp.cell_id_disc",
		  FT_UINT8, BASE_DEC, VALS(cbsp_cell_id_disc_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_cell_load1, { "Radio Resource Load 1", "cbsp.rr_load1",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_cell_load2, { "Radio Resource Load 2", "cbsp.rr_load2",
		  FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_num_bcast_compl, { "Number of Broadcasts Completed", "cbsp.num_bcast_compl",
		  FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_num_bcast_info, { "Number of Broadcasts Info", "cbsp.num_bcast_info",
		  FT_UINT8, BASE_HEX, VALS(cbsp_num_bcast_info_vals), 0, NULL, HFILL } },
		{ &hf_cbsp_lac, { "Location Area Code (LAC)", "cbsp.lac",
		  FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL } },
		{ &hf_cbsp_ci, { "Cell Identifier (CI)", "cbsp.ci",
		  FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL } },
	};
	static int *ett[] = {
		&ett_cbsp,
		&ett_cbsp_ie,
		&ett_cbsp_cbs_data_coding,
		&ett_cbsp_cbs_page_content,
		&ett_cbsp_cell_list,
		&ett_cbsp_fail_list,
		&ett_cbsp_load_list,
		&ett_cbsp_num_bcast_compl_list,
	};

	proto_cbsp = proto_register_protocol("3GPP/GSM Cell Broadcast Service Protocol", "cbsp", "cbsp");
	cbsp_handle = register_dissector("cbsp", dissect_cbsp, proto_cbsp);
	proto_register_field_array(proto_cbsp, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_cbsp(void)
{
	dissector_add_uint_with_preference("tcp.port", CBSP_TCP_PORT, cbsp_handle);
}

/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 8
 * tab-width: 8
 * indent-tabs-mode: t
 * End:
 *
 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
 * :indentSize=8:tabSize=8:noTabs=false:
 */