summaryrefslogtreecommitdiffstats
path: root/fakebts/RSLMsg.st
blob: 1807baf993e538631e1fb91798f058044a7d08e5 (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
"
 (C) 2012 by Holger Hans Peter Freyther
 All Rights Reserved

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
"

PackageLoader fileInPackage: #OsmoGSM.

Iterable extend [
    asRSLAttributeData [
        <category: '*-BTS-OML-Msg'>
        ^ RSLAttributeData new
            data: self; yourself
    ]
]

Osmo.TLVDescription class extend [
    newRSLDescription [
        <category: '*-BTS-RSL-Msg'>
        ^self new
            beForceTagged;
            yourself
    ]
]

Osmo.TLVParserBase subclass: RSLMessageBase [
    <category: 'BTS-RSL'>
    <comment: 'I am the base of all RSL messages. I follow GSM 08.58'>

    RSLMessageBase class [
        | messageType messageDefinition |

        messageType     [
            <category: 'tlv'>
            ^ self perform: messageType
        ]

        tlvDescription  [
            <category: 'tlv'>
            ^ RSLMessageDefinitions perform: messageDefinition
        ]

        rslMessageType: aType [
            <category: 'init'>
            messageType := aType asSymbol
        ]

        rslMessageDefinition: aDef [
            messageDefinition := aDef asSymbol
        ]
    ]

    RSLMessageBase class [
        discriminatorMask       [ <category: 'discriminator'> ^ 2r11111110 ]
        discriminatorReserved   [ <category: 'discriminator'> ^ 2r0000000 ]
        discriminatorRadioLink  [ <category: 'discriminator'> ^ 2r0000001 ]
        discriminatorDedicated  [ <category: 'discriminator'> ^ 2r0000100 ]
        discriminatorCommon     [ <category: 'discriminator'> ^ 2r0000110 ]
        discriminatorTRX        [ <category: 'discriminator'> ^ 2r0001000 ]
        discriminatorLCS        [ <category: 'discriminator'> ^ 2r0010000 ]
    ]

    RSLMessageBase class [
        messageRadioLinkMask                [ <category: 'msg-radio-link'> ^ 2r00001111 ]
        messageRadioLinkDataRequest         [ <category: 'msg-radio-link'> ^ 2r00000001 ]
        messageRadioLinkDataIndication      [ <category: 'msg-radio-link'> ^ 2r00000010 ]
        messageRadioLinkErrorIndication     [ <category: 'msg-radio-link'> ^ 2r00000011 ]
        messageRadioLinkEstablishRequest    [ <category: 'msg-radio-link'> ^ 2r00000100 ]
        messageRadioLinkEstablishConfirm    [ <category: 'msg-radio-link'> ^ 2r00000101 ]
        messageRadioLinkEstablishIndication [ <category: 'msg-radio-link'> ^ 2r00000110 ]
        messageRadioLinkReleaseRequest      [ <category: 'msg-radio-link'> ^ 2r00000111 ]
        messageRadioLinkReleaseConfirm      [ <category: 'msg-radio-link'> ^ 2r00001000 ]
        messageRadioLinkReleaseIndication   [ <category: 'msg-radio-link'> ^ 2r00001001 ]
        messageRadioLinkUnitDataRequest     [ <category: 'msg-radio-link'> ^ 2r00001010 ]
        messageRadioLinkUnitDataIndication  [ <category: 'msg-radio-link'> ^ 2r00001011 ]

        messageTrxMask                      [ <category: 'msg-trx-mgmnt'> ^ 2r00011111 ]
        messageTrxBcchInformation           [ <category: 'msg-trx-mgmnt'> ^ 2r00010001 ] 
        messageTrxCcchLoadIndication        [ <category: 'msg-trx-mgmnt'> ^ 2r00010010 ]
        messageTrxChannelRequired           [ <category: 'msg-trx-mgmnt'> ^ 2r00010011 ]
        messageTrxDeletingIndication        [ <category: 'msg-trx-mgmnt'> ^ 2r00010100 ]
        messageTrxPagingCommand             [ <category: 'msg-trx-mgmnt'> ^ 2r00010101 ]
        messageTrxImmediateAssignCommand    [ <category: 'msg-trx-mgmnt'> ^ 2r00010110 ]
        messageTrxSmsBroadcastRequest       [ <category: 'msg-trx-mgmnt'> ^ 2r00010111 ]
        messageTrxRfResourceIndication      [ <category: 'msg-trx-mgmnt'> ^ 2r00011001 ]
        messageTrxSacchFilling              [ <category: 'msg-trx-mgmnt'> ^ 2r00011010 ]
        messageTrxOverload                  [ <category: 'msg-trx-mgmnt'> ^ 2r00011011 ]
        messageTrxErrorReport               [ <category: 'msg-trx-mgmnt'> ^ 2r00011100 ]
        messageTrxSmsBroadcastCommand       [ <category: 'msg-trx-mgmnt'> ^ 2r00011101 ]
        messageTrxCbchLoadIndication        [ <category: 'msg-trx-mgmnt'> ^ 2r00011110 ]
        messageTrxNotificationCommand       [ <category: 'msg-trx-mgmnt'> ^ 2r00011111 ]

        messageDedChannelActication         [ <category: 'msg-ded-mgmnt'> ^ 2r00100001 ]
        messageDedChannelActivationAck      [ <category: 'msg-ded-mgmnt'> ^ 2r00100010 ]
        messageDedChannelActivationNack     [ <category: 'msg-ded-mgmnt'> ^ 2r00100011 ]
        messageDedConnectionFailure         [ <category: 'msg-ded-mgmnt'> ^ 2r00100100 ]
        messageDedDeactivateSacch           [ <category: 'msg-ded-mgmnt'> ^ 2r00100101 ]
        messageDedEncryptionCommand         [ <category: 'msg-ded-mgmnt'> ^ 2r00100110 ]
        messageDedHandoverDetection         [ <category: 'msg-ded-mgmnt'> ^ 2r00100111 ]
        messageDedMeasurementResult         [ <category: 'msg-ded-mgmnt'> ^ 2r00101000 ]
        messageDedModeModifyRequest         [ <category: 'msg-ded-mgmnt'> ^ 2r00101001 ]
        messageDedModeModifyAck             [ <category: 'msg-ded-mgmnt'> ^ 2r00101010 ]
        messageDedModeModifyNack            [ <category: 'msg-ded-mgmnt'> ^ 2r00101011 ]
        messageDedPhysicalContextRequest    [ <category: 'msg-ded-mgmnt'> ^ 2r00101100 ]
        messageDedPhysicalContextConfirm    [ <category: 'msg-ded-mgmnt'> ^ 2r00101101 ]
        messageDedRfChannelRelease          [ <category: 'msg-ded-mgmnt'> ^ 2r00101110 ]
        messageDedMsPowerControl            [ <category: 'msg-ded-mgmnt'> ^ 2r00101111 ]
        messageDedBsPowerControl            [ <category: 'msg-ded-mgmnt'> ^ 2r00110000 ]
        messageDedPreprocessConfigure       [ <category: 'msg-ded-mgmnt'> ^ 2r00110001 ]
        messageDedPreprocessedMeasureResult [ <category: 'msg-ded-mgmnt'> ^ 2r00110010 ]
        messageDedRfChannelReleaseAck       [ <category: 'msg-ded-mgmnt'> ^ 2r00110011 ]
        messageDedSacchInfoModify           [ <category: 'msg-ded-mgmnt'> ^ 2r00110100 ]
        messageDedTalkerDetection           [ <category: 'msg-ded-mgmnt'> ^ 2r00110101 ]
        messageDedListenerDetection         [ <category: 'msg-ded-mgmnt'> ^ 2r00110110 ]
        messageDedRemoteCodecConfigReport   [ <category: 'msg-ded-mgmnt'> ^ 2r00110111 ]
        messageDedRoundTripDelayReport      [ <category: 'msg-ded-mgmnt'> ^ 2r00111000 ]
        messageDedPreHandOverNotification   [ <category: 'msg-ded-mgmnt'> ^ 2r00111001 ]
        messageDedMultirateCodecModRequest  [ <category: 'msg-ded-mgmnt'> ^ 2r00111010 ]
        messageDedMultirateCodecModAck      [ <category: 'msg-ded-mgmnt'> ^ 2r00111011 ]
        messageDedMultirateCodecModNack     [ <category: 'msg-ded-mgmnt'> ^ 2r00111100 ]
        messageDedMultirateCodedModPerformed[ <category: 'msg-ded-mgmnt'> ^ 2r00111101 ]
        messageDedTfoReport                 [ <category: 'msg-ded-mgmnt'> ^ 2r00111110 ]
        messageDedTfoModificationRequest    [ <category: 'msg-ded-mgmnt'> ^ 2r00111111 ]
    ]

    RSLMessageBase class >> parse: aStream [
        | discrim transp type |
        <category: 'parsing'>

        transp := aStream peek bitAnd: 2r1.
        discrim := aStream next bitShift: -1.
        type := aStream next.

        self allSubclassesDo: [:each |
            (each canHandle: discrim transparent: transp type: type) ifTrue: [
                    | res |
                    res := each readFrom: aStream.
                    aStream atEnd ifFalse: [
                        aStream upToEnd printNl.
                        ^self error: 'Message was not fully parsed.'].
                    ^ res.
            ].
        ].

        ^ self error: 'Did not find a handler for messgae type: ', type displayString.
    ]

    RSLMessageBase class >> ignoredBaseClasses [
        <category: 'handling'>
        ^ {RSLCommonChannelManagement. RSLTRXManagement.
           RSLDedicatedChannelManagement. RSLRadioLinkManagement. RSLIPAVendorManagement}
    ]

    RSLMessageBase class >> canHandle: aDiscrim transparent: aTrans type: aType [
        <category: 'parsing'>

        "Ignore the common base classes."
        (self ignoredBaseClasses includes: self)
            ifTrue: [^false].

        "Check if discriminator, transparency (asnumber) and messageType match"
        aDiscrim = self messageDiscrimator
            ifFalse: [^false].
        aTrans = self isTransparent
            ifFalse: [^false].
        aType = self messageType
            ifFalse: [^false].
        ^ true.
    ]

    RSLMessageBase class >> readFrom: aStream [
        | rsl |
        <category: 'parsing'>
        rsl := self new.

        self tlvDescription do: [:each | | tag |
            tag := aStream peek.

            each isMandatory
                ifTrue: [rsl parseMandatory: each tag: tag stream: aStream].
            each isConditional
                ifTrue: [rsl parseConditional: each tag: tag stream: aStream].
            each isOptional
                ifTrue: [rsl parseOptional: each tag: tag stream: aStream].
        ].

        ^ rsl.
    ]

    writeHeaderOn: aMsg [
        | disc |
        <category: 'serialize'>
        disc := self class messageDiscrimator bitShift: 1.
        disc := disc bitOr: self class isTransparent.
        aMsg
            putByte: disc;
            putByte: self class messageType.
    ]
]

Object subclass: RSLInformationElement [
    <category: 'BTS-RSL'>
    <comment: 'I represent the base class of all RSL IEs'>

    RSLInformationElement class [
        attrChannelNumber                 [ <category: 'ie'> ^ 2r00000001 ]
        attrLinkIdentifier                [ <category: 'ie'> ^ 2r00000010 ]
        attrActivationType                [ <category: 'ie'> ^ 2r00000011 ]
        attrBSPower                       [ <category: 'ie'> ^ 2r00000100 ]
        attrChannelIdentification         [ <category: 'ie'> ^ 2r00000101 ]
        attrChannelMode                   [ <category: 'ie'> ^ 2r00000110 ]
        attrEncryptionInformation         [ <category: 'ie'> ^ 2r00000111 ]
        attrFrameNumber                   [ <category: 'ie'> ^ 2r00001000 ]
        attrHandoverReference             [ <category: 'ie'> ^ 2r00001001 ]
        attrL1Information                 [ <category: 'ie'> ^ 2r00001010 ]
        attrL3Information                 [ <category: 'ie'> ^ 2r00001011 ]
        attrMSIdentifty                   [ <category: 'ie'> ^ 2r00001100 ]
        attrMSPower                       [ <category: 'ie'> ^ 2r00001101 ]
        attrPagingGroup                   [ <category: 'ie'> ^ 2r00001110 ]
        attrPagingLoad                    [ <category: 'ie'> ^ 2r00001111 ]
        attrPhysicalContext               [ <category: 'ie'> ^ 2r00010000 ]
        attrAccessDelay                   [ <category: 'ie'> ^ 2r00010001 ]
        attrRACHLoad                      [ <category: 'ie'> ^ 2r00010010 ]
        attrRequestReference              [ <category: 'ie'> ^ 2r00010011 ]
        attrReleaseMode                   [ <category: 'ie'> ^ 2r00010100 ]
        attrResourceInformation           [ <category: 'ie'> ^ 2r00010101 ]
        attrRLMCause                      [ <category: 'ie'> ^ 2r00010110 ]
        attrStartingTime                  [ <category: 'ie'> ^ 2r00010111 ]
        attrTimingAdvance                 [ <category: 'ie'> ^ 2r00011000 ]
        attrUplinkMeasurements            [ <category: 'ie'> ^ 2r00011001 ]
        attrCause                         [ <category: 'ie'> ^ 2r00011010 ]
        attrMeasurementResultNumber       [ <category: 'ie'> ^ 2r00011011 ]
        attrMessageIdentifier             [ <category: 'ie'> ^ 2r00011100 ]
        attrReserved1                     [ <category: 'ie'> ^ 2r00011101 ]
        attrSystemInfoType                [ <category: 'ie'> ^ 2r00011110 ]
        attrMSPowerParameters             [ <category: 'ie'> ^ 2r00011111 ]
        attrBSPowerParameters             [ <category: 'ie'> ^ 2r00100000 ]
        attrPreprocessingParameters       [ <category: 'ie'> ^ 2r00100001 ]
        attrPreprocessingMeasurements     [ <category: 'ie'> ^ 2r00100010 ]
        attrReserved2                     [ <category: 'ie'> ^ 2r00100011 ]
        attrSmsCBInformation              [ <category: 'ie'> ^ 2r00100100 ]
        attrMsTimingOffset                [ <category: 'ie'> ^ 2r00100101 ]
        attrErroneousMeasure              [ <category: 'ie'> ^ 2r00100110 ]
        attrFullBcchInformation           [ <category: 'ie'> ^ 2r00100111 ]
        attrChannelNeeded                 [ <category: 'ie'> ^ 2r00101000 ]
        attrCbCommandType                 [ <category: 'ie'> ^ 2r00101001 ]
        attrSmsCbMessage                  [ <category: 'ie'> ^ 2r00101010 ]
        attrFullImmediateAssignInfo       [ <category: 'ie'> ^ 2r00101011 ]
        attrSacchInformation              [ <category: 'ie'> ^ 2r00101100 ]
        attrCbchLoadInformation           [ <category: 'ie'> ^ 2r00101101 ]
        attrSmsCbChannelIndicator         [ <category: 'ie'> ^ 2r00101110 ]
        attrGroupCallReference            [ <category: 'ie'> ^ 2r00101111 ]
        attrChannelDescription            [ <category: 'ie'> ^ 2r00110000 ]
        attrNchDrxInformation             [ <category: 'ie'> ^ 2r00110001 ]
        attrCommandIndicator              [ <category: 'ie'> ^ 2r00110010 ]
        attreMLPPPriority                 [ <category: 'ie'> ^ 2r00110011 ]
        attrUIC                           [ <category: 'ie'> ^ 2r00110100 ]
        attrMainChannelReference          [ <category: 'ie'> ^ 2r00110101 ]
        attrMultiRateConfiguration        [ <category: 'ie'> ^ 2r00110110 ]
        attrMultiRateControl              [ <category: 'ie'> ^ 2r00110111 ]
        attrSupportedCodecTypes           [ <category: 'ie'> ^ 2r00111000 ]
        attrCodecConfiguration            [ <category: 'ie'> ^ 2r00111001 ]
        attrRoundTripDelay                [ <category: 'ie'> ^ 2r00111010 ]
        attrTFOStatus                     [ <category: 'ie'> ^ 2r00111011 ]
        attrLLPAPDU                       [ <category: 'ie'> ^ 2r00111100 ]
    ]
]

Object subclass: RSLMessageDefinitions [
    <category: 'BTS-RSL'>
    <comment: 'I represent all TLV descriptions for (all) RSL messages.'>

    RSLMessageDefinitions class [
        channelNumberIE [
            <category: 'common-ie'>
            ^ Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrChannelNumber;
                  instVarName: #channel_number; parseClass: RSLChannelNumber;
                  beTV; valueSize: 1; yourself.
        ]

        linkIdentifierIE [
            <category: 'common-ie'>
            ^ Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrLinkIdentifier;
                  instVarName: #link_id; parseClass: RSLAttributeData;
                  beTV; valueSize: 1; yourself
        ]

        l3InfoIE [
            <category: 'common-ie'>
            ^Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrL3Information;
                  instVarName: #l3_info; parseClass: RSLAttributeData;
                  beTLV; beLen16; yourself
        ]

	causeIE [
            <category: 'common-ie'>
	    ^ Osmo.TLVDescription newRSLDescription
                tag: RSLInformationElement attrCause;
                instVarName: #cause; parseClass: RSLAttributeData;
                beTLV; minSize: 1; yourself
	]

        radioLinkMessageBase [
            <category: 'radio-link'>
            ^ OrderedCollection new
                add: self channelNumberIE;
                add: self linkIdentifierIE;
                yourself
        ]

        dataRequestMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
                add: self l3InfoIE;
                yourself
        ]

        dataIndicationMessage [
            <category: 'radio-link'>
            ^ self dataRequestMessage
        ]

        errorIndicationMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrRLMCause;
                  instVarName: #rlm_cause; parseClass: RSLAttributeData;
                  beTLV; minSize: 0 maxSize: 2; yourself);
                yourself
        ]

        establishRequestMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
        ]

        establishConfirmMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
        ]

        establishIndicationMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrL3Information;
                  instVarName: #l3_info; parseClass: RSLAttributeData;
                  beTLV; beOptional; beLen16; yourself);
                yourself
        ]

        releaseConfirmMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
        ]

        releaseIndicationMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
        ]

        releaseRequestMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrReleaseMode;
                  instVarName: #release_mode; parseClass: RSLAttributeData;
                  beTV; valueSize: 1; yourself);
                yourself
        ]

        unitDataRequestMessage [
            <category: 'radio-link'>
            ^ self radioLinkMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrL3Information;
                  instVarName: #l3_info; parseClass: RSLAttributeData;
                  minSize: 1 maxSize: 23;
                  beTLV; yourself);
                yourself
        ]

        unitDataIndicationMessage [
            <category: 'radio-link'>
            ^ self unitDataRequestMessage
        ]

        dedicatedChannelMessageBase [
            <category: 'dedicated-channel'>
            ^ OrderedCollection new
                add: self channelNumberIE;
                yourself
        ]

        channelActivationMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrActivationType;
                  instVarName: #activation_type; parseClass: RSLAttributeData;
                  beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrChannelMode;
                  instVarName: #channel_mode; parseClass: RSLAttributeData;
                  beTLV; minSize: 6 maxSize: 7; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrChannelIdentification;
                  instVarName: #channel_ident; parseClass: RSLAttributeData;
                  beOptional; beTLV; valueSize: 6; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrEncryptionInformation;
                  instVarName: #encr_info; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrHandoverReference;
                  instVarName: #handover_ref; parseClass: RSLAttributeData;
                  beConditional; beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrBSPower;
                  instVarName: #bs_power; parseClass: RSLAttributeData;
                  beOptional; beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrMSPower;
                  instVarName: #ms_power; parseClass: RSLAttributeData;
                  beOptional; beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrTimingAdvance;
                  instVarName: #timing_advance; parseClass: RSLAttributeData;
                  beConditional; beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrBSPowerParameters;
                  instVarName: #bs_powerparams; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 0; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrMSPowerParameters;
                  instVarName: #ms_powerparams; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 0; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrPhysicalContext;
                  instVarName: #physical_context; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 0; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrSacchInformation;
                  instVarName: #sacch_information; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrUIC;
                  instVarName: #uic; parseClass: RSLAttributeData;
                  beOptional; beTLV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrMainChannelReference;
                  instVarName: #main_chan_ref; parseClass: RSLAttributeData;
                  beOptional; beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrMultiRateConfiguration;
                  instVarName: #mr_conf; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 2; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrMultiRateControl;
                  instVarName: #mr_control; parseClass: RSLAttributeData;
                  beOptional; beTV; valueSize: 2; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrSupportedCodecTypes;
                  instVarName: #supported_codecs; parseClass: RSLAttributeData;
                  beOptional; beTLV; minSize: 3; yourself);
                yourself.
        ]

        channelActivationAckMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrFrameNumber;
                  instVarName: #frame_number; parseClass: RSLAttributeData;
                  beTV; valueSize: 2; yourself);
                yourself
        ]

        channelActivationNackMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
              add: self causeIE;
              yourself
        ]

        connectionFailureIndicationMessage [
            <category: 'dedicated-channel'>
            ^ self channelActivationNackMessage
        ]

        deactivateSacchMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
        ]

	handoverDetectionMessage [
	    <category: 'dedicated-channel'>
	    ^ self dedicatedChannelMessageBase
		add: (Osmo.TLVDescription newRSLDescription
		    tag: RSLInformationElement attrAccessDelay;
		    instVarName: #access_delay; parseClass: RSLAttributeData;
		    beOptional; beTV; valueSize: 1; yourself);
		yourself
	]

	modeModifyMessage [
	    <category: 'dedicated-channel'>
	    ^ self dedicatedChannelMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrChannelMode;
                  instVarName: #channel_mode; parseClass: RSLAttributeData;
                  beTLV; minSize: 6 maxSize: 7; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		  tag: RSLInformationElement attrEncryptionInformation;
		  instVarName: #encr_info; parseClass: RSLAttributeData;
		  beOptional; beTLV; minSize: 1; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		  tag: RSLInformationElement attrMainChannelReference;
		  instVarName: #main_channel; parseClass: RSLAttributeData;
		  beOptional; beTV; minSize: 1; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		  tag: RSLInformationElement attrMultiRateConfiguration;
		  instVarName: #mr; parseClass: RSLAttributeData;
		  beOptional; beTLV; minSize: 1; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		  tag: RSLInformationElement attrMultiRateControl;
		  instVarName: #mr_control; parseClass: RSLAttributeData;
		  beOptional; beTV; valueSize: 1; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		  tag: RSLInformationElement attrSupportedCodecTypes;
		  instVarName: #codec; parseClass: RSLAttributeData;
		  beOptional; beTLV; minSize: 3; yourself);
		yourself.
	]

	modeModifyAck [
	    <category: 'dedicated-channel'>
	    ^ self dedicatedChannelMessageBase
	]

	modeModifyNack [
	    <category: 'dedicated-channel'>
	    ^ self dedicatedChannelMessageBase
              add: (Osmo.TLVDescription newRSLDescription
                tag: RSLInformationElement attrCause;
                instVarName: #cause; parseClass: RSLAttributeData;
                beTLV; minSize: 1; yourself);
	     yourself
	]

        encryptionCommandMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrEncryptionInformation;
                  instVarName: #encr_info; parseClass: RSLAttributeData;
                  beTLV; minSize: 1; yourself);
                add: self linkIdentifierIE;
                add: (self l3InfoIE minSize: 4 maxSize: 4; yourself);
                yourself.
        ]

        rfChannelReleaseMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
        ]

        rfChannelReleaseAckMessage [
            <category: 'dedicated-channel'>
            ^ self dedicatedChannelMessageBase
        ]

        commonChannelManagementBase [
            <category: 'channel-management'>
            ^ OrderedCollection new
                add: self channelNumberIE;
                yourself
        ]

        bcchInformationMessage [
            <category: 'channel-management'>
            ^ self commonChannelManagementBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrSystemInfoType;
                  instVarName: #si_type; parseClass: RSLAttributeData;
                  beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrFullBcchInformation;
                  instVarName: #full_bcch; parseClass: RSLAttributeData;
                  beOptional; beTLV; valueSize: 23; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrStartingTime;
                  instVarName: #start_time; parseClass: RSLAttributeData;
                  beOptional; beTV; valueSize: 1; yourself);
                yourself
        ]

	pagingCommandMessage [
	    <category: 'channel-management'>
	    ^ self commonChannelManagementBase
		add: (Osmo.TLVDescription newRSLDescription
		 tag: RSLInformationElement attrPagingGroup;
		 instVarName: #paging_group; parseClass: RSLAttributeData;
		 beTV; valueSize: 1; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		 tag: RSLInformationElement attrMSIdentifty;
		 instVarName: #ms_identity; parseClass: RSLAttributeData;
		 beTLV; minSize: 1 maxSize: 9; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		 tag: RSLInformationElement attrChannelNeeded;
		 instVarName: #channel_needed; parseClass: RSLAttributeData;
		 beOptional; beTV; valueSize: 1; yourself);
		add: (Osmo.TLVDescription newRSLDescription
		 tag: RSLInformationElement attreMLPPPriority;
		 instVarName: #emlpp;
		 beOptional; beTV; valueSize: 2; yourself);
		yourself.
	]

        immediateAssignCommandMessage [
            <category: 'channel-management'>
            ^ self commonChannelManagementBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrFullImmediateAssignInfo;
                  instVarName: #full_info; parseClass: RSLAttributeData;
                  beOptional; beTLV; valueSize: 23; yourself);
                yourself
        ]

        channelRequiredMessage [
            <category: 'channel-management'>
            ^ self commonChannelManagementBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrRequestReference;
                  instVarName: #request_reference; parseClass: RSLAttributeData;
                  beTV; valueSize: 3; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrAccessDelay;
                  instVarName: #access_delay; parseClass: RSLAttributeData;
                  beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrPhysicalContext;
                  instVarName: #physical_context; parseClass: RSLAttributeData;
                  beTLV; minSize: 0; beOptional; yourself);
                yourself
        ]

        trxManagementMessageBase [
            <category: 'trx-management'>
            ^ OrderedCollection new
        ]

        sacchFillingMessage [
            <category: 'trx-management'>
            ^ self trxManagementMessageBase
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrSystemInfoType;
                  instVarName: #si_type; parseClass: RSLAttributeData;
                  beTV; valueSize: 1; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrL3Information;
                  instVarName: #l3_info; parseClass: RSLAttributeData;
                  beOptional; beTLV; beLen16; valueSize: 20; yourself);
                add: (Osmo.TLVDescription newRSLDescription
                  tag: RSLInformationElement attrStartingTime;
                  instVarName: #start_time; parseClass: RSLAttributeData;
                  beOptional; beTV; valueSize: 1; yourself);
                yourself
        ]
    ]
]

