Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit b423019

Browse files
committed
GMR-1: add partial support for the Global Mobile Radio RR protocol
1 parent d0ebc84 commit b423019

File tree

565 files changed

+25300
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+25300
-1
lines changed

pycrate_gmr1/TS101376_04_08.py

Lines changed: 673 additions & 0 deletions
Large diffs are not rendered by default.

pycrate_gmr1/TS101376_04_08_IE.py

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
# -*- coding: UTF-8 -*-
2+
#/**
3+
# * Software Name : pycrate
4+
# * Version : 0.4
5+
# *
6+
# * Copyright 2018. Benoit Michau. P1Sec.
7+
# *
8+
# * This library is free software; you can redistribute it and/or
9+
# * modify it under the terms of the GNU Lesser General Public
10+
# * License as published by the Free Software Foundation; either
11+
# * version 2.1 of the License, or (at your option) any later version.
12+
# *
13+
# * This library is distributed in the hope that it will be useful,
14+
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
# * Lesser General Public License for more details.
17+
# *
18+
# * You should have received a copy of the GNU Lesser General Public
19+
# * License along with this library; if not, write to the Free Software
20+
# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21+
# * MA 02110-1301 USA
22+
# *
23+
# *--------------------------------------------------------
24+
# * File Name : pycrate_mobile/TS101376_04_08_IE.py
25+
# * Created : 2018-12-26
26+
# * Authors : Benoit Michau
27+
# *--------------------------------------------------------
28+
#*/
29+
30+
#------------------------------------------------------------------------------#
31+
# ETSI TS 101 376 04-08 GMR-1 NAS protocol IEs
32+
# release V3.4.1
33+
#------------------------------------------------------------------------------#
34+
35+
from pycrate_core.utils import *
36+
from pycrate_core.elt import *
37+
from pycrate_core.base import *
38+
from pycrate_mobile.TS24007 import *
39+
40+
from pycrate_mobile.TS24008_IE import (
41+
ID,
42+
CalledPartyBCDNumber
43+
)
44+
from pycrate_mobile.TS44018_IE import (
45+
L2PseudoLength,
46+
TMSI,
47+
CipherResp,
48+
CipherModeSetting
49+
)
50+
from pycrate_mobile.TS23038 import (
51+
encode_7b,
52+
decode_7b
53+
)
54+
55+
56+
#------------------------------------------------------------------------------#
57+
# TS 101 376 04-08 IE specified with CSN.1
58+
#------------------------------------------------------------------------------#
59+
60+
from pycrate_gmr1_csn1.prefixed_gps_position_ie import prefixed_gps_position_ie
61+
62+
63+
#------------------------------------------------------------------------------#
64+
# Channel description
65+
# TS 101 376 04-08, section 11.5.2.5
66+
#------------------------------------------------------------------------------#
67+
68+
ChanType_dict = {
69+
1 : 'TCH3 No offset',
70+
3 : 'TCH3 1/2 symbol offset',
71+
4 : 'TCH9 No offset',
72+
5 : 'TCH9 1/2 symbol offset',
73+
6 : 'TCH6 No offset',
74+
7 : 'TCH6 1/2 symbol offset',
75+
13: 'Reserved for SDCCH frames xx00',
76+
14: 'Reserved for SDCCH frames xx01',
77+
15: 'Reserved for SDCCH frames xx10',
78+
16: 'Reserved for SDCCH frames xx11'
79+
}
80+
81+
class ChanDesc(Envelope):
82+
_GEN = (
83+
Uint('KABLocation', bl=6),
84+
Uint('RXTimeslot', bl=5),
85+
Uint('ARFCN', bl=11),
86+
Uint('TXTimeslot', bl=5),
87+
Uint('ChanType', bl=5, dic=ChanType_dict)
88+
)
89+
90+
91+
#------------------------------------------------------------------------------#
92+
# Page mode
93+
# TS 101 376 04-08, section 11.5.2.26
94+
#------------------------------------------------------------------------------#
95+
96+
PageMode_dict = {
97+
0 : 'Normal paging',
98+
1 : 'reserved',
99+
2 : 'Paging reorganization',
100+
3 : 'Same as before'
101+
}
102+
103+
104+
#------------------------------------------------------------------------------#
105+
# Request Reference
106+
# TS 101 376 04-08, section 11.5.2.30
107+
#------------------------------------------------------------------------------#
108+
109+
class RequestRef(Envelope):
110+
_GEN = (
111+
Uint('EstabCauseGroupID', bl=3),
112+
Uint('RandAccessInfo', bl=5),
113+
Uint8('FrameNum')
114+
)
115+
116+
117+
#------------------------------------------------------------------------------#
118+
# RR cause
119+
# TS 101 376 04-08, section 11.5.2.31
120+
#------------------------------------------------------------------------------#
121+
122+
class RRCause(Uint8):
123+
_dic = {
124+
0 : 'Normal event',
125+
1 : 'Abnormal release, unspecified',
126+
2 : 'Abnormal release, channel unacceptable',
127+
3 : 'Abnormal release, timer expired',
128+
4 : 'Abnormal release, no activity on the radio path',
129+
5 : 'Preemptive release',
130+
9 : 'Channel mode unacceptable',
131+
10: 'Frequency not implemented',
132+
11: 'Position unacceptable',
133+
65: 'Call already cleared',
134+
95: 'Semantically incorrect message',
135+
96: 'Invalid mandatory information',
136+
97: 'Message type nonexistent or not implemented',
137+
98: 'Message type not compatible with protocol state',
138+
111: 'Protocol error unspecified'
139+
}
140+
141+
142+
#------------------------------------------------------------------------------#
143+
# Timing offset
144+
# TS 101 376 04-08, section 11.5.2.40
145+
#------------------------------------------------------------------------------#
146+
147+
class TimingOffset(Envelope):
148+
_GEN = (
149+
Uint('TI', bl=1, dic={0:'no valid value', 1:'valid value'}),
150+
Int('Value', bl=15)
151+
)
152+
153+
154+
#------------------------------------------------------------------------------#
155+
# MES information flag
156+
# TS 101 376 04-08, section 11.5.2.44
157+
#------------------------------------------------------------------------------#
158+
159+
MESInfo_PV_dict = {
160+
0 : 'Position Verification not requested',
161+
1 : 'MES1 shall send a Channel Request for Position Verification following the completion of the upcoming call'
162+
}
163+
164+
MESInfo_ab_dict = {
165+
0 : 'Chan assigned: MES1 registered at selected GS',
166+
1 : 'Chan assigned: MES1 requires registration at selected GS',
167+
2 : 'Chan assigned: MES 1 Extended Channel Request required',
168+
3 : 'Pause Timer Indication'
169+
}
170+
171+
class MESInfoFlag(Envelope):
172+
_GEN = (
173+
Uint('PV', bl=1, dic=MESInfo_PV_dict),
174+
Uint('MES4', bl=1),
175+
Uint('MES3', bl=1),
176+
Uint('MES2', bl=1),
177+
Uint('MES1_D', bl=1, dic={1:'Dedicated Mode Position Update IE present', 0:'Dedicated Mode Position Update IE absent'}),
178+
Uint('MES1_I', bl=1, dic={1:'Idle Mode Position Update IE present', 0:'Idle Mode Position Update IE absent'}),
179+
Uint('MES1_ab', bl=2, dic=MESInfo_ab_dict),
180+
)
181+
182+
183+
#------------------------------------------------------------------------------#
184+
# Frequency offset
185+
# TS 101 376 04-08, section 11.5.2.49
186+
#------------------------------------------------------------------------------#
187+
188+
class FrequencyOffset(Envelope):
189+
_GEN = (
190+
Uint('FI', bl=1, dic={0:'no valid value', 1:'valid value'}),
191+
Int('Value', bl=12),
192+
Uint('spare', bl=3, rep=REPR_HEX)
193+
)
194+
195+
196+
#------------------------------------------------------------------------------#
197+
# Paging information
198+
# TS 101 376 04-08, section 11.5.2.51
199+
#------------------------------------------------------------------------------#
200+
201+
ChanNeeded_dict = {
202+
0 : 'any',
203+
1 : 'SDCCH',
204+
2 : 'TCH3',
205+
3 : 'spare'
206+
}
207+
208+
class PagingInfo(Envelope):
209+
_GEN = (
210+
Uint('MSC_ID', bl=6),
211+
Uint('ChanNeeded', bl=2, dic=ChanNeeded_dict)
212+
)
213+
214+
215+
#------------------------------------------------------------------------------#
216+
# Position display
217+
# TS 101 376 04-08, section 11.5.2.52
218+
#------------------------------------------------------------------------------#
219+
220+
PositionInfoFlag_dict = {
221+
0 : 'Position not available, MES may continue to use old position string',
222+
1 : 'No position display service provided. MES should not use the old position string',
223+
2 : 'Use Default 7-Bit alphabet to encode the country/region name string'
224+
}
225+
226+
class Buf7b(Buf):
227+
228+
def encode(self, val):
229+
# WNG: this check is not perfect, as some chars require 7 septets,
230+
# and we must have exactly 12 septets here
231+
if len(val) > 12:
232+
val = val[:12]
233+
elif len(val) < 12:
234+
val = val + (12-len(val))*' '
235+
self.set_val(encode_7b(val)[0])
236+
237+
def decode(self):
238+
val = decode_7b(self.get_val())
239+
if len(val) < 12:
240+
# in case of stripped last char (@ or \r)
241+
val = val + (12-len(val))*' '
242+
return val
243+
244+
def repr(self):
245+
if self._rep == REPR_HUM:
246+
return '<%s : %s>' % (self._name, self.decode())
247+
else:
248+
return Buf.repr(self)
249+
250+
__repr__ = repr
251+
252+
253+
class PositionDisplay(Envelope):
254+
_GEN = (
255+
Uint('DisplayInfoFlag', bl=4, dic=PositionInfoFlag_dict),
256+
Buf7b('CountryRegionName', bl=84, rep=REPR_HUM) # 12 7-bit chars
257+
)
258+
259+
260+
#------------------------------------------------------------------------------#
261+
# GPS position
262+
# TS 101 376 04-08, section 11.5.2.53
263+
#------------------------------------------------------------------------------#
264+
265+
class GPSPosition(Envelope):
266+
_GEN = (
267+
Uint('CPI', bl=1, dic={0:'GPS position is old', 1:'GPS position is current'}),
268+
Uint('GPSLatitude', bl=19),
269+
Uint('GPSLongitude', bl=20)
270+
)
271+
272+
273+
#------------------------------------------------------------------------------#
274+
# Idle or dedicated mode position update information
275+
# TS 101 376 04-08, section 11.5.2.54
276+
#------------------------------------------------------------------------------#
277+
278+
class PosUpdInfo(Envelope):
279+
_GEN = (
280+
Uint('GPSUpdDistance', bl=7),
281+
Uint('V', bl=1, dic={0:'no valid value', 1:'valid value'}),
282+
Uint8('GPSUpdTimer')
283+
)
284+
285+
286+
#------------------------------------------------------------------------------#
287+
# GPS timestamp
288+
# TS 101 376 04-08, section 11.5.2.57
289+
#------------------------------------------------------------------------------#
290+
291+
class GPSTimestamp(Uint16):
292+
pass
293+
294+
295+
#------------------------------------------------------------------------------#
296+
# GPS almanac data
297+
# TS 101 376 04-08, section 11.5.2.63
298+
#------------------------------------------------------------------------------#
299+
300+
class GPSAlmanacData(Envelope):
301+
_GEN = (
302+
Uint('PageNum', bl=5),
303+
Uint('WordNum', bl=3),
304+
Uint24('GPSAlmanacWord'),
305+
Uint('SFN', bl=1),
306+
Uint('CO', bl=2),
307+
Uint('spare', bl=5, rep=REPR_HEX)
308+
)
309+
310+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
-- ETSI TS 101 376-04-08, release 3
2+
-- 10.1.8.4 Channel Request Type 3 (Iu mode only)
3+
-- Channel Request Type 3 Message Content
4+
5+
< Channel Request Type 3 Message content > ::=
6+
{ 0 -- Critical Message Escape
7+
{ < Retry Counter: bit (2) >
8+
< Test Mode: bit (1) > }
9+
{ 0000
10+
-- RRC Connection Request
11+
{ < Random S-RNTI: bit (20) >
12+
< RRC Establishment Cause: bit (5) >
13+
< MES Position: <Relative Position IE>>
14+
< GMPRS Terminal Type Id: bit (7) >
15+
< RA Indicator: bit (1) >
16+
< Spare: bit (1)> }
17+
| 0001
18+
-- RRC Periodic GRA Update
19+
{ < S-RNTI: bit (20) >
20+
< MES Position: <Relative Position IE>>
21+
< Spare: bit (14) > }
22+
| 0010
23+
-- RRC GRA Update/Change in GRA
24+
{ < G-RNTI: bit (32) >
25+
< MES Position: <Relative Position IE>>
26+
< Spare: bit (2)> }
27+
| 0011
28+
-- RRC Cell Update
29+
{ < S-RNTI: bit (20) >
30+
< Cell Update Cause: bit (3)>
31+
< MES Position: <Relative Position IE>>
32+
< RB Info: <RB Request Struct IE>> }
33+
| 0100
34+
-- User Data Transfer - Application Type 1
35+
{ < S-RNTI: bit (20) >
36+
< MES Position: <Relative Position IE>>
37+
< RB Id: bit (5)>
38+
< User Data: bit (8) >
39+
< Spare: bit (1) > }
40+
| 0101
41+
-- Position Verification
42+
{ < S-RNTI or Random S-RNTI: bit (20) >
43+
< Enhanced MES Position: < Enhanced Relative Position IE>>
44+
< MES RRC Mode Indicator: bit (1) >
45+
< Spare: bit (1) > }
46+
! < Content part error: bit (*) = < no string > > }
47+
} ;
48+
49+
<RB Request Struct IE> ::=
50+
< RB Id: bit (5) >
51+
< RLC_BLOCK_COUNT: bit (6) > ;
52+
53+
<Relative Position IE> ::=
54+
< GPS Capability Indicator: bit (1) >
55+
< Relative Latitude: bit (12) >
56+
< Relative Longitude: bit (13) > ;
57+
58+
<Enhanced Relative Position IE> ::=
59+
< Enhanced Relative Latitude: bit (19) >
60+
< Enhanced Relative Longitude: bit (19) > ;
61+

0 commit comments

Comments
 (0)