Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 1 | module DIAMETER_ts32_299_Templates { |
| 2 | |
| 3 | /* (C) 2023 by sysmocom s.f.m.c. GmbH <info@sysmocom.de |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | * |
| 11 | * Templates for AVPs and messages for TS 32.299 |
| 12 | */ |
| 13 | |
| 14 | import from General_Types all; |
| 15 | import from DIAMETER_Types all; |
| 16 | import from DIAMETER_Templates all; |
| 17 | import from Osmocom_Types all; |
| 18 | import from Misc_Helpers all; |
| 19 | |
| 20 | /******************************* |
Pau Espin Pedrol | 9b3d062 | 2024-03-18 20:47:06 +0100 | [diff] [blame] | 21 | * Gy 3GPP TS 32.299 section 7 |
Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 22 | *******************************/ |
| 23 | |
| 24 | /* Gy AID : 3GPP TS 32.299 7.1.6, RFC4006 3.1: c_DIAMETER_CREDIT_CONTROL_AID */ |
| 25 | |
Pau Espin Pedrol | 9b3d062 | 2024-03-18 20:47:06 +0100 | [diff] [blame] | 26 | /* 3GPP TS 32.299 7.1.11 Result-Code AVP*/ |
| 27 | type enumerated DIAMETER_ts32_229_Resultcode { |
| 28 | /* transient */ |
| 29 | DIAMETER_END_USER_SERVICE_DENIED (4010), |
| 30 | DIAMETER_CREDIT_CONTROL_NOT_APPLICABLE (4011), |
| 31 | DIAMETER_CREDIT_LIMIT_REACHED (4012), |
| 32 | /* permanent */ |
| 33 | DIAMETER_AUTHORIZATION_REJECTED (5003), |
| 34 | DIAMETER_USER_UNKNOWN (5030), |
| 35 | DIAMETER_RATING_FAILED (5031) |
| 36 | } |
| 37 | |
Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 38 | /* 3GPP TS 32.299 6.4.2 Credit-Control-Request */ |
| 39 | template (present) PDU_DIAMETER |
| 40 | tr_DIA_Gy_CCR(template (present) DCC_NONE_CC_Request_Type req_type := INITIAL_REQUEST) |
| 41 | := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control, |
| 42 | avps := superset( |
| 43 | tr_AVP_SessionId, |
| 44 | tr_AVP_OriginHost, |
| 45 | tr_AVP_OriginRealm, |
| 46 | tr_AVP_DestinationRealm, |
| 47 | tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 48 | tr_AVP_CcReqType(req_type), |
| 49 | tr_AVP_CcReqNum(?) |
| 50 | )); |
| 51 | |
| 52 | /* 3GPP TS 32.299 6.4.3 Credit-Control-Answer message */ |
| 53 | template (value) PDU_DIAMETER |
| 54 | ts_DIA_Gy_CCA(template (value) UINT32 hbh_id, template (value) UINT32 ete_id, |
| 55 | template (value) octetstring sess_id, |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame^] | 56 | template (value) DIAMETER_Resultcode res_code, |
Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 57 | template (value) DCC_NONE_CC_Request_Type req_type, |
| 58 | template (value) AVP_Unsigned32 req_num) |
| 59 | := ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control, |
| 60 | app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id, |
| 61 | avps := { |
| 62 | ts_AVP_SessionId(sess_id), |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame^] | 63 | ts_AVP_ResultCode(res_code), |
Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 64 | ts_AVP_OriginHost("ocs.localdomain"), |
| 65 | ts_AVP_OriginRealm("localdomain"), |
| 66 | ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 67 | ts_AVP_CcReqType(req_type), |
| 68 | ts_AVP_CcReqNum(req_num)//, |
| 69 | // qos |
| 70 | // default eps bearer qos |
| 71 | // supported features |
| 72 | // origin |
| 73 | }); |
| 74 | /* Same as ts_DIA_Gy_CCA, but with extra AVP to grant access for limited amount of seconds */ |
| 75 | template (value) PDU_DIAMETER |
| 76 | ts_DIA_Gy_CCA_ValidityTime(template (value) UINT32 hbh_id, template (value) UINT32 ete_id, |
| 77 | template (value) octetstring sess_id, |
| 78 | template (value) DCC_NONE_CC_Request_Type req_type, |
| 79 | template (value) AVP_Unsigned32 req_num, |
| 80 | uint32_t validity_time) |
| 81 | := ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control, |
| 82 | app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id, |
| 83 | avps := { |
| 84 | ts_AVP_SessionId(sess_id), |
| 85 | ts_AVP_ResultCode(DIAMETER_SUCCESS), |
| 86 | ts_AVP_OriginHost("ocs.localdomain"), |
| 87 | ts_AVP_OriginRealm("localdomain"), |
| 88 | ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 89 | ts_AVP_CcReqType(req_type), |
| 90 | ts_AVP_CcReqNum(req_num), |
| 91 | ts_AVP_Multiple_Services_Credit_Control({ |
| 92 | ts_AVP_Validity_Time(validity_time), |
| 93 | ts_AVP_Granted_Service_Unit({ |
| 94 | //ts_AVP_CC_Time(validity_time*2), |
| 95 | ts_AVP_CC_Total_Octets(1000) |
| 96 | }) |
| 97 | }) |
| 98 | //, |
| 99 | // qos |
| 100 | // default eps bearer qos |
| 101 | // supported features |
| 102 | // origin |
| 103 | }); |
| 104 | /* Same as ts_DIA_Gy_CCA_ValidityTime, but with extra AVP to grant access for limited amount of octets */ |
| 105 | template (value) PDU_DIAMETER |
| 106 | ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(template (value) UINT32 hbh_id, template (value) UINT32 ete_id, |
| 107 | template (value) octetstring sess_id, |
| 108 | template (value) DCC_NONE_CC_Request_Type req_type, |
| 109 | template (value) AVP_Unsigned32 req_num, |
| 110 | uint32_t validity_time, uint32_t volume_threhsold) |
| 111 | := ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control, |
| 112 | app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id, |
| 113 | avps := { |
| 114 | ts_AVP_SessionId(sess_id), |
| 115 | ts_AVP_ResultCode(DIAMETER_SUCCESS), |
| 116 | ts_AVP_OriginHost("ocs.localdomain"), |
| 117 | ts_AVP_OriginRealm("localdomain"), |
| 118 | ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 119 | ts_AVP_CcReqType(req_type), |
| 120 | ts_AVP_CcReqNum(req_num), |
| 121 | ts_AVP_Multiple_Services_Credit_Control({ |
| 122 | ts_AVP_Validity_Time(validity_time), |
| 123 | ts_AVP_Granted_Service_Unit({ |
| 124 | ts_AVP_CC_Total_Octets(volume_threhsold*100) |
| 125 | }), |
| 126 | ts_AVP_3GPP_VolumeQuotaThreshold(volume_threhsold) |
| 127 | }) |
| 128 | //, |
| 129 | // qos |
| 130 | // default eps bearer qos |
| 131 | // supported features |
| 132 | // origin |
| 133 | }); |
| 134 | |
| 135 | function f_validate_gy_cc_report(PDU_DIAMETER rx_dia, template (present) DCA_3GPP_Reporting_Reason repreason_exp := ?, |
| 136 | template (present) integer cc_time_exp := ?, |
| 137 | template (present) integer cc_in_oct_exp := ?, |
| 138 | template (present) integer cc_out_oct_exp := ?) |
| 139 | { |
| 140 | var AVP multi_services_cc, used_service_unit; |
| 141 | var AVP_Grouped multi_services_cc_data, used_service_unit_data; |
| 142 | var template (omit) AVP repreason_tpl; |
| 143 | var AVP repreason, cc_time, cc_in_oct, cc_out_oct; |
| 144 | |
| 145 | multi_services_cc := f_DIAMETER_get_avp_or_fail(rx_dia, c_AVP_Code_DCC_NONE_Multiple_Services_Credit_Control); |
| 146 | multi_services_cc_data := valueof(multi_services_cc.avp_data.avp_DCC_NONE_Multiple_Services_Credit_Control); |
| 147 | |
| 148 | used_service_unit := f_AVP_Grouped_get_avp_or_fail(multi_services_cc_data, c_AVP_Code_DCC_NONE_Used_Service_Unit); |
| 149 | used_service_unit_data := valueof(used_service_unit.avp_data.avp_DCC_NONE_Used_Service_Unit); |
| 150 | |
| 151 | /* Reporting-Reason can be either inside Multiple-Services-Credit-Control or inside Used-Service-Unit */ |
| 152 | repreason_tpl := f_AVP_Grouped_get_avp(multi_services_cc_data, c_AVP_Code_DCA_3GPP_Reporting_Reason); |
| 153 | if (istemplatekind(repreason_tpl, "omit")) { |
| 154 | repreason := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCA_3GPP_Reporting_Reason); |
| 155 | } else { |
| 156 | repreason := valueof(repreason_tpl); |
| 157 | } |
| 158 | if (not match(repreason.avp_data.avp_DCA_3GPP_Reporting_Reason, repreason_exp)) { |
| 159 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 160 | log2str("3GPP-Reporting-Reason mismatch ", repreason, " vs exp ", repreason_exp)); |
| 161 | } |
| 162 | |
| 163 | cc_time := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Time); |
| 164 | if (not match(oct2int(cc_time.avp_data.avp_DCC_NONE_CC_Time), cc_time_exp)) { |
| 165 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 166 | log2str("3GPP-CC-Time mismatch ", cc_time, " vs exp ", cc_time_exp)); |
| 167 | } |
| 168 | |
| 169 | cc_in_oct := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Input_Octets); |
| 170 | if (not match(oct2int(cc_in_oct.avp_data.avp_DCC_NONE_CC_Input_Octets), cc_in_oct_exp)) { |
| 171 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 172 | log2str("3GPP-CC-Input-Octets mismatch ", cc_in_oct, " vs exp ", cc_in_oct_exp)); |
| 173 | } |
| 174 | |
| 175 | cc_out_oct := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Output_Octets); |
| 176 | if (not match(oct2int(cc_out_oct.avp_data.avp_DCC_NONE_CC_Output_Octets), cc_out_oct_exp)) { |
| 177 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 178 | log2str("3GPP-CC-Output-Octets mismatch ", cc_out_oct, " vs exp ", cc_out_oct_exp)); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | } /* module */ |