RSLInformationElement subclass: RSLAttributeData [
    | data |
    <category: 'RSL-OML'>
    <comment: 'I am a dummy holder for a plain byte array'>

    RSLAttributeData class >> readFrom: aStream with: anAttr [
        | size |
        size := anAttr hasLength
                  ifTrue: [size := self parseLength: aStream with: anAttr]
                  ifFalse: [anAttr valueSize].

        ^ self new
            data: (aStream next: size);
            yourself
    ]

    RSLAttributeData class >> parseLength: aStream with: anAttr [
        <category: 'parsing'>
        "L3 Information has a 16bit length.. for whatever reason"
        ^ anAttr isLen16
              ifTrue: [((aStream next: 2) asByteArray ushortAt: 1) swap16]
              ifFalse: [aStream next].
    ]

    data [
        <category: 'parsing'>
        ^ data
    ]

    data: aData [
        <category: 'parsing'>
        data := aData
    ]

    writeOn: aMsg with: attr [
        <category: 'serialize'>

        "Sanity checking"
        attr isFixedSize ifTrue: [
            data size = attr valueSize
                ifFalse: [^ self error: 'Element ', attr instVarName,
                              ' should be of size: ', attr valueSize printString.]
        ].

        "Write it out"
        attr isLen8 ifTrue: [aMsg putByte: data size].
        attr isLen16 ifTrue: [aMsg putLen16: data size].
        aMsg putByteArray: data.
    ]

    asRSLAttributeData [
        <category: 'conversion'>
        ^ self
    ]

    readStream [
        <category: 'reading'>
        ^ self data readStream
    ]
]

