| 1 |
#define TRACE_MODULE _pcrf_gx_path |
| 2 |
|
| 3 |
#include "core_lib.h" |
| 4 |
#include "core_debug.h" |
| 5 |
#include "core_pool.h" |
| 6 |
#include "core_pkbuf.h" |
| 7 |
|
| 8 |
#include "fd/fd_lib.h" |
| 9 |
#include "fd/gx/gx_dict.h" |
| 10 |
#include "fd/rx/rx_dict.h" |
| 11 |
#include "fd/gx/gx_message.h" |
| 12 |
#include "fd/rx/rx_message.h" |
| 13 |
|
| 14 |
#include "pcrf_context.h" |
| 15 |
#include "pcrf_fd_path.h" |
| 16 |
|
| 17 |
struct rx_sess_state { |
| 18 |
lnode_t node; |
| 19 |
|
| 20 |
os0_t sid; /* Rx Session-Id */ |
| 21 |
|
| 22 |
pcc_rule_t pcc_rule[MAX_NUM_OF_PCC_RULE]; |
| 23 |
int num_of_pcc_rule; |
| 24 |
|
| 25 |
struct sess_state *gx; |
| 26 |
}; |
| 27 |
|
| 28 |
struct sess_state { |
| 29 |
os0_t sid; /* Gx Session-Id */ |
| 30 |
|
| 31 |
c_uint32_t cc_request_type; /* CC-Request-Type */ |
| 32 |
os0_t peer_host; /* Peer Host */ |
| 33 |
|
| 34 |
c_int8_t *imsi_bcd; |
| 35 |
c_int8_t *apn; |
| 36 |
|
| 37 |
ED3(c_uint8_t ipv4:1;, |
| 38 |
c_uint8_t ipv6:1;, |
| 39 |
c_uint8_t reserved:6;) |
| 40 |
c_uint32_t addr; /* Framed-IPv4-Address */ |
| 41 |
c_uint8_t addr6[IPV6_LEN]; /* Framed-IPv6-Prefix */ |
| 42 |
|
| 43 |
list_t rx_list; |
| 44 |
|
| 45 |
struct timespec ts; /* Time of sending the message */ |
| 46 |
}; |
| 47 |
|
| 48 |
static struct session_handler *pcrf_gx_reg = NULL; |
| 49 |
static struct disp_hdl *hdl_gx_fb = NULL; |
| 50 |
static struct disp_hdl *hdl_gx_ccr = NULL; |
| 51 |
|
| 52 |
pool_declare(pcrf_gx_sess_pool, struct sess_state, MAX_POOL_OF_DIAMETER_SESS); |
| 53 |
pool_declare(pcrf_gx_rx_sess_pool, |
| 54 |
struct rx_sess_state, MAX_POOL_OF_DIAMETER_SESS); |
| 55 |
|
| 56 |
static void pcrf_gx_raa_cb(void *data, struct msg **msg); |
| 57 |
|
| 58 |
static status_t encode_pcc_rule_definition( |
| 59 |
struct avp *avp, pcc_rule_t *pcc_rule, int flow_presence); |
| 60 |
static int matched_flow( |
| 61 |
pcc_rule_t *pcc_rule, rx_media_component_t *media_component); |
| 62 |
static status_t install_flow( |
| 63 |
pcc_rule_t *pcc_rule, rx_media_component_t *media_component); |
| 64 |
static status_t update_qos( |
| 65 |
pcc_rule_t *pcc_rule, rx_media_component_t *media_component); |
| 66 |
|
| 67 |
static __inline__ struct sess_state *new_state(os0_t sid) |
| 68 |
{ |
| 69 |
struct sess_state *new = NULL; |
| 70 |
|
| 71 |
d_assert(sid, return NULL,); |
| 72 |
|
| 73 |
pool_alloc_node(&pcrf_gx_sess_pool, &new); |
| 74 |
d_assert(new, return NULL,); |
| 75 |
memset(new, 0, sizeof *new); |
| 76 |
|
| 77 |
new->sid = (os0_t)core_strdup((char *)sid); |
| 78 |
d_assert(new->sid, return NULL,); |
| 79 |
|
| 80 |
list_init(&new->rx_list); |
| 81 |
|
| 82 |
return new; |
| 83 |
} |
| 84 |
|
| 85 |
static struct rx_sess_state *add_rx_state(struct sess_state *gx, os0_t sid) |
| 86 |
{ |
| 87 |
struct rx_sess_state *new = NULL; |
| 88 |
|
| 89 |
d_assert(gx, return NULL,); |
| 90 |
d_assert(sid, return NULL,); |
| 91 |
|
| 92 |
pool_alloc_node(&pcrf_gx_rx_sess_pool, &new); |
| 93 |
d_assert(new, return NULL,); |
| 94 |
memset(new, 0, sizeof *new); |
| 95 |
|
| 96 |
new->sid = (os0_t)core_strdup((char *)sid); |
| 97 |
d_assert(new->sid, return NULL,); |
| 98 |
|
| 99 |
new->gx = gx; |
| 100 |
|
| 101 |
list_append(&gx->rx_list, new); |
| 102 |
|
| 103 |
return new; |
| 104 |
} |
| 105 |
|
| 106 |
static status_t remove_rx_state(struct rx_sess_state *rx_sess_data) |
| 107 |
{ |
| 108 |
struct sess_state *gx = NULL; |
| 109 |
int i; |
| 110 |
|
| 111 |
d_assert(rx_sess_data, return CORE_ERROR,); |
| 112 |
gx = rx_sess_data->gx; |
| 113 |
|
| 114 |
for (i = 0; i < rx_sess_data->num_of_pcc_rule; i++) |
| 115 |
{ |
| 116 |
PCC_RULE_FREE(&rx_sess_data->pcc_rule[i]); |
| 117 |
} |
| 118 |
|
| 119 |
if (rx_sess_data->sid) |
| 120 |
CORE_FREE(rx_sess_data->sid); |
| 121 |
|
| 122 |
list_remove(&gx->rx_list, rx_sess_data); |
| 123 |
pool_free_node(&pcrf_gx_rx_sess_pool, rx_sess_data); |
| 124 |
|
| 125 |
return CORE_OK; |
| 126 |
} |
| 127 |
|
| 128 |
static status_t remove_rx_state_all(struct sess_state *gx) |
| 129 |
{ |
| 130 |
struct rx_sess_state *rx_sess_data = NULL, *next_rx_sess_data = NULL; |
| 131 |
|
| 132 |
d_assert(gx, return CORE_ERROR,); |
| 133 |
|
| 134 |
rx_sess_data = list_first(&gx->rx_list); |
| 135 |
while(rx_sess_data) |
| 136 |
{ |
| 137 |
next_rx_sess_data = list_next(rx_sess_data); |
| 138 |
|
| 139 |
remove_rx_state(rx_sess_data); |
| 140 |
|
| 141 |
rx_sess_data = next_rx_sess_data; |
| 142 |
} |
| 143 |
|
| 144 |
return CORE_OK; |
| 145 |
} |
| 146 |
|
| 147 |
static struct rx_sess_state *find_rx_state(struct sess_state *gx, os0_t sid) |
| 148 |
{ |
| 149 |
struct rx_sess_state *rx_sess_data = NULL; |
| 150 |
|
| 151 |
d_assert(gx, return NULL,); |
| 152 |
d_assert(sid, return NULL,); |
| 153 |
|
| 154 |
rx_sess_data = list_first(&gx->rx_list); |
| 155 |
while(rx_sess_data) |
| 156 |
{ |
| 157 |
if (!strcmp((char *)rx_sess_data->sid, (char *)sid)) |
| 158 |
return rx_sess_data; |
| 159 |
|
| 160 |
rx_sess_data = list_next(rx_sess_data); |
| 161 |
} |
| 162 |
|
| 163 |
return NULL; |
| 164 |
} |
| 165 |
|
| 166 |
static void state_cleanup(struct sess_state *sess_data, os0_t sid, void *opaque) |
| 167 |
{ |
| 168 |
d_assert(sess_data, return,); |
| 169 |
|
| 170 |
if (sess_data->peer_host) |
| 171 |
CORE_FREE(sess_data->peer_host); |
| 172 |
|
| 173 |
if (sess_data->imsi_bcd) |
| 174 |
CORE_FREE(sess_data->imsi_bcd); |
| 175 |
if (sess_data->apn) |
| 176 |
CORE_FREE(sess_data->apn); |
| 177 |
|
| 178 |
if (sess_data->ipv4) |
| 179 |
pcrf_sess_set_ipv4(&sess_data->addr, NULL); |
| 180 |
if (sess_data->ipv6) |
| 181 |
pcrf_sess_set_ipv6(sess_data->addr6, NULL); |
| 182 |
|
| 183 |
if (sess_data->sid) |
| 184 |
CORE_FREE(sess_data->sid); |
| 185 |
|
| 186 |
remove_rx_state_all(sess_data); |
| 187 |
|
| 188 |
pool_free_node(&pcrf_gx_sess_pool, sess_data); |
| 189 |
} |
| 190 |
|
| 191 |
static int pcrf_gx_fb_cb(struct msg **msg, struct avp *avp, |
| 192 |
struct session *sess, void *opaque, enum disp_action *act) |
| 193 |
{ |
| 194 |
/* This CB should never be called */ |
| 195 |
d_warn("Unexpected message received!"); |
| 196 |
|
| 197 |
return ENOTSUP; |
| 198 |
} |
| 199 |
|
| 200 |
static int pcrf_gx_ccr_cb( struct msg **msg, struct avp *avp, |
| 201 |
struct session *sess, void *opaque, enum disp_action *act) |
| 202 |
{ |
| 203 |
status_t rv; |
| 204 |
int ret = 0, i; |
| 205 |
|
| 206 |
struct msg *ans, *qry; |
| 207 |
struct avp *avpch1, *avpch2; |
| 208 |
struct avp_hdr *hdr; |
| 209 |
union avp_value val; |
| 210 |
struct sess_state *sess_data = NULL; |
| 211 |
|
| 212 |
gx_message_t gx_message; |
| 213 |
|
| 214 |
c_uint32_t cc_request_number = 0; |
| 215 |
c_uint32_t result_code = FD_DIAMETER_MISSING_AVP; |
| 216 |
|
| 217 |
d_trace(3, "[PCRF] Credit-Control-Request\n"); |
| 218 |
|
| 219 |
d_assert(msg, return EINVAL,); |
| 220 |
|
| 221 |
ret = fd_sess_state_retrieve(pcrf_gx_reg, sess, &sess_data); |
| 222 |
d_assert(ret == 0, return EINVAL,); |
| 223 |
|
| 224 |
if (!sess_data) |
| 225 |
{ |
| 226 |
os0_t sid; |
| 227 |
size_t sidlen; |
| 228 |
|
| 229 |
ret = fd_sess_getsid(sess, &sid, &sidlen); |
| 230 |
d_assert(ret == 0, return EINVAL,); |
| 231 |
|
| 232 |
sess_data = new_state(sid); |
| 233 |
d_assert(sess_data, return EINVAL,); |
| 234 |
} |
| 235 |
|
| 236 |
/* Initialize Message */ |
| 237 |
memset(&gx_message, 0, sizeof(gx_message_t)); |
| 238 |
|
| 239 |
/* Create answer header */ |
| 240 |
qry = *msg; |
| 241 |
ret = fd_msg_new_answer_from_req(fd_g_config->cnf_dict, msg, 0); |
| 242 |
d_assert(ret == 0, return EINVAL,); |
| 243 |
ans = *msg; |
| 244 |
|
| 245 |
/* Get Origin-Host */ |
| 246 |
ret = fd_msg_search_avp(qry, fd_origin_host, &avp); |
| 247 |
d_assert(ret == 0, return EINVAL,); |
| 248 |
if (avp) |
| 249 |
{ |
| 250 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 251 |
d_assert(ret == 0, return EINVAL,); |
| 252 |
|
| 253 |
if (sess_data->peer_host) |
| 254 |
CORE_FREE(sess_data->peer_host); |
| 255 |
sess_data->peer_host = |
| 256 |
(os0_t)core_strdup((char *)hdr->avp_value->os.data); |
| 257 |
d_assert(sess_data->peer_host, return CORE_ERROR,); |
| 258 |
} |
| 259 |
else |
| 260 |
{ |
| 261 |
d_error("no_CC-Request-Type "); |
| 262 |
result_code = FD_DIAMETER_MISSING_AVP; |
| 263 |
goto out; |
| 264 |
} |
| 265 |
|
| 266 |
/* Get CC-Request-Type */ |
| 267 |
ret = fd_msg_search_avp(qry, gx_cc_request_type, &avp); |
| 268 |
d_assert(ret == 0, return EINVAL,); |
| 269 |
if (avp) |
| 270 |
{ |
| 271 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 272 |
d_assert(ret == 0, return EINVAL,); |
| 273 |
sess_data->cc_request_type = hdr->avp_value->i32; |
| 274 |
} |
| 275 |
else |
| 276 |
{ |
| 277 |
d_error("no_CC-Request-Type "); |
| 278 |
result_code = FD_DIAMETER_MISSING_AVP; |
| 279 |
goto out; |
| 280 |
} |
| 281 |
|
| 282 |
/* Get CC-Request-Number */ |
| 283 |
ret = fd_msg_search_avp(qry, gx_cc_request_number, &avp); |
| 284 |
d_assert(ret == 0, return EINVAL,); |
| 285 |
if (avp) |
| 286 |
{ |
| 287 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 288 |
d_assert(ret == 0, return EINVAL,); |
| 289 |
cc_request_number = hdr->avp_value->i32; |
| 290 |
} |
| 291 |
|
| 292 |
/* Get Framed-IP-Address */ |
| 293 |
ret = fd_msg_search_avp(qry, gx_framed_ip_address, &avp); |
| 294 |
d_assert(ret == 0, return EINVAL,); |
| 295 |
if (avp) |
| 296 |
{ |
| 297 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 298 |
d_assert(ret == 0, return EINVAL,); |
| 299 |
|
| 300 |
memcpy(&sess_data->addr, hdr->avp_value->os.data, |
| 301 |
sizeof sess_data->addr); |
| 302 |
pcrf_sess_set_ipv4(&sess_data->addr, sess_data->sid); |
| 303 |
sess_data->ipv4 = 1; |
| 304 |
} |
| 305 |
|
| 306 |
/* Get Framed-IPv6-Prefix */ |
| 307 |
ret = fd_msg_search_avp(qry, gx_framed_ipv6_prefix, &avp); |
| 308 |
d_assert(ret == 0, return EINVAL,); |
| 309 |
if (avp) |
| 310 |
{ |
| 311 |
paa_t *paa = NULL; |
| 312 |
|
| 313 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 314 |
d_assert(ret == 0, return EINVAL,); |
| 315 |
|
| 316 |
paa = (paa_t *)hdr->avp_value->os.data; |
| 317 |
d_assert(paa, return EINVAL,); |
| 318 |
d_assert(paa->len == IPV6_LEN * 8 /* 128bit */, return EINVAL, |
| 319 |
"Invalid Framed-IPv6-Prefix Length:%d", paa->len); |
| 320 |
memcpy(sess_data->addr6, paa->addr6, sizeof sess_data->addr6); |
| 321 |
pcrf_sess_set_ipv6(sess_data->addr6, sess_data->sid); |
| 322 |
sess_data->ipv6 = 1; |
| 323 |
} |
| 324 |
|
| 325 |
/* Set the Auth-Application-Id AVP */ |
| 326 |
ret = fd_msg_avp_new(fd_auth_application_id, 0, &avp); |
| 327 |
d_assert(ret == 0, return EINVAL,); |
| 328 |
val.i32 = GX_APPLICATION_ID; |
| 329 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 330 |
d_assert(ret == 0, return EINVAL,); |
| 331 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 332 |
d_assert(ret == 0, return EINVAL,); |
| 333 |
|
| 334 |
/* Set CC-Request-Type */ |
| 335 |
ret = fd_msg_avp_new(gx_cc_request_type, 0, &avp); |
| 336 |
d_assert(ret == 0, return EINVAL,); |
| 337 |
val.i32 = sess_data->cc_request_type; |
| 338 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 339 |
d_assert(ret == 0, return EINVAL,); |
| 340 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 341 |
d_assert(ret == 0, return EINVAL,); |
| 342 |
|
| 343 |
/* Set CC-Request-Number */ |
| 344 |
ret = fd_msg_avp_new(gx_cc_request_number, 0, &avp); |
| 345 |
d_assert(ret == 0, return EINVAL,); |
| 346 |
val.i32 = cc_request_number; |
| 347 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 348 |
d_assert(ret == 0, return EINVAL,); |
| 349 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 350 |
d_assert(ret == 0, return EINVAL,); |
| 351 |
|
| 352 |
/* Get IMSI + APN */ |
| 353 |
ret = fd_msg_search_avp(qry, gx_subscription_id, &avp); |
| 354 |
d_assert(ret == 0, return EINVAL,); |
| 355 |
if (avp) |
| 356 |
{ |
| 357 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 358 |
d_assert(ret == 0, return EINVAL,); |
| 359 |
ret = fd_avp_search_avp(avp, gx_subscription_id_type, &avpch1); |
| 360 |
d_assert(ret == 0, return EINVAL,); |
| 361 |
if (avpch1) |
| 362 |
{ |
| 363 |
ret = fd_msg_avp_hdr(avpch1, &hdr); |
| 364 |
d_assert(ret == 0, return EINVAL,); |
| 365 |
if (hdr->avp_value->i32 != GX_SUBSCRIPTION_ID_TYPE_END_USER_IMSI) |
| 366 |
{ |
| 367 |
d_error("Not implemented Subscription-Id-Type(%d)", |
| 368 |
hdr->avp_value->i32); |
| 369 |
result_code = FD_DIAMETER_AVP_UNSUPPORTED; |
| 370 |
goto out; |
| 371 |
} |
| 372 |
} |
| 373 |
else |
| 374 |
{ |
| 375 |
d_error("no_Subscription-Id-Type"); |
| 376 |
result_code = FD_DIAMETER_MISSING_AVP; |
| 377 |
goto out; |
| 378 |
} |
| 379 |
ret = fd_avp_search_avp(avp, gx_subscription_id_data, &avpch1); |
| 380 |
d_assert(ret == 0, return EINVAL,); |
| 381 |
if (avpch1) |
| 382 |
{ |
| 383 |
ret = fd_msg_avp_hdr(avpch1, &hdr); |
| 384 |
d_assert(ret == 0, return EINVAL,); |
| 385 |
if (sess_data->imsi_bcd) |
| 386 |
CORE_FREE(sess_data->imsi_bcd); |
| 387 |
sess_data->imsi_bcd = core_strdup((char *)hdr->avp_value->os.data); |
| 388 |
d_assert(sess_data->imsi_bcd, return CORE_ERROR,); |
| 389 |
} |
| 390 |
else |
| 391 |
{ |
| 392 |
d_error("no_Subscription-Id-Data"); |
| 393 |
result_code = FD_DIAMETER_MISSING_AVP; |
| 394 |
goto out; |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
if (sess_data->imsi_bcd == NULL) |
| 399 |
{ |
| 400 |
d_error("no_Subscription-Id"); |
| 401 |
result_code = FD_DIAMETER_MISSING_AVP; |
| 402 |
goto out; |
| 403 |
} |
| 404 |
|
| 405 |
ret = fd_msg_search_avp(qry, gx_called_station_id, &avp); |
| 406 |
d_assert(ret == 0, return EINVAL,); |
| 407 |
if (avp) |
| 408 |
{ |
| 409 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 410 |
d_assert(ret == 0, return EINVAL,); |
| 411 |
if (sess_data->apn) |
| 412 |
CORE_FREE(sess_data->apn); |
| 413 |
sess_data->apn = core_strdup((char *)hdr->avp_value->os.data); |
| 414 |
d_assert(sess_data->apn, return CORE_ERROR,); |
| 415 |
} |
| 416 |
|
| 417 |
if (sess_data->apn == NULL) |
| 418 |
{ |
| 419 |
d_error("no_Called-Station-Id"); |
| 420 |
result_code = FD_DIAMETER_MISSING_AVP; |
| 421 |
goto out; |
| 422 |
} |
| 423 |
|
| 424 |
/* Retrieve QoS Data from Database */ |
| 425 |
rv = pcrf_db_qos_data(sess_data->imsi_bcd, sess_data->apn, &gx_message); |
| 426 |
if (rv != CORE_OK) |
| 427 |
{ |
| 428 |
d_error("Cannot get data for IMSI(%s)+APN(%s)'\n", |
| 429 |
sess_data->imsi_bcd, sess_data->apn); |
| 430 |
result_code = FD_DIAMETER_UNKNOWN_SESSION_ID; |
| 431 |
goto out; |
| 432 |
} |
| 433 |
|
| 434 |
if (sess_data->cc_request_type == GX_CC_REQUEST_TYPE_INITIAL_REQUEST || |
| 435 |
sess_data->cc_request_type == GX_CC_REQUEST_TYPE_UPDATE_REQUEST) |
| 436 |
{ |
| 437 |
int charging_rule = 0; |
| 438 |
|
| 439 |
for (i = 0; i < gx_message.num_of_pcc_rule; i++) |
| 440 |
{ |
| 441 |
pcc_rule_t *pcc_rule = &gx_message.pcc_rule[i]; |
| 442 |
if (pcc_rule->num_of_flow) |
| 443 |
{ |
| 444 |
if (charging_rule == 0) |
| 445 |
{ |
| 446 |
ret = fd_msg_avp_new(gx_charging_rule_install, 0, &avp); |
| 447 |
d_assert(ret == 0, return CORE_ERROR,); |
| 448 |
|
| 449 |
charging_rule = 1; |
| 450 |
} |
| 451 |
|
| 452 |
rv = encode_pcc_rule_definition(avp, pcc_rule, 1); |
| 453 |
d_assert(rv == CORE_OK, return EINVAL,); |
| 454 |
} |
| 455 |
} |
| 456 |
|
| 457 |
if (charging_rule) |
| 458 |
{ |
| 459 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 460 |
d_assert(ret == 0, return CORE_ERROR,); |
| 461 |
} |
| 462 |
|
| 463 |
/* Set QoS-Information */ |
| 464 |
if (gx_message.pdn.ambr.downlink || gx_message.pdn.ambr.uplink) |
| 465 |
{ |
| 466 |
ret = fd_msg_avp_new(gx_qos_information, 0, &avp); |
| 467 |
d_assert(ret == 0, return EINVAL,); |
| 468 |
|
| 469 |
if (gx_message.pdn.ambr.uplink) |
| 470 |
{ |
| 471 |
ret = fd_msg_avp_new(gx_apn_aggregate_max_bitrate_ul, 0, |
| 472 |
&avpch1); |
| 473 |
d_assert(ret == 0, return EINVAL,); |
| 474 |
val.u32 = gx_message.pdn.ambr.uplink; |
| 475 |
ret = fd_msg_avp_setvalue (avpch1, &val); |
| 476 |
d_assert(ret == 0, return EINVAL,); |
| 477 |
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); |
| 478 |
d_assert(ret == 0, return EINVAL,); |
| 479 |
} |
| 480 |
|
| 481 |
if (gx_message.pdn.ambr.downlink) |
| 482 |
{ |
| 483 |
ret = fd_msg_avp_new(gx_apn_aggregate_max_bitrate_dl, 0, |
| 484 |
&avpch1); |
| 485 |
d_assert(ret == 0, return EINVAL,); |
| 486 |
val.u32 = gx_message.pdn.ambr.downlink; |
| 487 |
ret = fd_msg_avp_setvalue (avpch1, &val); |
| 488 |
d_assert(ret == 0, return EINVAL,); |
| 489 |
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); |
| 490 |
d_assert(ret == 0, return EINVAL,); |
| 491 |
} |
| 492 |
|
| 493 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 494 |
d_assert(ret == 0, return EINVAL,); |
| 495 |
} |
| 496 |
|
| 497 |
/* Set Default-EPS-Bearer-QoS */ |
| 498 |
ret = fd_msg_avp_new(gx_default_eps_bearer_qos, 0, &avp); |
| 499 |
d_assert(ret == 0, return EINVAL,); |
| 500 |
|
| 501 |
ret = fd_msg_avp_new(gx_qos_class_identifier, 0, &avpch1); |
| 502 |
d_assert(ret == 0, return EINVAL,); |
| 503 |
val.u32 = gx_message.pdn.qos.qci; |
| 504 |
ret = fd_msg_avp_setvalue (avpch1, &val); |
| 505 |
d_assert(ret == 0, return EINVAL,); |
| 506 |
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); |
| 507 |
d_assert(ret == 0, return EINVAL,); |
| 508 |
|
| 509 |
ret = fd_msg_avp_new(gx_allocation_retention_priority, 0, &avpch1); |
| 510 |
d_assert(ret == 0, return EINVAL,); |
| 511 |
|
| 512 |
ret = fd_msg_avp_new(gx_priority_level, 0, &avpch2); |
| 513 |
d_assert(ret == 0, return EINVAL,); |
| 514 |
val.u32 = gx_message.pdn.qos.arp.priority_level; |
| 515 |
ret = fd_msg_avp_setvalue (avpch2, &val); |
| 516 |
d_assert(ret == 0, return EINVAL,); |
| 517 |
ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 518 |
d_assert(ret == 0, return EINVAL,); |
| 519 |
|
| 520 |
ret = fd_msg_avp_new(gx_pre_emption_capability, 0, &avpch2); |
| 521 |
d_assert(ret == 0, return EINVAL,); |
| 522 |
val.u32 = gx_message.pdn.qos.arp.pre_emption_capability; |
| 523 |
ret = fd_msg_avp_setvalue (avpch2, &val); |
| 524 |
d_assert(ret == 0, return EINVAL,); |
| 525 |
ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 526 |
d_assert(ret == 0, return EINVAL,); |
| 527 |
|
| 528 |
ret = fd_msg_avp_new(gx_pre_emption_vulnerability, 0, &avpch2); |
| 529 |
d_assert(ret == 0, return EINVAL,); |
| 530 |
val.u32 = gx_message.pdn.qos.arp.pre_emption_vulnerability; |
| 531 |
ret = fd_msg_avp_setvalue (avpch2, &val); |
| 532 |
d_assert(ret == 0, return EINVAL,); |
| 533 |
ret = fd_msg_avp_add (avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 534 |
d_assert(ret == 0, return EINVAL,); |
| 535 |
|
| 536 |
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); |
| 537 |
d_assert(ret == 0, return EINVAL,); |
| 538 |
|
| 539 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 540 |
d_assert(ret == 0, return EINVAL,); |
| 541 |
|
| 542 |
/* Set Supported Features */ |
| 543 |
ret = fd_msg_avp_new(gx_supported_features, 0, &avp); |
| 544 |
d_assert(ret == 0, return EINVAL,); |
| 545 |
|
| 546 |
ret = fd_msg_avp_new(gx_feature_list_id, 0, &avpch1); |
| 547 |
d_assert(ret == 0, return EINVAL,); |
| 548 |
val.i32 = 1; |
| 549 |
ret = fd_msg_avp_setvalue (avpch1, &val); |
| 550 |
d_assert(ret == 0, return EINVAL,); |
| 551 |
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); |
| 552 |
d_assert(ret == 0, return EINVAL,); |
| 553 |
|
| 554 |
ret = fd_msg_avp_new(gx_feature_list, 0, &avpch1); |
| 555 |
d_assert(ret == 0, return EINVAL,); |
| 556 |
val.u32 = 0x0000000b; |
| 557 |
ret = fd_msg_avp_setvalue (avpch1, &val); |
| 558 |
d_assert(ret == 0, return EINVAL,); |
| 559 |
ret = fd_msg_avp_add (avp, MSG_BRW_LAST_CHILD, avpch1); |
| 560 |
d_assert(ret == 0, return EINVAL,); |
| 561 |
|
| 562 |
ret = fd_msg_avp_add(ans, MSG_BRW_LAST_CHILD, avp); |
| 563 |
d_assert(ret == 0, return EINVAL,); |
| 564 |
} |
| 565 |
else if (sess_data->cc_request_type == |
| 566 |
GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) |
| 567 |
{ |
| 568 |
struct rx_sess_state *rx_sess_data = NULL, *next_rx_sess_data = NULL; |
| 569 |
rx_sess_data = list_first(&sess_data->rx_list); |
| 570 |
while(rx_sess_data) |
| 571 |
{ |
| 572 |
next_rx_sess_data = list_next(rx_sess_data); |
| 573 |
|
| 574 |
rv = pcrf_rx_send_asr( |
| 575 |
rx_sess_data->sid, RX_ABORT_CAUSE_BEARER_RELEASED); |
| 576 |
d_assert(rv == CORE_OK,,); |
| 577 |
|
| 578 |
remove_rx_state(rx_sess_data); |
| 579 |
rx_sess_data = next_rx_sess_data; |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
/* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ |
| 584 |
ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); |
| 585 |
d_assert(ret == 0, return EINVAL,); |
| 586 |
|
| 587 |
if (sess_data->cc_request_type != GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) |
| 588 |
{ |
| 589 |
/* Store this value in the session */ |
| 590 |
ret = fd_sess_state_store(pcrf_gx_reg, sess, &sess_data); |
| 591 |
d_assert(ret == 0,,); |
| 592 |
d_assert(sess_data == NULL,,); |
| 593 |
} |
| 594 |
else |
| 595 |
{ |
| 596 |
state_cleanup(sess_data, NULL, NULL); |
| 597 |
} |
| 598 |
|
| 599 |
/* Send the answer */ |
| 600 |
ret = fd_msg_send(msg, NULL, NULL); |
| 601 |
d_assert(ret == 0,,); |
| 602 |
|
| 603 |
d_trace(3, "[PCRF] Credit-Control-Answer\n"); |
| 604 |
|
| 605 |
/* Add this value to the stats */ |
| 606 |
d_assert(pthread_mutex_lock(&fd_logger_self()->stats_lock) == 0,,); |
| 607 |
fd_logger_self()->stats.nb_echoed++; |
| 608 |
d_assert(pthread_mutex_unlock(&fd_logger_self()->stats_lock) ==0,, ); |
| 609 |
|
| 610 |
gx_message_free(&gx_message); |
| 611 |
|
| 612 |
return 0; |
| 613 |
|
| 614 |
out: |
| 615 |
/* Set the Result-Code */ |
| 616 |
if (result_code == FD_DIAMETER_AVP_UNSUPPORTED) |
| 617 |
{ |
| 618 |
ret = fd_msg_rescode_set(ans, |
| 619 |
"DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); |
| 620 |
d_assert(ret == 0, return EINVAL,); |
| 621 |
} |
| 622 |
else if (result_code == FD_DIAMETER_UNKNOWN_SESSION_ID) |
| 623 |
{ |
| 624 |
ret = fd_msg_rescode_set(ans, |
| 625 |
"DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); |
| 626 |
d_assert(ret == 0, return EINVAL,); |
| 627 |
} |
| 628 |
else if (result_code == FD_DIAMETER_MISSING_AVP) |
| 629 |
{ |
| 630 |
ret = fd_msg_rescode_set(ans, |
| 631 |
"DIAMETER_MISSING_AVP", NULL, NULL, 1); |
| 632 |
d_assert(ret == 0, return EINVAL,); |
| 633 |
} |
| 634 |
else |
| 635 |
{ |
| 636 |
ret = fd_message_experimental_rescode_set(ans, result_code); |
| 637 |
d_assert(ret == 0, return EINVAL,); |
| 638 |
} |
| 639 |
|
| 640 |
if (sess_data->cc_request_type != GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) |
| 641 |
{ |
| 642 |
/* Store this value in the session */ |
| 643 |
ret = fd_sess_state_store(pcrf_gx_reg, sess, &sess_data); |
| 644 |
d_assert(sess_data == NULL,,); |
| 645 |
} |
| 646 |
else |
| 647 |
{ |
| 648 |
state_cleanup(sess_data, NULL, NULL); |
| 649 |
} |
| 650 |
|
| 651 |
ret = fd_msg_send(msg, NULL, NULL); |
| 652 |
d_assert(ret == 0,,); |
| 653 |
|
| 654 |
gx_message_free(&gx_message); |
| 655 |
|
| 656 |
return 0; |
| 657 |
} |
| 658 |
|
| 659 |
status_t pcrf_gx_send_rar( |
| 660 |
c_uint8_t *gx_sid, c_uint8_t *rx_sid, rx_message_t *rx_message) |
| 661 |
{ |
| 662 |
status_t rv; |
| 663 |
int ret = 0, i, j; |
| 664 |
int count = 0; |
| 665 |
|
| 666 |
struct msg *req = NULL; |
| 667 |
struct avp *avp, *avpch1; |
| 668 |
union avp_value val; |
| 669 |
struct sess_state *sess_data = NULL, *svg; |
| 670 |
struct rx_sess_state *rx_sess_data = NULL; |
| 671 |
struct session *session = NULL; |
| 672 |
int new; |
| 673 |
size_t sidlen; |
| 674 |
|
| 675 |
gx_message_t gx_message; |
| 676 |
int charging_rule = 0; |
| 677 |
|
| 678 |
d_assert(gx_sid, return CORE_ERROR,); |
| 679 |
d_assert(rx_sid, return CORE_ERROR,); |
| 680 |
d_assert(rx_message, return CORE_ERROR,); |
| 681 |
|
| 682 |
d_trace(3, "[PCRF] Re-Auth-Request\n"); |
| 683 |
|
| 684 |
/* Initialize Message */ |
| 685 |
memset(&gx_message, 0, sizeof(gx_message_t)); |
| 686 |
|
| 687 |
/* Set default error result code */ |
| 688 |
rx_message->result_code = FD_DIAMETER_UNKNOWN_SESSION_ID; |
| 689 |
|
| 690 |
/* Create the request */ |
| 691 |
ret = fd_msg_new(gx_cmd_rar, MSGFL_ALLOC_ETEID, &req); |
| 692 |
d_assert(ret == 0, return CORE_ERROR,); |
| 693 |
{ |
| 694 |
struct msg_hdr * h; |
| 695 |
ret = fd_msg_hdr( req, &h ); |
| 696 |
d_assert(ret == 0, return CORE_ERROR,); |
| 697 |
h->msg_appl = GX_APPLICATION_ID; |
| 698 |
} |
| 699 |
|
| 700 |
/* Retrieve session by Session-Id */ |
| 701 |
sidlen = strlen((char *)gx_sid); |
| 702 |
ret = fd_sess_fromsid_msg((os0_t)gx_sid, sidlen, &session, &new); |
| 703 |
d_assert(ret == 0, return CORE_ERROR,); |
| 704 |
if (new) |
| 705 |
{ |
| 706 |
d_error("No session data"); |
| 707 |
ret = fd_msg_free(req); |
| 708 |
d_assert(ret == 0,,); |
| 709 |
rx_message->result_code = FD_DIAMETER_UNKNOWN_PEER; |
| 710 |
return CORE_ERROR; |
| 711 |
} |
| 712 |
|
| 713 |
/* Add Session-Id to the message */ |
| 714 |
ret = fd_message_session_id_set(req, (os0_t)gx_sid, sidlen); |
| 715 |
d_assert(ret == 0, return CORE_ERROR,); |
| 716 |
|
| 717 |
/* Save the session associated with the message */ |
| 718 |
ret = fd_msg_sess_set(req, session); |
| 719 |
d_assert(ret == 0, return CORE_ERROR,); |
| 720 |
|
| 721 |
/* Retrieve session state in this session */ |
| 722 |
ret = fd_sess_state_retrieve(pcrf_gx_reg, session, &sess_data); |
| 723 |
d_assert(ret == 0, return CORE_ERROR,); |
| 724 |
if (sess_data == NULL) |
| 725 |
{ |
| 726 |
d_error("No session data"); |
| 727 |
ret = fd_msg_free(req); |
| 728 |
d_assert(ret == 0,,); |
| 729 |
rx_message->result_code = FD_DIAMETER_UNKNOWN_SESSION_ID; |
| 730 |
return CORE_ERROR; |
| 731 |
} |
| 732 |
|
| 733 |
/* Find RX session state */ |
| 734 |
rx_sess_data = find_rx_state(sess_data, rx_sid); |
| 735 |
if (rx_message->cmd_code == RX_CMD_CODE_AA) |
| 736 |
{ |
| 737 |
if (!rx_sess_data) |
| 738 |
{ |
| 739 |
rx_sess_data = add_rx_state(sess_data, rx_sid); |
| 740 |
d_assert(rx_sess_data, return CORE_ERROR,); |
| 741 |
} |
| 742 |
|
| 743 |
/* Retrieve QoS Data from Database */ |
| 744 |
rv = pcrf_db_qos_data(sess_data->imsi_bcd, sess_data->apn, &gx_message); |
| 745 |
if (rv != CORE_OK) |
| 746 |
{ |
| 747 |
d_error("Cannot get data for IMSI(%s)+APN(%s)'\n", |
| 748 |
sess_data->imsi_bcd, sess_data->apn); |
| 749 |
rx_message->result_code = |
| 750 |
RX_DIAMETER_IP_CAN_SESSION_NOT_AVAILABLE; |
| 751 |
goto out; |
| 752 |
} |
| 753 |
|
| 754 |
/* Match Media-Component with PCC Rule */ |
| 755 |
for (i = 0; i < rx_message->num_of_media_component; i++) |
| 756 |
{ |
| 757 |
int flow_presence = 0; |
| 758 |
pcc_rule_t *pcc_rule = NULL; |
| 759 |
pcc_rule_t *db_pcc_rule = NULL; |
| 760 |
c_uint8_t qci = 0; |
| 761 |
rx_media_component_t *media_component = |
| 762 |
&rx_message->media_component[i]; |
| 763 |
|
| 764 |
if (media_component->media_component_number == 0) |
| 765 |
{ |
| 766 |
continue; |
| 767 |
} |
| 768 |
|
| 769 |
switch(media_component->media_type) |
| 770 |
{ |
| 771 |
case RX_MEDIA_TYPE_AUDIO: |
| 772 |
{ |
| 773 |
qci = PDN_QCI_1; |
| 774 |
break; |
| 775 |
} |
| 776 |
default: |
| 777 |
{ |
| 778 |
d_error("Not implemented : [Media-Type:%d]", |
| 779 |
media_component->media_type); |
| 780 |
rx_message->result_code = FD_DIAMETER_INVALID_AVP_VALUE; |
| 781 |
goto out; |
| 782 |
} |
| 783 |
} |
| 784 |
|
| 785 |
for (j = 0; j < gx_message.num_of_pcc_rule; j++) |
| 786 |
{ |
| 787 |
if (gx_message.pcc_rule[j].qos.qci == qci) |
| 788 |
{ |
| 789 |
db_pcc_rule = &gx_message.pcc_rule[j]; |
| 790 |
break; |
| 791 |
} |
| 792 |
} |
| 793 |
|
| 794 |
if (!db_pcc_rule) |
| 795 |
{ |
| 796 |
d_error("CHECK WEBUI : No PCC Rule in DB [QCI:%d]", qci); |
| 797 |
d_error("Please add PCC Rule using WEBUI"); |
| 798 |
rx_message->result_code = |
| 799 |
RX_DIAMETER_REQUESTED_SERVICE_NOT_AUTHORIZED; |
| 800 |
goto out; |
| 801 |
} |
| 802 |
|
| 803 |
for (j = 0; j < rx_sess_data->num_of_pcc_rule; j++) |
| 804 |
{ |
| 805 |
if (rx_sess_data->pcc_rule[j].qos.qci == qci) |
| 806 |
{ |
| 807 |
pcc_rule = &rx_sess_data->pcc_rule[j]; |
| 808 |
break; |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
if (!pcc_rule) |
| 813 |
{ |
| 814 |
pcc_rule = |
| 815 |
&rx_sess_data->pcc_rule[rx_sess_data->num_of_pcc_rule]; |
| 816 |
|
| 817 |
/* Device PCC Rule Info from DB Profile */ |
| 818 |
pcc_rule->name = core_strdup(db_pcc_rule->name); |
| 819 |
d_assert(pcc_rule->name, return CORE_ERROR,); |
| 820 |
|
| 821 |
memcpy(&pcc_rule->qos, &db_pcc_rule->qos, sizeof(qos_t)); |
| 822 |
|
| 823 |
pcc_rule->flow_status = db_pcc_rule->flow_status; |
| 824 |
pcc_rule->precedence = db_pcc_rule->precedence; |
| 825 |
|
| 826 |
/* Install Flow */ |
| 827 |
flow_presence = 1; |
| 828 |
rv = install_flow(pcc_rule, media_component); |
| 829 |
if (rv != CORE_OK) |
| 830 |
{ |
| 831 |
rx_message->result_code = RX_DIAMETER_FILTER_RESTRICTIONS; |
| 832 |
d_error("install_flow() failed"); |
| 833 |
goto out; |
| 834 |
} |
| 835 |
|
| 836 |
rx_sess_data->num_of_pcc_rule++; |
| 837 |
} |
| 838 |
else |
| 839 |
{ |
| 840 |
d_assert(strcmp(pcc_rule->name, db_pcc_rule->name) == 0, |
| 841 |
return CORE_ERROR, "Mismatch Rule Name [%s:%s]", |
| 842 |
pcc_rule->name, db_pcc_rule->name); |
| 843 |
|
| 844 |
/* Check Flow */ |
| 845 |
count = matched_flow(pcc_rule, media_component); |
| 846 |
if (count == -1) |
| 847 |
{ |
| 848 |
rx_message->result_code = RX_DIAMETER_FILTER_RESTRICTIONS; |
| 849 |
d_error("matched_flow() failed"); |
| 850 |
goto out; |
| 851 |
} |
| 852 |
|
| 853 |
if (pcc_rule->num_of_flow != count) |
| 854 |
{ |
| 855 |
/* Re-install Flow */ |
| 856 |
flow_presence = 1; |
| 857 |
rv = install_flow(pcc_rule, media_component); |
| 858 |
if (rv != CORE_OK) |
| 859 |
{ |
| 860 |
rx_message->result_code = |
| 861 |
RX_DIAMETER_FILTER_RESTRICTIONS; |
| 862 |
d_error("install_flow() failed"); |
| 863 |
goto out; |
| 864 |
} |
| 865 |
|
| 866 |
} |
| 867 |
|
| 868 |
} |
| 869 |
|
| 870 |
/* Update QoS */ |
| 871 |
rv = update_qos(pcc_rule, media_component); |
| 872 |
if (rv != CORE_OK) |
| 873 |
{ |
| 874 |
rx_message->result_code = |
| 875 |
RX_DIAMETER_REQUESTED_SERVICE_NOT_AUTHORIZED; |
| 876 |
d_error("update_qos() failed"); |
| 877 |
goto out; |
| 878 |
} |
| 879 |
|
| 880 |
/* if we failed to get QoS from IMS, apply WEBUI QoS */ |
| 881 |
if (pcc_rule->qos.mbr.downlink == 0) |
| 882 |
pcc_rule->qos.mbr.downlink = db_pcc_rule->qos.mbr.downlink; |
| 883 |
if (pcc_rule->qos.mbr.uplink == 0) |
| 884 |
pcc_rule->qos.mbr.uplink = db_pcc_rule->qos.mbr.uplink; |
| 885 |
if (pcc_rule->qos.gbr.downlink == 0) |
| 886 |
pcc_rule->qos.gbr.downlink = db_pcc_rule->qos.gbr.downlink; |
| 887 |
if (pcc_rule->qos.gbr.uplink == 0) |
| 888 |
pcc_rule->qos.gbr.uplink = db_pcc_rule->qos.gbr.uplink; |
| 889 |
|
| 890 |
if (charging_rule == 0) |
| 891 |
{ |
| 892 |
ret = fd_msg_avp_new(gx_charging_rule_install, 0, &avp); |
| 893 |
d_assert(ret == 0, return CORE_ERROR,); |
| 894 |
charging_rule = 1; |
| 895 |
} |
| 896 |
|
| 897 |
rv = encode_pcc_rule_definition(avp, pcc_rule, flow_presence); |
| 898 |
d_assert(rv == CORE_OK, return CORE_ERROR,); |
| 899 |
} |
| 900 |
|
| 901 |
if (charging_rule == 1) |
| 902 |
{ |
| 903 |
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); |
| 904 |
d_assert(ret == 0, return CORE_ERROR,); |
| 905 |
} |
| 906 |
|
| 907 |
} |
| 908 |
else if (rx_message->cmd_code == RX_CMD_CODE_SESSION_TERMINATION) |
| 909 |
{ |
| 910 |
d_assert(rx_sess_data, return CORE_ERROR,); |
| 911 |
|
| 912 |
for (i = 0; i < rx_sess_data->num_of_pcc_rule; i++) |
| 913 |
{ |
| 914 |
d_assert(rx_sess_data->pcc_rule[i].name,,); |
| 915 |
|
| 916 |
if (charging_rule == 0) |
| 917 |
{ |
| 918 |
ret = fd_msg_avp_new(gx_charging_rule_remove, 0, &avp); |
| 919 |
d_assert(ret == 0, return CORE_ERROR,); |
| 920 |
charging_rule = 1; |
| 921 |
} |
| 922 |
|
| 923 |
ret = fd_msg_avp_new(gx_charging_rule_name, 0, &avpch1); |
| 924 |
d_assert(ret == 0, return CORE_ERROR,); |
| 925 |
val.os.data = (c_uint8_t *)rx_sess_data->pcc_rule[i].name; |
| 926 |
val.os.len = strlen(rx_sess_data->pcc_rule[i].name); |
| 927 |
ret = fd_msg_avp_setvalue(avpch1, &val); |
| 928 |
d_assert(ret == 0, return CORE_ERROR,); |
| 929 |
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avpch1); |
| 930 |
d_assert(ret == 0, return CORE_ERROR,); |
| 931 |
} |
| 932 |
|
| 933 |
if (charging_rule == 1) |
| 934 |
{ |
| 935 |
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); |
| 936 |
d_assert(ret == 0, return CORE_ERROR,); |
| 937 |
} |
| 938 |
|
| 939 |
remove_rx_state(rx_sess_data); |
| 940 |
} |
| 941 |
else |
| 942 |
d_assert(0, return CORE_ERROR, |
| 943 |
"Invalid Command Code(%d)", rx_message->cmd_code); |
| 944 |
|
| 945 |
if (charging_rule == 0) |
| 946 |
{ |
| 947 |
rx_message->result_code = ER_DIAMETER_SUCCESS; |
| 948 |
goto out; |
| 949 |
} |
| 950 |
|
| 951 |
/* Set Origin-Host & Origin-Realm */ |
| 952 |
ret = fd_msg_add_origin(req, 0); |
| 953 |
d_assert(ret == 0, return CORE_ERROR,); |
| 954 |
|
| 955 |
/* Set the Destination-Realm AVP */ |
| 956 |
ret = fd_msg_avp_new(fd_destination_realm, 0, &avp); |
| 957 |
d_assert(ret == 0, return CORE_ERROR,); |
| 958 |
val.os.data = (unsigned char *)(fd_g_config->cnf_diamrlm); |
| 959 |
val.os.len = strlen(fd_g_config->cnf_diamrlm); |
| 960 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 961 |
d_assert(ret == 0, return CORE_ERROR,); |
| 962 |
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); |
| 963 |
d_assert(ret == 0, return CORE_ERROR,); |
| 964 |
|
| 965 |
/* Set the Destination-Host AVP */ |
| 966 |
ret = fd_msg_avp_new(fd_destination_host, 0, &avp); |
| 967 |
d_assert(ret == 0, return CORE_ERROR,); |
| 968 |
val.os.data = sess_data->peer_host; |
| 969 |
val.os.len = strlen((char *)sess_data->peer_host); |
| 970 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 971 |
d_assert(ret == 0, return CORE_ERROR,); |
| 972 |
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); |
| 973 |
d_assert(ret == 0, return CORE_ERROR,); |
| 974 |
|
| 975 |
/* Set the Auth-Application-Id AVP */ |
| 976 |
ret = fd_msg_avp_new(fd_auth_application_id, 0, &avp); |
| 977 |
d_assert(ret == 0, return CORE_ERROR,); |
| 978 |
val.i32 = GX_APPLICATION_ID; |
| 979 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 980 |
d_assert(ret == 0, return CORE_ERROR,); |
| 981 |
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); |
| 982 |
d_assert(ret == 0, return CORE_ERROR,); |
| 983 |
|
| 984 |
/* Set the Re-Auth-Request-Type */ |
| 985 |
ret = fd_msg_avp_new(fd_re_auth_request_type, 0, &avp); |
| 986 |
d_assert(ret == 0, return CORE_ERROR,); |
| 987 |
val.i32 = FD_RE_AUTH_REQUEST_TYPE_AUTHORIZE_ONLY; |
| 988 |
ret = fd_msg_avp_setvalue(avp, &val); |
| 989 |
d_assert(ret == 0, return CORE_ERROR,); |
| 990 |
ret = fd_msg_avp_add(req, MSG_BRW_LAST_CHILD, avp); |
| 991 |
d_assert(ret == 0, return CORE_ERROR,); |
| 992 |
|
| 993 |
ret = clock_gettime(CLOCK_REALTIME, &sess_data->ts); |
| 994 |
d_assert(ret == 0, return CORE_ERROR,); |
| 995 |
|
| 996 |
/* Keep a pointer to the session data for debug purpose, |
| 997 |
* in real life we would not need it */ |
| 998 |
svg = sess_data; |
| 999 |
|
| 1000 |
/* Store this value in the session */ |
| 1001 |
ret = fd_sess_state_store(pcrf_gx_reg, session, &sess_data); |
| 1002 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1003 |
d_assert(sess_data == NULL, return CORE_ERROR,); |
| 1004 |
|
| 1005 |
/* Send the request */ |
| 1006 |
ret = fd_msg_send(&req, pcrf_gx_raa_cb, svg); |
| 1007 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1008 |
|
| 1009 |
/* Increment the counter */ |
| 1010 |
d_assert(pthread_mutex_lock(&fd_logger_self()->stats_lock) == 0,,); |
| 1011 |
fd_logger_self()->stats.nb_sent++; |
| 1012 |
d_assert(pthread_mutex_unlock(&fd_logger_self()->stats_lock) == 0,, ); |
| 1013 |
|
| 1014 |
/* Set no error */ |
| 1015 |
rx_message->result_code = ER_DIAMETER_SUCCESS; |
| 1016 |
|
| 1017 |
gx_message_free(&gx_message); |
| 1018 |
|
| 1019 |
return CORE_OK; |
| 1020 |
|
| 1021 |
out: |
| 1022 |
/* Store this value in the session */ |
| 1023 |
ret = fd_sess_state_store(pcrf_gx_reg, session, &sess_data); |
| 1024 |
d_assert(sess_data == NULL,,); |
| 1025 |
|
| 1026 |
gx_message_free(&gx_message); |
| 1027 |
|
| 1028 |
return CORE_ERROR; |
| 1029 |
} |
| 1030 |
|
| 1031 |
static void pcrf_gx_raa_cb(void *data, struct msg **msg) |
| 1032 |
{ |
| 1033 |
int ret; |
| 1034 |
|
| 1035 |
struct sess_state *sess_data = NULL; |
| 1036 |
struct timespec ts; |
| 1037 |
struct session *session; |
| 1038 |
struct avp *avp, *avpch1; |
| 1039 |
struct avp_hdr *hdr; |
| 1040 |
unsigned long dur; |
| 1041 |
int error = 0; |
| 1042 |
int new; |
| 1043 |
|
| 1044 |
c_uint32_t result_code; |
| 1045 |
|
| 1046 |
d_trace(3, "[PCRF] Re-Auth-Answer\n"); |
| 1047 |
|
| 1048 |
ret = clock_gettime(CLOCK_REALTIME, &ts); |
| 1049 |
d_assert(ret == 0, return,); |
| 1050 |
|
| 1051 |
/* Search the session, retrieve its data */ |
| 1052 |
ret = fd_msg_sess_get(fd_g_config->cnf_dict, *msg, &session, &new); |
| 1053 |
d_assert(ret == 0, return,); |
| 1054 |
d_assert(new == 0, return, ); |
| 1055 |
|
| 1056 |
ret = fd_sess_state_retrieve(pcrf_gx_reg, session, &sess_data); |
| 1057 |
d_assert(ret == 0, return,); |
| 1058 |
d_assert(sess_data && (void *)sess_data == data, return, ); |
| 1059 |
|
| 1060 |
/* Value of Result Code */ |
| 1061 |
ret = fd_msg_search_avp(*msg, fd_result_code, &avp); |
| 1062 |
d_assert(ret == 0, return,); |
| 1063 |
if (avp) |
| 1064 |
{ |
| 1065 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 1066 |
d_assert(ret == 0, return,); |
| 1067 |
result_code = hdr->avp_value->i32; |
| 1068 |
d_trace(5, " Result Code: %d\n", hdr->avp_value->i32); |
| 1069 |
} |
| 1070 |
else |
| 1071 |
{ |
| 1072 |
ret = fd_msg_search_avp(*msg, fd_experimental_result, &avp); |
| 1073 |
d_assert(ret == 0, return,); |
| 1074 |
if (avp) |
| 1075 |
{ |
| 1076 |
ret = fd_avp_search_avp(avp, fd_experimental_result_code, &avpch1); |
| 1077 |
d_assert(ret == 0, return,); |
| 1078 |
if (avpch1) |
| 1079 |
{ |
| 1080 |
ret = fd_msg_avp_hdr(avpch1, &hdr); |
| 1081 |
d_assert(ret == 0, return,); |
| 1082 |
result_code = hdr->avp_value->i32; |
| 1083 |
d_trace(5, " Experimental Result Code: %d\n", result_code); |
| 1084 |
} |
| 1085 |
} |
| 1086 |
else |
| 1087 |
{ |
| 1088 |
d_error("no Result-Code"); |
| 1089 |
error++; |
| 1090 |
} |
| 1091 |
} |
| 1092 |
|
| 1093 |
/* Value of Origin-Host */ |
| 1094 |
ret = fd_msg_search_avp(*msg, fd_origin_host, &avp); |
| 1095 |
d_assert(ret == 0, return,); |
| 1096 |
if (avp) |
| 1097 |
{ |
| 1098 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 1099 |
d_assert(ret == 0, return,); |
| 1100 |
d_trace(5, " From '%.*s'\n", |
| 1101 |
(int)hdr->avp_value->os.len, hdr->avp_value->os.data); |
| 1102 |
} |
| 1103 |
else |
| 1104 |
{ |
| 1105 |
d_error("no_Origin-Host"); |
| 1106 |
error++; |
| 1107 |
} |
| 1108 |
|
| 1109 |
/* Value of Origin-Realm */ |
| 1110 |
ret = fd_msg_search_avp(*msg, fd_origin_realm, &avp); |
| 1111 |
d_assert(ret == 0, return,); |
| 1112 |
if (avp) |
| 1113 |
{ |
| 1114 |
ret = fd_msg_avp_hdr(avp, &hdr); |
| 1115 |
d_assert(ret == 0, return,); |
| 1116 |
d_trace(5, " ('%.*s')\n", |
| 1117 |
(int)hdr->avp_value->os.len, hdr->avp_value->os.data); |
| 1118 |
} |
| 1119 |
else |
| 1120 |
{ |
| 1121 |
d_error("no_Origin-Realm"); |
| 1122 |
error++; |
| 1123 |
} |
| 1124 |
|
| 1125 |
/* Free the message */ |
| 1126 |
d_assert(pthread_mutex_lock(&fd_logger_self()->stats_lock) == 0,,); |
| 1127 |
dur = ((ts.tv_sec - sess_data->ts.tv_sec) * 1000000) + |
| 1128 |
((ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); |
| 1129 |
if (fd_logger_self()->stats.nb_recv) |
| 1130 |
{ |
| 1131 |
/* Ponderate in the avg */ |
| 1132 |
fd_logger_self()->stats.avg = (fd_logger_self()->stats.avg * |
| 1133 |
fd_logger_self()->stats.nb_recv + dur) / |
| 1134 |
(fd_logger_self()->stats.nb_recv + 1); |
| 1135 |
/* Min, max */ |
| 1136 |
if (dur < fd_logger_self()->stats.shortest) |
| 1137 |
fd_logger_self()->stats.shortest = dur; |
| 1138 |
if (dur > fd_logger_self()->stats.longest) |
| 1139 |
fd_logger_self()->stats.longest = dur; |
| 1140 |
} |
| 1141 |
else |
| 1142 |
{ |
| 1143 |
fd_logger_self()->stats.shortest = dur; |
| 1144 |
fd_logger_self()->stats.longest = dur; |
| 1145 |
fd_logger_self()->stats.avg = dur; |
| 1146 |
} |
| 1147 |
if (error) |
| 1148 |
fd_logger_self()->stats.nb_errs++; |
| 1149 |
else |
| 1150 |
fd_logger_self()->stats.nb_recv++; |
| 1151 |
|
| 1152 |
d_assert(pthread_mutex_unlock(&fd_logger_self()->stats_lock) == 0,,); |
| 1153 |
|
| 1154 |
/* Display how long it took */ |
| 1155 |
if (ts.tv_nsec > sess_data->ts.tv_nsec) |
| 1156 |
d_trace(15, "in %d.%06ld sec\n", |
| 1157 |
(int)(ts.tv_sec - sess_data->ts.tv_sec), |
| 1158 |
(long)(ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); |
| 1159 |
else |
| 1160 |
d_trace(15, "in %d.%06ld sec\n", |
| 1161 |
(int)(ts.tv_sec + 1 - sess_data->ts.tv_sec), |
| 1162 |
(long)(1000000000 + ts.tv_nsec - sess_data->ts.tv_nsec) / 1000); |
| 1163 |
|
| 1164 |
ret = fd_sess_state_store(pcrf_gx_reg, session, &sess_data); |
| 1165 |
d_assert(ret == 0, return,); |
| 1166 |
d_assert(sess_data == NULL, return,); |
| 1167 |
|
| 1168 |
ret = fd_msg_free(*msg); |
| 1169 |
d_assert(ret == 0,,); |
| 1170 |
*msg = NULL; |
| 1171 |
|
| 1172 |
return; |
| 1173 |
} |
| 1174 |
|
| 1175 |
status_t pcrf_gx_init(void) |
| 1176 |
{ |
| 1177 |
int ret; |
| 1178 |
struct disp_when data; |
| 1179 |
|
| 1180 |
pool_init(&pcrf_gx_sess_pool, MAX_POOL_OF_DIAMETER_SESS); |
| 1181 |
pool_init(&pcrf_gx_rx_sess_pool, MAX_POOL_OF_DIAMETER_SESS); |
| 1182 |
|
| 1183 |
/* Install objects definitions for this application */ |
| 1184 |
ret = gx_dict_init(); |
| 1185 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1186 |
|
| 1187 |
/* Create handler for sessions */ |
| 1188 |
ret = fd_sess_handler_create(&pcrf_gx_reg, state_cleanup, NULL, NULL); |
| 1189 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1190 |
|
| 1191 |
memset(&data, 0, sizeof(data)); |
| 1192 |
data.app = gx_application; |
| 1193 |
|
| 1194 |
ret = fd_disp_register(pcrf_gx_fb_cb, DISP_HOW_APPID, &data, NULL, |
| 1195 |
&hdl_gx_fb); |
| 1196 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1197 |
|
| 1198 |
data.command = gx_cmd_ccr; |
| 1199 |
ret = fd_disp_register(pcrf_gx_ccr_cb, DISP_HOW_CC, &data, NULL, |
| 1200 |
&hdl_gx_ccr); |
| 1201 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1202 |
|
| 1203 |
/* Advertise the support for the application in the peer */ |
| 1204 |
ret = fd_disp_app_support(gx_application, fd_vendor, 1, 0); |
| 1205 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1206 |
|
| 1207 |
return CORE_OK; |
| 1208 |
} |
| 1209 |
|
| 1210 |
void pcrf_gx_final(void) |
| 1211 |
{ |
| 1212 |
int ret; |
| 1213 |
|
| 1214 |
ret = fd_sess_handler_destroy(&pcrf_gx_reg, NULL); |
| 1215 |
d_assert(ret == 0,,); |
| 1216 |
|
| 1217 |
if (hdl_gx_fb) |
| 1218 |
(void) fd_disp_unregister(&hdl_gx_fb, NULL); |
| 1219 |
if (hdl_gx_ccr) |
| 1220 |
(void) fd_disp_unregister(&hdl_gx_ccr, NULL); |
| 1221 |
|
| 1222 |
if (pool_used(&pcrf_gx_sess_pool)) |
| 1223 |
d_error("%d not freed in pcrf_gx_sess_pool[%d] of GX-SM", |
| 1224 |
pool_used(&pcrf_gx_sess_pool), pool_size(&pcrf_gx_sess_pool)); |
| 1225 |
d_trace(9, "%d not freed in pcrf_gx_sess_pool[%d] of GX-SM\n", |
| 1226 |
pool_used(&pcrf_gx_sess_pool), pool_size(&pcrf_gx_sess_pool)); |
| 1227 |
if (pool_used(&pcrf_gx_rx_sess_pool)) |
| 1228 |
d_error("%d not freed in pcrf_gx_rx_sess_pool[%d] of GX-SM", |
| 1229 |
pool_used(&pcrf_gx_rx_sess_pool), pool_size(&pcrf_gx_rx_sess_pool)); |
| 1230 |
d_trace(9, "%d not freed in pcrf_gx_rx_sess_pool[%d] of GX-SM\n", |
| 1231 |
pool_used(&pcrf_gx_rx_sess_pool), pool_size(&pcrf_gx_rx_sess_pool)); |
| 1232 |
|
| 1233 |
pool_final(&pcrf_gx_sess_pool); |
| 1234 |
pool_final(&pcrf_gx_rx_sess_pool); |
| 1235 |
} |
| 1236 |
|
| 1237 |
static status_t encode_pcc_rule_definition( |
| 1238 |
struct avp *avp, pcc_rule_t *pcc_rule, int flow_presence) |
| 1239 |
{ |
| 1240 |
struct avp *avpch1, *avpch2, *avpch3, *avpch4; |
| 1241 |
union avp_value val; |
| 1242 |
int ret = 0, i; |
| 1243 |
|
| 1244 |
d_assert(avp, return CORE_ERROR,); |
| 1245 |
d_assert(pcc_rule, return CORE_ERROR,); |
| 1246 |
|
| 1247 |
ret = fd_msg_avp_new(gx_charging_rule_definition, 0, &avpch1); |
| 1248 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1249 |
ret = fd_msg_avp_new(gx_charging_rule_name, 0, &avpch2); |
| 1250 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1251 |
val.os.data = (c_uint8_t *)pcc_rule->name; |
| 1252 |
val.os.len = strlen(pcc_rule->name); |
| 1253 |
ret = fd_msg_avp_setvalue(avpch2, &val); |
| 1254 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1255 |
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 1256 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1257 |
|
| 1258 |
if (flow_presence == 1) |
| 1259 |
{ |
| 1260 |
for (i = 0; i < pcc_rule->num_of_flow; i++) |
| 1261 |
{ |
| 1262 |
flow_t *flow = &pcc_rule->flow[i]; |
| 1263 |
|
| 1264 |
ret = fd_msg_avp_new(gx_flow_information, 0, &avpch2); |
| 1265 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1266 |
|
| 1267 |
ret = fd_msg_avp_new(gx_flow_direction, 0, &avpch3); |
| 1268 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1269 |
val.i32 = flow->direction; |
| 1270 |
ret = fd_msg_avp_setvalue(avpch3, &val); |
| 1271 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1272 |
ret = fd_msg_avp_add(avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1273 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1274 |
|
| 1275 |
ret = fd_msg_avp_new(gx_flow_description, 0, &avpch3); |
| 1276 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1277 |
val.os.data = (c_uint8_t *)flow->description; |
| 1278 |
val.os.len = strlen(flow->description); |
| 1279 |
ret = fd_msg_avp_setvalue(avpch3, &val); |
| 1280 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1281 |
ret = fd_msg_avp_add(avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1282 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1283 |
|
| 1284 |
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 1285 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1286 |
} |
| 1287 |
} |
| 1288 |
|
| 1289 |
ret = fd_msg_avp_new(gx_flow_status, 0, &avpch2); |
| 1290 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1291 |
val.i32 = pcc_rule->flow_status; |
| 1292 |
ret = fd_msg_avp_setvalue(avpch2, &val); |
| 1293 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1294 |
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 1295 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1296 |
|
| 1297 |
ret = fd_msg_avp_new(gx_qos_information, 0, &avpch2); |
| 1298 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1299 |
|
| 1300 |
ret = fd_msg_avp_new(gx_qos_class_identifier, 0, &avpch3); |
| 1301 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1302 |
val.u32 = pcc_rule->qos.qci; |
| 1303 |
ret = fd_msg_avp_setvalue (avpch3, &val); |
| 1304 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1305 |
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1306 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1307 |
|
| 1308 |
ret = fd_msg_avp_new(gx_allocation_retention_priority, 0, &avpch3); |
| 1309 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1310 |
|
| 1311 |
ret = fd_msg_avp_new(gx_priority_level, 0, &avpch4); |
| 1312 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1313 |
val.u32 = pcc_rule->qos.arp.priority_level; |
| 1314 |
ret = fd_msg_avp_setvalue (avpch4, &val); |
| 1315 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1316 |
ret = fd_msg_avp_add (avpch3, MSG_BRW_LAST_CHILD, avpch4); |
| 1317 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1318 |
|
| 1319 |
ret = fd_msg_avp_new(gx_pre_emption_capability, 0, &avpch4); |
| 1320 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1321 |
val.u32 = pcc_rule->qos.arp.pre_emption_capability; |
| 1322 |
ret = fd_msg_avp_setvalue (avpch4, &val); |
| 1323 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1324 |
ret = fd_msg_avp_add (avpch3, MSG_BRW_LAST_CHILD, avpch4); |
| 1325 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1326 |
|
| 1327 |
ret = fd_msg_avp_new(gx_pre_emption_vulnerability, 0, &avpch4); |
| 1328 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1329 |
val.u32 = pcc_rule->qos.arp.pre_emption_vulnerability; |
| 1330 |
ret = fd_msg_avp_setvalue (avpch4, &val); |
| 1331 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1332 |
ret = fd_msg_avp_add (avpch3, MSG_BRW_LAST_CHILD, avpch4); |
| 1333 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1334 |
|
| 1335 |
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1336 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1337 |
|
| 1338 |
if (pcc_rule->qos.mbr.uplink) |
| 1339 |
{ |
| 1340 |
ret = fd_msg_avp_new(gx_max_requested_bandwidth_ul, 0, &avpch3); |
| 1341 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1342 |
val.u32 = pcc_rule->qos.mbr.uplink; |
| 1343 |
ret = fd_msg_avp_setvalue (avpch3, &val); |
| 1344 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1345 |
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1346 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1347 |
} |
| 1348 |
|
| 1349 |
if (pcc_rule->qos.mbr.downlink) |
| 1350 |
{ |
| 1351 |
ret = fd_msg_avp_new(gx_max_requested_bandwidth_dl, 0, &avpch3); |
| 1352 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1353 |
val.u32 = pcc_rule->qos.mbr.downlink; |
| 1354 |
ret = fd_msg_avp_setvalue (avpch3, &val); |
| 1355 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1356 |
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1357 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1358 |
} |
| 1359 |
|
| 1360 |
if (pcc_rule->qos.gbr.uplink) |
| 1361 |
{ |
| 1362 |
ret = fd_msg_avp_new(gx_guaranteed_bitrate_ul, 0, &avpch3); |
| 1363 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1364 |
val.u32 = pcc_rule->qos.gbr.uplink; |
| 1365 |
ret = fd_msg_avp_setvalue (avpch3, &val); |
| 1366 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1367 |
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1368 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1369 |
} |
| 1370 |
|
| 1371 |
if (pcc_rule->qos.gbr.downlink) |
| 1372 |
{ |
| 1373 |
ret = fd_msg_avp_new(gx_guaranteed_bitrate_dl, 0, &avpch3); |
| 1374 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1375 |
val.u32 = pcc_rule->qos.gbr.downlink; |
| 1376 |
ret = fd_msg_avp_setvalue (avpch3, &val); |
| 1377 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1378 |
ret = fd_msg_avp_add (avpch2, MSG_BRW_LAST_CHILD, avpch3); |
| 1379 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1380 |
} |
| 1381 |
|
| 1382 |
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 1383 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1384 |
|
| 1385 |
ret = fd_msg_avp_new(gx_precedence, 0, &avpch2); |
| 1386 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1387 |
val.u32 = pcc_rule->precedence; |
| 1388 |
ret = fd_msg_avp_setvalue (avpch2, &val); |
| 1389 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1390 |
ret = fd_msg_avp_add(avpch1, MSG_BRW_LAST_CHILD, avpch2); |
| 1391 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1392 |
|
| 1393 |
ret = fd_msg_avp_add(avp, MSG_BRW_LAST_CHILD, avpch1); |
| 1394 |
d_assert(ret == 0, return CORE_ERROR,); |
| 1395 |
|
| 1396 |
return CORE_OK; |
| 1397 |
} |
| 1398 |
|
| 1399 |
static status_t flow_rx_to_gx(flow_t *rx_flow, flow_t *gx_flow) |
| 1400 |
{ |
| 1401 |
int len; |
| 1402 |
|
| 1403 |
d_assert(rx_flow, return CORE_ERROR,); |
| 1404 |
d_assert(gx_flow, return CORE_ERROR,); |
| 1405 |
|
| 1406 |
if (!strncmp(rx_flow->description, |
| 1407 |
"permit out", strlen("permit out"))) |
| 1408 |
{ |
| 1409 |
gx_flow->direction = FLOW_DOWNLINK_ONLY; |
| 1410 |
|
| 1411 |
len = strlen(rx_flow->description)+1; |
| 1412 |
gx_flow->description = core_malloc(len); |
| 1413 |
core_cpystrn(gx_flow->description, rx_flow->description, len); |
| 1414 |
} |
| 1415 |
else if (!strncmp(rx_flow->description, |
| 1416 |
"permit in", strlen("permit in"))) |
| 1417 |
{ |
| 1418 |
gx_flow->direction = FLOW_UPLINK_ONLY; |
| 1419 |
|
| 1420 |
/* 'permit in' should be changed |
| 1421 |
* 'permit out' in Gx Diameter */ |
| 1422 |
len = strlen(rx_flow->description)+2; |
| 1423 |
gx_flow->description = core_malloc(len); |
| 1424 |
strcpy(gx_flow->description, "permit out"); |
| 1425 |
strcat(gx_flow->description, |
| 1426 |
&rx_flow->description[strlen("permit in")]); |
| 1427 |
d_assert(len == strlen(gx_flow->description)+1, return CORE_ERROR,); |
| 1428 |
} |
| 1429 |
else |
| 1430 |
{ |
| 1431 |
d_error("Invalid Flow Descripton : [%s]", rx_flow->description); |
| 1432 |
return CORE_ERROR; |
| 1433 |
} |
| 1434 |
|
| 1435 |
return CORE_OK; |
| 1436 |
} |
| 1437 |
|
| 1438 |
static int matched_flow( |
| 1439 |
pcc_rule_t *pcc_rule, rx_media_component_t *media_component) |
| 1440 |
{ |
| 1441 |
status_t rv; |
| 1442 |
int i, j, k; |
| 1443 |
int matched = 0; |
| 1444 |
int new = 0; |
| 1445 |
|
| 1446 |
d_assert(pcc_rule, return CORE_ERROR,); |
| 1447 |
d_assert(media_component, return CORE_ERROR,); |
| 1448 |
|
| 1449 |
for (i = 0; i < media_component->num_of_sub; i++) |
| 1450 |
{ |
| 1451 |
rx_media_sub_component_t *sub = &media_component->sub[i]; |
| 1452 |
|
| 1453 |
if (sub->flow_number == 0) |
| 1454 |
{ |
| 1455 |
continue; |
| 1456 |
} |
| 1457 |
|
| 1458 |
for (j = 0; j < sub->num_of_flow; j++) |
| 1459 |
{ |
| 1460 |
new++; |
| 1461 |
} |
| 1462 |
} |
| 1463 |
|
| 1464 |
if (new == 0) |
| 1465 |
{ |
| 1466 |
/* No new flow in Media-Component */ |
| 1467 |
return pcc_rule->num_of_flow; |
| 1468 |
} |
| 1469 |
|
| 1470 |
for (i = 0; i < media_component->num_of_sub; i++) |
| 1471 |
{ |
| 1472 |
rx_media_sub_component_t *sub = &media_component->sub[i]; |
| 1473 |
|
| 1474 |
if (sub->flow_number == 0) |
| 1475 |
{ |
| 1476 |
continue; |
| 1477 |
} |
| 1478 |
|
| 1479 |
for (j = 0; j < sub->num_of_flow; j++) |
| 1480 |
{ |
| 1481 |
flow_t gx_flow; |
| 1482 |
flow_t *rx_flow = &sub->flow[j]; |
| 1483 |
|
| 1484 |
rv = flow_rx_to_gx(rx_flow, &gx_flow); |
| 1485 |
if (rv != CORE_OK) |
| 1486 |
{ |
| 1487 |
d_error("flow reformatting error"); |
| 1488 |
return CORE_ERROR; |
| 1489 |
} |
| 1490 |
|
| 1491 |
for (k = 0; k < pcc_rule->num_of_flow; k++) |
| 1492 |
{ |
| 1493 |
if (gx_flow.direction == pcc_rule->flow[k].direction && |
| 1494 |
!strcmp(gx_flow.description, pcc_rule->flow[k].description)) |
| 1495 |
{ |
| 1496 |
matched++; |
| 1497 |
break; |
| 1498 |
} |
| 1499 |
} |
| 1500 |
|
| 1501 |
FLOW_FREE(&gx_flow); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
|
| 1505 |
return matched; |
| 1506 |
} |
| 1507 |
|
| 1508 |
static status_t install_flow( |
| 1509 |
pcc_rule_t *pcc_rule, rx_media_component_t *media_component) |
| 1510 |
{ |
| 1511 |
status_t rv; |
| 1512 |
int i, j; |
| 1513 |
|
| 1514 |
d_assert(pcc_rule, return CORE_ERROR,); |
| 1515 |
d_assert(media_component, return CORE_ERROR,); |
| 1516 |
|
| 1517 |
/* Remove Flow from PCC Rule */ |
| 1518 |
for (i = 0; i < pcc_rule->num_of_flow; i++) |
| 1519 |
{ |
| 1520 |
FLOW_FREE(&pcc_rule->flow[i]); |
| 1521 |
} |
| 1522 |
pcc_rule->num_of_flow = 0; |
| 1523 |
|
| 1524 |
for (i = 0; i < media_component->num_of_sub; i++) |
| 1525 |
{ |
| 1526 |
rx_media_sub_component_t *sub = &media_component->sub[i]; |
| 1527 |
|
| 1528 |
if (sub->flow_number == 0) |
| 1529 |
{ |
| 1530 |
continue; |
| 1531 |
} |
| 1532 |
|
| 1533 |
/* Copy Flow to PCC Rule */ |
| 1534 |
for (j = 0; j < sub->num_of_flow; j++) |
| 1535 |
{ |
| 1536 |
flow_t *rx_flow = &sub->flow[j]; |
| 1537 |
flow_t *gx_flow = &pcc_rule->flow[pcc_rule->num_of_flow]; |
| 1538 |
|
| 1539 |
rv = flow_rx_to_gx(rx_flow, gx_flow); |
| 1540 |
if (rv != CORE_OK) |
| 1541 |
{ |
| 1542 |
d_error("flow reformatting error"); |
| 1543 |
return CORE_ERROR; |
| 1544 |
} |
| 1545 |
|
| 1546 |
pcc_rule->num_of_flow++; |
| 1547 |
} |
| 1548 |
} |
| 1549 |
|
| 1550 |
return CORE_OK; |
| 1551 |
} |
| 1552 |
|
| 1553 |
static status_t update_qos( |
| 1554 |
pcc_rule_t *pcc_rule, rx_media_component_t *media_component) |
| 1555 |
{ |
| 1556 |
status_t rv; |
| 1557 |
int i, j; |
| 1558 |
|
| 1559 |
d_assert(pcc_rule, return CORE_ERROR,); |
| 1560 |
d_assert(media_component, return CORE_ERROR,); |
| 1561 |
|
| 1562 |
pcc_rule->qos.mbr.downlink = 0; |
| 1563 |
pcc_rule->qos.mbr.uplink = 0; |
| 1564 |
pcc_rule->qos.gbr.downlink = 0; |
| 1565 |
pcc_rule->qos.gbr.uplink = 0; |
| 1566 |
|
| 1567 |
for (i = 0; i < media_component->num_of_sub; i++) |
| 1568 |
{ |
| 1569 |
rx_media_sub_component_t *sub = &media_component->sub[i]; |
| 1570 |
|
| 1571 |
if (sub->flow_number == 0) |
| 1572 |
{ |
| 1573 |
continue; |
| 1574 |
} |
| 1575 |
|
| 1576 |
for (j = 0; j < sub->num_of_flow; j++) |
| 1577 |
{ |
| 1578 |
flow_t gx_flow; |
| 1579 |
flow_t *rx_flow = &sub->flow[j]; |
| 1580 |
|
| 1581 |
rv = flow_rx_to_gx(rx_flow, &gx_flow); |
| 1582 |
if (rv != CORE_OK) |
| 1583 |
{ |
| 1584 |
d_error("flow reformatting error"); |
| 1585 |
return CORE_ERROR; |
| 1586 |
} |
| 1587 |
|
| 1588 |
if (gx_flow.direction == FLOW_DOWNLINK_ONLY) |
| 1589 |
{ |
| 1590 |
if (sub->flow_usage == RX_FLOW_USAGE_RTCP) |
| 1591 |
{ |
| 1592 |
if (media_component->rr_bandwidth && |
| 1593 |
media_component->rs_bandwidth) |
| 1594 |
{ |
| 1595 |
pcc_rule->qos.mbr.downlink += |
| 1596 |
(media_component->rr_bandwidth + |
| 1597 |
media_component->rs_bandwidth); |
| 1598 |
} |
| 1599 |
else if (media_component->max_requested_bandwidth_dl) |
| 1600 |
{ |
| 1601 |
if (media_component->rr_bandwidth && |
| 1602 |
!media_component->rs_bandwidth) |
| 1603 |
{ |
| 1604 |
pcc_rule->qos.mbr.downlink += |
| 1605 |
c_max(0.05 * |
| 1606 |
media_component->max_requested_bandwidth_dl, |
| 1607 |
media_component->rr_bandwidth); |
| 1608 |
} |
| 1609 |
if (!media_component->rr_bandwidth && |
| 1610 |
media_component->rs_bandwidth) |
| 1611 |
{ |
| 1612 |
pcc_rule->qos.mbr.downlink += |
| 1613 |
c_max(0.05 * |
| 1614 |
media_component->max_requested_bandwidth_dl, |
| 1615 |
media_component->rs_bandwidth); |
| 1616 |
} |
| 1617 |
if (!media_component->rr_bandwidth && |
| 1618 |
!media_component->rs_bandwidth) |
| 1619 |
{ |
| 1620 |
pcc_rule->qos.mbr.downlink += |
| 1621 |
0.05 * |
| 1622 |
media_component->max_requested_bandwidth_dl; |
| 1623 |
} |
| 1624 |
} |
| 1625 |
} |
| 1626 |
else |
| 1627 |
{ |
| 1628 |
if (gx_flow.description) |
| 1629 |
{ |
| 1630 |
pcc_rule->qos.mbr.downlink += |
| 1631 |
media_component->max_requested_bandwidth_dl; |
| 1632 |
pcc_rule->qos.gbr.downlink += |
| 1633 |
media_component->min_requested_bandwidth_dl; |
| 1634 |
} |
| 1635 |
} |
| 1636 |
} |
| 1637 |
else if (gx_flow.direction == FLOW_UPLINK_ONLY) |
| 1638 |
{ |
| 1639 |
if (sub->flow_usage == RX_FLOW_USAGE_RTCP) |
| 1640 |
{ |
| 1641 |
if (media_component->rr_bandwidth && |
| 1642 |
media_component->rs_bandwidth) |
| 1643 |
{ |
| 1644 |
pcc_rule->qos.mbr.uplink += |
| 1645 |
(media_component->rr_bandwidth + |
| 1646 |
media_component->rs_bandwidth); |
| 1647 |
} |
| 1648 |
else if (media_component->max_requested_bandwidth_ul) |
| 1649 |
{ |
| 1650 |
if (media_component->rr_bandwidth && |
| 1651 |
!media_component->rs_bandwidth) |
| 1652 |
{ |
| 1653 |
pcc_rule->qos.mbr.uplink += |
| 1654 |
c_max(0.05 * |
| 1655 |
media_component->max_requested_bandwidth_ul, |
| 1656 |
media_component->rr_bandwidth); |
| 1657 |
} |
| 1658 |
if (!media_component->rr_bandwidth && |
| 1659 |
media_component->rs_bandwidth) |
| 1660 |
{ |
| 1661 |
pcc_rule->qos.mbr.uplink += |
| 1662 |
c_max(0.05 * |
| 1663 |
media_component->max_requested_bandwidth_ul, |
| 1664 |
media_component->rs_bandwidth); |
| 1665 |
} |
| 1666 |
if (!media_component->rr_bandwidth && |
| 1667 |
!media_component->rs_bandwidth) |
| 1668 |
{ |
| 1669 |
pcc_rule->qos.mbr.uplink += |
| 1670 |
0.05 * |
| 1671 |
media_component->max_requested_bandwidth_ul; |
| 1672 |
} |
| 1673 |
} |
| 1674 |
} |
| 1675 |
else |
| 1676 |
{ |
| 1677 |
if (gx_flow.description) |
| 1678 |
{ |
| 1679 |
pcc_rule->qos.mbr.uplink += |
| 1680 |
media_component->max_requested_bandwidth_ul; |
| 1681 |
pcc_rule->qos.gbr.uplink += |
| 1682 |
media_component->min_requested_bandwidth_ul; |
| 1683 |
} |
| 1684 |
} |
| 1685 |
} |
| 1686 |
else |
| 1687 |
d_assert(0, return CORE_ERROR, |
| 1688 |
"Invalid Direction(%d)", gx_flow.direction); |
| 1689 |
|
| 1690 |
FLOW_FREE(&gx_flow); |
| 1691 |
} |
| 1692 |
} |
| 1693 |
|
| 1694 |
if (pcc_rule->qos.mbr.downlink == 0) |
| 1695 |
{ |
| 1696 |
pcc_rule->qos.mbr.downlink += |
| 1697 |
media_component->max_requested_bandwidth_dl; |
| 1698 |
pcc_rule->qos.mbr.downlink += |
| 1699 |
(media_component->rr_bandwidth + media_component->rs_bandwidth); |
| 1700 |
} |
| 1701 |
|
| 1702 |
if (pcc_rule->qos.mbr.uplink == 0) |
| 1703 |
{ |
| 1704 |
pcc_rule->qos.mbr.uplink += |
| 1705 |
media_component->max_requested_bandwidth_ul; |
| 1706 |
pcc_rule->qos.mbr.uplink += |
| 1707 |
(media_component->rr_bandwidth + media_component->rs_bandwidth); |
| 1708 |
} |
| 1709 |
|
| 1710 |
if (pcc_rule->qos.gbr.downlink == 0) |
| 1711 |
pcc_rule->qos.gbr.downlink = pcc_rule->qos.mbr.downlink; |
| 1712 |
if (pcc_rule->qos.gbr.uplink == 0) |
| 1713 |
pcc_rule->qos.gbr.uplink = pcc_rule->qos.mbr.uplink; |
| 1714 |
|
| 1715 |
return CORE_OK; |
| 1716 |
} |