summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-gmr1_rr.c
blob: 2e2c9b32f11fc45d0524f503b718002e5398229d (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
/* packet-gmr1_rr.c
 *
 * Routines for GMR-1 Radio Resource dissection in wireshark.
 * Copyright (c) 2011 Sylvain Munaut <tnt@246tNt.com>
 *
 * References:
 *  [1] ETSI TS 101 376-4-8 V1.3.1 - GMR-1 04.008
 *  [2] ETSI TS 101 376-4-8 V2.2.1 - GMPRS-1 04.008
 *  [3] ETSI TS 101 376-4-8 V3.1.1 - GMR-1 3G 44.008
 *  [4] ETSI TS 100 940 V7.21.0 - GSM 04.08
 *  [5] ETSI TS 101 376-4-12 V3.2.1 - GMR-1 3G 44.060
 *  [6] ETSI TS 101 376-5-6 V1.3.1 - GMR-1 05.008
 *
 * 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/expert.h>

#include "packet-gmr1_common.h"

#include "packet-gmr1_rr.h"

void proto_register_gmr1_rr(void);

/* GMR-1 RR and CCCH proto */
static int proto_gmr1_rr = -1;
static int proto_gmr1_ccch = -1;

/* Fallback CCCH sub tree */
static gint ett_msg_ccch = -1;

static gint ett_rr_pd = -1;

static expert_field ei_gmr1_missing_mandatory_element = EI_INIT;


/* ------------------------------------------------------------------------ */
/* RR Information Elements                                                  */
/* ------------------------------------------------------------------------ */

enum gmr1_ie_rr_idx {
	GMR1_IE_RR_CHAN_DESC = 0,		/* [1] 11.5.2.5   */
	GMR1_IE_RR_CHAN_MODE,			/* [1] 11.5.2.6   */
	GMR1_IE_RR_CIPH_MODE_SETTING,		/* [4] 10.5.2.9   */
	GMR1_IE_RR_CIPH_RESP,			/* [4] 10.5.2.10  */
	GMR1_IE_RR_L2_PSEUDO_LEN,		/* [1] 11.5.2.19  */
	GMR1_IE_RR_PAGE_MODE,			/* [1] 11.5.2.26  */
	GMR1_IE_RR_REQ_REF,			/* [1] 11.5.2.30  */
	GMR1_IE_RR_CAUSE,			/* [1] 11.5.2.31  */
	GMR1_IE_RR_TIMING_OFS,			/* [1] 11.5.2.40  */
	GMR1_IE_RR_TMSI_PTMSI,			/* [4] 10.5.2.42  */
	GMR1_IE_RR_WAIT_IND,			/* [4] 10.5.2.43  */
	GMR1_IE_RR_MES_INFO_FLG,		/* [1] 11.5.2.44  */
	GMR1_IE_RR_FREQ_OFS,			/* [1] 11.5.2.49  */
	GMR1_IE_RR_PAGE_INFO,			/* [1] 11.5.2.51  */
	GMR1_IE_RR_POS_DISPLAY,			/* [1] 11.5.2.52  */
	GMR1_IE_RR_POS_UPD_INFO,		/* [1] 11.5.2.54  */
	GMR1_IE_RR_BCCH_CARRIER,		/* [1] 11.5.2.55  */
	GMR1_IE_RR_REJECT_CAUSE,		/* [1] 11.5.2.56  */
	GMR1_IE_RR_GPS_TIMESTAMP,		/* [1] 11.5.2.57  */
	GMR1_IE_RR_PWR_CTRL_PRM,		/* [1] 11.5.2.60  */
	GMR1_IE_RR_TMSI_AVAIL_MSK,		/* [1] 11.5.2.62  */
	GMR1_IE_RR_GPS_ALMANAC,			/* [1] 11.5.2.63  */
	GMR1_IE_RR_MSC_ID,			/* [1] 11.5.2.100 */
	GMR1_IE_RR_GPS_DISCR,			/* [1] 11.5.2.101 */
	GMR1_IE_RR_PKT_IMM_ASS_3_PRM,		/* [3] 11.5.2.105 */
	GMR1_IE_RR_PKT_FREQ_PRM,		/* [3] 11.5.2.106 */
	GMR1_IE_RR_PKT_IMM_ASS_2_PRM,		/* [3] 11.5.2.107 */
	GMR1_IE_RR_USF,				/* [3] 11.5.2.110 */
	GMR1_IE_RR_TIMING_ADV_IDX,		/* [3] 10.1.18.3.4 */
	GMR1_IE_RR_TLLI,			/* [5] 12.16      */
	GMR1_IE_RR_PKT_PWR_CTRL_PRM,		/* [3] 10.1.18.3.3 */
	GMR1_IE_RR_PERSISTENCE_LVL,		/* [3] 10.1.18.4.2 */
	NUM_GMR1_IE_RR	/* Terminator */
};

static const value_string gmr1_ie_rr_strings[] = {
	{ GMR1_IE_RR_CHAN_DESC,
	  "Channel Description" },		/* [1] 11.5.2.5   */
	{ GMR1_IE_RR_CHAN_MODE,
	  "Channel Mode" },			/* [1] 11.5.2.6   */
	{ GMR1_IE_RR_CIPH_MODE_SETTING,
	  "Cipher Mode Setting" },		/* [4] 10.5.2.9   */
	{ GMR1_IE_RR_CIPH_RESP,
	  "Cipher Response" },			/* [4] 10.5.2.10  */
	{ GMR1_IE_RR_L2_PSEUDO_LEN,
	  "L2 Pseudo Length" },			/* [1] 11.5.2.19  */
	{ GMR1_IE_RR_PAGE_MODE,
	  "Page Mode" },			/* [1] 11.5.2.26  */
	{ GMR1_IE_RR_REQ_REF,
	  "Request Reference" },		/* [1] 11.5.2.30  */
	{ GMR1_IE_RR_CAUSE,
	  "RR Cause" },				/* [1] 11.5.2.31  */
	{ GMR1_IE_RR_TIMING_OFS,
	  "Timing Offset" },			/* [1] 11.5.2.40  */
	{ GMR1_IE_RR_TMSI_PTMSI,
	  "TMSI/P-TMSI" },			/* [4] 10.5.2.42  */
	{ GMR1_IE_RR_WAIT_IND,
	  "Wait Indication" },			/* [4] 10.5.2.43  */
	{ GMR1_IE_RR_MES_INFO_FLG,
	  "MES Information Flag" },		/* [1] 11.5.2.44  */
	{ GMR1_IE_RR_FREQ_OFS,
	  "Frequency Offset" },			/* [1] 11.5.2.49  */
	{ GMR1_IE_RR_PAGE_INFO,
	  "Paging Information" },		/* [1] 11.5.2.51  */
	{ GMR1_IE_RR_POS_DISPLAY,
	  "Position Display" },			/* [1] 11.5.2.52  */
	{ GMR1_IE_RR_POS_UPD_INFO,
	  "Position Update Information" },	/* [1] 11.5.2.54  */
	{ GMR1_IE_RR_BCCH_CARRIER,
	  "BCCH Carrier Specification"},	/* [1] 11.5.2.55  */
	{ GMR1_IE_RR_REJECT_CAUSE,
	  "Reject Cause" },			/* [1] 11.5.2.56  */
	{ GMR1_IE_RR_GPS_TIMESTAMP,
	  "GPS timestamp" },			/* [1] 11.5.2.57  */
	{ GMR1_IE_RR_PWR_CTRL_PRM,
	  "Power Control Params" },		/* [1] 11.5.2.60  */
	{ GMR1_IE_RR_TMSI_AVAIL_MSK,
	  "TMSI Availability Mask" },		/* [1] 11.5.2.62  */
	{ GMR1_IE_RR_GPS_ALMANAC,
	  "GPS Almanac Data" },			/* [1] 11.5.2.63  */
	{ GMR1_IE_RR_MSC_ID,
	  "MSC ID" },				/* [1] 11.5.2.100 */
	{ GMR1_IE_RR_GPS_DISCR,
	  "GPS Discriminator" },		/* [1] 11.5.2.101 */
	{ GMR1_IE_RR_PKT_IMM_ASS_3_PRM,
	  "Packet Imm. Ass. Type 3 Params" },	/* [3] 11.5.2.105 */
	{ GMR1_IE_RR_PKT_FREQ_PRM,
	  "Packet Frequency Parameters" },	/* [3] 11.5.2.106 */
	{ GMR1_IE_RR_PKT_IMM_ASS_2_PRM,
	  "Packet Imm. Ass. Type 2 Params" },	/* [3] 11.5.2.107 */
	{ GMR1_IE_RR_USF,
	  "USF" },				/* [3] 11.5.2.110 */
	{ GMR1_IE_RR_TIMING_ADV_IDX,
	  "Timing Advance Index" },		/* [3] 10.1.18.3.4 */
	{ GMR1_IE_RR_TLLI,
	  "TLLI" },				/* [5] 12.16      */
	{ GMR1_IE_RR_PKT_PWR_CTRL_PRM,
	  "Packet Power Control Params" },	/* [3] 10.1.18.3.3 */
	{ GMR1_IE_RR_PERSISTENCE_LVL,
	  "Persistence Level" },		/* [3] 10.1.18.4.2 */
	{ 0, NULL },
};
value_string_ext gmr1_ie_rr_strings_ext = VALUE_STRING_EXT_INIT(gmr1_ie_rr_strings);

gint ett_gmr1_ie_rr[NUM_GMR1_IE_RR];


/* Fields */
static int hf_rr_msg_type = -1;
static int hf_rr_chan_desc_kab_loc = -1;
static int hf_rr_chan_desc_rx_tn = -1;
static int hf_rr_chan_desc_arfcn = -1;
static int hf_rr_chan_desc_tx_tn = -1;
static int hf_rr_chan_desc_chan_type = -1;
static int hf_rr_chan_mode = -1;
static int hf_rr_ciph_mode_setting_sc = -1;
static int hf_rr_ciph_mode_setting_algo = -1;
static int hf_rr_ciph_resp_cr = -1;
static int hf_rr_ciph_resp_spare = -1;
static int hf_rr_l2_pseudo_len = -1;
static int hf_rr_page_mode = -1;
static int hf_rr_page_mode_spare = -1;
static int hf_rr_req_ref_est_cause = -1;
static int hf_rr_req_ref_ra = -1;
static int hf_rr_req_ref_fn = -1;
static int hf_rr_cause = -1;
static int hf_rr_timing_ofs_ti = -1;
static int hf_rr_timing_ofs_value = -1;
static int hf_rr_tmsi_ptmsi = -1;
static int hf_rr_wait_ind_timeout = -1;
static int hf_rr_mif_mes1_ab = -1;
static int hf_rr_mif_mes1_i = -1;
static int hf_rr_mif_mes1_d = -1;
static int hf_rr_mif_mes2 = -1;
static int hf_rr_mif_mes3 = -1;
static int hf_rr_mif_mes4 = -1;
static int hf_rr_mif_pv = -1;
static int hf_rr_freq_ofs_fi = -1;
static int hf_rr_freq_ofs_value = -1;
static int hf_rr_freq_ofs_spare = -1;
static int hf_rr_page_info_msc_id = -1;
static int hf_rr_page_info_chan_needed = -1;
static int hf_rr_pos_display_flag = -1;
static int hf_rr_pos_display_text = -1;
static int hf_rr_pos_upd_info_v = -1;
static int hf_rr_pos_upd_info_dist = -1;
static int hf_rr_pos_upd_info_time = -1;
static int hf_rr_bcch_carrier_arfcn = -1;
static int hf_rr_bcch_carrier_si = -1;
static int hf_rr_bcch_carrier_ri = -1;
static int hf_rr_bcch_carrier_spare = -1;
static int hf_rr_reject_cause = -1;
static int hf_rr_reject_cause_b = -1;
static int hf_rr_gps_timestamp = -1;
static int hf_rr_gps_power_control_params = -1;
static int hf_rr_tmsi_avail_msk_tmsi[4] = { -1, -1, -1, -1 };
static int hf_rr_gps_almanac_pn = -1;
static int hf_rr_gps_almanac_wn = -1;
static int hf_rr_gps_almanac_word = -1;
static int hf_rr_gps_almanac_sfn = -1;
static int hf_rr_gps_almanac_co = -1;
static int hf_rr_gps_almanac_spare = -1;
static int hf_rr_msc_id = -1;
static int hf_rr_msc_id_spare = -1;
static int hf_rr_gps_discr = -1;
static int hf_rr_pkt_imm_ass_3_prm_rlc_mode = -1;
static int hf_rr_pkt_imm_ass_3_prm_spare = -1;
static int hf_rr_pkt_imm_ass_3_prm_dl_tfi = -1;
static int hf_rr_pkt_imm_ass_3_prm_start_fn = -1;
static int hf_rr_pkt_imm_ass_3_prm_mac_slot_alloc = -1;
static int hf_rr_pkt_freq_prm_arfcn = -1;
static int hf_rr_pkt_freq_prm_dl_freq_plan_id = -1;
static int hf_rr_pkt_freq_prm_dl_bw = -1;
static int hf_rr_pkt_freq_prm_ul_freq_dist = -1;
static int hf_rr_pkt_freq_prm_ul_bw = -1;
static int hf_rr_pkt_freq_prm_spare = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_spare1 = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_final_alloc = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_usf_granularity = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_dl_ctl_mac_slot = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_mac_mode = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_start_fn = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_rlc_dblk_gnt = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_mcs = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_tfi = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_spare2 = -1;
static int hf_rr_pkt_imm_ass_2_prm_ac_mac_slot_alloc = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_chan_mcs_cmd = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_chan_mcs_cmd_pnb512 = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_spare1 = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_rlc_dblk_gnt = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_spare2 = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_tfi = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_usf_granularity = -1;
static int hf_rr_pkt_imm_ass_2_prm_d_mac_slot_alloc = -1;
static int hf_rr_usf_value = -1;
static int hf_rr_usf_spare = -1;
static int hf_rr_timing_adv_idx_value = -1;
static int hf_rr_timing_adv_idx_spare = -1;
static int hf_rr_tlli = -1;
static int hf_rr_pkt_pwr_ctrl_prm_par = -1;
static int hf_rr_pkt_pwr_ctrl_prm_spare = -1;
static int hf_rr_persistence_lvl[4] = { -1, -1, -1, -1 };
static int hf_rr_protocol_discriminator = -1;
static int hf_rr_message_elements = -1;

/* Generic display vals/func */
static const value_string rr_gen_ie_presence_vals[] = {
	{ 0, "IE is absent" },
	{ 1, "IE is present" },
	{ 0, NULL }
};

static void
rr_gen_ie_seconds_fmt(gchar *s, guint32 v)
{
	snprintf(s, ITEM_LABEL_LENGTH, "%u seconds", v);
}



/* [1] 11.5.2.5 - Channel Description */
static const value_string rr_chan_desc_chan_type_vals[] = {
	{  1, "TCH3 No offset" },
	{  3, "TCH3 1/2 symbol offset" },
	{  6, "TCH6 No offset" },
	{  7, "TCH6 1/2 symbol offset" },
	{  4, "TCH9 No offset" },
	{  5, "TCH9 1/2 symbol offset" },
	{ 13, "Reserved for SDCCH frames xx00" },
	{ 14, "Reserved for SDCCH frames xx01" },
	{ 15, "Reserved for SDCCH frames xx10" },
	{ 16, "Reserved for SDCCH frames xx11" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_chan_desc)
{
	gint bit_offset;

	bit_offset = offset << 3;

	/* KAB Location (6 bits)*/
	proto_tree_add_bits_item(tree, hf_rr_chan_desc_kab_loc, tvb,
	                         bit_offset, 6, ENC_BIG_ENDIAN);
	bit_offset += 6;

	/* RX Timeslot (5 bits) */
	proto_tree_add_bits_item(tree, hf_rr_chan_desc_rx_tn, tvb,
	                         bit_offset, 5, ENC_BIG_ENDIAN);
	bit_offset += 5;

	/* ARFCN (11 bits) */
	proto_tree_add_bits_item(tree, hf_rr_chan_desc_arfcn, tvb,
	                         bit_offset, 11, ENC_BIG_ENDIAN);
	bit_offset += 11;

	/* TX Timeslot (5 bits) */
	proto_tree_add_bits_item(tree, hf_rr_chan_desc_tx_tn, tvb,
	                         bit_offset, 5, ENC_BIG_ENDIAN);
	bit_offset += 5;

	/* Channel Type (5 bits) */
	proto_tree_add_bits_item(tree, hf_rr_chan_desc_chan_type, tvb,
	                         bit_offset, 5, ENC_BIG_ENDIAN);
	/*bit_offset += 5;*/

	return 4;
}

/* [1] 11.5.2.6 - Channel Mode */
static const value_string rr_chan_mode_vals[] = {
	{ 0x00, "Signalling only" },
	{ 0x01, "Speech" },
	{ 0x03, "Data, 12,0 kbit/s radio I/F rate" },
	{ 0x0b, "Data, 6,0 kbit/s radio I/F rate" },
	{ 0x13, "Data, 3,6 kbit/s radio I/F rate" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_chan_mode)
{
	/* Channel Mode */
	proto_tree_add_item(tree, hf_rr_chan_mode, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [4] 10.5.2.9 - Cipher Mode Setting */
static const value_string rr_ciph_mode_setting_sc_vals[] = {
	{ 0, "No ciphering"},
	{ 1, "Start ciphering"},
	{ 0, NULL }
};

static const value_string rr_ciph_mode_setting_algo_vals[] = {
	{ 0, "A5/1" },
	{ 1, "A5/2" },
	{ 2, "A5/3" },
	{ 3, "A5/4" },
	{ 4, "A5/5" },
	{ 5, "A5/6" },
	{ 6, "A5/7" },
	{ 7, "Reserved" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_ciph_mode_setting)
{
	/* SC */
	proto_tree_add_item(tree, hf_rr_ciph_mode_setting_sc, tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Algo */
	proto_tree_add_item(tree, hf_rr_ciph_mode_setting_algo, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [4] 10.5.2.10 - Cipher Response */
static const value_string rr_ciph_resp_cr_vals[] = {
	{ 0, "IMEISV shall not be included"},
	{ 1, "IMEISV shall be included"},
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_ciph_resp)
{
	/* CR */
	proto_tree_add_item(tree, hf_rr_ciph_resp_cr, tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(tree, hf_rr_ciph_resp_spare, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.19 - L2 Pseudo Length */
GMR1_IE_FUNC(gmr1_ie_rr_l2_pseudo_len)
{
	/* L2 Pseudo Length value */
	proto_tree_add_item(tree, hf_rr_l2_pseudo_len, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.26 - Page Mode */
static const value_string rr_page_mode_vals[] = {
	{ 0, "Normal Paging" },
	{ 1, "Reserved (Changed from Extended Paging in GSM)" },
	{ 2, "Paging Reorganization" },
	{ 3, "Same as before" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_page_mode)
{
	/* Page mode */
	proto_tree_add_item(tree, hf_rr_page_mode, tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(tree, hf_rr_page_mode_spare, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.30 - Request Reference */
static const value_string rr_req_ref_est_cause_vals[] = {
	{ 0, "MO call" },
	{ 1, "In response to paging/alerting" },
	{ 2, "Location update/IMSI detach" },
	{ 3, "Emergency call" },
	{ 4, "Supplementary/short message service" },
	{ 5, "Position verification" },
	{ 6, "Any other valid cause" },
	{ 7, "Reserved" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_req_ref)
{
	/* Establishement Cause + RA */
	proto_tree_add_item(tree, hf_rr_req_ref_est_cause, tvb, offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_rr_req_ref_ra, tvb, offset, 1, ENC_BIG_ENDIAN);
	offset++;

	/* Frame number % 256 */
	proto_tree_add_item(tree, hf_rr_req_ref_fn, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 2;
}

/* [1] 11.5.2.31 - RR Cause */
static const value_string rr_cause_vals[] = {
	{ 0x00, "Normal event" },
	{ 0x01, "Abnormal release, unspecified" },
	{ 0x02, "Abnormal release, channel unacceptable" },
	{ 0x03, "Abnormal release, timer expired" },
	{ 0x04, "Abnormal release, no activity on the radio path" },
	{ 0x05, "Preemptive release" },
	{ 0x09, "Channel mode unacceptable" },
	{ 0x0a, "Frequency not implemented" },
	{ 0x0b, "Position unacceptable" },
	{ 0x41, "Call already cleared" },
	{ 0x5f, "Semantically incorrect message" },
	{ 0x60, "Invalid mandatory information" },
	{ 0x61, "Message type nonexistent or not implemented" },
	{ 0x62, "Message type not compatible with protocol state" },
	{ 0x6f, "Protocol error unspecified" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_cause)
{
	/* RR Cause */
	proto_tree_add_item(tree, hf_rr_cause, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.40 - Timing Offset */
static const value_string rr_timing_ofs_ti_vals[] = {
	{ 0, "The timing offset parameter in this IE to be ignored" },
	{ 1, "The timing offset parameter has a valid value" },
	{ 0, NULL }
};

static void
rr_timing_ofs_value_fmt(gchar *s, guint32 v)
{
	gint32 sv = (signed)v;

	snprintf(s, ITEM_LABEL_LENGTH, "%.3f symbols ( ~ %.3f ms )",
		sv / 40.0f, (sv / 40.0f) * (10.0f / 234.0f));
}

GMR1_IE_FUNC(gmr1_ie_rr_timing_ofs)
{
	gint bit_offset;

	bit_offset = offset << 3;

	/* TI */
	proto_tree_add_bits_item(tree, hf_rr_timing_ofs_ti, tvb,
	                         bit_offset, 1, ENC_BIG_ENDIAN);
	bit_offset++;

	/* Value */
	proto_tree_add_bits_item(tree, hf_rr_timing_ofs_value, tvb,
	                         bit_offset, 15, ENC_BIG_ENDIAN);
	/*bit_offset += 15;*/

	return 2;
}

/* [4] 10.5.2.42 - TMSI/P-TMSI */
GMR1_IE_FUNC(gmr1_ie_rr_tmsi_ptmsi)
{
	/* TMSI/P-TMSI value as hex */
	proto_tree_add_item(tree, hf_rr_tmsi_ptmsi, tvb, offset, 4, ENC_BIG_ENDIAN);

	return 4;
}

/* [4] 10.5.2.43 - Wait Indication */
GMR1_IE_FUNC(gmr1_ie_rr_wait_ind)
{
	/* Timeout value */
	proto_tree_add_item(tree, hf_rr_wait_ind_timeout, tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.44 - MES Information Flag */
static const value_string rr_mif_mes1_ab_vals[] = {
	{ 0, "Chan. Assigned: MES1 registered at selected GS" },
	{ 1, "Chan. Assigned: MES1 requires registration at selected GS" },
	{ 2, "Chan. Assigned; MES 1 Extended Channel Req. Reqd" },
	{ 3, "Pause Timer Indication" },
	{ 0, NULL }
};

static const value_string rr_mif_mes234_vals[] = {
	{ 0, "MES doesn't exists" },
	{ 1, "Pause Timer Ind for this MES" },
	{ 0, NULL }
};

static const value_string rr_mif_pv_vals[] = {
	{ 0, "Position Verification not requested" },
	{ 1, "MES1 shall send a Channel Request for Position Verification following the completion of the upcoming call" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_mes_info_flg)
{
	proto_tree_add_item(tree, hf_rr_mif_mes1_ab,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	proto_tree_add_item(tree, hf_rr_mif_mes1_i,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	proto_tree_add_item(tree, hf_rr_mif_mes1_d,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	proto_tree_add_item(tree, hf_rr_mif_mes2,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	proto_tree_add_item(tree, hf_rr_mif_mes3,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	proto_tree_add_item(tree, hf_rr_mif_mes4,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	proto_tree_add_item(tree, hf_rr_mif_pv,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.49 - Frequency Offset */
static const value_string rr_freq_ofs_fi_vals[] = {
	{ 0, "The frequency offset parameter in this IE to be ignored" },
	{ 1, "The frequency offset parameter has a valid value" },
	{ 0, NULL }
};

static void
rr_freq_ofs_value_fmt(gchar *s, guint32 v)
{
	gint32 sv = (signed)v;

	snprintf(s, ITEM_LABEL_LENGTH, "%d Hz", sv);
}

GMR1_IE_FUNC(gmr1_ie_rr_freq_ofs)
{
	gint bit_offset;

	bit_offset = offset << 3;

	/* FI */
	proto_tree_add_bits_item(tree, hf_rr_freq_ofs_fi, tvb,
	                         bit_offset, 1, ENC_BIG_ENDIAN);
	bit_offset++;

	/* Value */
	proto_tree_add_bits_item(tree, hf_rr_freq_ofs_value, tvb,
	                         bit_offset, 12, ENC_BIG_ENDIAN);
	bit_offset += 12;

	/* Spare */
	proto_tree_add_bits_item(tree, hf_rr_freq_ofs_spare, tvb,
	                         bit_offset, 3, ENC_BIG_ENDIAN);
	/*bit_offset += 3;*/

	return 2;
}

/* [1] 11.5.2.51 - Paging Information */
static const value_string rr_page_info_chan_needed_vals[] = {
	{ 0, "Any" },
	{ 1, "SDCCH" },
	{ 2, "TCH3" },
	{ 3, "PDCCH" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_page_info)
{
	/* MSC ID & Channe needed */
	proto_tree_add_item(tree, hf_rr_page_info_msc_id,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_rr_page_info_chan_needed,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.52 - Position Display */
static const value_string rr_pos_display_flag_vals[] = {
	{ 0, "Position not available" },
	{ 1, "No position display service" },
	{ 2, "Use default 7-bit alphabet (GSM 03.38)" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_pos_display)
{
	const unsigned char *txt_raw;
	gchar *txt_packed, *txt_unpacked;
	tvbuff_t *txt_packed_tvb;
	int i;

	/* Flag */
	proto_tree_add_item(tree, hf_rr_pos_display_flag,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Get text in an aligned tvbuff */
	/* Do not use tvb_new_octet_aligned(), GSM 7bit packing bit parsing
	   goes from LSB to MSB so a trick is applied here for the last byte */
	txt_raw = tvb_get_ptr(tvb, offset, 11);
	txt_packed = (gchar*)wmem_alloc(pinfo->pool, 11);
	for (i=0; i<10; i++)
		txt_packed[i] = (txt_raw[i] << 4) | (txt_raw[i+1] >> 4);
	txt_packed[10] = txt_raw[10];
	txt_packed_tvb = tvb_new_real_data(txt_packed, 11, 11);

	/* Unpack text */
	txt_unpacked = tvb_get_ts_23_038_7bits_string_packed(pinfo->pool, txt_packed_tvb, 0, 12);
	tvb_free(txt_packed_tvb);

	/* Display it */
	proto_tree_add_string(tree, hf_rr_pos_display_text, tvb, offset, 11,
	                      txt_unpacked);

	return 11;
}

/* [1] 11.5.2.54 - Position Update Information */
static const value_string rr_pos_upd_info_v_vals[] = {
	{ 0, "Information in this IE is Invalid and should be ignored" },
	{ 1, "Information in this IE is Valid" },
	{ 0, NULL }
};

static void
rr_pos_upd_info_dist_fmt(gchar *s, guint32 v)
{
	snprintf(s, ITEM_LABEL_LENGTH, "%d km", v);
}

static void
rr_pos_upd_info_time_fmt(gchar *s, guint32 v)
{
	snprintf(s, ITEM_LABEL_LENGTH, "%d minutes", v);
}

GMR1_IE_FUNC(gmr1_ie_rr_pos_upd_info)
{
	gint curr_offset = offset;

	/* Valid & GPS Update Distance */
	proto_tree_add_item(tree, hf_rr_pos_upd_info_v,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_rr_pos_upd_info_dist,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	curr_offset++;

	/* GPS Update Timer */
	proto_tree_add_item(tree, hf_rr_pos_upd_info_time,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	curr_offset++;

	return 2;
}

/* [1] 11.5.2.55 - BCCH Carrier */
static const value_string rr_bcch_carrier_si_vals[] = {
	{ 0, "BCCH carrier is on the same satellite" },
	{ 1, "BCCH carrier is on a different satellite" },
	{ 0, NULL }
};

static const value_string rr_bcch_carrier_ri_vals[] = {
	{ 0, "Spot beam reselection not needed; use the spot beam with given BCCH" },
	{ 1, "Spot beam reselection needed; use the BCCH for spot beam reselection" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_bcch_carrier)
{
	gint bit_offset;

	bit_offset = offset << 3;

	/* ARFCN */
	proto_tree_add_bits_item(tree, hf_rr_bcch_carrier_arfcn,
	                         tvb, bit_offset, 11, ENC_BIG_ENDIAN);
	bit_offset += 11;

	/* Sat ind */
	proto_tree_add_bits_item(tree, hf_rr_bcch_carrier_si,
	                         tvb, bit_offset, 1, ENC_BIG_ENDIAN);
	bit_offset++;

	/* Resel ind */
	proto_tree_add_bits_item(tree, hf_rr_bcch_carrier_ri,
	                         tvb, bit_offset, 1, ENC_BIG_ENDIAN);
	bit_offset++;

	/* Spare */
	proto_tree_add_bits_item(tree, hf_rr_bcch_carrier_spare,
	                         tvb, bit_offset, 3, ENC_BIG_ENDIAN);
	/*bit_offset += 3;*/

	return 2;
}

/* [1] 11.5.2.56 - Reject Cause */
static const value_string rr_reject_cause_vals[] = {
	{ 0x00, "Lack of resources (default)" },
	{ 0x11, "Invalid position for selected LAI" },
	{ 0x12, "Invalid position for selected spot beam" },
	{ 0x13, "Invalid position" },
	{ 0x15, "Position too old" },
	{ 0x16, "Invalid position for service provider" },
	{ 0x17, "Redirect to new satellite" },
	{ 0x3f, "Reported position acceptable" },
	{ 0, NULL }
};

GMR1_IE_FUNC(gmr1_ie_rr_reject_cause)
{
	/* Cause */
	proto_tree_add_item(tree, hf_rr_reject_cause,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* BCCH carrier */
	proto_tree_add_item(tree, hf_rr_reject_cause_b,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.57 - GPS timestamp */
static void
rr_gps_timestamp_fmt(gchar *s, guint32 v)
{
	if (v == 0xffff)
		snprintf(s, ITEM_LABEL_LENGTH, "> 65535 minutes or N/A");
	else
		snprintf(s, ITEM_LABEL_LENGTH, "%d minutes", v);
}

GMR1_IE_FUNC(gmr1_ie_rr_gps_timestamp)
{
	/* GPS timestamp */
	proto_tree_add_item(tree, hf_rr_gps_timestamp,
	                    tvb, offset, 2, ENC_BIG_ENDIAN);

	return 2;
}

/* [1] 11.5.2.60 - Power Control Params */
GMR1_IE_FUNC(gmr1_ie_rr_pwr_ctrl_prm)
{
	/* It's CSN1 encoded and we have no real world sample. Until we do,
	 * we don't pollute the code with a bunch of untested stuff ... */

	proto_tree_add_item(tree, hf_rr_gps_power_control_params, tvb, offset, 5, ENC_NA);

	return 5;
}

/* [1] 11.5.2.62 - Availability Mask */
GMR1_IE_FUNC(gmr1_ie_rr_tmsi_avail_msk)
{
	int i;

	for (i=0; i<4; i++)
		proto_tree_add_item(tree, hf_rr_tmsi_avail_msk_tmsi[i],
				    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.63 - GPS Almanac Data */
static void
rr_gps_almanac_pn_fmt(gchar *s, guint32 v)
{
	snprintf(s, ITEM_LABEL_LENGTH, "%d", v+1);
}

static const value_string rr_gps_almanac_sfn_vals[] = {
	{ 0, "Frame 4" },
	{ 1, "Frame 5" },
	{ 0, NULL }
};


GMR1_IE_FUNC(gmr1_ie_rr_gps_almanac)
{
	gint curr_offset = offset;

	/* Page Number & Word Number */
	proto_tree_add_item(tree, hf_rr_gps_almanac_pn,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_rr_gps_almanac_wn,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	curr_offset++;

	/* Almanac Data */
	proto_tree_add_item(tree, hf_rr_gps_almanac_word,
	                    tvb, curr_offset, 3, ENC_BIG_ENDIAN);
	curr_offset += 3;

	/* SubFrame Number & CO & Spare */
	proto_tree_add_item(tree, hf_rr_gps_almanac_sfn,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_rr_gps_almanac_co,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	proto_tree_add_item(tree, hf_rr_gps_almanac_spare,
	                    tvb, curr_offset, 1, ENC_BIG_ENDIAN);
	curr_offset++;

	return 5;
}

/* [1] 11.5.2.100 - MSC ID */
GMR1_IE_FUNC(gmr1_ie_rr_msc_id)
{
	/* MSC ID */
	proto_tree_add_item(tree, hf_rr_msc_id,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare bits */
	proto_tree_add_item(tree, hf_rr_msc_id_spare,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [1] 11.5.2.101 - GPS Discriminator */
GMR1_IE_FUNC(gmr1_ie_rr_gps_discr)
{
	/* GPS Position CRC value */
	proto_tree_add_item(tree, hf_rr_gps_discr, tvb, offset, 2, ENC_BIG_ENDIAN);

	return 2;
}

/* [3] 11.5.2.105 - Packet Imm. Ass. Type 3 Params */
static const value_string rr_pkt_imm_ass_3_prm_rlc_mode_vals[] = {
	{ 0, "RLC acknowledged mode" },
	{ 1, "RLC unacknowledged mode" },
	{ 0, NULL }
};

static const crumb_spec_t rr_pkt_imm_ass_3_prm_dl_tfi_crumbs[] = {
	{  0, 3 },
	{ 12, 4 },
	{  0, 0 }
};

GMR1_IE_FUNC(gmr1_ie_rr_pkt_imm_ass_3_prm)
{
	/* RLC Mode */
	proto_tree_add_item(tree, hf_rr_pkt_imm_ass_3_prm_rlc_mode,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(tree, hf_rr_pkt_imm_ass_3_prm_spare,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Downlink Tempory Flow Identifier (TFI) */
	proto_tree_add_split_bits_item_ret_val(
		tree, hf_rr_pkt_imm_ass_3_prm_dl_tfi,
		tvb, offset << 3,
		rr_pkt_imm_ass_3_prm_dl_tfi_crumbs,
		NULL);

	/* Starting Frame Number */
	proto_tree_add_item(tree, hf_rr_pkt_imm_ass_3_prm_start_fn,
	                    tvb, offset+1, 1, ENC_BIG_ENDIAN);

	/* MAC Slot allocation */
	proto_tree_add_item(tree, hf_rr_pkt_imm_ass_3_prm_mac_slot_alloc,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	return 3;
}

/* [3] 11.5.2.106 - Packet Frequency Parameters */
static const value_string rr_pkt_freq_prm_dl_freq_plan_id_vals[] = {
	{ 0, "S-Band" },	/* Pretty much a guess ... */
	{ 1, "L-Band" },	/* didn't find exact value in specs */
	{ 0, NULL }
};

static const crumb_spec_t rr_pkt_freq_prm_arfcn_crumbs[] = {
	{  0, 8 },
	{ 13, 3 },
	{  0, 0 }
};

static const crumb_spec_t rr_pkt_freq_prm_ul_freq_dist_crumbs[] = {
	{  0, 1 },
	{ 12, 4 },
	{  0, 0 }
};

static void
rr_pkt_freq_prm_xx_bw_fmt(gchar *s, guint32 v)
{
	snprintf(s, ITEM_LABEL_LENGTH, "%d * 31.25 kHz = %.2f kHz (%d)", v, 31.25f*v, v);
}

GMR1_IE_FUNC(gmr1_ie_rr_pkt_freq_prm)
{
	/* ARFCN */
	proto_tree_add_split_bits_item_ret_val(
		tree, hf_rr_pkt_freq_prm_arfcn,
		tvb, offset << 3,
		rr_pkt_freq_prm_arfcn_crumbs,
		NULL);

	/* DL Freq plan ID */
	proto_tree_add_item(tree, hf_rr_pkt_freq_prm_dl_freq_plan_id,
	                    tvb, offset+1, 1, ENC_BIG_ENDIAN);

	/* DL bandwidth */
	proto_tree_add_item(tree, hf_rr_pkt_freq_prm_dl_bw,
	                    tvb, offset+1, 1, ENC_BIG_ENDIAN);

	/* UL Freq distance */
	proto_tree_add_split_bits_item_ret_val(
		tree, hf_rr_pkt_freq_prm_ul_freq_dist,
		tvb, (offset+1) << 3,
		rr_pkt_freq_prm_ul_freq_dist_crumbs,
		NULL);

	/* UL bandwidth */
	proto_tree_add_item(tree, hf_rr_pkt_freq_prm_ul_bw,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(tree, hf_rr_pkt_freq_prm_spare,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	return 3;
}

/* [3] 11.5.2.107 - Packet Imm. Ass. Type 2 Params */
static const value_string rr_pkt_imm_ass_2_prm_ac_mac_mode_vals[] = {
	{ 0, "Dynamic allocation" },
	{ 1, "Reserved" },
	{ 2, "Reserved" },
	{ 3, "Reserved" },
	{ 0, NULL }
};

static const crumb_spec_t rr_pkt_imm_ass_2_prm_ac_rlc_dblk_gnt_crumbs[] = {
	{  0, 4 },
	{ 13, 3 },
	{  0, 0 }
};

GMR1_IE_FUNC(gmr1_ie_rr_pkt_imm_ass_2_prm)
{
	proto_tree *subtree_ac, *subtree_d;


	/* Terminal AC */
	/* ----------- */

	subtree_ac = proto_tree_add_subtree(tree, tvb, offset, 5,
			ett_gmr1_ie_rr[GMR1_IE_RR_PKT_IMM_ASS_2_PRM], NULL, "GMPRS Terminal type A or C");

	/* Spare */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_spare1,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Final Allocation */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_final_alloc,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* USF Granularity */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_usf_granularity,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Downlink Control MAC slot */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_dl_ctl_mac_slot,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* MAC Mode */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_mac_mode,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Starting Frame Number */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_start_fn,
	                    tvb, offset+1, 1, ENC_BIG_ENDIAN);

	/* RLC Data Blocks Granted */
	proto_tree_add_split_bits_item_ret_val(
		tree, hf_rr_pkt_imm_ass_2_prm_ac_rlc_dblk_gnt,
		tvb, (offset+1) << 3,
		rr_pkt_imm_ass_2_prm_ac_rlc_dblk_gnt_crumbs,
		NULL);

	/* MCS */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_mcs,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	/* TFI */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_tfi,
	                    tvb, offset+3, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_spare2,
	                    tvb, offset+3, 1, ENC_BIG_ENDIAN);

	/* MAC Slot allocation */
	proto_tree_add_item(subtree_ac, hf_rr_pkt_imm_ass_2_prm_ac_mac_slot_alloc,
	                    tvb, offset+4, 1, ENC_BIG_ENDIAN);

	/* Terminal D */
	/* ---------- */

	subtree_d = proto_tree_add_subtree(tree, tvb, offset, 5,
			ett_gmr1_ie_rr[GMR1_IE_RR_PKT_IMM_ASS_2_PRM], NULL, "GMPRS Terminal type D");

	/* Channel MCS command */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_chan_mcs_cmd,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Channel MCS command PNB(5,12) */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_chan_mcs_cmd_pnb512,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_spare1,
	                    tvb, offset+1, 1, ENC_BIG_ENDIAN);

	/* RLC Data Blocks Granted */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_rlc_dblk_gnt,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_spare2,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	/* TFI */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_tfi,
	                    tvb, offset+3, 1, ENC_BIG_ENDIAN);

	/* USF Granularity */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_usf_granularity,
	                    tvb, offset+3, 1, ENC_BIG_ENDIAN);

	/* MAC Slot allocation */
	proto_tree_add_item(subtree_d, hf_rr_pkt_imm_ass_2_prm_d_mac_slot_alloc,
	                    tvb, offset+4, 1, ENC_BIG_ENDIAN);


	return 5;
}

/* [3] 11.5.2.110 - USF */
GMR1_IE_FUNC(gmr1_ie_rr_usf)
{
	/* Spare */
	proto_tree_add_item(tree, hf_rr_usf_spare,
	                    tvb, offset, 3, ENC_BIG_ENDIAN);

	/* USF */
	proto_tree_add_item(tree, hf_rr_usf_value,
	                    tvb, offset+2, 1, ENC_BIG_ENDIAN);

	return 3;
}

/* [3] 10.1.18.3.4 & [5] 12.29 - Timing Advance Index */
GMR1_IE_FUNC(gmr1_ie_rr_timing_adv_idx)
{
	/* TAI */
	proto_tree_add_item(tree, hf_rr_timing_adv_idx_value,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(tree, hf_rr_timing_adv_idx_spare,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [5] 12.16 - TLLI */
GMR1_IE_FUNC(gmr1_ie_rr_tlli)
{
	/* TLLI value as hex */
	proto_tree_add_item(tree, hf_rr_tlli, tvb, offset, 4, ENC_BIG_ENDIAN);

	return 4;
}

/* [3] 10.1.18.3.3 & [5] 10.4.10a & [6] 5.3.3 - Packet Power Control Params */
static void
rr_pkt_pwr_ctrl_prm_par_fmt(gchar *s, guint32 v)
{
	if (v >= 61) {
		snprintf(s, ITEM_LABEL_LENGTH, "Escape %d (%d)", v-60, v);
		return;
	}

	snprintf(s, ITEM_LABEL_LENGTH, "%.1f dB (%d)", v*0.4f, v);
}

GMR1_IE_FUNC(gmr1_ie_rr_pkt_pwr_ctrl_prm)
{
	/* Power Attenuation Request (PAR) */
	proto_tree_add_item(tree, hf_rr_pkt_pwr_ctrl_prm_par,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	/* Spare */
	proto_tree_add_item(tree, hf_rr_pkt_pwr_ctrl_prm_spare,
	                    tvb, offset, 1, ENC_BIG_ENDIAN);

	return 1;
}

/* [3] 10.1.18.4.2 & [5] 12.14 - Persistence Level */
GMR1_IE_FUNC(gmr1_ie_rr_persistence_lvl)
{
	int i;

	for (i=0; i<4; i++)
		proto_tree_add_item(tree, hf_rr_persistence_lvl[i],
				    tvb, offset + (i>>1), 1, ENC_BIG_ENDIAN);

	return 2;
}


elem_fcn gmr1_ie_rr_func[NUM_GMR1_IE_RR] = {
	gmr1_ie_rr_chan_desc,		/* Channel Description */
	gmr1_ie_rr_chan_mode,		/* Channel Mode */
	gmr1_ie_rr_ciph_mode_setting,	/* Cipher Mode Setting */
	gmr1_ie_rr_ciph_resp,		/* Cipher Response */
	gmr1_ie_rr_l2_pseudo_len,	/* L2 Pseudo Length */
	gmr1_ie_rr_page_mode,		/* Page Mode */
	gmr1_ie_rr_req_ref,		/* Request Reference */
	gmr1_ie_rr_cause,		/* RR Cause */
	gmr1_ie_rr_timing_ofs,		/* Timing Offset */
	gmr1_ie_rr_tmsi_ptmsi,		/* TMSI/P-TMSI */
	gmr1_ie_rr_wait_ind,		/* Wait Indication */
	gmr1_ie_rr_mes_info_flg,	/* MES Information Flag */
	gmr1_ie_rr_freq_ofs,		/* Frequency Offset */
	gmr1_ie_rr_page_info,		/* Paging Information */
	gmr1_ie_rr_pos_display,		/* Position Display */
	gmr1_ie_rr_pos_upd_info,	/* Position Update Information */
	gmr1_ie_rr_bcch_carrier,	/* BCCH Carrier */
	gmr1_ie_rr_reject_cause,	/* Reject Cause */
	gmr1_ie_rr_gps_timestamp,	/* GPS timestamp */
	gmr1_ie_rr_pwr_ctrl_prm,	/* Power Control Params */
	gmr1_ie_rr_tmsi_avail_msk,	/* TMSI Availability Mask */
	gmr1_ie_rr_gps_almanac,		/* GPS Almanac Data */
	gmr1_ie_rr_msc_id,		/* MSC ID */
	gmr1_ie_rr_gps_discr,		/* GPS Discriminator */
	gmr1_ie_rr_pkt_imm_ass_3_prm,	/* Packet Imm. Ass. Type 3 Params */
	gmr1_ie_rr_pkt_freq_prm,	/* Packet Frequency Parameters */
	gmr1_ie_rr_pkt_imm_ass_2_prm,	/* Packet Imm. Ass. Type 2 Params */
	gmr1_ie_rr_usf,			/* USF */
	gmr1_ie_rr_timing_adv_idx,	/* Timing Advance Index */
	gmr1_ie_rr_tlli,		/* TLLI */
	gmr1_ie_rr_pkt_pwr_ctrl_prm,	/* Packet Power Control Params */
	gmr1_ie_rr_persistence_lvl,	/* Persistence Level */
};


/* ------------------------------------------------------------------------ */
/* RR Messages                                                              */
/* ------------------------------------------------------------------------ */

/* [1] 10.1.18 - Immediate Assignment */
GMR1_MSG_FUNC(gmr1_rr_msg_imm_ass)
{
	guint8 mif;

	GMR1_MSG_FUNC_BEGIN

	/* MES Information Flag			[1] 11.5.2.44	- M V 1 */
	mif = tvb_get_guint8(tvb, curr_offset);

	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_MES_INFO_FLG, NULL, ei_gmr1_missing_mandatory_element);

	/* Request Reference 1 (MES1)		[1] 11.5.2.30	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES1", ei_gmr1_missing_mandatory_element);

	/* GPS Discriminator			[1] 11.5.2.101	- C V 2 */
	if ((mif & 0x03) != 0x02) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_DISCR, " - MES1", ei_gmr1_missing_mandatory_element);
	}

	/* Channel Description			[1] 11.5.2.5	- C V 4 */
	if ((mif & 0x03) != 0x03) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CHAN_DESC, " - MES1", ei_gmr1_missing_mandatory_element);
	}

	/* Timing Offset			[1] 11.5.2.40	- C V 2 */
	if ((mif & 0x03) != 0x03) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TIMING_OFS, " - MES1", ei_gmr1_missing_mandatory_element);
	}

	/* Frequency Offset			[1] 11.5.2.49	- C V 2 */
	if ((mif & 0x03) != 0x03) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_FREQ_OFS, " - MES1", ei_gmr1_missing_mandatory_element);
	}

	/* Idle Mode Pos. Upd. Info.		[1] 11.5.2.54	- C V 2 */
	if (mif & 0x04) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_POS_UPD_INFO, " - Idle Mode", ei_gmr1_missing_mandatory_element);
	}

	/* Ded. Mode Pos. Upd. Info.		[1] 11.5.2.54	- C V 2 */
	if (mif & 0x08) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_POS_UPD_INFO, " - Dedicated Mode", ei_gmr1_missing_mandatory_element);
	}

	/* Request Reference 2 (MES2)		[1] 11.5.2.30	- C V 2 */
	if (mif & 0x10) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES2", ei_gmr1_missing_mandatory_element);
	}

	/* Request Reference 3 (MES3)		[1] 11.5.2.30	- C V 2 */
	if (mif & 0x20) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES3", ei_gmr1_missing_mandatory_element);
	}

	/* Request Reference 4 (MES4)		[1] 11.5.2.30	- C V 2 */
	if (mif & 0x40) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES4", ei_gmr1_missing_mandatory_element);
	}

	/* IA Rest Octets			[1] 11.5.2.16	- M V 0..18 */
		/* FIXME */

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.20.1 - Immediate Assignment Reject Type 1 */
GMR1_MSG_FUNC(gmr1_rr_msg_imm_ass_rej_1)
{
	guint8 rej_cause;

	GMR1_MSG_FUNC_BEGIN

	/* Request Reference 1 (MES1) 		[1] 11.5.2.30	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES1", ei_gmr1_missing_mandatory_element);

	/* GPS Discriminator			[1] 11.5.2.101	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_DISCR, NULL, ei_gmr1_missing_mandatory_element);

	/* Reject Cause				[1] 11.5.2.56	- M V 1 */
	rej_cause = tvb_get_guint8(tvb, curr_offset);

	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REJECT_CAUSE, NULL, ei_gmr1_missing_mandatory_element);

	/* Wait Indication 1 (MES1)		[4] 10.5.2.43	- C V 1 */
	if ((rej_cause & 0xfc) == 0x00) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_WAIT_IND, " - MES1", ei_gmr1_missing_mandatory_element);
	}

	/* Request Reference 2 (MES2) 		[1] 11.5.2.30	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES2", ei_gmr1_missing_mandatory_element);

	/* Wait Indication 2 (MES2)		[4] 10.5.2.43	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_WAIT_IND, " - MES2", ei_gmr1_missing_mandatory_element);

	/* Request Reference 3 (MES3)		[1] 11.5.2.30	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES3", ei_gmr1_missing_mandatory_element);

	/* Wait Indication 3 (MES3)		[4] 10.5.2.43	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_WAIT_IND, " - MES3", ei_gmr1_missing_mandatory_element);

	/* Request Reference 4 (MES4)		[1] 11.5.2.30	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, " - MES4", ei_gmr1_missing_mandatory_element);

	/* Wait Indication 4 (MES4)		[4] 10.5.2.43	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_WAIT_IND, " - MES4", ei_gmr1_missing_mandatory_element);

	/* Idle Mode Position Update Info.	[1] 11.5.2.54	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_POS_UPD_INFO, " - Idle Mode", ei_gmr1_missing_mandatory_element);

	/* BCCH Carrier Specification		[1] 11.5.2.55	- C V 2 */
	if (rej_cause & 1) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_BCCH_CARRIER, NULL, ei_gmr1_missing_mandatory_element);
	}

	/* MSC ID				[1] 11.5.2.100	- C V 1 */
	if ((rej_cause & 0xfc) == 0x5c) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_MSC_ID, NULL, ei_gmr1_missing_mandatory_element);
	}

	/* IAR Rest Octets			[1] 11.5.2.17	- M V 1..4 */
		/* FIXME */

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.20.4 - Position Verification Notify */
GMR1_MSG_FUNC(gmr1_rr_msg_pos_verif_notify)
{
	GMR1_MSG_FUNC_BEGIN

	/* Request Reference 			[1] 11.5.2.30	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_REQ_REF, NULL, ei_gmr1_missing_mandatory_element);

	/* GPS Discriminator			[1] 11.5.2.101	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_DISCR, NULL, ei_gmr1_missing_mandatory_element);

	/* Position Display 			[1] 11.5.2.52	- M V 11 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_POS_DISPLAY, NULL, ei_gmr1_missing_mandatory_element);

	/* 78 Idle Mode Position Update Info.	[1] 11.5.2.54	- O TV 3 */
	ELEM_OPT_TV(0x78, GMR1_IE_RR, GMR1_IE_RR_POS_UPD_INFO, NULL);

	/* IAR Rest Octets			[1] 11.5.2.17	- M V 3..6 */
		/* FIXME */

	GMR1_MSG_FUNC_END
}

/* [3] 10.1.18.3 - Immediate Assignment Type 2 */
GMR1_MSG_FUNC(gmr1_rr_msg_imm_ass_2)
{
	GMR1_MSG_FUNC_BEGIN

	/* USF					[3] 11.5.2.110	- M V 3 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_USF, NULL, ei_gmr1_missing_mandatory_element);

	/* Timing Advance Index			[3] 10.1.18.3.4	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TIMING_ADV_IDX, NULL, ei_gmr1_missing_mandatory_element);

	/* TLLI					[5] 12.16	- M V 4 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TLLI, NULL, ei_gmr1_missing_mandatory_element);

	/* Timing Offset			[1] 11.5.2.40	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TIMING_OFS, NULL, ei_gmr1_missing_mandatory_element);

	/* Frequency Offset			[1] 11.5.2.49	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_FREQ_OFS, NULL, ei_gmr1_missing_mandatory_element);

	/* Packet Imm. Ass. Type 2 Params.	[3] 11.5.2.107	- M V 5 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PKT_IMM_ASS_2_PRM, NULL, ei_gmr1_missing_mandatory_element);

	/* Packet Frequency Parameters		[3] 11.5.2.106	- M V 3 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PKT_FREQ_PRM, NULL, ei_gmr1_missing_mandatory_element);

	/* Packet Power Control Parameters	[3] 10.1.18.3.3	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PKT_PWR_CTRL_PRM, NULL, ei_gmr1_missing_mandatory_element);

	GMR1_MSG_FUNC_END
}

/* [3] 10.1.18.4 - Immediate Assignment Type 3 */
GMR1_MSG_FUNC(gmr1_rr_msg_imm_ass_3)
{
	GMR1_MSG_FUNC_BEGIN

	/* Page Mode				[1] 11.5.2.26	- M V 1/2 */
	/* Spare Half Octet			[1] 11.5.1.8	- M V 1/2 */
	ELEM_MAND_VV_SHORT(GMR1_IE_RR, GMR1_IE_RR_PAGE_MODE,
	                   GMR1_IE_COMMON, GMR1_IE_COM_SPARE_NIBBLE, ei_gmr1_missing_mandatory_element);

	/* Persistence Level			[3] 10.1.18.4.2	- M V 2 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PERSISTENCE_LVL, NULL, ei_gmr1_missing_mandatory_element);

	/* Timing Advance Index			[3] 10.1.18.3.4	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TIMING_ADV_IDX, NULL, ei_gmr1_missing_mandatory_element);

	/* TLLI					[5] 12.16	- M V 4 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TLLI, NULL, ei_gmr1_missing_mandatory_element);

	/* Packet Imm. Ass. Type 3 Params	[3] 11.5.2.105	- M V 3 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PKT_IMM_ASS_3_PRM, NULL, ei_gmr1_missing_mandatory_element);

	/* Packet Frequency Parameters		[3] 11.5.2.106	- M V 3 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PKT_FREQ_PRM, NULL, ei_gmr1_missing_mandatory_element);

	/* Packet Power Control Parameters	[3] 10.1.18.3.3	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PKT_PWR_CTRL_PRM, NULL, ei_gmr1_missing_mandatory_element);

	/* P1 Rest Octets			[1] 11.5.2.23	- M V 6 */
		/* FIXME */

	GMR1_MSG_FUNC_END
}

/* [3] 10.1.9 - Ciphering Mode Command */
GMR1_MSG_FUNC(gmr1_rr_msg_ciph_mode_cmd)
{
	GMR1_MSG_FUNC_BEGIN

	/* Cipher Mode Setting			[4] 10.5.2.9	- M V 1/2 */
	/* Cipher Response			[4] 10.5.2.10	- M V 1/2 */
	ELEM_MAND_VV_SHORT(GMR1_IE_RR, GMR1_IE_RR_CIPH_MODE_SETTING,
	                   GMR1_IE_RR, GMR1_IE_RR_CIPH_RESP, ei_gmr1_missing_mandatory_element);

	/* 75  Position Display			[1] 11.5.2.52	- O TV 12 */
	ELEM_OPT_TV(0x75, GMR1_IE_RR, GMR1_IE_RR_POS_DISPLAY, NULL);

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.10 - Ciphering Mode Complete */
GMR1_MSG_FUNC(gmr1_rr_msg_ciph_mode_complete)
{
	GMR1_MSG_FUNC_BEGIN

	/* 17  Mobile Identity			[1] 11.5.1.4	- O TLV 3-11 */
	ELEM_OPT_TLV(0x17, GSM_A_PDU_TYPE_COMMON, DE_MID, NULL);

	/* 76  GPS Timestamp			[1] 11.5.2.57	- O TV 3 */
	ELEM_OPT_TV(0x76, GMR1_IE_RR, GMR1_IE_RR_GPS_TIMESTAMP, NULL);

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.2.1 - Assignment Command 1 */
GMR1_MSG_FUNC(gmr1_rr_msg_ass_cmd_1)
{
	GMR1_MSG_FUNC_BEGIN

	/* Channel Description			[1] 11.5.2.5	- M V 4 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CHAN_DESC, NULL, ei_gmr1_missing_mandatory_element);

	/* 7D  Timing Offset			[1] 11.5.2.40	- O TV 3 */
	ELEM_OPT_TV(0x7D, GMR1_IE_RR, GMR1_IE_RR_TIMING_OFS, NULL);

	/* 7F  Frequency Offset			[1] 11.5.2.49	- O TV 3 */
	ELEM_OPT_TV(0x7F, GMR1_IE_RR, GMR1_IE_RR_FREQ_OFS, NULL);

	/* 63  Channel Mode			[1] 11.5.2.6	- O TV 2 */
	ELEM_OPT_TV(0x63, GMR1_IE_RR, GMR1_IE_RR_CHAN_MODE, NULL);

	/* 71  Power Control Parameters		[1] 11.5.2.60	- O TV 6 */
	ELEM_OPT_TV(0x71, GMR1_IE_RR, GMR1_IE_RR_PWR_CTRL_PRM, NULL);

	/* 9-  Cipher Mode Setting		[4] 10.5.2.9	- O TV 1 */
	ELEM_OPT_TV_SHORT(0x90, GMR1_IE_RR, GMR1_IE_RR_CIPH_MODE_SETTING, NULL);

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.7 - Channel Release */
GMR1_MSG_FUNC(gmr1_rr_msg_chan_release)
{
	GMR1_MSG_FUNC_BEGIN

	/* RR Cause				[1] 11.5.2.31	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CAUSE, NULL, ei_gmr1_missing_mandatory_element);

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.24 - Paging Request Type 3 */
GMR1_MSG_FUNC(gmr1_rr_msg_pag_req_3)
{
	guint8 tam;

	GMR1_MSG_FUNC_BEGIN

	/* Page Mode				[1] 11.5.2.26	- M V 1/2 */
	/* TMSI Availability Mask		[1] 11.5.2.62	- M V 1/2 */
	tam = (tvb_get_guint8(tvb, curr_offset) & 0xf0) >> 4;

	ELEM_MAND_VV_SHORT(GMR1_IE_RR, GMR1_IE_RR_PAGE_MODE,
	                   GMR1_IE_RR, GMR1_IE_RR_TMSI_AVAIL_MSK, ei_gmr1_missing_mandatory_element);

	/* Mobile Identity 1 (TMSI)		[4] 10.5.2.42	- C V 4 */
	if (tam & 0x01) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TMSI_PTMSI, " - 1", ei_gmr1_missing_mandatory_element);
	}

	/* GPS Almanac Data 1			[1] 11.5.2.63	- C V 5 */
	if (!(tam & 0x01)) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_ALMANAC, " - 1", ei_gmr1_missing_mandatory_element);
	}

	/* Mobile Identity 2 (TMSI)		[4] 10.5.2.42	- C V 4 */
	if (tam & 0x02) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TMSI_PTMSI, " - 2", ei_gmr1_missing_mandatory_element);
	}

	/* GPS Almanac Data 2			[1] 11.5.2.63	- C V 5 */
	if (!(tam & 0x02)) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_ALMANAC, " - 2", ei_gmr1_missing_mandatory_element);
	}

	/* Mobile Identity 3 (TMSI)		[4] 10.5.2.42	- C V 4 */
	if (tam & 0x04) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TMSI_PTMSI, " - 3", ei_gmr1_missing_mandatory_element);
	}

	/* GPS Almanac Data 3			[1] 11.5.2.63	- C V 5 */
	if (!(tam & 0x04)) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_ALMANAC, " - 3", ei_gmr1_missing_mandatory_element);
	}

	/* Mobile Identity 4 (TMSI)		[4] 10.5.2.42	- C V 4 */
	if (tam & 0x08) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_TMSI_PTMSI, " - 4", ei_gmr1_missing_mandatory_element);
	}

	/* GPS Almanac Data 4			[1] 11.5.2.63	- C V 5 */
	if (!(tam & 0x08)) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_GPS_ALMANAC, " - 4", ei_gmr1_missing_mandatory_element);
	}

	/* Paging Information 1			[1] 11.5.2.51	- C V 1 */
	if (tam & 0x01) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PAGE_INFO, " - 1", ei_gmr1_missing_mandatory_element);
	}

	/* Paging Information 2			[1] 11.5.2.51	- C V 1 */
	if (tam & 0x02) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PAGE_INFO, " - 2", ei_gmr1_missing_mandatory_element);
	}

	/* Paging Information 3			[1] 11.5.2.51	- C V 1 */
	if (tam & 0x04) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PAGE_INFO, " - 3", ei_gmr1_missing_mandatory_element);
	}

	/* Paging Information 4			[1] 11.5.2.51	- C V 1 */
	if (tam & 0x08) {
		ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_PAGE_INFO, " - 4", ei_gmr1_missing_mandatory_element);
	}

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.25 - Paging Response */
GMR1_MSG_FUNC(gmr1_rr_msg_pag_resp)
{
	GMR1_MSG_FUNC_BEGIN

	/* Ciphering Key Sequence Number	[4] 10.5.1.2	- M V 1/2 */
	/* Spare Half Octet			[1] 11.5.1.8	- M V 1/2 */
	ELEM_MAND_VV_SHORT(GSM_A_PDU_TYPE_COMMON, DE_CIPH_KEY_SEQ_NUM,
	                   GMR1_IE_COMMON, GMR1_IE_COM_SPARE_NIBBLE, ei_gmr1_missing_mandatory_element);

	/* Mobile Earth Station Classmark 2	[1] 11.5.1.6	- M L V 4 */
	ELEM_MAND_LV(GMR1_IE_COMMON, GMR1_IE_COM_CM2, NULL, ei_gmr1_missing_mandatory_element);

	/* Mobile Identity			[4] 10.5.1.4	- M L V 2-9 */
	ELEM_MAND_LV(GSM_A_PDU_TYPE_COMMON, DE_MID, NULL, ei_gmr1_missing_mandatory_element);

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.5 - Channel Mode Modify */
GMR1_MSG_FUNC(gmr1_rr_msg_chan_mode_modify)
{
	GMR1_MSG_FUNC_BEGIN

	/* Channel Description			[1] 11.5.2.5	- M V 4 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CHAN_DESC, NULL, ei_gmr1_missing_mandatory_element);

	/* Channel Mode				[1] 11.5.2.6	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CHAN_MODE, NULL, ei_gmr1_missing_mandatory_element);

	GMR1_MSG_FUNC_END
}

/* [1] 10.1.6 - Channel Mode Modify Acknowledge */
GMR1_MSG_FUNC(gmr1_rr_msg_chan_mode_mod_ack)
{
	GMR1_MSG_FUNC_BEGIN

	/* Channel Description			[1] 11.5.2.5	- M V 4 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CHAN_DESC, NULL, ei_gmr1_missing_mandatory_element);

	/* Channel Mode				[1] 11.5.2.6	- M V 1 */
	ELEM_MAND_V(GMR1_IE_RR, GMR1_IE_RR_CHAN_MODE, NULL, ei_gmr1_missing_mandatory_element);

	GMR1_MSG_FUNC_END
}


/* See [3] 11.4.1 - Table 11.1 */
static const value_string gmr1_msg_rr_strings[] = {
	/* Channel establishment messages */
	{ 0x3f, "Immediate Assignment" },
	{ 0x3a, "Immediate Assignment Reject Type 1" },
	{ 0x3b, "Immediate Assignment Reject Type 2" },
	/*
	 * XXX - [3] 11.4.1 - Table 11.1 ([3] is ETSI TS 101 376-4-8
	 * V3.1.1, which is GMR-1 3G 44.008) has 0x3e meaning both
	 * "Extended Immediate Assignment" and "Immediate Assignment Type 2"
	 * and has 0x3b meaning both "Immediate Asignment Reject Type 2"
	 * and "Extended Imm. Assignment Reject".
	 *
	 * [3] makes some references to [1] ([1] is ETSI TS 101 376-4-8
	 * V1.3.1, which is GMR-1 04.008, not to be confused with GMR-1
	 * 3G 44.008), saying some messages are the same as in GMR-1
	 * 04.008.  [1]:
	 *
	 *    says, in 10.1.18.2, that "Extended immediate assignment"
	 *    "is sent on the main signalling link by the network to
	 *    the MES in response to an EXTENDED CHANNEL REQUEST message
	 *    by the MES";
	 *
	 *    says, in 10.1.20.2, that "Immediate assignment reject type 2"
	 *    "may be sent to the MES by the network on the CCCH to indicate
	 *    that no channel is available for assignment or that the MES
	 *    cannot be allowed access";
	 *
	 *    says, in 10.1.20.3, that "Extended immediate assignment
	 *    reject" "message is sent by the network on the DCCH to
	 *    indicate that no channel is available for assignment or
	 *    that the MES cannot be allowed access";
	 *
	 *    does not mention "Immediate assignment type 2" anywhere
	 *    that I can see.
	 *
	 * [3]:
	 *
	 *    says, in 10.1.18.2, that "Extended immediate assignment
	 *    (A/Gb mode only)" is "Same as clause 10.1.18.2 of
	 *    GMR-1 04.008";
	 *
	 *    says, in 10.1.18.3, that "Intermediate assignment Type
	 *    2 (A/Gb mode only)" "is sent on the CCCH by the network
	 *    to the MES to change the channel configuration to a
	 *    dedicated configuration while staying in the same cell";
	 *
	 *    says, in 10.1.20.2, that "Immediate assignment reject
	 *    type 2" is "Same as clause 10.1.20.2 of GMR-1 04.008";
	 *
	 *    says, in 10.1.20.3, that "Extended immediate assignment
	 *    reject" is "Same as clause 10.1.20.3 of GMR-1 04.008".
	 *
	 * This is currently handled by ORing 0x100 into the values
	 * for the DCCH, and, in gmr1_get_msg_rr_params(), if the dcch
	 * parameter is set (which it is if called from gmr1_get_msg_params()
	 * in packet-gmr1_common.c), 0x100 is ORed into the value
	 * passed to try_val_to_str_idx().  If that returns NULL, or
	 * isn't called in the first placee, it calls try_val_to_str_idx()
	 * without ORing in 0x100.
	 *
	 * So that's why a 1-byte field has, in a value_string used with
	 * it, two values that don't fit into 1 byte.
	 *
	 * It Would Be Nice if this could be done in a somewhat less
	 * hackish and opaque fashion.
	 */
	{ 0x13e, "Extended Immediate Assignment" },
	{ 0x13b, "Extended Imm. Assignment Reject" },
	{ 0x39, "Position Verification Notify" },
	{ 0x3c, "Immediate Assignment Reject Type 3" },
	{ 0x3e, "Immediate Assignment Type 2" },
	{ 0x3d, "Immediate Assignment Type 3" },

	/* Ciphering messages */
	{ 0x35, "Ciphering Mode Command" },
	{ 0x32, "Ciphering Mode Complete" },

	/* Channel assignment/handover messages */
	{ 0x2e, "Assignment Command 1" },
	{ 0x2a, "Assignment Command 2" },
	{ 0x29, "Assignment Complete" },
	{ 0x2f, "Assignment Failure" },
	{ 0x2b, "Handover Command" },
	{ 0x2c, "Handover Complete" },

	/* Channel release messages */
	{ 0x0d, "Channel Release" },
	{ 0x0e, "TtT Signalling Link Failure" },

	/* Paging messages */
	{ 0x21, "Paging Request Type 1" },
	{ 0x22, "Paging Request Type 2" },
	{ 0x24, "Paging Request Type 3" },
	{ 0x27, "Paging Response" },

	/* Miscellaneous messages */
	{ 0x10, "Channel Mode Modify" },
	{ 0x12, "RR Status" },
	{ 0x17, "Channel Mode Modify Acknowledge" },
	{ 0x16, "Classmark Change" },
	{ 0x13, "Classmark Enquiry" },
	{ 0x14, "Position Update Request" },
	{ 0x15, "Position Update Accept" },
	{ 0x11, "Link Correction Message" },

	{ 0x01, "Power Control Parameters Update" },
	{ 0x02, "Guard Time Violation" },
	{ 0x04, "Extended Channel Request" },

	/* Status and Diagnostic Messages */
	{ 0x40, "Information Request" },
	{ 0x41, "Information Response Position" },
	{ 0x42, "Information Response Version" },
	{ 0x43, "Information Response Spot Beam Selection" },
	{ 0x44, "Information Response Power Control" },
	{ 0x45, "Information Response Vendor Specific" },
	{ 0x46, "Information Response Current Beam" },
	{ 0x4f, "Information Response Error" },

	/* End */
	{ 0, NULL }
};


#define NUM_GMR1_MSG_RR (sizeof(gmr1_msg_rr_strings) / sizeof(value_string))
static gint ett_msg_rr[NUM_GMR1_MSG_RR];

	/* same order as gmr1_msg_rr_strings */
static const gmr1_msg_func_t gmr1_msg_rr_func[NUM_GMR1_MSG_RR] = {
	/* Channel establishment messages */
	gmr1_rr_msg_imm_ass,		/* Imm. Ass.*/
	gmr1_rr_msg_imm_ass_rej_1,	/* Imm. Ass. Reject Type 1 */
	NULL,				/* Imm. Ass. Reject Type 2 */
	NULL,				/* Extended Imm. Ass. */
	NULL,				/* Extended Imm. Ass. Reject */
	gmr1_rr_msg_pos_verif_notify,	/* Position Verification Notify */
	NULL,				/* Imm. Ass. Reject Type 3 */
	gmr1_rr_msg_imm_ass_2,		/* Imm. Ass. Type 2 */
	gmr1_rr_msg_imm_ass_3,		/* Imm. Ass. Type 3 */

	/* Ciphering messages */
	gmr1_rr_msg_ciph_mode_cmd,	/* Ciphering Mode Command */
	gmr1_rr_msg_ciph_mode_complete,	/* Ciphering Mode Complete */

	/* Channel assignment/handover messages */
	gmr1_rr_msg_ass_cmd_1,		/* Assignment Command 1 */
	NULL,				/* Assignment Command 2 */
	NULL,				/* Assignment Complete */
	NULL,				/* Assignment Failure */
	NULL,				/* Handover Command */
	NULL,				/* Handover Complete */

	/* Channel release messages */
	gmr1_rr_msg_chan_release,	/* Channel Release */
	NULL,				/* TtT Signalling Link Failure */

	/* Paging messages */
	NULL,				/* Paging Request Type 1 */
	NULL,				/* Paging Request Type 2 */
	gmr1_rr_msg_pag_req_3,		/* Paging Request Type 3 */
	gmr1_rr_msg_pag_resp,		/* Paging Response */

	/* Miscellaneous messages */
	gmr1_rr_msg_chan_mode_modify,	/* Channel Mode Modify */
	NULL,				/* RR Status */
	gmr1_rr_msg_chan_mode_mod_ack,	/* Channel Mode Modify Acknowledge */
	NULL,				/* Classmark Change */
	NULL,				/* Classmark Enquiry */
	NULL,				/* Position Update Request */
	NULL,				/* Position Update Accept */
	NULL,				/* Link Correction Message */

	NULL,				/* Power Control Parameters Update */
	NULL,				/* Guard Time Violation */
	NULL,				/* Extended Channel Request */

	/* Status and Diagnostic Messages */
	NULL,				/* Info. Req. */
	NULL,				/* Info. Resp. Position */
	NULL,				/* Info. Resp. Version */
	NULL,				/* Info. Resp. Spot Beam Selection */
	NULL,				/* Info. Resp. Power Control */
	NULL,				/* Info. Resp. Vendor Specific */
	NULL,				/* Info. Resp. Current Beam */
	NULL,				/* Info. Resp. Error */

	NULL,
};


void
gmr1_get_msg_rr_params(guint8 oct, int dcch, const gchar **msg_str,
		       int *ett_tree, int *hf_idx, gmr1_msg_func_t *msg_func_p)
{
	const gchar *m = NULL;
	gint idx;

	/*
	 * See the large comment in gmr1_msg_rr_strings[] for an
	 * explanation of why we're doing this.
	 */
	if (dcch)
		m = try_val_to_str_idx((guint32)oct | 0x100, gmr1_msg_rr_strings, &idx);

	if (!m)
		m = try_val_to_str_idx((guint32)oct, gmr1_msg_rr_strings, &idx);

	*msg_str = m;
	*hf_idx = hf_rr_msg_type;
	if (m != NULL) {
		*ett_tree  = ett_msg_rr[idx];
		*msg_func_p = gmr1_msg_rr_func[idx];
	} else {
		*ett_tree = -1;
		*msg_func_p = NULL;
	}
}


/* ------------------------------------------------------------------------ */
/* Dissector code                                                           */
/* ------------------------------------------------------------------------ */

static int
dissect_gmr1_ccch(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
	guint32 len, offset;
	gmr1_msg_func_t msg_func;
	const gchar *msg_str;
	gint ett_tree;
	int hf_idx;
	proto_item *ccch_item = NULL, *pd_item = NULL;
	proto_tree *ccch_tree = NULL, *pd_tree = NULL;
	guint32 oct[3];
	guint8 pd;
	gint ti = -1;

	/* Scan init */
	len = tvb_reported_length(tvb);
	offset = 0;

	/* Safety */
	if (len < 3) {
		/* Can't be a CCCH */
		goto err;
	}

	col_append_str(pinfo->cinfo, COL_INFO, "(CCCH) ");

	/* First octed with pseudo len */
	oct[0] = tvb_get_guint8(tvb, offset++);

	/* Check protocol descriptor */
	oct[1] = tvb_get_guint8(tvb, offset++);

	if ((oct[1] & GMR1_PD_EXT_MSK) == GMR1_PD_EXT_VAL)
		pd = oct[1] & 0xff;
	else
		pd = oct[1] & 0x0f;

	col_append_fstr(pinfo->cinfo, COL_INFO, "(%s) ",
		val_to_str(pd, gmr1_pd_short_vals, "Unknown (%u)"));

	if (pd != GMR1_PD_RR)
		goto err;	/* CCCH is only RR */

	/* Get message parameters */
	oct[2] = tvb_get_guint8(tvb, offset);

	gmr1_get_msg_rr_params(oct[2], 0, &msg_str, &ett_tree, &hf_idx, &msg_func);

	/* Create protocol tree */
	if (msg_str == NULL)
	{
		ccch_item = proto_tree_add_protocol_format(
			tree, proto_gmr1_ccch, tvb, 0, len,
			"GMR-1 CCCH - Message Type (0x%02x)", oct[2]);
		ccch_tree = proto_item_add_subtree(ccch_item, ett_msg_ccch);

		col_append_fstr(pinfo->cinfo, COL_INFO, "Message Type (0x%02x) ", oct[2]);
	}
	else
	{
		ccch_item = proto_tree_add_protocol_format(
			tree, proto_gmr1_ccch, tvb, 0, -1,
			"GMR-1 CCCH - %s", msg_str);
		ccch_tree = proto_item_add_subtree(ccch_item, ett_tree);

		col_append_fstr(pinfo->cinfo, COL_INFO, "%s ", msg_str);
	}

	/* Start over */
	offset = 0;

	/* L2 Pseudo Length - [1] 11.5.2.19 */
	offset += elem_v(tvb, ccch_tree, pinfo, GMR1_IE_RR, GMR1_IE_RR_L2_PSEUDO_LEN, offset, NULL);

	/* Protocol discriminator item */
	pd_item = proto_tree_add_uint(
		ccch_tree, hf_rr_protocol_discriminator, tvb, 1, 1, pd);

	pd_tree = proto_item_add_subtree(pd_item, ett_rr_pd);

		/* Skip indicator / Transaction indicator */
	if (ti == -1) {
		proto_tree_add_item(pd_tree, hf_gmr1_skip_ind, tvb, 1, 1, ENC_BIG_ENDIAN);
	} else {
		/* FIXME !!! */
	}

		/* Protocol discriminator value */
	proto_tree_add_item(pd_tree, hf_gmr1_l3_pd, tvb, 1, 1, ENC_BIG_ENDIAN);


		/* Move on */
	offset++;

	/* Message type - [1] 11.4 */
	proto_tree_add_uint_format(
		ccch_tree, hf_idx, tvb, offset, 1, oct[2],
		"Message Type: %s", msg_str ? msg_str : "(Unknown)"
	);

	offset++;

	/* Decode elements */
	if (msg_func) {
		(*msg_func)(tvb, ccch_tree, pinfo, offset, len - offset);
	} else {
		proto_tree_add_item(ccch_tree, hf_rr_message_elements, tvb, offset, len - offset, ENC_NA);
	}

	/* Error handling */
err:
	call_data_dissector(tvb, pinfo, tree);
	return tvb_captured_length(tvb);
}

void
proto_register_gmr1_rr(void)
{
	static hf_register_info hf[] = {
		{ &hf_rr_msg_type,
		  { "Radio Resources Management Message Type", "gmr1.rr.msg_type",
		    FT_UINT8, BASE_HEX, VALS(gmr1_msg_rr_strings), 0x00,
		    NULL, HFILL }	/* FIXME handle CCCH/DCCH conflicts */
		},
		{ &hf_rr_chan_desc_kab_loc,
		  { "KAB Location", "gmr1.rr.chan_desc.kab_loc",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_chan_desc_rx_tn,
		  { "RX Timeslot", "gmr1.rr.chan_desc.rx_tn",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_chan_desc_arfcn,
		  { "ARFCN", "gmr1.rr.chan_desc.arfcn",
		    FT_UINT16, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_chan_desc_tx_tn,
		  { "TX Timeslot", "gmr1.rr.chan_desc.tx_tn",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_chan_desc_chan_type,
		  { "Channel Type", "gmr1.rr.chan_desc.chan_type",
		    FT_UINT8, BASE_DEC, VALS(rr_chan_desc_chan_type_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_chan_mode,
		  { "Channel Mode", "gmr1.rr.chan_mode",
		    FT_UINT8, BASE_DEC, VALS(rr_chan_mode_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_ciph_mode_setting_sc,
		  { "SC", "gmr1.rr.ciph_mode_setting.sc",
		    FT_UINT8, BASE_DEC, VALS(rr_ciph_mode_setting_sc_vals), 0x01,
		    NULL, HFILL }
		},
		{ &hf_rr_ciph_mode_setting_algo,
		  { "Algorithm", "gmr1.rr.ciph_mode_setting.algo",
		    FT_UINT8, BASE_DEC, VALS(rr_ciph_mode_setting_algo_vals), 0x0e,
		    NULL, HFILL }
		},
		{ &hf_rr_ciph_resp_cr,
		  { "CR", "gmr1.rr.ciph_resp.cr",
		    FT_UINT8, BASE_DEC, VALS(rr_ciph_resp_cr_vals), 0x10,
		    NULL, HFILL }
		},
		{ &hf_rr_ciph_resp_spare,
		  { "Spare", "gmr1.rr.ciph_resp.spare",
		    FT_UINT8, BASE_DEC, NULL, 0xe0,
		    NULL, HFILL }
		},
		{ &hf_rr_l2_pseudo_len,
		  { "L2 Pseudo Length value", "gmr1.rr.l2_pseudo_len",
		    FT_UINT8, BASE_DEC, NULL, 0xfc,
		    NULL, HFILL }
		},
		{ &hf_rr_page_mode,
		  { "Page Mode", "gmr1.rr.page_mode.mode",
		    FT_UINT8, BASE_DEC, VALS(rr_page_mode_vals), 0x03,
		    NULL, HFILL }
		},
		{ &hf_rr_page_mode_spare,
		  { "Spare", "gmr1.rr.page_mode.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x0c,
		    NULL, HFILL }
		},
		{ &hf_rr_req_ref_est_cause,
		  { "Establishment cause group ID", "gmr1.rr.req_ref.est_cause",
		    FT_UINT8, BASE_DEC, VALS(rr_req_ref_est_cause_vals), 0xe0,
		    NULL, HFILL }
		},
		{ &hf_rr_req_ref_ra,
		  { "Random Access Information", "gmr1.rr.req_ref.ra",
		    FT_UINT8, BASE_HEX, NULL, 0x1f,
		    NULL, HFILL }
		},
		{ &hf_rr_req_ref_fn,
		  { "Frame Number mod 256", "gmr1.rr.req_ref.fn",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_cause,
		  { "RR Cause", "gmr1.rr.cause",
		    FT_UINT8, BASE_DEC, VALS(rr_cause_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_timing_ofs_ti,
		  { "TI", "gmr1.rr.timing_offset.ti",
		    FT_UINT8, BASE_DEC, VALS(rr_timing_ofs_ti_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_timing_ofs_value,
		  { "Timing Offset value", "gmr1.rr.timing_offset.value",
		    FT_INT16, BASE_CUSTOM, CF_FUNC(rr_timing_ofs_value_fmt), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_tmsi_ptmsi,
		  { "TMSI/P-TMSI Value","gmr1.rr.tmsi_ptmsi",
		    FT_UINT32,BASE_HEX,  NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_wait_ind_timeout,
		  { "T3122/T3142 timeout", "gmr1.rr.wait_ind.timeout",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_gen_ie_seconds_fmt), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_mes1_ab,
		  { "MES1 - Assignment Type", "gmr1.rr.mes_info_flag.1.ab",
		    FT_UINT8, BASE_DEC, VALS(rr_mif_mes1_ab_vals), 0x03,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_mes1_i,
		  { "MES1 - Idle mode position update", "gmr1.rr.mes_info_flag.1.i",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x04,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_mes1_d,
		  { "MES1 - Dedicated mode position update", "gmr1.rr.mes_info_flag.1.d",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x08,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_mes2,
		  { "MES2", "gmr1.rr.mes_info_flag.2",
		    FT_UINT8, BASE_DEC, VALS(rr_mif_mes234_vals), 0x10,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_mes3,
		  { "MES3", "gmr1.rr.mes_info_flag.3",
		    FT_UINT8, BASE_DEC, VALS(rr_mif_mes234_vals), 0x20,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_mes4,
		  { "MES4", "gmr1.rr.mes_info_flag.4",
		    FT_UINT8, BASE_DEC, VALS(rr_mif_mes234_vals), 0x40,
		    NULL, HFILL }
		},
		{ &hf_rr_mif_pv,
		  { "Position Verification indicator", "gmr1.rr.mes_info_flag.pv",
		    FT_UINT8, BASE_DEC, VALS(rr_mif_pv_vals), 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_freq_ofs_fi,
		  { "FI", "gmr1.rr.frequency_offset.fi",
		    FT_UINT8, BASE_DEC, VALS(rr_freq_ofs_fi_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_freq_ofs_value,
		  { "Frequency Offset value", "gmr1.rr.frequency_offset.value",
		    FT_INT16, BASE_CUSTOM, CF_FUNC(rr_freq_ofs_value_fmt), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_freq_ofs_spare,
		  { "Spare", "gmr1.rr.frequency_offset.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_page_info_msc_id,
		  { "MSC ID", "gmr1.rr.paging_info.msc_id",
		    FT_UINT8, BASE_DEC, NULL, 0xfc,
		    NULL, HFILL }
		},
		{ &hf_rr_page_info_chan_needed,
		  { "Channel Needed", "gmr1.rr.paging_info.chan_needed",
		    FT_UINT8, BASE_DEC, VALS(rr_page_info_chan_needed_vals), 0x03,
		    NULL, HFILL }
		},
		{ &hf_rr_pos_display_flag,
		  { "Display Information Flag", "gmr1.rr.pos_display.flag",
		    FT_UINT8, BASE_DEC, VALS(rr_pos_display_flag_vals), 0xf0,
		    NULL, HFILL }
		},
		{ &hf_rr_pos_display_text,
		  { "Country and Region name", "gmr1.rr.pos_display.text",
		    FT_STRING, BASE_NONE, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_pos_upd_info_v,
		  { "Valid", "gmr1.rr.pos_upd_info.valid",
		    FT_UINT8, BASE_DEC, VALS(rr_pos_upd_info_v_vals), 0x01,
		    NULL, HFILL }
		},
		{ &hf_rr_pos_upd_info_dist,
		  { "GPS Update Distance", "gmr1.rr.pos_upd_info.distance",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_pos_upd_info_dist_fmt), 0xfe,
		    NULL, HFILL }
		},
		{ &hf_rr_pos_upd_info_time,
		  { "GPS Update Timer", "gmr1.rr.pos_upd_info.time",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_pos_upd_info_time_fmt), 0xff,
		    NULL, HFILL }
		},
		{ &hf_rr_bcch_carrier_arfcn,
		  { "ARFCN", "gmr1.rr.bcch_carrier.arfcn",
		    FT_UINT16, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_bcch_carrier_si,
		  { "Satellite Indication", "gmr1.rr.bcch_carrier.si",
		    FT_UINT8, BASE_DEC, VALS(rr_bcch_carrier_si_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_bcch_carrier_ri,
		  { "Reselection Indication", "gmr1.rr.bcch_carrier.ri",
		    FT_UINT8, BASE_DEC, VALS(rr_bcch_carrier_ri_vals), 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_bcch_carrier_spare,
		  { "Spare", "gmr1.rr.bcch_carrier.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_reject_cause,
		  { "Cause", "gmr1.rr.reject_cause.cause",
		    FT_UINT8, BASE_DEC, VALS(rr_reject_cause_vals), 0xfc,
		    NULL, HFILL }
		},
		{ &hf_rr_reject_cause_b,
		  { "BCCH Carrier IE presence", "gmr1.rr.reject_cause.b",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x01,
		    NULL, HFILL }
		},
		{ &hf_rr_gps_timestamp,
		  { "GPS timestamp", "gmr1.rr.gps_timestamp",
		    FT_UINT16, BASE_CUSTOM, CF_FUNC(rr_gps_timestamp_fmt), 0xffff,
		    NULL, HFILL }
		},
		{ &hf_rr_gps_power_control_params,
		  { "Power Control Parameters", "gmr1.rr.power_control_params",
		    FT_BYTES, BASE_NONE, NULL, 0x0,
		    NULL, HFILL }
		},
		{ &hf_rr_tmsi_avail_msk_tmsi[0],
		  { "TMSI 1 Presence", "gmr1.rr.tmsi_avail_msk.tmsi1",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x10,
		    NULL, HFILL }
		},
		{ &hf_rr_tmsi_avail_msk_tmsi[1],
		  { "TMSI 2 Presence", "gmr1.rr.tmsi_avail_msk.tmsi2",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x20,
		    NULL, HFILL }
		},
		{ &hf_rr_tmsi_avail_msk_tmsi[2],
		  { "TMSI 3 Presence", "gmr1.rr.tmsi_avail_msk.tmsi3",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x40,
		    NULL, HFILL }
		},
		{ &hf_rr_tmsi_avail_msk_tmsi[3],
		  { "TMSI 4 Presence", "gmr1.rr.tmsi_avail_msk.tmsi4",
		    FT_UINT8, BASE_DEC, VALS(rr_gen_ie_presence_vals), 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_gps_almanac_pn,
		  { "Page Number", "gmr1.rr.gps_almanac.pn",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_gps_almanac_pn_fmt), 0xf8,
		    "See ICD-GPS-200", HFILL }
		},
		{ &hf_rr_gps_almanac_wn,
		  { "Word Number", "gmr1.rr.gps_almanac.wn",
		    FT_UINT8, BASE_DEC, NULL, 0x07,
		    "See ICD-GPS-200", HFILL }
		},
		{ &hf_rr_gps_almanac_word,
		  { "GPS Almanac Word", "gmr1.rr.gps_almanac.word",
		    FT_UINT24, BASE_HEX, NULL, 0x00,
		    "See ICD-GPS-200", HFILL }
		},
		{ &hf_rr_gps_almanac_sfn,
		  { "Sub Frame Number", "gmr1.rr.gps_almanac.sfn",
		    FT_UINT8, BASE_DEC, VALS(rr_gps_almanac_sfn_vals), 0x80,
		    "See ICD-GPS-200", HFILL }
		},
		{ &hf_rr_gps_almanac_co,
		  { "CO", "gmr1.rr.gps_almanac.co",
		    FT_UINT8, BASE_DEC, NULL, 0x40,
		    NULL, HFILL }
		},
		{ &hf_rr_gps_almanac_spare,
		  { "Spare", "gmr1.rr.gps_almanac.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x3f,
		    NULL, HFILL }
		},
		{ &hf_rr_msc_id,
		  { "MSC ID", "gmr1.rr.msc_id",
		    FT_UINT8, BASE_DEC, NULL, 0xfc,
		    NULL, HFILL }
		},
		{ &hf_rr_msc_id_spare,
		  { "Spare", "gmr1.rr.msc_id.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x03,
		    NULL, HFILL }
		},
		{ &hf_rr_gps_discr,
		  { "GPS Position field CRC-16", "gmr1.rr.gps_discriminator",
		    FT_UINT16, BASE_HEX, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_3_prm_rlc_mode,
		  { "RLC Mode", "gmr1.rr.pkt_imm_ass_3_prm",
		    FT_UINT8, BASE_DEC, VALS(rr_pkt_imm_ass_3_prm_rlc_mode_vals), 0x01,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_3_prm_spare,
		  { "Spare", "gmr1.rr.pkt_imm_ass_3_prm.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x1e,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_3_prm_dl_tfi,
		  { "Downlink TFI", "gmr1.rr.pkt_imm_ass_3_prm.tfi",
		    FT_UINT8, BASE_HEX, NULL, 0x00,
		    "Temporary Flow Identifier", HFILL }
		},
		{ &hf_rr_pkt_imm_ass_3_prm_start_fn,
		  { "Start Framenumber", "gmr1.rr.pkt_imm_ass_3_prm.start_fn",
		    FT_UINT8, BASE_DEC, NULL, 0xf0,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_3_prm_mac_slot_alloc,
		  { "MAC-slot Allocation", "gmr1.rr.pkt_imm_ass_3_prm.mac_slot_alloc",
		    FT_UINT8, BASE_HEX, NULL, 0xff,
		    "LSB=slot 0, MSB=slot 7", HFILL }
		},
		{ &hf_rr_pkt_freq_prm_arfcn,
		  { "ARFCN", "gmr1.rr.pkt_freq_prm.arfcn",
		    FT_UINT16, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_freq_prm_dl_freq_plan_id,
		  { "Downlink Freq. Plan ID", "gmr1.rr.pkt_freq_prm.dl_freq_plan_id",
		    FT_UINT8, BASE_DEC, VALS(rr_pkt_freq_prm_dl_freq_plan_id_vals), 0x08,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_freq_prm_dl_bw,
		  { "Downlink Bandwidth", "gmr1.rr.pkt_freq_prm.dl_bw",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_pkt_freq_prm_xx_bw_fmt), 0x70,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_freq_prm_ul_freq_dist,
		  { "Uplink Freq. Distance", "gmr1.rr.pkt_freq_prm.ul_freq_dist",
		    FT_INT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_freq_prm_ul_bw,
		  { "Uplink Bandwidth", "gmr1.rr.pkt_freq_prm.ul_bw",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_pkt_freq_prm_xx_bw_fmt), 0x70,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_freq_prm_spare,
		  { "Spare", "gmr1.rr.pkt_freq_prm.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_spare1,
		  { "Spare", "gmr1.rr.pkt_imm_ass_2_prm.ac.spare1",
		    FT_UINT8, BASE_DEC, NULL, 0x01,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_final_alloc,
		  { "Final Allocation", "gmr1.rr.pkt_imm_ass_2_prm.ac.final_alloc",
		    FT_UINT8, BASE_DEC, NULL, 0x02,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_usf_granularity,
		  { "USF Granularity", "gmr1.rr.pkt_imm_ass_2_prm.ac.usf_granularity",
		    FT_UINT8, BASE_DEC, NULL, 0x04,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_dl_ctl_mac_slot,
		  { "Downlink Control MAC-slot", "gmr1.rr.pkt_imm_ass_2_prm.ac.dl_ctl_mac_slot",
		    FT_UINT8, BASE_DEC, NULL, 0x38,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_mac_mode,
		  { "MAC mode", "gmr1.rr.pkt_imm_ass_2_prm.ac.mac_mode",
		    FT_UINT8, BASE_DEC, VALS(rr_pkt_imm_ass_2_prm_ac_mac_mode_vals), 0xc0,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_start_fn,
		  { "Starting Frame Number", "gmr1.rr.pkt_imm_ass_2_prm.ac.start_fn",
		    FT_UINT8, BASE_DEC, NULL, 0x0f,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_rlc_dblk_gnt,
		  { "RLC Data Blocks Granted", "gmr1.rr.pkt_imm_ass_2_prm.ac.rlc_dblk_gnt",
		    FT_UINT8, BASE_DEC, NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_mcs,
		  { "MCS", "gmr1.rr.pkt_imm_ass_2_prm.ac.mcs",
		    FT_UINT8, BASE_DEC, NULL, 0xf8,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_tfi,
		  { "TFI", "gmr1.rr.pkt_imm_ass_2_prm.ac.tfi",
		    FT_UINT8, BASE_HEX, NULL, 0x7f,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_spare2,
		  { "Spare", "gmr1.rr.pkt_imm_ass_2_prm.ac.spare2",
		    FT_UINT8, BASE_HEX, NULL, 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_ac_mac_slot_alloc,
		  { "MAC-slot Allocation", "gmr1.rr.pkt_imm_ass_2_prm.ac.mac_slot_alloc",
		    FT_UINT8, BASE_HEX, NULL, 0xff,
		    "LSB=slot 0, MSB=slot 7", HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_chan_mcs_cmd,
		  { "Channel MCS Command", "gmr1.rr.pkt_imm_ass_2_prm.d.chan_mcs_cmd",
		    FT_UINT8, BASE_HEX, NULL, 0x0f,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_chan_mcs_cmd_pnb512,
		  { "Channel MCS Command PNB 5,12", "gmr1.rr.pkt_imm_ass_2_prm.d.chan_mcs_cmd_pnb512",
		    FT_UINT8, BASE_HEX, NULL, 0xf0,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_spare1,
		  { "Spare", "gmr1.rr.pkt_imm_ass_2_prm.d.spare1",
		    FT_UINT8, BASE_HEX, NULL, 0xff,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_rlc_dblk_gnt,
		  { "RLC Data Blocks Granted", "gmr1.rr.pkt_imm_ass_2_prm.d.rlc_dblk_gnt",
		    FT_UINT8, BASE_DEC, NULL, 0x7f,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_spare2,
		  { "Spare", "gmr1.rr.pkt_imm_ass_2_prm.d.spare2",
		    FT_UINT8, BASE_HEX, NULL, 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_tfi,
		  { "TFI", "gmr1.rr.pkt_imm_ass_2_prm.d.tfi",
		    FT_UINT8, BASE_HEX, NULL, 0x7f,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_usf_granularity,
		  { "USF Granularity", "gmr1.rr.pkt_imm_ass_2_prm.ac.usf_granularity",
		    FT_UINT8, BASE_DEC, NULL, 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_imm_ass_2_prm_d_mac_slot_alloc,
		  { "MAC-slot Allocation", "gmr1.rr.pkt_imm_ass_2_prm.d.mac_slot_alloc",
		    FT_UINT8, BASE_HEX, NULL, 0xff,
		    "LSB=slot 0, MSB=slot 7", HFILL }
		},
		{ &hf_rr_usf_value,
		  { "Uplink state flag (USF)", "gmr1.rr.usf.value",
		    FT_UINT8, BASE_HEX, NULL, 0x3f,
		    NULL, HFILL }
		},
		{ &hf_rr_usf_spare,
		  { "Spare", "gmr1.rr.usf.spare",
		    FT_UINT24, BASE_DEC, NULL, 0xffffc0,
		    NULL, HFILL }
		},
		{ &hf_rr_timing_adv_idx_value,
		  { "TAI Value", "gmr1.rr.timing_adv_idx.tai",
		    FT_UINT8, BASE_DEC, NULL, 0x7f,
		    NULL, HFILL }
		},
		{ &hf_rr_timing_adv_idx_spare,
		  { "Spare", "gmr1.rr.timing_adv_idx.spare",
		    FT_UINT8, BASE_DEC, NULL, 0x80,
		    NULL, HFILL }
		},
		{ &hf_rr_tlli,
		  { "TLLI", "gmr1.rr.tlli",
		    FT_UINT32, BASE_HEX,  NULL, 0x00,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_pwr_ctrl_prm_par,
		  { "Power Attenuation Request (PAR)", "gmr1.rr.pkt_pwr_ctrl_prm.par",
		    FT_UINT8, BASE_CUSTOM, CF_FUNC(rr_pkt_pwr_ctrl_prm_par_fmt), 0x3f,
		    NULL, HFILL }
		},
		{ &hf_rr_pkt_pwr_ctrl_prm_spare,
		  { "Spare", "gmr1.rr.pkt_pwr_ctrl_prm.spare",
		    FT_UINT8, BASE_DEC, NULL, 0xc0,
		    NULL, HFILL }
		},
		{ &hf_rr_persistence_lvl[0],
		  { "for Radio priority 1", "gmr1.rr.persistence_lvl.p1",
		    FT_UINT8, BASE_DEC, NULL, 0xf0,
		    NULL, HFILL }
		},
		{ &hf_rr_persistence_lvl[1],
		  { "for Radio priority 2", "gmr1.rr.persistence_lvl.p2",
		    FT_UINT8, BASE_DEC, NULL, 0x0f,
		    NULL, HFILL }
		},
		{ &hf_rr_persistence_lvl[2],
		  { "for Radio priority 3", "gmr1.rr.persistence_lvl.p3",
		    FT_UINT8, BASE_DEC, NULL, 0xf0,
		    NULL, HFILL }
		},
		{ &hf_rr_persistence_lvl[3],
		  { "for Radio priority 4", "gmr1.rr.persistence_lvl.p4",
		    FT_UINT8, BASE_DEC, NULL, 0x0f,
		    NULL, HFILL }
		},
		{ &hf_rr_protocol_discriminator,
		  { "Protocol Discriminator", "gmr1.rr.protocol_discriminator",
			FT_UINT8, BASE_DEC, VALS(gmr1_pd_vals), 0x0,
			NULL, HFILL }
		},
		{ &hf_rr_message_elements,
		  { "Message elements", "gmr1.rr.message_elements",
			FT_BYTES, BASE_NONE, NULL, 0x0,
			NULL, HFILL }
		},
	};

	static ei_register_info ei[] = {
		{ &ei_gmr1_missing_mandatory_element, { "gmr1.rr.missing_mandatory_element", PI_PROTOCOL, PI_ERROR, "Missing Mandatory element, rest of dissection is suspect", EXPFILL }},
	};

	expert_module_t* expert_gmr1_rr;

#define NUM_INDIVIDUAL_ELEMS 2
	static gint *ett[NUM_INDIVIDUAL_ELEMS +
	                 NUM_GMR1_IE_RR +
	                 NUM_GMR1_MSG_RR];

	unsigned int last_offset, i;

	/* Setup protocol subtree array */
	ett[0] = &ett_msg_ccch;
	ett[1] = &ett_rr_pd;

	last_offset = NUM_INDIVIDUAL_ELEMS;

	for (i=0; i<NUM_GMR1_IE_RR; i++,last_offset++) {
		ett_gmr1_ie_rr[i] = -1;
		ett[last_offset] = &ett_gmr1_ie_rr[i];
	}

	for (i=0; i<NUM_GMR1_MSG_RR; i++,last_offset++) {
		ett_msg_rr[i] = -1;
		ett[last_offset] = &ett_msg_rr[i];
	}

	proto_register_subtree_array(ett, array_length(ett));

	/* Register the protocol name and field description */
	proto_gmr1_rr = proto_register_protocol("GEO-Mobile Radio (1) RR", "GMR-1 RR", "gmr1.rr");

	proto_register_field_array(proto_gmr1_rr, hf, array_length(hf));

	expert_gmr1_rr = expert_register_protocol(proto_gmr1_rr);
	expert_register_field_array(expert_gmr1_rr, ei, array_length(ei));

	/* Register the protocol name and field description */
	proto_gmr1_ccch = proto_register_protocol("GEO-Mobile Radio (1) CCCH", "GMR-1 CCCH", "gmr1.ccch");

	/* Register dissector */
	register_dissector("gmr1_ccch", dissect_gmr1_ccch, proto_gmr1_ccch);
}

/*
 * 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:
 */