RSLAttributeData subclass: RSLChannelNumber [
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 Channel Number as of 9.3.1'>

    RSLChannelNumber class [
        cnBmAcch      [ <category: 'c-bits'> ^ 2r00001 ]
        cnLmAcch      [ <category: 'c-bits'> ^ 2r00010 ]
        cnSdcch4Acch  [ <category: 'c-bits'> ^ 2r00100 ]
        cnSdcch8Acch  [ <category: 'c-bits'> ^ 2r01000 ]
        cnBcch        [ <category: 'c-bits'> ^ 2r10000 ]
        cnRach        [ <category: 'c-bits'> ^ 2r10001 ]
        cnPchAgch     [ <category: 'c-bits'> ^ 2r10010 ]
    ]

    RSLChannelNumber class >> ccchRach [
        <category: 'creation'>
        ^ self new
            data: #(2r10001000)
            yourself.
    ]

    cBits [
        <category: 'C-bits-query'>
        ^ self data first bitShift: -3.
    ]

    testCBits: bits [
        | mask |
        <category: 'C-bits-query'>

        mask := bits.
        mask highBit to: 5 do: [:each | mask := mask bitAt: each put: 1].
        ^ (self cBits bitAnd: mask) = bits
        
    ]

    isBmAcch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnBmAcch.
    ]

    isLmAcch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnLmAcch.
    ]

    isSdcch4Acch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnSdcch4Acch.
    ]

    isSdcch8Acch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnSdcch8Acch.
    ]

    isBcch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnBcch.
    ]

    isRacch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnRach.
    ]

    isPchAgch [
        <category: 'C-bits-query'>
        ^ self testCBits: self class cnPchAgch.
    ]

    subslotNumber [
        | mask high |
        <category: 'subslot'>

        "Sanity checking"
        (self cBits bitAt: 5) = 1
            ifTrue: [^self error: 'No subslots on BCCH/RACCH/PCH'].

        "Now find the T-bits for the subslot"
        mask := self cBits.
        high := mask highBit.
        1 to: high - 1 do: [:each | mask := mask bitAt: each put: 1].
        high to: 5 do: [:each | mask := mask bitAt: each put: 0].
        ^ self cBits bitAnd: mask.
    ]
    
    timeslotNumber [
        <category: 'accessing'>
        ^ self data first bitAnd: 2r111
    ]
]

