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