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 | } |
| 467 | setverdict(fail); |
| 468 | return ''O; |
| 469 | } |
| 470 | |
| 471 | template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier, |
| 472 | template IpcpOptionList opts) := { |
| 473 | code := code, |
| 474 | identifier := identifier, |
| 475 | len := ?, |
| 476 | options := opts |
| 477 | } |
| 478 | template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := { |
| 479 | code := IPCP_OPT_PrimaryDNS, |
| 480 | len := 6, |
| 481 | data := addr |
| 482 | } |
| 483 | template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := { |
| 484 | code := IPCP_OPT_SecondaryDNS, |
| 485 | len := 6, |
| 486 | data := addr |
| 487 | } |
| 488 | template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?, |
| 489 | template OCT4 dns2 := ?) := |
| 490 | tr_IPCP(LCP_Configure_Ack, identifier, |
| 491 | { *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * }); |
| 492 | |
| 493 | template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := { |
| 494 | code := code, |
| 495 | identifier := identifier, |
| 496 | len := 0, /* overwritten */ |
| 497 | options := opts |
| 498 | } |
| 499 | template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) := |
| 500 | ts_IPCP(LCP_Configure_Request, identifier, |
| 501 | { tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) }); |
| 502 | |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 503 | template IpcpPacket ts_IPCP_ReqDNS_Primary(uint8_t identifier := 0) := |
| 504 | ts_IPCP(LCP_Configure_Request, identifier, |
| 505 | { tr_IPCP_PrimaryDns('00000000'O) }); |
| 506 | template IpcpPacket ts_IPCP_ReqDNS_Secondary(uint8_t identifier := 0) := |
| 507 | ts_IPCP(LCP_Configure_Request, identifier, |
| 508 | { tr_IPCP_SecondaryDns('00000000'O) }); |
| 509 | |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 510 | function f_teardown_ind_IE(in template (omit) BIT1 ind) return template (omit) TearDownInd { |
| 511 | if (istemplatekind(ind, "omit")) { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 512 | return omit; |
| 513 | } |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 514 | var TearDownInd ret := { |
| 515 | type_gtpc := '13'O, |
| 516 | tdInd := valueof(ind), |
| 517 | spare:= '0000000'B |
| 518 | } |
| 519 | return ret; |
| 520 | } |
| 521 | |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 522 | template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template (omit) BIT1 teardown_ind) := { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 523 | deletePDPContextRequest := { |
| 524 | cause := omit, |
| 525 | tearDownIndicator := f_teardown_ind_IE(teardown_ind), |
| 526 | nsapi := { |
| 527 | type_gtpc := '14'O, |
| 528 | nsapi := nsapi, |
| 529 | unused := '0000'B |
| 530 | }, |
| 531 | protConfigOptions := omit, |
| 532 | userLocationInformation := omit, |
| 533 | mS_TimeZone := omit, |
| 534 | extendedCommonFlags := omit, |
| 535 | uLI_Timestamp := omit, |
| 536 | private_extension_gtpc := omit |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid, |
Harald Welte | 57b9b7f | 2018-02-18 22:28:13 +0100 | [diff] [blame] | 541 | BIT4 nsapi, template (omit) BIT1 teardown_ind) := { |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 542 | peer := peer, |
| 543 | gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid, |
| 544 | valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq) |
| 545 | } |
| 546 | |
Harald Welte | 6f20316 | 2018-02-18 22:04:55 +0100 | [diff] [blame] | 547 | template GTPC_PDUs ts_DeletePdpRespPDU(OCT1 cause, |
| 548 | template ProtConfigOptions pco := omit) := { |
| 549 | deletePDPContextResponse := { |
| 550 | cause := { '00'O, cause }, |
| 551 | protConfigOptions := pco, |
| 552 | userLocationInformation := omit, |
| 553 | mS_TimeZone := omit, |
| 554 | uLI_Timestamp := omit, |
| 555 | private_extension_gtpc := omit |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | template Gtp1cUnitdata ts_GTPC_DeletePdpResp(GtpPeer peer, uint16_t seq, OCT4 teid, |
| 560 | OCT1 cause, |
| 561 | template ProtConfigOptions pco := omit) := { |
| 562 | peer := peer, |
| 563 | gtpc := ts_GTP1C_PDU(deletePDPContextResponse, teid, |
| 564 | valueof(ts_DeletePdpRespPDU(cause, pco)), seq) |
| 565 | } |
| 566 | |
| 567 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 568 | |
| 569 | /* GTP-U */ |
| 570 | |
| 571 | template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := { |
| 572 | pn_bit := ?, |
| 573 | s_bit := ?, |
| 574 | e_bit := ?, |
| 575 | spare := ?, |
| 576 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 577 | pt := '1'B, |
| 578 | /* Version shall be set to decimal 1 ('001'). */ |
| 579 | version := '001'B, |
| 580 | messageType := msg_type, |
| 581 | lengthf := ?, |
| 582 | teid := teid, |
| 583 | opt_part := *, |
| 584 | gtpu_IEs := ies |
| 585 | } |
| 586 | |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 587 | function f_GTPU_s_bit(template (omit) uint16_t seq) return BIT1 { |
| 588 | if (istemplatekind(seq, "omit")) { |
| 589 | return '0'B; |
| 590 | } |
| 591 | return '1'B; |
| 592 | } |
| 593 | |
| 594 | function f_GTPU_opt_part(template (omit) uint16_t seq) return template (omit) GTPU_Header_optional_part { |
| 595 | if (istemplatekind(seq, "omit")) { |
| 596 | return omit; |
| 597 | } |
| 598 | var GTPU_Header_optional_part ret := { |
| 599 | sequenceNumber := int2oct(valueof(seq), 2), |
| 600 | npduNumber := '00'O, |
| 601 | nextExtHeader := '00'O, |
| 602 | gTPU_extensionHeader_List := omit |
| 603 | }; |
| 604 | return ret; |
| 605 | } |
| 606 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 607 | /* generalized GTP-U send template */ |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 608 | 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] | 609 | /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN |
| 610 | * flag is set to 1. */ |
| 611 | pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */ |
| 612 | /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and |
| 613 | * 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] | 614 | * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. |
| 615 | * |
| 616 | * Note that the caller must ensure that these conditions hold. |
| 617 | * The caller can either pass a sequence number (we set s_bit to '1'B) when appropriate, |
| 618 | * or may omit the sequence number (we set s_bit to '0'B). */ |
| 619 | s_bit := f_GTPU_s_bit(seq), |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 620 | /* Extension header presence */ |
| 621 | e_bit := '0'B, |
| 622 | spare := '0'B, |
| 623 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 624 | pt := '1'B, |
| 625 | /* Version shall be set to decimal 1 ('001'). */ |
| 626 | version := '001'B, |
| 627 | messageType := msg_type, |
| 628 | lengthf := 0, /* we assume encoder overwrites this */ |
| 629 | teid := teid, |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 630 | opt_part := f_GTPU_opt_part(seq), |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 631 | gtpu_IEs := ies |
| 632 | } |
| 633 | |
| 634 | template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := { |
| 635 | peer := peer, |
| 636 | gtpu := tr_GTP1U_PDU(msg_type, teid) |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /* template matching reception of GTP-U echo-request */ |
| 641 | template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O); |
| 642 | |
| 643 | /* template matching reception of GTP-U GPDU */ |
| 644 | template GTPU_IEs t_GPDU(template octetstring data) := { |
| 645 | g_PDU_IEs := { |
| 646 | data := data |
| 647 | } |
| 648 | } |
| 649 | template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := { |
| 650 | peer := peer, |
| 651 | gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data)) |
| 652 | } |
| 653 | |
| 654 | template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := { |
| 655 | echoResponse_IEs := { |
| 656 | recovery_gtpu := { |
| 657 | type_gtpu := '00'O, /* we assume encoder fixes? */ |
| 658 | restartCounter := restart_counter |
| 659 | }, |
| 660 | private_extension_gtpu := omit |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /* master template for sending a GTP-U echo response */ |
| 665 | template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := { |
| 666 | peer := peer, |
| 667 | gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr))) |
| 668 | } |
| 669 | |
Pau Espin Pedrol | f3e2538 | 2018-07-18 13:46:40 +0200 | [diff] [blame^] | 670 | template GSNAddress_gtpu ts_UGsnAddr(octetstring ip_addr) := { |
| 671 | type_gtpu := '85'O, |
| 672 | lengthf := lengthof(ip_addr), |
| 673 | gSNAddressValue := ip_addr |
| 674 | } |
| 675 | |
| 676 | template TeidDataI_gtpu ts_UteidDataI(OCT4 teid) := { |
| 677 | type_gtpu := '10'O, |
| 678 | teidDataI := teid |
| 679 | } |
| 680 | |
| 681 | template GTPU_IEs ts_UErrorIndication(OCT4 teid, octetstring gsn_addr) := { |
| 682 | errorIndication_IEs := { |
| 683 | teidDataI_gtpu := ts_UteidDataI(teid), |
| 684 | gSNAddress_gtpu := ts_UGsnAddr(gsn_addr), |
| 685 | private_extension_gtpu := omit |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /* master template for sending a GTP-U Error indication */ |
| 690 | template Gtp1uUnitdata ts_GTPU_ErrorIndication(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring gsn_addr) := { |
| 691 | peer := peer, |
| 692 | gtpu := ts_GTP1U_PDU('1A'O, seq, '00000000'O, valueof(ts_UErrorIndication(teid, gsn_addr))) |
| 693 | } |
| 694 | |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 695 | /* master template for sending a GTP-U user plane data */ |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 696 | 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] | 697 | peer := peer, |
| 698 | gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }}) |
| 699 | } |
| 700 | } |