RSLMessageBase subclass: RSLCommonChannelManagement [
    | channel_number |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 8.5 Common Channel Management Message'>

    RSLCommonChannelManagement class >> messageDiscrimator [
        <category: 'parsing'>
        ^ self discriminatorCommon.
    ]

    RSLCommonChannelManagement class >> isTransparent [
        <category: 'parsing'>
        ^ 0
    ]

    channelNumber: aNumber [
        <category: 'creation'>
        channel_number := aNumber
    ]

    channelNumber [
        <category: 'accessing'>
        ^ channel_number
    ]
]

RSLCommonChannelManagement subclass: RSLChannelRequired [
    | request_reference access_delay physical_context |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.5.3 Channel Required Message.'>
    <rslMessageType: #messageTrxChannelRequired>
    <rslMessageDefinition: #channelRequiredMessage>

    requestReference: aRef [
        <category: 'creation'>
        request_reference := aRef.
    ]

    accessDelay: aDelay [
        <category: 'creation'>
        access_delay := aDelay
    ]
]

RSLCommonChannelManagement subclass: RSLBCCHInformation [
    | si_type full_bcch start_time |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.5.1 BCCH Information Message.'>
    <rslMessageType: #messageTrxBcchInformation>
    <rslMessageDefinition: #bcchInformationMessage>
]

