Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 1 | module GTP_Templates { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from GTPC_Types all; |
| 6 | import from GTPU_Types all; |
| 7 | import from GTP_CodecPort all; |
| 8 | import from IPCP_Types all; |
| 9 | |
Harald Welte | 3b4c356 | 2018-03-01 10:01:58 +0100 | [diff] [blame] | 10 | /* Table 38 of 3GPP TS 29.060 */ |
| 11 | type enumerated GTP_Cause { |
| 12 | GTP_CAUSE_REQUEST_IMEI (1), |
| 13 | GTP_CAUSE_REQUEST_IMSI_AND_IMEI (2), |
| 14 | GTP_CAUSE_NO_IDENTITY_NEDED (3), |
| 15 | GTP_CAUSE_MS_REFUSES (4), |
| 16 | GTP_CAUSE_MS_IS_NOT_GPRS_RESPONDING (5), |
| 17 | /* reserved */ |
| 18 | GTP_CAUSE_REQUEST_ACCEPTED (128) |
| 19 | /* FIXME */ |
| 20 | }; |
| 21 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 22 | /* generalized GTP-C receive template */ |
| 23 | template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := { |
| 24 | /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an |
| 25 | * error if this flag is set to '1'. */ |
| 26 | pn_bit := '0'B, |
| 27 | /* Sequence number flag (S) shall be set to '1'. */ |
| 28 | s_bit := '1'B, |
| 29 | e_bit := ?, |
| 30 | spare := ?, |
| 31 | /* Protocol Type flag (PT) shall be set to '1'.*/ |
| 32 | pt := '1'B, |
| 33 | /* Version shall be set to decimal 1 ('001'). */ |
| 34 | version := '001'B, |
| 35 | messageType := msg_type, |
| 36 | lengthf := ?, |
| 37 | teid := teid, |
| 38 | opt_part := *, |
| 39 | gtpc_pdu := pdu |
| 40 | } |
| 41 | |
| 42 | /* generalized GTP-C send template */ |
| 43 | template PDU_GTPC ts_GTP1C_PDU(OCT1 msg_type, OCT4 teid, GTPC_PDUs pdu, uint16_t seq_nr) := { |
| 44 | /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an |
| 45 | * error if this flag is set to '1'. */ |
| 46 | pn_bit := '0'B, |
| 47 | /* Sequence number flag (S) shall be set to '1'. */ |
| 48 | s_bit := '1'B, |
| 49 | e_bit := '0'B, |
| 50 | spare := '0'B, |
| 51 | /* Protocol Type flag (PT) shall be set to '1'.*/ |
| 52 | pt := '1'B, |
| 53 | /* Version shall be set to decimal 1 ('001'). */ |
| 54 | version := '001'B, |
| 55 | messageType := msg_type, |
| 56 | lengthf := 0, /* we assume encoder overwrites this */ |
| 57 | teid := teid, |
| 58 | opt_part := { |
| 59 | sequenceNumber := int2oct(seq_nr, 2), |
| 60 | npduNumber := '00'O, |
| 61 | nextExtHeader := '00'O, |
| 62 | gTPC_extensionHeader_List := omit |
| 63 | }, |
| 64 | gtpc_pdu := pdu |
| 65 | } |
| 66 | |
| 67 | /* recovery IE */ |
| 68 | template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := { |
| 69 | type_gtpc := '0E'O, |
| 70 | restartCounter := restart_counter |
| 71 | } |
| 72 | |
| 73 | template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := { |
| 74 | type_gtpc := '0E'O, |
| 75 | restartCounter := restart_counter |
| 76 | } |
| 77 | |
| 78 | /* template matching reception of GTP-C echo-request */ |
| 79 | template Gtp1cUnitdata tr_GTPC_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdus := ?) := { |
| 80 | peer := peer, |
| 81 | gtpc := tr_GTP1C_PDU(msg_type, teid, pdus) |
| 82 | } |
| 83 | |
| 84 | /* template matching reception of GTP-C echo-request */ |
| 85 | template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O); |
| 86 | |
| 87 | template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := { |
| 88 | echoResponse := { |
| 89 | recovery := tr_Recovery(restart_counter), |
| 90 | private_extension_gtpc := * |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /* template matching reception of GTP-C echo-response */ |
| 95 | template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?)); |
| 96 | |
| 97 | template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := { |
| 98 | echoResponse := { |
| 99 | recovery := ts_Recovery(restart_counter), |
| 100 | private_extension_gtpc := omit |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | /* master template for senidng a GTP-C echo response */ |
| 105 | template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := { |
| 106 | peer := peer, |
| 107 | gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq) |
| 108 | } |
| 109 | |
| 110 | template GTPC_PDUs ts_EchoReqPDU := { |
| 111 | echoRequest := { |
| 112 | private_extension_gtpc := omit |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /* master template for sending a GTP-C echo request */ |
| 117 | template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := { |
| 118 | peer := peer, |
| 119 | gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq) |
| 120 | } |
| 121 | |
| 122 | template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := { |
| 123 | type_gtpc := '80'O, |
| 124 | endUserAddress := { |
| 125 | endUserAddressIPv4 := { |
| 126 | lengthf := 2, |
| 127 | pdp_typeorg := '0001'B, |
| 128 | spare := '1111'B, |
| 129 | pdp_typenum := '21'O, |
| 130 | ipv4_address := ip_addr |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit); |
| 135 | template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := { |
| 136 | endUserAddress := { |
| 137 | endUserAddressIPv4 := { |
| 138 | lengthf := 2+lengthof(ip_addr) |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := { |
| 144 | type_gtpc := '80'O, |
| 145 | endUserAddress := { |
| 146 | endUserAddressIPv6 := { |
| 147 | lengthf := 2, |
| 148 | pdp_typeorg := '0001'B, |
| 149 | spare := '1111'B, |
| 150 | pdp_typenum := '57'O, |
| 151 | ipv6_address := ip_addr |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit); |
| 156 | template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := { |
| 157 | endUserAddress := { |
| 158 | endUserAddressIPv6 := { |
| 159 | lengthf := 2+lengthof(ip_addr) |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 164 | /* 3GPP TS 29.060 Figure 37A: End User Address Information Element for IPv4v6 (both static) */ |
| 165 | template EndUserAddress t_EuaIPv4v6(template OCT4 ip_addr4, template OCT16 ip_addr6) := { |
| 166 | type_gtpc := '80'O, |
| 167 | endUserAddress := { |
| 168 | endUserAddressIPv4andIPv6 := { |
| 169 | lengthf := 2, |
| 170 | pdp_typeorg := '0001'B, |
| 171 | spare := '1111'B, |
| 172 | pdp_typenum := '8D'O, |
| 173 | ipv4_address := ip_addr4, |
| 174 | ipv6_address := ip_addr6 |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | template EndUserAddress t_EuaIPv4Dynv6Dyn := t_EuaIPv4v6(omit, omit); |
| 179 | template EndUserAddress tr_EuaIPv4v6(template OCT4 ip_addr4, template OCT16 ip_addr6) modifies t_EuaIPv4v6 := { |
| 180 | endUserAddress := { |
| 181 | endUserAddressIPv4andIPv6 := { |
| 182 | lengthf := 2+lengthof(ip_addr4)+lengthof(ip_addr6) |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 187 | template AccessPointName ts_APN(octetstring apn) := { |
| 188 | type_gtpc := '83'O, |
| 189 | lengthf := lengthof(apn), |
| 190 | apn_value := apn |
| 191 | } |
| 192 | |
| 193 | template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := { |
| 194 | type_gtpc := '85'O, |
| 195 | lengthf := lengthof(ip_addr), |
| 196 | addressf := ip_addr |
| 197 | } |
| 198 | |
| 199 | template MSISDN ts_Msisdn(octetstring msisdn) := { |
| 200 | type_gtpc := '86'O, |
| 201 | lengthf := lengthof(msisdn), |
| 202 | msisdn := msisdn |
| 203 | } |
| 204 | |
| 205 | template QualityOfServiceProfile ts_QosDefault := { |
| 206 | type_gtpc := '87'O, |
| 207 | lengthf := 4, |
| 208 | allocRetensionPrio := '00'O, |
| 209 | qos_ProfileValue := { |
| 210 | reliabilityClass := '011'B, |
| 211 | delayClass := '001'B, |
| 212 | spare1 := '00'B, |
| 213 | precedenceClass := '010'B, |
| 214 | spare2 := '0'B, |
| 215 | peakThroughput := '1001'B, |
| 216 | meanThroughput := '11111'B, |
| 217 | spare3 := '000'B, |
| 218 | deliverErroneusSDU := omit, |
| 219 | deliveryOrder := omit, |
| 220 | trafficClass := omit, |
| 221 | maxSDUSize := omit, |
| 222 | maxBitrateUplink := omit, |
| 223 | maxBitrateDownlink := omit, |
| 224 | sduErrorRatio := omit, |
| 225 | residualBER := omit, |
| 226 | trafficHandlingPriority := omit, |
| 227 | transferDelay := omit, |
| 228 | guaranteedBitRateUplink := omit, |
| 229 | guaranteedBitRateDownlink := omit, |
| 230 | sourceStatisticsDescriptor := omit, |
| 231 | signallingIndication := omit, |
| 232 | spare4 := omit, |
| 233 | maxBitrateDownlinkExt := omit, |
| 234 | guaranteedBitRateDownlinkExt := omit, |
| 235 | maxBitrateUplinkExt := omit, |
| 236 | guaranteedBitRateUplinkExt := omit |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | template IMSI_gtpc ts_Imsi(hexstring digits) := { |
| 241 | type_gtpc := '02'O, |
| 242 | digits := digits, |
| 243 | padding := 'F'H |
| 244 | } |
| 245 | |
| 246 | template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl, |
| 247 | BIT4 nsapi, EndUserAddress eua, octetstring apn, |
| 248 | octetstring sgsn_ip_sign, octetstring sgsn_ip_data, |
| 249 | octetstring msisdn, template ProtConfigOptions pco := omit) := { |
| 250 | createPDPContextRequest := { |
| 251 | imsi := ts_Imsi(imsi), |
| 252 | rai := omit, |
| 253 | recovery := ts_Recovery(restart_ctr), |
| 254 | selectionMode := { |
| 255 | type_gtpc := '0F'O, |
| 256 | selectModeValue := '00'B, |
| 257 | spare := '111111'B |
| 258 | }, |
| 259 | teidDataI := { |
| 260 | type_gtpc := '00'O, |
| 261 | teidDataI := teid_data |
| 262 | }, |
| 263 | teidControlPlane := { |
| 264 | type_gtpc := '00'O, |
| 265 | teidControlPlane := teid_ctrl |
| 266 | }, |
| 267 | nsapi := { |
| 268 | type_gtpc := '00'O, |
| 269 | nsapi := nsapi, |
| 270 | unused := '0000'B |
| 271 | }, |
| 272 | linked_nsapi := omit, |
| 273 | charging_char := omit, |
| 274 | trace_ref := omit, |
| 275 | trace_type := omit, |
| 276 | endUserAddress := eua, |
| 277 | accessPointName := ts_APN(apn), |
| 278 | protConfigOptions := pco, |
| 279 | sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign), |
| 280 | sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data), |
| 281 | msisdn := ts_Msisdn(msisdn), |
| 282 | qualityOfServiceProfile := ts_QosDefault, |
| 283 | tft := omit, |
| 284 | triggerId := omit, |
| 285 | omcId := omit, |
| 286 | commonFlags := omit, |
| 287 | aPN_Restriction := omit, |
| 288 | ratType := omit, |
| 289 | userLocationInformation := omit, |
| 290 | mS_TimeZone := omit, |
| 291 | imeisv := omit, |
| 292 | camelChargingInformationContainer := omit, |
| 293 | additionalTraceInfo := omit, |
| 294 | correlationID := omit, |
| 295 | evolvedAllocationRetentionPriorityI := omit, |
| 296 | extendedCommonFlags := omit, |
| 297 | userCSGInformation := omit, |
| 298 | aPN_AMBR := omit, |
| 299 | signallingPriorityIndication := omit, |
| 300 | cN_OperatorSelectionEntity := omit, |
| 301 | private_extension_gtpc := omit |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi, |
| 306 | OCT1 restart_ctr, OCT4 teid_data, |
| 307 | OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua, |
| 308 | octetstring apn, octetstring sgsn_ip_sign, |
| 309 | octetstring sgsn_ip_data, octetstring msisdn, |
| 310 | template ProtConfigOptions pco := omit) := { |
| 311 | peer := peer, |
| 312 | gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O, |
| 313 | valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl, |
| 314 | nsapi, eua, apn, sgsn_ip_sign, |
| 315 | sgsn_ip_data, msisdn, pco)), seq) |
| 316 | } |
| 317 | |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 318 | |
| 319 | template NSAPI_GTPC ts_NSAPI(BIT4 nsapi) := { |
| 320 | type_gtpc := '14'O, |
| 321 | nsapi := nsapi, |
| 322 | unused := '0000'B |
| 323 | } |
| 324 | |
| 325 | template ReorderingRequired ts_ReorderReq(boolean req := false) := { |
| 326 | type_gtpc := '08'O, |
| 327 | reordreq := bool2bit(req), |
| 328 | spare := '0000000'B |
| 329 | } |
| 330 | |
| 331 | template GTPC_PDUs ts_CreatePdpRespPDU(OCT1 cause, OCT4 teid_data, OCT4 teid_ctrl, BIT4 nsapi, |
| 332 | octetstring ggsn_ip_sign, octetstring ggsn_ip_data, |
Harald Welte | 7aff2ca | 2018-02-18 15:34:50 +0100 | [diff] [blame] | 333 | OCT4 chg_id, template EndUserAddress eua := omit, |
Pau Espin Pedrol | 9401345 | 2018-07-17 15:50:21 +0200 | [diff] [blame] | 334 | template Recovery_gtpc recovery := omit, |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 335 | template ProtConfigOptions pco := omit) := { |
| 336 | createPDPContextResponse := { |
| 337 | cause := { '00'O, cause }, |
| 338 | reorderingRequired := ts_ReorderReq(false), |
Pau Espin Pedrol | 9401345 | 2018-07-17 15:50:21 +0200 | [diff] [blame] | 339 | recovery := recovery, |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 340 | teidDataI := { |
| 341 | type_gtpc := '00'O, |
| 342 | teidDataI := teid_data |
| 343 | }, |
| 344 | teidControlPlane := { |
| 345 | type_gtpc := '00'O, |
| 346 | teidControlPlane := teid_ctrl |
| 347 | }, |
| 348 | nsapi := ts_NSAPI(nsapi), |
Harald Welte | 7aff2ca | 2018-02-18 15:34:50 +0100 | [diff] [blame] | 349 | chargingID := { |
| 350 | type_gtpc := '7F'O, |
| 351 | chargingID := chg_id |
| 352 | }, |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 353 | endUserAddress := eua, |
| 354 | protConfigOptions := pco, |
| 355 | ggsn_addr_controlPlane := ts_GsnAddr(ggsn_ip_sign), |
| 356 | ggsn_addr_traffic := ts_GsnAddr(ggsn_ip_data), |
| 357 | alt_ggsn_addr_controlPane := omit, |
| 358 | alt_ggsn_addr_traffic := omit, |
| 359 | qualityOfServiceProfile := ts_QosDefault, |
| 360 | commonFlags := omit, |
| 361 | aPN_Restriction := omit, |
| 362 | mS_InfoChangeReportingAction := omit, |
| 363 | bearerControlMode := omit, |
| 364 | evolvedAllocationRetentionPriorityI := omit, |
| 365 | extendedCommonFlag := omit, |
| 366 | csg_information_reporting_action := omit, |
| 367 | aPN_AMBR := omit, |
| 368 | gGSN_BackOffTime := omit, |
| 369 | private_extension_gtpc := omit |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | template Gtp1cUnitdata ts_GTPC_CreatePdpResp(GtpPeer peer, uint16_t seq, OCT4 teid, |
| 374 | OCT1 cause, |
| 375 | OCT4 teid_ctrl, OCT4 teid_data, |
| 376 | BIT4 nsapi, octetstring ggsn_ip_sign, |
Harald Welte | 7aff2ca | 2018-02-18 15:34:50 +0100 | [diff] [blame] | 377 | octetstring ggsn_ip_data, OCT4 chg_id, |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 378 | template EndUserAddress eua := omit, |
Pau Espin Pedrol | 9401345 | 2018-07-17 15:50:21 +0200 | [diff] [blame] | 379 | template Recovery_gtpc recovery := omit, |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 380 | template ProtConfigOptions pco := omit) := { |
| 381 | peer := peer, |
| 382 | gtpc := ts_GTP1C_PDU(createPDPContextResponse, teid, |
| 383 | valueof(ts_CreatePdpRespPDU(cause, teid_data, teid_ctrl, nsapi, |
Harald Welte | 7aff2ca | 2018-02-18 15:34:50 +0100 | [diff] [blame] | 384 | ggsn_ip_sign, ggsn_ip_data, chg_id, |
Pau Espin Pedrol | 9401345 | 2018-07-17 15:50:21 +0200 | [diff] [blame] | 385 | eua, recovery, pco)), seq) |
Harald Welte | eded9ad | 2018-02-17 20:57:34 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 388 | /* PCO send base template */ |
| 389 | template ProtConfigOptions ts_PCO := { |
| 390 | type_gtpc := '84'O, |
| 391 | lengthf := 0, |
| 392 | configProtocol := '000'B, |
| 393 | spare := '0000'B, |
| 394 | extension0 := '1'B, |
| 395 | protocols := {} |
| 396 | } |
| 397 | /* PCO receive base template */ |
| 398 | template ProtConfigOptions tr_PCO := { |
| 399 | type_gtpc := '84'O, |
| 400 | lengthf := ?, |
| 401 | configProtocol := '000'B, |
| 402 | spare := ?, |
| 403 | extension0 := '1'B, |
| 404 | protocols := {} |
| 405 | } |
| 406 | |
| 407 | template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := { |
| 408 | protocols := { |
| 409 | { protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O } |
| 410 | } |
| 411 | } |
| 412 | template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := { |
| 413 | protocols := { |
| 414 | *, { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents }, * |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := { |
| 419 | protocols := { |
| 420 | /* dummy PAP entry to check if our parser in the GGSN can properly iterate over |
| 421 | * the list of protocols, see Change-Id Icc2e6716c33d78d3c3e000f529806228d8aa155e */ |
| 422 | { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O }, |
| 423 | { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := |
| 424 | enc_IpcpPacket(valueof(ts_IPCP_ReqDNS)) } |
| 425 | } |
| 426 | } |
| 427 | |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 428 | template ProtConfigOptions ts_PCO_IPv4_PRI_DNS_IPCP modifies ts_PCO := { |
| 429 | protocols := { |
| 430 | /* dummy PAP entry to check if our parser can cope with a single primary DNS entry |
| 431 | * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */ |
| 432 | { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O }, |
| 433 | { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := |
| 434 | enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Primary)) } |
| 435 | } |
| 436 | } |
| 437 | template ProtConfigOptions ts_PCO_IPv4_SEC_DNS_IPCP modifies ts_PCO := { |
| 438 | protocols := { |
| 439 | /* dummy PAP entry to check if our parser can cope with a single secondary DNS entry |
| 440 | * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */ |
| 441 | { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O }, |
| 442 | { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := |
| 443 | enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Secondary)) } |
| 444 | } |
| 445 | } |
| 446 | template ProtConfigOptions ts_PCO_IPv4_SEPARATE_DNS_IPCP modifies ts_PCO := { |
| 447 | protocols := { |
| 448 | /* dummy PAP entry to check if our parser can cope with a primary and secondary DNS |
| 449 | * in separate IPCP containers OS#3381 */ |
| 450 | { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O }, |
| 451 | { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := |
| 452 | enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Primary)) }, |
| 453 | { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := |
| 454 | enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Secondary)) } |
| 455 | } |
| 456 | } |
| 457 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 458 | template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := { |
| 459 | protocolID := prot_id, |
| 460 | lengthProtoID := ?, |
| 461 | protoIDContents := ? |
| 462 | } |
| 463 | template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := { |
| 464 | protocols := { *, tr_PCO_Proto(prot_id), * } |
| 465 | } |
| 466 | |
| 467 | template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := { |
| 468 | protocols := { |
| 469 | { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O } |
| 470 | } |
| 471 | } |
| 472 | template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := { |
| 473 | protocols := { |
| 474 | *, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, * |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | /* extract a given protocol payload from PCO */ |
| 479 | function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol, integer nth_match := 1) return octetstring { |
| 480 | var integer i; |
| 481 | var integer num_matches := 0; |
| 482 | for (i := 0; i < lengthof(pco.protocols); i := i + 1) { |
| 483 | if (pco.protocols[i].protocolID == protocol) { |
| 484 | num_matches := num_matches + 1; |
| 485 | if (num_matches == nth_match) { |
| 486 | return pco.protocols[i].protoIDContents; |
| 487 | } |
| 488 | } |
| 489 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 490 | setverdict(fail, "Could not extract protocol payload from protocol ", protocol); |
| 491 | mtc.stop; |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 492 | return ''O; |
| 493 | } |
| 494 | |
| 495 | template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier, |
| 496 | template IpcpOptionList opts) := { |
| 497 | code := code, |
| 498 | identifier := identifier, |
| 499 | len := ?, |
| 500 | options := opts |
| 501 | } |
| 502 | template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := { |
| 503 | code := IPCP_OPT_PrimaryDNS, |
| 504 | len := 6, |
| 505 | data := addr |
| 506 | } |
| 507 | template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := { |
| 508 | code := IPCP_OPT_SecondaryDNS, |
| 509 | len := 6, |
| 510 | data := addr |
| 511 | } |
| 512 | template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?, |
| 513 | template OCT4 dns2 := ?) := |
| 514 | tr_IPCP(LCP_Configure_Ack, identifier, |
| 515 | { *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * }); |
| 516 | |
| 517 | template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := { |
| 518 | code := code, |
| 519 | identifier := identifier, |
| 520 | len := 0, /* overwritten */ |
| 521 | options := opts |
| 522 | } |
| 523 | template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) := |
| 524 | ts_IPCP(LCP_Configure_Request, identifier, |
| 525 | { tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) }); |
| 526 | |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 527 | template IpcpPacket ts_IPCP_ReqDNS_Primary(uint8_t identifier := 0) := |
| 528 | ts_IPCP(LCP_Configure_Request, identifier, |
| 529 | { tr_IPCP_PrimaryDns('00000000'O) }); |
| 530 | template IpcpPacket ts_IPCP_ReqDNS_Secondary(uint8_t identifier := 0) := |
| 531 | ts_IPCP(LCP_Configure_Request, identifier, |
| 532 | { tr_IPCP_SecondaryDns('00000000'O) }); |
| 533 | |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 534 | function f_teardown_ind_IE(in template (omit) BIT1 ind) return template (omit) TearDownInd { |
| 535 | if (istemplatekind(ind, "omit")) { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 536 | return omit; |
| 537 | } |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 538 | var TearDownInd ret := { |
| 539 | type_gtpc := '13'O, |
| 540 | tdInd := valueof(ind), |
| 541 | spare:= '0000000'B |
| 542 | } |
| 543 | return ret; |
| 544 | } |
| 545 | |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 546 | template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template (omit) BIT1 teardown_ind) := { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 547 | deletePDPContextRequest := { |
| 548 | cause := omit, |
| 549 | tearDownIndicator := f_teardown_ind_IE(teardown_ind), |
| 550 | nsapi := { |
| 551 | type_gtpc := '14'O, |
| 552 | nsapi := nsapi, |
| 553 | unused := '0000'B |
| 554 | }, |
| 555 | protConfigOptions := omit, |
| 556 | userLocationInformation := omit, |
| 557 | mS_TimeZone := omit, |
| 558 | extendedCommonFlags := omit, |
| 559 | uLI_Timestamp := omit, |
| 560 | private_extension_gtpc := omit |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid, |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 565 | BIT4 nsapi, template (omit) BIT1 teardown_ind) := { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 566 | peer := peer, |
| 567 | gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid, |
| 568 | valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq) |
| 569 | } |
| 570 | |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 571 | template GTPC_PDUs ts_DeletePdpRespPDU(OCT1 cause, |
| 572 | template ProtConfigOptions pco := omit) := { |
| 573 | deletePDPContextResponse := { |
| 574 | cause := { '00'O, cause }, |
| 575 | protConfigOptions := pco, |
| 576 | userLocationInformation := omit, |
| 577 | mS_TimeZone := omit, |
| 578 | uLI_Timestamp := omit, |
| 579 | private_extension_gtpc := omit |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | template Gtp1cUnitdata ts_GTPC_DeletePdpResp(GtpPeer peer, uint16_t seq, OCT4 teid, |
| 584 | OCT1 cause, |
| 585 | template ProtConfigOptions pco := omit) := { |
| 586 | peer := peer, |
| 587 | gtpc := ts_GTP1C_PDU(deletePDPContextResponse, teid, |
| 588 | valueof(ts_DeletePdpRespPDU(cause, pco)), seq) |
| 589 | } |
| 590 | |
| 591 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 592 | |
| 593 | /* GTP-U */ |
| 594 | |
| 595 | template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := { |
| 596 | pn_bit := ?, |
| 597 | s_bit := ?, |
| 598 | e_bit := ?, |
| 599 | spare := ?, |
| 600 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 601 | pt := '1'B, |
| 602 | /* Version shall be set to decimal 1 ('001'). */ |
| 603 | version := '001'B, |
| 604 | messageType := msg_type, |
| 605 | lengthf := ?, |
| 606 | teid := teid, |
| 607 | opt_part := *, |
| 608 | gtpu_IEs := ies |
| 609 | } |
| 610 | |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 611 | function f_GTPU_s_bit(template (omit) uint16_t seq) return BIT1 { |
| 612 | if (istemplatekind(seq, "omit")) { |
| 613 | return '0'B; |
| 614 | } |
| 615 | return '1'B; |
| 616 | } |
| 617 | |
| 618 | function f_GTPU_opt_part(template (omit) uint16_t seq) return template (omit) GTPU_Header_optional_part { |
| 619 | if (istemplatekind(seq, "omit")) { |
| 620 | return omit; |
| 621 | } |
| 622 | var GTPU_Header_optional_part ret := { |
| 623 | sequenceNumber := int2oct(valueof(seq), 2), |
| 624 | npduNumber := '00'O, |
| 625 | nextExtHeader := '00'O, |
| 626 | gTPU_extensionHeader_List := omit |
| 627 | }; |
| 628 | return ret; |
| 629 | } |
| 630 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 631 | /* generalized GTP-U send template */ |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 632 | template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, template (omit) uint16_t seq, OCT4 teid, GTPU_IEs ies) := { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 633 | /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN |
| 634 | * flag is set to 1. */ |
| 635 | pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */ |
| 636 | /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and |
| 637 | * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response, |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 638 | * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. |
| 639 | * |
| 640 | * Note that the caller must ensure that these conditions hold. |
| 641 | * The caller can either pass a sequence number (we set s_bit to '1'B) when appropriate, |
| 642 | * or may omit the sequence number (we set s_bit to '0'B). */ |
| 643 | s_bit := f_GTPU_s_bit(seq), |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 644 | /* Extension header presence */ |
| 645 | e_bit := '0'B, |
| 646 | spare := '0'B, |
| 647 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 648 | pt := '1'B, |
| 649 | /* Version shall be set to decimal 1 ('001'). */ |
| 650 | version := '001'B, |
| 651 | messageType := msg_type, |
| 652 | lengthf := 0, /* we assume encoder overwrites this */ |
| 653 | teid := teid, |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 654 | opt_part := f_GTPU_opt_part(seq), |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 655 | gtpu_IEs := ies |
| 656 | } |
| 657 | |
| 658 | template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := { |
| 659 | peer := peer, |
| 660 | gtpu := tr_GTP1U_PDU(msg_type, teid) |
| 661 | } |
| 662 | |
| 663 | |
| 664 | /* template matching reception of GTP-U echo-request */ |
| 665 | template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O); |
| 666 | |
| 667 | /* template matching reception of GTP-U GPDU */ |
| 668 | template GTPU_IEs t_GPDU(template octetstring data) := { |
| 669 | g_PDU_IEs := { |
| 670 | data := data |
| 671 | } |
| 672 | } |
| 673 | template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := { |
| 674 | peer := peer, |
| 675 | gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data)) |
| 676 | } |
| 677 | |
| 678 | template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := { |
| 679 | echoResponse_IEs := { |
| 680 | recovery_gtpu := { |
| 681 | type_gtpu := '00'O, /* we assume encoder fixes? */ |
| 682 | restartCounter := restart_counter |
| 683 | }, |
| 684 | private_extension_gtpu := omit |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | /* master template for sending a GTP-U echo response */ |
| 689 | template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := { |
| 690 | peer := peer, |
| 691 | gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr))) |
| 692 | } |
| 693 | |
Pau Espin Pedrol | f3e2538 | 2018-07-18 13:46:40 +0200 | [diff] [blame] | 694 | template GSNAddress_gtpu ts_UGsnAddr(octetstring ip_addr) := { |
| 695 | type_gtpu := '85'O, |
| 696 | lengthf := lengthof(ip_addr), |
| 697 | gSNAddressValue := ip_addr |
| 698 | } |
| 699 | |
| 700 | template TeidDataI_gtpu ts_UteidDataI(OCT4 teid) := { |
| 701 | type_gtpu := '10'O, |
| 702 | teidDataI := teid |
| 703 | } |
| 704 | |
| 705 | template GTPU_IEs ts_UErrorIndication(OCT4 teid, octetstring gsn_addr) := { |
| 706 | errorIndication_IEs := { |
| 707 | teidDataI_gtpu := ts_UteidDataI(teid), |
| 708 | gSNAddress_gtpu := ts_UGsnAddr(gsn_addr), |
| 709 | private_extension_gtpu := omit |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /* master template for sending a GTP-U Error indication */ |
| 714 | template Gtp1uUnitdata ts_GTPU_ErrorIndication(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring gsn_addr) := { |
| 715 | peer := peer, |
| 716 | gtpu := ts_GTP1U_PDU('1A'O, seq, '00000000'O, valueof(ts_UErrorIndication(teid, gsn_addr))) |
| 717 | } |
| 718 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 719 | /* master template for sending a GTP-U user plane data */ |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 720 | template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, template (omit) uint16_t seq, OCT4 teid, octetstring data) := { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 721 | peer := peer, |
| 722 | gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }}) |
| 723 | } |
| 724 | } |