|
| 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 | + |
0 commit comments