RSLCommonChannelManagement subclass: RSLPagingCommand [
    | paging_group ms_identity channel_needed emlpp |

    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.5.5'>
    <rslMessageType: #messageTrxPagingCommand>
    <rslMessageDefinition: #pagingCommandMessage>

    pagingGroup [
	<category: 'accessing'>
	^ paging_group
    ]

    msIdenity [
	<category: 'accessing'>
	^ OsmoGSM.GSM48MIdentity
		parseFrom: ms_identity data readStream
		length: ms_identity data size.
    ]

    channelNeeded [
	<category: 'accessing'>
	^ channel_needed
    ]

    emlppPriority [
	<category: 'accessing'>
	^ emlpp
    ]
]

RSLCommonChannelManagement subclass: RSLImmediateAssignment [
    | full_info |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.5.6 Immediate Assign Command'>
    <rslMessageType: #messageTrxImmediateAssignCommand>
    <rslMessageDefinition: #immediateAssignCommandMessage>

    fullL3Info [
        <category: 'accessing'>
        ^ full_info
    ]
]

RSLMessageBase subclass: RSLTRXManagement [
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.6 TRX Management base'>

    RSLTRXManagement class >> isTransparent [
        <category: 'parsing'>
        ^ 0
    ]

    RSLTRXManagement class >> messageDiscrimator [
        <category: 'parsing'>
        ^ self discriminatorTRX
    ]
]

