This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 129
/
TS44018_IE.py
1816 lines (1497 loc) · 60.4 KB
/
TS44018_IE.py
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
# -*- coding: UTF-8 -*-
#/**
# * Software Name : pycrate
# * Version : 0.4
# *
# * Copyright 2018. Benoit Michau. ANSSI. P1sec.
# *
# * This library is free software; you can redistribute it and/or
# * modify it under the terms of the GNU Lesser General Public
# * License as published by the Free Software Foundation; either
# * version 2.1 of the License, or (at your option) any later version.
# *
# * This library 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
# * Lesser General Public License for more details.
# *
# * You should have received a copy of the GNU Lesser General Public
# * License along with this library; if not, write to the Free Software
# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# * MA 02110-1301 USA
# *
# *--------------------------------------------------------
# * File Name : pycrate_mobile/TS44018_IE.py
# * Created : 2018-06-21
# * Authors : Benoit Michau
# *--------------------------------------------------------
#*/
#------------------------------------------------------------------------------#
# 3GPP TS 44.018 GSM / EDGE RRC protocol
# release 13 (d80)
#------------------------------------------------------------------------------#
from pycrate_core.utils import *
from pycrate_core.elt import Envelope, Array, Sequence, Alt, \
REPR_RAW, REPR_HEX, REPR_BIN, REPR_HD, REPR_HUM
from pycrate_core.base import *
from pycrate_core.repr import *
from .TS24007 import RestOctets
from .TS24008_IE import LAI, RAI, ID, MSCm2, BroadcastCallRef, TMGI, AddUpdateParams, \
CellId, CKSN_dict
#------------------------------------------------------------------------------#
# TS 44.018 IE specified with CSN.1
#------------------------------------------------------------------------------#
from pycrate_csn1dir.ba_list_pref import ba_list_pref
from pycrate_csn1dir.utran_freq_list import utran_freq_list
from pycrate_csn1dir.individual_priorities import individual_priorities
from pycrate_csn1dir.classmark_3_value_part import classmark_3_value_part
from pycrate_csn1dir.dynamic_arfcn_mapping import dynamic_arfcn_mapping
from pycrate_csn1dir.ia_rest_octets import ia_rest_octets
from pycrate_csn1dir.ipa_rest_octets import ipa_rest_octets
from pycrate_csn1dir.iax_rest_octets import iax_rest_octets
from pycrate_csn1dir.iar_rest_octets import iar_rest_octets
from pycrate_csn1dir.notification_facch import notification_facch
from pycrate_csn1dir.ntn_rest_octets import ntn_rest_octets
from pycrate_csn1dir.vbs_vgcs_reconfigure import vbs_vgcs_reconfigure
from pycrate_csn1dir.vbs_vgcs_reconfigure2 import vbs_vgcs_reconfigure2
from pycrate_csn1dir.p1_rest_octets import p1_rest_octets
from pycrate_csn1dir.p2_rest_octets import p2_rest_octets
from pycrate_csn1dir.p3_rest_octets import p3_rest_octets
from pycrate_csn1dir.si1_rest_octets import si1_rest_octets
from pycrate_csn1dir.si2bis_rest_octets import si2bis_rest_octets
from pycrate_csn1dir.si2ter_rest_octets import si2ter_rest_octets
from pycrate_csn1dir.si2quater_rest_octets import si2quater_rest_octets
from pycrate_csn1dir.si2n_rest_octets import si2n_rest_octets
from pycrate_csn1dir.si3_rest_octet import si3_rest_octet
from pycrate_csn1dir.si4_rest_octets import si4_rest_octets
from pycrate_csn1dir.si6_rest_octets import si6_rest_octets
from pycrate_csn1dir.si9_rest_octets import si9_rest_octets
from pycrate_csn1dir.si_13_rest_octets import si_13_rest_octets
from pycrate_csn1dir.si16_rest_octets import si16_rest_octets, si17_rest_octets
from pycrate_csn1dir.si_19_rest_octets import si_19_rest_octets
from pycrate_csn1dir.si_18_rest_octets import si_18_rest_octets
from pycrate_csn1dir.si14_rest_octets import si14_rest_octets
from pycrate_csn1dir.si15_rest_octets import si15_rest_octets
from pycrate_csn1dir.si_13alt_rest_octets import si_13alt_rest_octets
from pycrate_csn1dir.si_21_rest_octets import si_21_rest_octets
from pycrate_csn1dir.si_22_rest_octets import si_22_rest_octets
from pycrate_csn1dir.si_23_rest_octets import si_23_rest_octets
from pycrate_csn1dir.gprs_broadcast_information_value_part import gprs_broadcast_information_value_part
from pycrate_csn1dir.rr_packet_uplink_assignment_value_part import rr_packet_uplink_assignment_value_part
from pycrate_csn1dir.rr_packet_downlink_assignment_value_part import rr_packet_downlink_assignment_value_part
from pycrate_csn1dir.dtm_information_details_value_part import dtm_information_details_value_part
from pycrate_csn1dir.channel_request_description_2_value_part import channel_request_description_2_value_part
from pycrate_csn1dir.packet_channel_description import packet_channel_description
from pycrate_csn1dir.measurement_results_contents import measurement_results_contents
from pycrate_csn1dir.gprs_broadcast_information_value_part import gprs_broadcast_information_value_part
from pycrate_csn1dir.mprach_description_value_part import mprach_description_value_part
from pycrate_csn1dir.mbms_p_t_m_channel_description_value_part import mbms_p_t_m_channel_description_value_part
from pycrate_csn1dir.mbms_session_parameters_list_value_part import mbms_session_parameters_list_value_part
from pycrate_csn1dir.ec_packet_channel_description_type_1 import ec_packet_channel_description_type_1
from pycrate_csn1dir.rr_packet_downlink_assignment_type_2_value_part import \
rr_packet_downlink_assignment_type_2_value_part
from pycrate_csn1dir.ec_immediate_assignment_type_2_message_content import \
ec_immediate_assignment_type_2_message_content
from pycrate_csn1dir.cell_selection_indicator_after_release_of_all_tch_and_sdcch_value_part import \
cell_selection_indicator_after_release_of_all_tch_and_sdcch_value_part
#------------------------------------------------------------------------------#
# generic objects
#------------------------------------------------------------------------------#
class BitMap(Buf):
"""handles bit map
derives from the Buf object and includes get() / set() / unset() methods
for handling bit value at given offset
"""
_rep = REPR_HEX
# dedicated method to get, set and unset at a given offset
def get(self, off):
return 1 & (self.to_uint()>>(off-1))
def set(self, off):
u = self.to_uint()
o = 1<<(off-1)
if not u & o:
self.from_uint(u+o)
def unset(self, off):
u = self.to_uint()
o = 1<<(off-1)
if u & o:
self.from_uint(u-o)
#------------------------------------------------------------------------------#
# BA Range
# TS 44.018, 10.5.2.1a
#------------------------------------------------------------------------------#
class BARange(Envelope):
_GEN = (
Uint8('Num'),
Array('Ranges', GEN=Envelope('Range', GEN=(
Uint('RANGE_LOWER', bl=10),
Uint('RANGE_HIGHER', bl=10)))),
Buf('spare', rep=REPR_HEX)
)
#------------------------------------------------------------------------------#
# Cell Channel Description
# TS 44.018, 10.5.2.1b
#------------------------------------------------------------------------------#
# This is the same structure as FreqList defined in 10.5.2.13,
# but with a fixed length of 16 bytes
# _FreqListRange is the generic class template for all Range* as defined
# in 10.5.2.13
# For range 512 and range 1024, there is a W(parent) selection
# which requires some damned numerology !
# So we build a dict of W_index -> W_parent_index up to index 511 (rank 8),
# what corresponds to the longest sequence of W (for range 512)
# For all _FreqListRange / _FreqListRangeLong / _FreqListRange1024
# only Layout and eventually Range need to be set
def __exp_ind(ind):
l = [i*2 for i in ind]
r = [1+i for i in l]
return l + r
def _build_w_parent_dict(rank=8):
ind, par = [[1]], {}
for i in range(rank):
ind.append( __exp_ind(ind[i]) )
for j in range(0, len(ind[-1]), 2):
par[ind[i+1][j]] = ind[i][j>>1]
par[ind[i+1][j+1]] = ind[i][j>>1]
return par
class _FreqListRange(Envelope):
_Range = 0
_Layout = ()
_Parent = _build_w_parent_dict(8)
_GEN = ()
def _from_char(self, char):
# char can be of variable length in bits
# hence, the number of W has to be set according to this
# and the layout of bit length for W
if self._Range == 1024:
self[0]._from_char(char)
off = 6
else:
off = 17
i = 1
while i <= len(self._Layout):
ccur, wbl = char._cur, self._Layout[i-1]
if char._len_bit - ccur >= wbl:
w = Uint('W_%i' % i, bl=wbl)
w._from_char(char)
self.append(w)
i += 1
off += wbl
else:
break
# add some spare bits for octet-alignment
sbl = -off % 8
if sbl:
s = Uint('spare', bl=sbl, rep=REPR_HEX)
s._from_char(char)
self.append(s)
def _decode(self):
if self._Range == 1024:
start = 1
else:
start = 0
if self[-1]._name[0:1] != 'W':
# spare bits field present
end = len(self._content) - 1
else:
end = len(self._content)
W, F = [None] + self.get_val()[start:end], []
for i in range(1, len(W)):
# INDEX = i
N = W[i]
if N == 0:
break
else:
J = [j for j in (1, 2, 4, 8, 16, 32, 64, 128, 256) if j <= i].pop()
while i > 1:
if 2*i < 3*J:
i -= J>>1
N = 1 + (N + W[self._dec_get_w_ind(i)] + self._Range//J - 2) \
% (2*self._Range//J - 1)
else:
i -= J
N = 1 + (N + W[self._dec_get_w_ind(i)] + 2*self._Range//J - 2) \
% (2*self._Range//J - 1)
J = J//2
F.append(N)
F.sort()
return F
def _dec_get_w_ind(self, ind):
# this is used for range 128, 256
# a different method is used for range 512 and 1024
return ind
def _encode(self, arfcns):
# TODO: read 44.018 annex J
raise(PycrateErr('not implemented'))
# _FreqListRangeLong and _FreqListRange1024 are parent classes as defined in
# 10.5.2.13
class _FreqListRangeLong(_FreqListRange):
_Range = 512
def _dec_get_w_ind(self, ind):
return self._Parent[ind]
class _FreqListRange1024(_FreqListRangeLong):
_Range = 1024
_GEN = (
Uint('F0', val=0, bl=1),
)
def decode(self):
"""returns the list of ARFCNs set
"""
if self[0].get_val():
# ARFCN 0 part of the set
return [0] + self._decode()
else:
return self._decode()
def encode(self, arfcns):
"""sets a list of ARFCNs
"""
# TODO
raise(PycrateErr('not implemented'))
# _FreqListAlt2, _FreqListAlt1 and _FreqList are parent classes with common
# methods used children classes which have different generators
# _FreqListAlt2 has the following generator layout, where the BitmapVar may
# have different bit length:
# _GEN = (
# Uint('FmtExt2', bl=2, dic={0: 'range 512', 1: 'range 256', 2: 'range 128', 3: 'variable bit map'}),
# Uint('OriginARFCN', val=0, bl=10),
# Alt(GEN={
# 0: FreqListRange512(),
# 1: FreqListRange256(),
# 2: FreqListRange128(),
# 3: FreqListBitmapVar()},
# sel=lambda self: self.get_env()[0].get_val())
# )
class _FreqListAlt2(Envelope):
def decode(self):
"""returns the list of ARFCNs set
"""
orig_arfcn = self[1].get_val()
# 512 is a special case of _FreqListRange in that the ARFCNs are not added to ORIG-ARFCN mod 1024
if self[2].get_alt()._Range == 512:
return [orig_arfcn] + self[2].get_alt()._decode()
else:
return [orig_arfcn] + \
list(map(lambda x: (orig_arfcn + x) % 1024, self[2].get_alt()._decode()))
def encode(self, arfcns):
"""sets a list of ARFCNs
"""
arfcns = set(arfcns)
try:
arfcns.sort()
orig_arfcn = arfcns.pop(0)
self[1].set_val(orig_arfcn)
if self[0].get_val() == 3:
# variable bitmap, update every ARFCNs
rem_orig_arfcn = lambda x: x-orig_arfcn
arfcns = list(map(rem_orig_arfcn, arfcns))
# WARN: this will raise in case of RangeX
self[2].get_alt()._encode(arfcns)
except:
pass
class _FreqListAlt1(Envelope):
def decode(self):
"""returns the list of ARFCNs set
"""
return self[1].get_alt().decode()
def encode(self, arfcns):
"""sets a list of ARFCNs
"""
self[1].get_alt().encode(arfcns)
class _FreqList(Envelope):
def decode(self):
"""returns the list of ARFCNs set
"""
try:
return self[2].get_alt().decode()
except:
return []
def encode(self, arfcns):
"""sets the list of ARFCNs
"""
# TODO: choose the best possible encoding ?!
raise(PycrateErr('not implemented'))
# FreqListBitmapVar and FreqListBitmap0 are defined in 10.5.2.13
# but actually used as-is in several places
class FreqListBitmapVar(BitMap):
def _decode(self):
rrfcns = []
rr_uint, rr_bl = self.to_uint(), self.get_bl()
for i in range(0, rr_bl):
if rr_uint & 1<<(rr_bl-i-1):
rrfcns.append(i+1)
return rrfcns
def _encode(self, rrfcns):
# bitmap length is the maximum offset, rounding to the octet boundary
rr_uint, rr_bl = 0, max(rrfcns)
if rr_bl % 8:
rr_bl += -rr_bl % 8
for o in rrfcns:
rr_uint += 1<<(rr_bl-o-1)
self.from_uint(rr_uint)
class FreqListBitmap0(BitMap):
_bl = 124
def decode(self):
"""returns the list of ARFCNs set
"""
arfcns = []
ar_uint, ar_bl = self.to_uint(), 124
for i in range(0, ar_bl):
if ar_uint & (1<<i):
arfcns.append(1+i)
arfcns.sort()
return arfcns
def encode(self, arfcns):
"""sets a list of ARFCNs
"""
ar_uint, ar_bl = 0, 124
for ar in set(arfcns):
if isinstance(ar, integer_types) and 0 < ar <= ar_bl:
ar_uint += 1<<(124-ar)
self.set_val(uint_to_bytes(ar_uint, 124))
# Actual Cell Channel definitions
class CellChanRange1024(_FreqListRange1024):
_Layout = (10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 6)
class CellChanRange512(_FreqListRangeLong):
_Layout = (9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5)
class CellChanRange256(_FreqListRange):
_Range = 256
_Layout = (8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4)
class CellChanRange128(_FreqListRange):
_Range = 128
_Layout = (7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3)
class CellChanAlt2(_FreqListAlt2):
_GEN = (
Uint('FmtExt2', bl=2, dic={0: 'range 512', 1: 'range 256', 2: 'range 128', 3: 'variable bit map'}),
Uint('OriginARFCN', val=0, bl=10),
Alt(GEN={
0: CellChanRange512(),
1: CellChanRange256(),
2: CellChanRange128(),
3: FreqListBitmapVar('CellChanBitmapVar', bl=111)},
sel=lambda self: self.get_env()[0].get_val())
)
class CellChanAlt1(_FreqListAlt1):
_GEN = (
Uint('FmtExt', bl=1, dic={0:'range 1024'}),
Alt(GEN={
0: CellChanRange1024(),
1: CellChanAlt2()},
sel=lambda self: self.get_env()[0].get_val())
)
# 16 bytes, 128 bits
class CellChan(_FreqList):
_GEN = (
Uint('Fmt', bl=2, dic={0:'bit map 0', 1:'undefined', 3: 'undefined'}),
Uint('spare', bl=2),
Alt(GEN={
0: FreqListBitmap0('CellChanBitmap0'),
2: CellChanAlt1()},
DEFAULT=Buf('undefined', rep=REPR_HEX),
sel=lambda self: self.get_env()[0].get_val())
)
#------------------------------------------------------------------------------#
# Cell Description
# TS 44.018, 10.5.2.2
#------------------------------------------------------------------------------#
class CellDesc(Envelope):
_GEN = (
Uint('BCCHARFCN_hi', bl=2),
Uint('NCC', bl=3),
Uint('BCC', bl=3),
Uint8('BCCHARFCN_lo'),
Uint16('BCCHARFCN', trans=True)
)
def __init__(self, *args, **kwargs):
Envelope.__init__(self, *args, **kwargs)
self[4].set_valauto(lambda: self[3].get_val() + (self[0].get_val()<<8))
#------------------------------------------------------------------------------#
# Cell Options
# TS 44.018, 10.5.2.3
#------------------------------------------------------------------------------#
_DTXInd_dict = {
0 : 'MS may use uplink discontinuous Tx',
1 : 'MS shall use uplink discontinuous Tx',
2 : 'MS shall not use uplink discontinuous Tx',
}
class CellOpt(Envelope):
_GEN = (
Uint('DynARFCNMappingInd', bl=1),
Uint('PwrCtrlInd', bl=1),
Uint('DTXInd', bl=2, dic=_DTXInd_dict),
Uint('RadioLinkTimeout', bl=4)
)
#------------------------------------------------------------------------------#
# Cell Selection Parameters
# TS 44.018, 10.5.2.4
#------------------------------------------------------------------------------#
_CellReselHyst_dict = {
0 : '0 dB RXLEV hysteresis for LA re-selection',
1 : '2 dB RXLEV hysteresis for LA re-selection',
2 : '4 dB RXLEV hysteresis for LA re-selection',
3 : '6 dB RXLEV hysteresis for LA re-selection',
4 : '8 dB RXLEV hysteresis for LA re-selection',
5 : '10 dB RXLEV hysteresis for LA re-selection',
6 : '12 dB RXLEV hysteresis for LA re-selection',
7 : '14 dB RXLEV hysteresis for LA re-selection',
}
_NECI_dict = {
0 : 'New establishment causes not supported',
1 : 'New establishment causes supported'
}
class CellSelParams(Envelope):
_GEN = (
Uint('CellReselectHyst', bl=3, dic=_CellReselHyst_dict),
Uint('MS-TXPWR-MAX-CCH', bl=5),
Uint('ACS', bl=1),
Uint('NECI', bl=1, dic=_NECI_dict),
Uint('RXLEV-ACCESS-MIN', bl=6)
)
#------------------------------------------------------------------------------#
# Channel Description
# TS 44.018, 10.5.2.5
#------------------------------------------------------------------------------#
ChanDescType_dict = {
1 : 'TCH/F + ACCHs; TSC Set 1 shall be used',
17 : 'TCH/F + ACCHs; TSC Set 2 shall be used; subchannel 0',
18 : 'TCH/F + ACCHs; TSC Set 2 shall be used; subchannel 1',
4 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); TSC Set 1 shall be used; subchannel 0',
5 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); TSC Set 1 shall be used; subchannel 1',
6 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); TSC Set 1 shall be used; subchannel 2',
7 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); TSC Set 1 shall be used; subchannel 3',
8 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 0',
9 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 1',
10 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 2',
11 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 3',
12 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 4',
13 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 5',
14 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 6',
15 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); TSC Set 1 shall be used; subchannel 7',
}
ChanDescHop_dict = {
0 : 'Single RF channel',
1 : 'RF hopping channel',
}
class ChanDesc(Envelope):
_GEN = (
Uint('ChanType', bl=5, dic=ChanDescType_dict),
Uint('TN', bl=3),
Uint('TSC', bl=3),
Uint('HopChan', bl=1, dic=ChanDescHop_dict),
Alt(GEN={
0: Envelope('ChanSingle', GEN=(
Uint('spare', bl=2, rep=REPR_HEX),
Uint('ARFCN', bl=10)
)),
1: Envelope('ChanHopping', GEN=(
Uint('MAIO', bl=6),
Uint('HSN', bl=6)
))},
sel=lambda self:self.get_env()[3].get_val())
)
#------------------------------------------------------------------------------#
# Channel Description 2
# TS 44.018, 10.5.2.5a
#------------------------------------------------------------------------------#
ChanDesc2Type_dict = {
0 : 'TCH/F + FACCH/F and SACCH/M',
1 : 'TCH/F + FACCH/F and SACCH/F',
2 : 'TCH/H + ACCHs, subchannel 0',
3 : 'TCH/H + ACCHs, subchannel 1',
4 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); subchannel 0',
5 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); subchannel 1',
6 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); subchannel 2',
7 : 'SDCCH/4 + SACCH/C4 or CBCH (SDCCH/4); subchannel 3',
8 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 0',
9 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 1',
10 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 2',
11 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 3',
12 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 4',
13 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 5',
14 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 6',
15 : 'SDCCH/8 + SACCH/C8 or CBCH (SDCCH/8); subchannel 7',
24 : 'TCH/F + ACCHs using TSC Set 2',
28 : 'TCH/H + ACCHs using TSC Set 2; subchannel 0',
29 : 'TCH/H + ACCHs using TSC Set 2; subchannel 1',
16 : 'TCH/F + FACCH/F and SACCH/M; no additional timeslots',
17 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n-1',
18 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n+1, n-1',
19 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n+1, n-1 and n-2',
20 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n+1, n-1, n-2, and n-3',
21 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n+1, n-1, n-2, n-3 and n-4',
22 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n+1, n-1, n-2, n-3, n-4 and n-5',
23 : 'TCH/F + FACCH/F and SACCH/M; additional bidirectional TCH/Fs and SACCH/Ms at timeslot n+1, n-1, n-2, n-3, n-4, n-5 and n-6',
25 : 'TCH/F + FACCH/F and SACCH/M; additional unidirectional TCH/FDs and SACCH/MDs at timeslot n-1',
26 : 'TCH/F + FACCH/F and SACCH/M; additional unidirectional TCH/FDs and SACCH/MDs at timeslot n+1, n-1',
27 : 'TCH/F + FACCH/F and SACCH/M; additional unidirectional TCH/FDs and SACCH/MDs at timeslot n+1, n-1 and n-2'
}
ChanDescHop_dict = {
0 : 'Single RF channel',
1 : 'RF hopping channel',
}
class ChanDesc2(Envelope):
_GEN = (
Uint('ChanType', bl=5, dic=ChanDesc2Type_dict),
Uint('TN', bl=3),
Uint('TSC', bl=3),
Uint('HopChan', bl=1, dic=ChanDescHop_dict),
Alt(GEN={
0: Envelope('ChanSingle', GEN=(
Uint('spare', bl=2, rep=REPR_HEX),
Uint('ARFCN', bl=10)
)),
1: Envelope('ChanHopping', GEN=(
Uint('MAIO', bl=6),
Uint('HSN', bl=6)
))},
sel=lambda self:self.get_env()[3].get_val())
)
#------------------------------------------------------------------------------#
# Channel Description 3
# TS 44.018, 10.5.2.5c
#------------------------------------------------------------------------------#
class ChanDesc3(Envelope):
_GEN = (
Uint('TSC', bl=3),
Uint('HopChan', bl=1, dic=ChanDescHop_dict),
Alt(GEN={
0: Envelope('ChanSingle', GEN=(
Uint('spare', bl=2, rep=REPR_HEX),
Uint('ARFCN', bl=10)
)),
1: Envelope('ChanHopping', GEN=(
Uint('MAIO', bl=6),
Uint('HSN', bl=6)
))},
sel=lambda self:self.get_env()[1].get_val())
)
#------------------------------------------------------------------------------#
# Channel Mode
# TS 44.018, 10.5.2.6
#------------------------------------------------------------------------------#
class ChanMode(Uint8):
_dic = {
0 : 'signalling only',
1 : 'GSM FR or GSM HR',
0xc1: 'GSM FR or GSM HR in VAMOS mode',
0x21: 'GSM EFR',
0xc2: 'GSM EFR in VAMOS mode',
0x41: 'FR AMR or HR AMR',
0xc3: 'FR AMR or HR AMR in VAMOS mode',
0x81: 'OFR AMR-WB or OHR AMR-WB',
0x82: 'FR AMR-WB',
0xc5: 'FR AMR-WB in VAMOS mode',
0x83: 'OHR AMR',
0x61: 'data, 43.5 kbit/s (downlink)+14.5 kbps (uplink)',
0x62: 'data, 29.0 kbit/s (downlink)+14.5 kbps (uplink)',
0x64: 'data, 43.5 kbit/s (downlink)+29.0 kbps (uplink)',
0x67: 'data, 14.5 kbit/s (downlink)+43.5 kbps (uplink)',
0x65: 'data, 14.5 kbit/s (downlink)+29.0 kbps (uplink)',
0x66: 'data, 29.0 kbit/s (downlink)+43.5 kbps (uplink)',
0x47: 'data, 43.5 kbit/s radio interface rate',
0x63: 'data, 32.0 kbit/s radio interface rate',
0x43: 'data, 29.0 kbit/s radio interface rate',
15 : 'data, 14.5 kbit/s radio interface rate',
3 : 'data, 12.0 kbit/s radio interface rate',
11 : 'data, 6.0 kbit/s radio interface rate',
0x13: 'data, 6.0 kbit/s radio interface rate',
0x10: 'data, 64.0 kbit/s Transparent Data Bearer'
}
#------------------------------------------------------------------------------#
# Channel Mode 2
# TS 44.018, 10.5.2.7
#------------------------------------------------------------------------------#
class ChanMode2(Uint8):
_dic = {
0 : 'signalling only',
5 : 'GSM HR',
0xc1: 'GSM HR in VAMOS mode',
0x25: 'speech half rate version 2',
0x45: 'HR AMR',
0xc3: 'HR AMR in VAMOS mode',
0x85: 'OHR AMR-WB',
0x46: 'OHR AMR',
15 : 'data, 6.0 kbit/s radio interface rate',
0x17: 'data, 3.6 kbit/s radio interface rate'
}
#------------------------------------------------------------------------------#
# Classmark Enquiry Mask
# TS 44.018, 10.5.2.7c
#------------------------------------------------------------------------------#
class CmEnquiryMask(Envelope):
_GEN = (
Uint('CmChange', bl=1, dic={0:'requested', 1:'not requested'}),
Uint('UTRANCmChange', bl=3, dic={0:'requested', 7:'not requested'}),
Uint('cdma2000CmChange', bl=1, dic={0:'requested', 1:'not requested'}),
Uint('GERANIUModeCmChange', bl=1, dic={0:'requested', 1:'not requested'}),
Uint('spare', bl=2)
)
#------------------------------------------------------------------------------#
# Channel Needed
# TS 44.018, 10.5.2.8
#------------------------------------------------------------------------------#
_ChanNeeded_dict = {
0 : 'Any channel',
1 : 'SDCCH',
2 : 'TCH/F (Full rate)',
3 : 'TCH/H or TCH/F (Dual rate)'
}
class ChanNeeded(Envelope):
_GEN = (
Uint('SECOND', bl=2, dic=_ChanNeeded_dict),
Uint('FIRST', bl=2, dic=_ChanNeeded_dict)
)
#------------------------------------------------------------------------------#
# Cipher Mode Setting
# TS 44.018, 10.5.2.9
#------------------------------------------------------------------------------#
_AlgoId_dict = {
0 : 'A5/1',
1 : 'A5/2',
2 : 'A5/3',
3 : 'A5/4',
4 : 'A5/5',
5 : 'A5/6',
6 : 'A5/7',
7 : 'reserved'
}
class CipherModeSetting(Envelope):
_GEN = (
Uint('AlgoId', bl=3, dic=_AlgoId_dict),
Uint('SC', bl=1, dic={0:'no ciphering', 1:'start ciphering'})
)
#------------------------------------------------------------------------------#
# Cipher Response
# TS 44.018, 10.5.2.10
#------------------------------------------------------------------------------#
class CipherResp(Envelope):
_GEN = (
Uint('spare', bl=3),
Uint('CR', bl=1, dic={0:'IMEISV shall not be included', 1:'IMEISV shall be included'})
)
#------------------------------------------------------------------------------#
# Control Channel Description
# TS 44.018, 10.5.2.11
#------------------------------------------------------------------------------#
_CCCHConf_dict = {
0 : '1 PHY chan for CCCH, not combined with SDCCH',
1 : '1 PHY chan for CCCH, combined with SDCCH',
2 : '2 PHY chan for CCCH, combined with SDCCH',
4 : '3 PHY chan for CCCH, combined with SDCCH',
6 : '4 PHY chan for CCCH, combined with SDCCH',
}
_CBQ3_dict = {
0 : 'Iu mode not supported',
1 : 'Iu mode capable MSs barred',
2 : 'Iu mode supported, cell not barred',
3 : 'Iu mode supported, cell not barred. The network shall not use this value.'
}
class CtrlChanDesc(Envelope):
_GEN = (
Uint('MSCRel', bl=1, dic={0:'release 98 or older', 1:'release 99 onwards'}),
Uint('ATT', bl=1, dic={0:'IMSI attach and detach not allowed', 1:'MS shall apply IMSI attach and detach'}),
Uint('BS-AG-BLKS-RES', bl=3),
Uint('CCCHConf', bl=3, dic=_CCCHConf_dict),
Uint('SI22Ind', bl=1, dic={1:'SI22 broadcasted'}),
Uint('CBQ3', bl=2, dic=_CBQ3_dict),
Uint('spare', bl=2),
Uint('BS-PA-MFRMS', bl=3),
Uint8('T3212', dic={0:'periodic location updating shall not be used in the cell'})
)
#------------------------------------------------------------------------------#
# Frequency Channel Sequence
# TS 44.018, 10.5.2.12
#------------------------------------------------------------------------------#
class FreqChanSeq(Envelope):
_GEN = (
Uint('spare', bl=1),
Uint('LowestARFCN', bl=7),
Array(GEN=Uint('IncSkipARFCN', bl=4), num=16)
)
#------------------------------------------------------------------------------#
# Frequency List
# TS 44.018, 10.5.2.13
#------------------------------------------------------------------------------#
# from 11 (W1 only) to 1035 bits (W1 -> W264)
class FreqListRange1024(_FreqListRange):
_Layout = (10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7) + \
16 * (6,) + \
32 * (5,) + \
64 * (4,) + \
128 * (3,) + \
11 * (2,)
# from 15 (W1 only) to 1013 bits (W1 -> W511), could be 1023 bits
class FreqListRange512(_FreqListRange):
_Layout = (9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6) + \
16 * (5,) + \
32 * (4,) + \
64 * (3,) + \
128 * (2,) + \
256 * (1,)
# from 8 (W1 only) to 502 bits (W1 -> W255), could be 1023 bits
class FreqListRange256(_FreqListRange):
_Range = 256
_Layout = (8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5) + \
16 * (4,) + \
32 * (3,) + \
64 * (2,) + \
128 * (1,)
# from 8 (W1 only) to 247 bits (W1 to W127), could be 1023 bits
class FreqListRange128(_FreqListRange):
_Range = 128
_Layout = (7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4) + \
16 * (3,) + \
32 * (2,) + \
64 * (1,)
class FreqListAlt2(_FreqListAlt2):
_GEN = (
Uint('FmtExt2', bl=2, dic={0: 'range 512', 1: 'range 256', 2: 'range 128', 3: 'variable bit map'}),
Uint('OriginARFCN', val=0, bl=10),
Alt(GEN={
0: FreqListRange512(),
1: FreqListRange256(),
2: FreqListRange128(),
3: FreqListBitmapVar()},
sel=lambda self: self.get_env()[0].get_val())
)
class FreqListAlt1(_FreqListAlt1):
_GEN = (
Uint('FmtExt', bl=1, dic={0:'range 1024'}),
Alt(GEN={
0: FreqListRange1024(),
1: FreqListAlt2()},
sel=lambda self: self.get_env()[0].get_val())
)
# from 2 to 130 bytes, 16 to 1040 bits
class FreqList(_FreqList):
_GEN = (
Uint('Fmt', bl=2, dic={0:'bit map 0', 1:'undefined', 3: 'undefined'}),
Uint('spare', bl=2),
Alt(GEN={
0: FreqListBitmap0(),
2: FreqListAlt1()},
DEFAULT=Buf('undefined', rep=REPR_HEX),
sel=lambda self: self.get_env()[0].get_val())
)
#------------------------------------------------------------------------------#
# Frequency Short List
# TS 44.018, 10.5.2.14
#------------------------------------------------------------------------------#
# This is the same structure as FreqList defined in 10.5.2.13,
# but with a fixed length of 9 bytes
class FreqShortListRange1024(_FreqListRange1024):
_Layout = (10, 9, 9, 8, 8, 8, 8)
class FreqShortListRange512(_FreqListRangeLong):
_Layout = (9, 8, 8, 7, 7, 7, 7)
class FreqShortListRange256(_FreqListRange):
_Range = 256
_Layout = (8, 7, 7, 6, 6, 6, 6, 5)
class FreqShortListRange128(_FreqListRange):
_Range = 128
_Layout = (7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4)
class FreqShortListAlt2(_FreqListAlt2):
_GEN = (
Uint('FmtExt2', bl=2, dic={0: 'range 512', 1: 'range 256', 2: 'range 128', 3: 'variable bit map'}),
Uint('OriginARFCN', val=0, bl=10),
Alt(GEN={
0: FreqShortListRange512(),
1: FreqShortListRange256(),
2: FreqShortListRange128(),
3: FreqListBitmapVar('FreqShortListBitmapVar', bl=55)},
sel=lambda self: self.get_env()[0].get_val())
)
class FreqShortListAlt1(_FreqListAlt1):
_GEN = (
Uint('FmtExt', bl=1, dic={0:'range 1024'}),
Alt(GEN={
0: FreqShortListRange1024(),
1: FreqShortListAlt2()},
sel=lambda self: self.get_env()[0].get_val())
)
# 9 bytes, 72 bits
class FreqShortList(_FreqList):
_GEN = (
Uint('Fmt', val=2, bl=2),
Uint('spare', bl=2),
Alt(GEN={
2: FreqShortListAlt1()},
DEFAULT=Buf('undefined', rep=REPR_HEX),
sel=lambda self: self.get_env()[0].get_val())
)
#------------------------------------------------------------------------------#
# Group Channel Description
# TS 44.018, 10.5.2.14b
#------------------------------------------------------------------------------#
GroupChanDescType_dict = {
1 : 'TCH/FS + ACCHs (speech codec version 1)',
2 : 'TCH/HS + ACCHs (speech codec version 1); subchannel 0',
3 : 'TCH/HS + ACCHs (speech codec version 1); subchannel 1',
16 : 'TCH/FS + ACCHs (speech codec version 2)',
17 : 'TCH/AFS + ACCHs (speech codec version 3)',
18 : 'TCH/AHS + ACCHs (speech codec version 3); subchannel 0',
19 : 'TCH/AHS + ACCHs (speech codec version 3); subchannel 1',
4 : 'SDCCH/4 + SACCH/C4; subchannel 0',
5 : 'SDCCH/4 + SACCH/C4; subchannel 1',
6 : 'SDCCH/4 + SACCH/C4; subchannel 2',
7 : 'SDCCH/4 + SACCH/C4; subchannel 3',
8 : 'SDCCH/8 + SACCH/C8; subchannel 0',
9 : 'SDCCH/8 + SACCH/C8; subchannel 1',
10 : 'SDCCH/8 + SACCH/C8; subchannel 2',
11 : 'SDCCH/8 + SACCH/C8; subchannel 3',
12 : 'SDCCH/8 + SACCH/C8; subchannel 4',
13 : 'SDCCH/8 + SACCH/C8; subchannel 5',
14 : 'SDCCH/8 + SACCH/C8; subchannel 6',
15 : 'SDCCH/8 + SACCH/C8; subchannel 7',