blob: c30865996a8a77941944e9b9bc8bdcfefdccb0ec [file] [log] [blame]
Pau Espin Pedrol867b1302024-01-24 16:14:28 +01001module 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
14import from General_Types all;
15import from DIAMETER_Types all;
16import from DIAMETER_Templates all;
17import from Osmocom_Types all;
18import from Misc_Helpers all;
19
20/*******************************
Pau Espin Pedrol9b3d0622024-03-18 20:47:06 +010021 * Gy 3GPP TS 32.299 section 7
Pau Espin Pedrol867b1302024-01-24 16:14:28 +010022 *******************************/
23
24/* Gy AID : 3GPP TS 32.299 7.1.6, RFC4006 3.1: c_DIAMETER_CREDIT_CONTROL_AID */
25
Pau Espin Pedrol9b3d0622024-03-18 20:47:06 +010026/* 3GPP TS 32.299 7.1.11 Result-Code AVP*/
27type 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 Pedrol867b1302024-01-24 16:14:28 +010038/* 3GPP TS 32.299 6.4.2 Credit-Control-Request */
39template (present) PDU_DIAMETER
40tr_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 */
53template (value) PDU_DIAMETER
54ts_DIA_Gy_CCA(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
55 template (value) octetstring sess_id,
56 template (value) DCC_NONE_CC_Request_Type req_type,
57 template (value) AVP_Unsigned32 req_num)
58:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
59 app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
60 avps := {
61 ts_AVP_SessionId(sess_id),
62 ts_AVP_ResultCode(DIAMETER_SUCCESS),
63 ts_AVP_OriginHost("ocs.localdomain"),
64 ts_AVP_OriginRealm("localdomain"),
65 ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
66 ts_AVP_CcReqType(req_type),
67 ts_AVP_CcReqNum(req_num)//,
68 // qos
69 // default eps bearer qos
70 // supported features
71 // origin
72 });
73/* Same as ts_DIA_Gy_CCA, but with extra AVP to grant access for limited amount of seconds */
74template (value) PDU_DIAMETER
75ts_DIA_Gy_CCA_ValidityTime(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
76 template (value) octetstring sess_id,
77 template (value) DCC_NONE_CC_Request_Type req_type,
78 template (value) AVP_Unsigned32 req_num,
79 uint32_t validity_time)
80:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
81 app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
82 avps := {
83 ts_AVP_SessionId(sess_id),
84 ts_AVP_ResultCode(DIAMETER_SUCCESS),
85 ts_AVP_OriginHost("ocs.localdomain"),
86 ts_AVP_OriginRealm("localdomain"),
87 ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
88 ts_AVP_CcReqType(req_type),
89 ts_AVP_CcReqNum(req_num),
90 ts_AVP_Multiple_Services_Credit_Control({
91 ts_AVP_Validity_Time(validity_time),
92 ts_AVP_Granted_Service_Unit({
93 //ts_AVP_CC_Time(validity_time*2),
94 ts_AVP_CC_Total_Octets(1000)
95 })
96 })
97 //,
98 // qos
99 // default eps bearer qos
100 // supported features
101 // origin
102 });
103/* Same as ts_DIA_Gy_CCA_ValidityTime, but with extra AVP to grant access for limited amount of octets */
104template (value) PDU_DIAMETER
105ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(template (value) UINT32 hbh_id, template (value) UINT32 ete_id,
106 template (value) octetstring sess_id,
107 template (value) DCC_NONE_CC_Request_Type req_type,
108 template (value) AVP_Unsigned32 req_num,
109 uint32_t validity_time, uint32_t volume_threhsold)
110:= ts_DIAMETER(flags:='01000000'B, cmd_code:=Credit_Control,
111 app_id:=int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4), hbh_id:=hbh_id, ete_id:=ete_id,
112 avps := {
113 ts_AVP_SessionId(sess_id),
114 ts_AVP_ResultCode(DIAMETER_SUCCESS),
115 ts_AVP_OriginHost("ocs.localdomain"),
116 ts_AVP_OriginRealm("localdomain"),
117 ts_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
118 ts_AVP_CcReqType(req_type),
119 ts_AVP_CcReqNum(req_num),
120 ts_AVP_Multiple_Services_Credit_Control({
121 ts_AVP_Validity_Time(validity_time),
122 ts_AVP_Granted_Service_Unit({
123 ts_AVP_CC_Total_Octets(volume_threhsold*100)
124 }),
125 ts_AVP_3GPP_VolumeQuotaThreshold(volume_threhsold)
126 })
127 //,
128 // qos
129 // default eps bearer qos
130 // supported features
131 // origin
132 });
133
134function f_validate_gy_cc_report(PDU_DIAMETER rx_dia, template (present) DCA_3GPP_Reporting_Reason repreason_exp := ?,
135 template (present) integer cc_time_exp := ?,
136 template (present) integer cc_in_oct_exp := ?,
137 template (present) integer cc_out_oct_exp := ?)
138{
139 var AVP multi_services_cc, used_service_unit;
140 var AVP_Grouped multi_services_cc_data, used_service_unit_data;
141 var template (omit) AVP repreason_tpl;
142 var AVP repreason, cc_time, cc_in_oct, cc_out_oct;
143
144 multi_services_cc := f_DIAMETER_get_avp_or_fail(rx_dia, c_AVP_Code_DCC_NONE_Multiple_Services_Credit_Control);
145 multi_services_cc_data := valueof(multi_services_cc.avp_data.avp_DCC_NONE_Multiple_Services_Credit_Control);
146
147 used_service_unit := f_AVP_Grouped_get_avp_or_fail(multi_services_cc_data, c_AVP_Code_DCC_NONE_Used_Service_Unit);
148 used_service_unit_data := valueof(used_service_unit.avp_data.avp_DCC_NONE_Used_Service_Unit);
149
150 /* Reporting-Reason can be either inside Multiple-Services-Credit-Control or inside Used-Service-Unit */
151 repreason_tpl := f_AVP_Grouped_get_avp(multi_services_cc_data, c_AVP_Code_DCA_3GPP_Reporting_Reason);
152 if (istemplatekind(repreason_tpl, "omit")) {
153 repreason := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCA_3GPP_Reporting_Reason);
154 } else {
155 repreason := valueof(repreason_tpl);
156 }
157 if (not match(repreason.avp_data.avp_DCA_3GPP_Reporting_Reason, repreason_exp)) {
158 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
159 log2str("3GPP-Reporting-Reason mismatch ", repreason, " vs exp ", repreason_exp));
160 }
161
162 cc_time := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Time);
163 if (not match(oct2int(cc_time.avp_data.avp_DCC_NONE_CC_Time), cc_time_exp)) {
164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
165 log2str("3GPP-CC-Time mismatch ", cc_time, " vs exp ", cc_time_exp));
166 }
167
168 cc_in_oct := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Input_Octets);
169 if (not match(oct2int(cc_in_oct.avp_data.avp_DCC_NONE_CC_Input_Octets), cc_in_oct_exp)) {
170 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
171 log2str("3GPP-CC-Input-Octets mismatch ", cc_in_oct, " vs exp ", cc_in_oct_exp));
172 }
173
174 cc_out_oct := f_AVP_Grouped_get_avp_or_fail(used_service_unit_data, c_AVP_Code_DCC_NONE_CC_Output_Octets);
175 if (not match(oct2int(cc_out_oct.avp_data.avp_DCC_NONE_CC_Output_Octets), cc_out_oct_exp)) {
176 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
177 log2str("3GPP-CC-Output-Octets mismatch ", cc_out_oct, " vs exp ", cc_out_oct_exp));
178 }
179}
180
181} /* module */