RSLTRXManagement subclass: RSLSACCHFilling [
    | si_type l3_info start_time |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.6.2 SACCH Filling'>
    <rslMessageType: #messageTrxSacchFilling>
    <rslMessageDefinition: #sacchFillingMessage>
]

RSLMessageBase subclass: RSLDedicatedChannelManagement [
    | channel_number |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.4 Dedicated Channel Management.'>

    RSLDedicatedChannelManagement class >> messageDiscrimator [
        <category: 'parsing'>
        ^ self discriminatorDedicated
    ]

    RSLDedicatedChannelManagement class >> isTransparent [
        <category: 'parsing'>
        ^ 0
    ]

    channelNumber: aNr [
        <category: 'creation'>
        channel_number := aNr.
    ]

    channelNumber [
        <category: 'accessing'>
        ^ channel_number
    ]
]

RSLDedicatedChannelManagement subclass: RSLChannelActivation [
    | activation_type channel_mode channel_ident encr_info
      handover_ref bs_power ms_power timing_advance bs_powerparams 
      ms_powerparams physical_context sacch_information uic
      main_chan_ref mr_conf mr_control supported_codecs |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.4.1 Channel Activation.'>
    <rslMessageType: #messageDedChannelActication>
    <rslMessageDefinition: #channelActivationMessage>
]

RSLDedicatedChannelManagement subclass: RSLChannelActivationAck [
    | frame_number |
    <comment: 'I represent a GSM 08.58 GSM 8.4.2 Channel Activation Ack.'>
    <rslMessageType: #messageDedChannelActivationAck>
    <rslMessageDefinition: #channelActivationAckMessage>

    frameNumber: aNumber [
        <category: 'creation'>
        frame_number := aNumber
    ]
]

RSLDedicatedChannelManagement subclass: RSLRFChannelRelease [
    <comment: 'I represent a GSM 08.58 GSM 8.4.14 RF Channel Release'>
    <rslMessageType: #messageDedRfChannelRelease>
    <rslMessageDefinition: #rfChannelReleaseMessage>
]

RSLDedicatedChannelManagement subclass: RSLRFChannelReleaseAck [
    <comment: 'I represent a GSM 08.58 GSM 8.4.19 RF Channel Release Ack'>
    <rslMessageType: #messageDedRfChannelReleaseAck>
    <rslMessageDefinition: #rfChannelReleaseAckMessage>
]

RSLDedicatedChannelManagement subclass: RSLSacchDeactivate [
    <comment: 'I represent a GSM 08.58 GSM 8.4.5 DEACTIVATE SACCH'>
    <rslMessageType: #messageDedDeactivateSacch>
    <rslMessageDefinition: #deactivateSacchMessage>
]

RSLDedicatedChannelManagement subclass: RSLEncryptionCommand [
    | encr_info l3_info link_id |
    <comment: 'I represent a GSM 08.58 GSM 8.4.6 ENCRyption CoMmaD'>
    <rslMessageType: #messageDedEncryptionCommand>
    <rslMessageDefinition: #encryptionCommandMessage>

    l3Information [
        <category: 'access'>
        ^ l3_info
    ]

    linkIdentifier [
        <category: 'access'>
        ^ link_id
    ]
]

RSLDedicatedChannelManagement subclass: RSLHandoverDetection [
    | access_delay |
    <comment: 'I represent a GSM 08.58 GSM 8.4.7 HANDOVER DETECTION'>
    <rslMessageType: #messageDedHandoverDetection>
    <rslMessageDefinition: #handoverDetectionMessage>
]

RSLDedicatedChannelManagement subclass: RSLModeModifyRequest [
    | channel_mode encr_info main_channel mr mr_control codec |
    <comment: 'I represent a GSM 08.58 8.4.9 MODE MODIFY'>
    <rslMessageType: #messageDedModeModifyRequest>
    <rslMessageDefinition: #modeModifyMessage>
]

RSLDedicatedChannelManagement subclass: RSLModeModifyAck [
    <comment: 'I represent a GSM 08.58 8.4.10 MODE MODIFY ACKNOWLEDGE'>
    <rslMessageType: #messageDedModeModifyAck>
    <rslMessageDefinition: #modeModifyAck>
]

RSLDedicatedChannelManagement subclass: RSLModeModifyNack [
    | cause |
    <comment: 'I represent a GSM 08.58 8.4.11 MODE MODIFY NEGATIVE ACKNOWLEDGE'>
    <rslMessageType: #messageDedModeModifyNack>
    <rslMessageDefinition: #modeModifyNack>
]

RSLMessageBase subclass: RSLRadioLinkManagement [
    | channel_number link_id |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.3 Radio Linklayer messages'>

    RSLRadioLinkManagement class >> isTransparent [
        <category: 'parsing'>
        "Let us see how far we get without having the direction. E.g everything
        from the BTS is not transparent."
        ^ ({RSLDataRequest} includes: self)
            ifTrue: [1]
            ifFalse: [0].
    ]

    RSLRadioLinkManagement class >> messageDiscrimator [
        <category: 'parsing'>
        ^ self discriminatorRadioLink
    ]

    channelNumber: aNr [
        <category: 'creation'>
        channel_number := aNr
    ]

    linkIdentifier: aLinkId [
        <category: 'creation'>
        link_id := aLinkId
    ]

    channelNumber [
        <category: 'query'>
        ^ channel_number
    ]

    linkIdentifier [
        <category: 'query'>
        ^ link_id
    ]
]

RSLRadioLinkManagement subclass: RSLDataIndication [
    | l3_info |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.3.2 Data indication'>
    <rslMessageType: #messageRadioLinkDataIndication>
    <rslMessageDefinition: #dataIndicationMessage>

    l3Information: aL3Info [
        <category: 'creation'>
        l3_info := aL3Info
    ]
]

RSLRadioLinkManagement subclass: RSLEstablishIndication [
    | l3_info |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.3.6 Establish indication'>
    <rslMessageType: #messageRadioLinkEstablishIndication>
    <rslMessageDefinition: #establishIndicationMessage>

    l3Information: anInfo [
        <category: 'parsing'>
        l3_info := anInfo
    ]
]

RSLRadioLinkManagement subclass: RSLReleaseRequest [
    | release_mode |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.3.7 Release Request'>
    <rslMessageType: #messageRadioLinkReleaseRequest>
    <rslMessageDefinition: #releaseRequestMessage>
]

RSLRadioLinkManagement subclass: RSLReleaseConfirm [
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.3.8 Release Confirm'>
    <rslMessageType: #messageRadioLinkReleaseConfirm>
    <rslMessageDefinition: #releaseConfirmMessage>
]

RSLRadioLinkManagement subclass: RSLDataRequest [
    | l3_info |
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 GSM 8.3.1 Data Request'>
    <rslMessageType: #messageRadioLinkDataRequest>
    <rslMessageDefinition: #dataRequestMessage>

    l3Information [
        <category: 'access'>
        ^ l3_info
    ]
]

RSLRadioLinkManagement subclass: RSLReleaseIndication [
    <category: 'BTS-RSL'>
    <comment: 'I represent a GSM 08.58 8.3.9 Data Request'>
    <rslMessageType: #messageRadioLinkReleaseIndication>
    <rslMessageDefinition: #releaseIndicationMessage>
]

RSLMessageDefinitions subclass: RSLIPAMessageDefinitions [
    RSLIPAMessageDefinitions class [
        connectionIdentifierIE [
	    ^ Osmo.TLVDescription newRSLDescription
		tag: 16rF8; instVarName: #conn_id; parseClass: RSLAttributeData;
		beTV; valueSize: 2; yourself
	]

	localIPIE [
	    ^ Osmo.TLVDescription newRSLDescription
		tag: 16rF5; instVarName: #local_ip; parseClass: RSLAttributeData;
		beTV; valueSize: 4; yourself
	]

	localPortIE [
	    ^ Osmo.TLVDescription newRSLDescription
		tag: 16rF3; instVarName: #local_port; parseClass: RSLAttributeData;
		beTV; valueSize: 2; yourself
	]

	remoteIPIE [
	    ^ self localIPIE
		tag: 16rF0; instVarName: #remote_ip; yourself
	]

	remotePortIE [
	    ^ self localPortIE
		tag: 16rF1; instVarName: #remote_port; yourself.
	]

	speechModeIE [
	    ^ Osmo.TLVDescription newRSLDescription
		tag: 16rF4; instVarName: #speech_mode; parseClass: RSLAttributeData;
		beTV; valueSize: 1; yourself
	]

	rtpPayloadTypeIE [
	    ^ Osmo.TLVDescription newRSLDescription
		tag: 16rF2; instVarName: #rtp_payload; parseClass: RSLAttributeData;
		beTV; valueSize: 1; yourself
	]

	connectionStatisticsIE [
	    ^ Osmo.TLVDescription newRSLDescription
		tag: 16rF6; instVarName: #stats; parseClass: RSLAttributeData;
		beTLV; valueSize: 28; yourself
	]

	createConnectionMessage [
	    ^ OrderedCollection new
		add: self channelNumberIE;
		add: self speechModeIE;
		add: self rtpPayloadTypeIE;
		yourself
	]

	createConnectionAckMessage [
	    ^ OrderedCollection new
		add: self channelNumberIE;
		add: self connectionIdentifierIE;
		add: self localPortIE;
		add: self localIPIE;
		yourself
	]

	modifyConnectionMessage [
	    <category: 'ipa'>
	    ^ OrderedCollection new
		add: self channelNumberIE;
		add: self connectionIdentifierIE;
		add: self remoteIPIE;
		add: self remotePortIE;
		add: self speechModeIE;
		add: self rtpPayloadTypeIE;
		yourself
	]

	modifyConnectionAckMessage [
	    ^ OrderedCollection new
		add: self channelNumberIE;
		add: self connectionIdentifierIE;
		yourself
	]

	deleteConnectionIndMessage [
	    ^ OrderedCollection new
		add: self channelNumberIE;
		add: self connectionIdentifierIE;
		add: self connectionStatisticsIE;
		add: self causeIE;
		yourself
	]
    ]
]

RSLMessageBase subclass: RSLIPAVendorManagement [
    <category: 'BTS-RSL-IPA'>
    <comment: 'I represent a ip.access vendor extension'>

    RSLIPAVendorManagement class [
	messageCRCX	    [ <category: 'tag'> ^ 16r70 ]
	messageCRCXAck	    [ <category: 'tag'> ^ 16r71 ]
	messageCRCXNack	    [ <category: 'tag'> ^ 16r72 ]
	messageMDCX	    [ <category: 'tag'> ^ 16r73 ]
	messageMDCXAck	    [ <category: 'tag'> ^ 16r74 ]
	messageMDCXNack	    [ <category: 'tag'> ^ 16r75 ]
	messageDLCXInd	    [ <category: 'tag'> ^ 16r76 ]
	messageDLCX	    [ <category: 'tag'> ^ 16r77 ]
	messageDLCXAck	    [ <category: 'tag'> ^ 16r78 ]
	messageDLCXNack	    [ <category: 'tag'> ^ 16r79 ]
    ]

    RSLIPAVendorManagement class >> messageDiscrimator [
	<category: 'parsing'>
	^ 63
    ]

    RSLIPAVendorManagement class >> isTransparent [
	^ 0
    ]

    RSLIPAVendorManagement class >> tlvDescription  [
        <category: 'tlv'>
	^ RSLIPAMessageDefinitions perform: messageDefinition
    ]
]

RSLIPAVendorManagement subclass: RSLIPACreateConnection [
    | channel_number speech_mode rtp_payload |
    <category: 'BTS-RSL-IPA'>
    <comment: 'I represent a Create Connection (CRCX) message'>
    <rslMessageType: #messageCRCX>
    <rslMessageDefinition: #createConnectionMessage>

    channelNumber [
	^ channel_number
    ]
]

RSLIPAVendorManagement subclass: RSLIPACreateConnectionAck [
    | channel_number conn_id local_port local_ip |
    <category: 'BTS-RSL-IPA'>
    <comment: 'I represent a Create Connection (CRCX) ACK message'>
    <rslMessageType: #messageCRCXAck>
    <rslMessageDefinition: #createConnectionAckMessage>

    channelNumber: aNumber [
	<category: 'creation'>
	channel_number := aNumber
    ]

    connectionIdentifier: anId [
	<category: 'creation'>
	conn_id := anId
    ]

    localPort: aPort [
	local_port := aPort
    ]

    localIP: anAddr [
	local_ip := anAddr
    ]
]

RSLIPAVendorManagement subclass: RSLIPAModifyConnection [
    | channel_number conn_id remote_ip remote_port speech_mode rtp_payload |
    <category: 'BTS-RSL-IPA'>
    <comment: 'I represent a Modify Connection (MDCX) message'>
    <rslMessageType: #messageMDCX>
    <rslMessageDefinition: #modifyConnectionMessage>

    channelNumber [
	^ channel_number
    ]
]

RSLIPAVendorManagement subclass: RSLIPAModifyConnectionAck [
    | channel_number conn_id |
    <category: 'BTS-RSL-IPA'>
    <comment: 'I represent a Modify Connection (MDCX) ACK message'>
    <rslMessageType: #messageMDCXAck>
    <rslMessageDefinition: #modifyConnectionAckMessage>

    channelNumber: aNumber [
	<category: 'creation'>
	channel_number := aNumber
    ]

    connectionIdentifier: anId [
	<category: 'creation'>
	conn_id := anId
    ]
]

RSLIPAVendorManagement subclass: RSLIPADeleteConnectionInd [
    | channel_number conn_id stats cause |
    <category: 'BTS-RSL-IPA'>
    <comment: 'I represent a Delete Connection (DLCX) Indication message'>
    <rslMessageType: #messageDLCXInd>
    <rslMessageDefinition: #deleteConnectionIndMessage>

    defaultValues [
	stats := (ByteArray new: 28) asRSLAttributeData.
	cause := (ByteArray new: 1) asRSLAttributeData.
    ]

    channelNumber: aNumber [
	<category: 'creation'>
	channel_number := aNumber
    ]

    connectionIdentifier: anId [
	<category: 'creation'>
	conn_id := anId
    ]
]